Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
More UserData work
https://bugs.webkit.org/show_bug.cgi?id=125524

Reviewed by Dan Bernstein.

* Shared/APIObject.h:
* Shared/UserData.cpp:
(WebKit::UserData::transform):
New helper function that takes an API::Object and returns a new API::Object with all "sub-objects" (arrays etc)
transformed by calling the transformer.

* Shared/UserData.h:
(WebKit::UserData::object):
New getter.

* UIProcess/WebProcessProxy.cpp:
(WebKit::WebProcessProxy::apiObjectByConvertingToHandles):
Helper function that creates a new API::Object graph by converting WebFrameProxy objects to FrameHandles.

* WebProcess/WebProcess.cpp:
(WebKit::WebProcess::apiObjectByConvertingFromHandles):
Helper function that creates a new API::Object graph by converting FrameHandles to WebFrame objects.

Canonical link: https://commits.webkit.org/143584@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@160378 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
Anders Carlsson committed Dec 10, 2013
1 parent 26fe22b commit e285ca8
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Source/WebKit2/ChangeLog
@@ -1,3 +1,28 @@
2013-12-10 Anders Carlsson <andersca@apple.com>

More UserData work
https://bugs.webkit.org/show_bug.cgi?id=125524

Reviewed by Dan Bernstein.

* Shared/APIObject.h:
* Shared/UserData.cpp:
(WebKit::UserData::transform):
New helper function that takes an API::Object and returns a new API::Object with all "sub-objects" (arrays etc)
transformed by calling the transformer.

* Shared/UserData.h:
(WebKit::UserData::object):
New getter.

* UIProcess/WebProcessProxy.cpp:
(WebKit::WebProcessProxy::apiObjectByConvertingToHandles):
Helper function that creates a new API::Object graph by converting WebFrameProxy objects to FrameHandles.

* WebProcess/WebProcess.cpp:
(WebKit::WebProcess::apiObjectByConvertingFromHandles):
Helper function that creates a new API::Object graph by converting FrameHandles to WebFrame objects.

2013-12-10 Alberto Garcia <berto@igalia.com>

[WK2] [SOUP] Allow running the network process with an arbitrary prefix command
Expand Down
2 changes: 2 additions & 0 deletions Source/WebKit2/Shared/APIObject.h
Expand Up @@ -26,7 +26,9 @@
#ifndef APIObject_h
#define APIObject_h

#include <functional>
#include <wtf/RefCounted.h>
#include <wtf/RefPtr.h>

#if PLATFORM(MAC)
#include "WKFoundation.h"
Expand Down
22 changes: 22 additions & 0 deletions Source/WebKit2/Shared/UserData.cpp
Expand Up @@ -44,6 +44,28 @@ UserData::~UserData()
{
}

RefPtr<API::Object> UserData::transform(API::Object* object, const std::function<RefPtr<API::Object> (const API::Object&)> transformer)
{
if (!object)
return nullptr;

if (object->type() == API::Object::Type::Array) {
auto& array = static_cast<API::Array&>(*object);

Vector<RefPtr<API::Object>> elements;
elements.reserveInitialCapacity(array.elements().size());
for (const auto& element : array.elements())
elements.uncheckedAppend(transform(element.get(), transformer));

return API::Array::create(std::move(elements));
}

if (auto transformedObject = transformer(*object))
return transformedObject;

return object;
}

void UserData::encode(CoreIPC::ArgumentEncoder& encoder) const
{
encode(encoder, m_object.get());
Expand Down
4 changes: 4 additions & 0 deletions Source/WebKit2/Shared/UserData.h
Expand Up @@ -45,6 +45,10 @@ class UserData {
explicit UserData(API::Object* = nullptr);
~UserData();

static RefPtr<API::Object> transform(API::Object*, const std::function<RefPtr<API::Object> (const API::Object&)> transformer);

API::Object* object() const { return m_object.get(); }

void encode(CoreIPC::ArgumentEncoder&) const;
static bool decode(CoreIPC::ArgumentDecoder&, UserData&);

Expand Down
17 changes: 17 additions & 0 deletions Source/WebKit2/UIProcess/WebProcessProxy.cpp
Expand Up @@ -26,13 +26,15 @@
#include "config.h"
#include "WebProcessProxy.h"

#include "APIFrameHandle.h"
#include "CustomProtocolManagerProxyMessages.h"
#include "DataReference.h"
#include "DownloadProxyMap.h"
#include "PluginInfoStore.h"
#include "PluginProcessManager.h"
#include "TextChecker.h"
#include "TextCheckerState.h"
#include "UserData.h"
#include "WebBackForwardListItem.h"
#include "WebContext.h"
#include "WebNavigationDataStore.h"
Expand Down Expand Up @@ -685,4 +687,19 @@ void WebProcessProxy::disableSuddenTermination()
WebCore::disableSuddenTermination();
}

RefPtr<API::Object> WebProcessProxy::apiObjectByConvertingToHandles(API::Object* object)
{
return UserData::transform(object, [](const API::Object& object) -> RefPtr<API::Object> {
switch (object.type()) {
case API::Object::Type::Frame: {
auto& frame = static_cast<const WebFrameProxy&>(object);
return API::FrameHandle::create(frame.frameID());
}

default:
return nullptr;
}
});
}

} // namespace WebKit
2 changes: 2 additions & 0 deletions Source/WebKit2/UIProcess/WebProcessProxy.h
Expand Up @@ -126,6 +126,8 @@ class WebProcessProxy : public ChildProcessProxy, ResponsivenessTimer::Client {

void requestTermination();

RefPtr<API::Object> apiObjectByConvertingToHandles(API::Object*);

private:
explicit WebProcessProxy(WebContext&);

Expand Down
18 changes: 18 additions & 0 deletions Source/WebKit2/WebProcess/WebProcess.cpp
Expand Up @@ -26,13 +26,15 @@
#include "config.h"
#include "WebProcess.h"

#include "APIFrameHandle.h"
#include "AuthenticationManager.h"
#include "EventDispatcher.h"
#include "InjectedBundle.h"
#include "InjectedBundleUserMessageCoders.h"
#include "Logging.h"
#include "PluginProcessConnectionManager.h"
#include "StatisticsData.h"
#include "UserData.h"
#include "WebApplicationCacheManager.h"
#include "WebConnectionToUIProcess.h"
#include "WebContextMessages.h"
Expand Down Expand Up @@ -1184,4 +1186,20 @@ void WebProcess::nonVisibleProcessCleanupTimerFired(Timer<WebProcess>*)
#endif
}

RefPtr<API::Object> WebProcess::apiObjectByConvertingFromHandles(API::Object* object)
{
return UserData::transform(object, [this](const API::Object& object) -> RefPtr<API::Object> {
switch (object.type()) {
case API::Object::Type::FrameHandle: {
auto& frameHandle = static_cast<const API::FrameHandle&>(object);

return webFrame(frameHandle.frameID());
}

default:
return nullptr;
}
});
}

} // namespace WebKit
6 changes: 6 additions & 0 deletions Source/WebKit2/WebProcess/WebProcess.h
Expand Up @@ -47,6 +47,10 @@
#include <dispatch/dispatch.h>
#endif

namespace API {
class Object;
}

namespace WebCore {
class PageGroup;
class ResourceRequest;
Expand Down Expand Up @@ -181,6 +185,8 @@ class WebProcess : public ChildProcess, private DownloadManager::Client {
void resetAllGeolocationPermissions();
#endif // PLATFORM(IOS)

RefPtr<API::Object> apiObjectByConvertingFromHandles(API::Object*);

private:
WebProcess();

Expand Down

0 comments on commit e285ca8

Please sign in to comment.