Skip to content
Permalink
Browse files
Add runJavaScriptInFrame for WebPageProxy/WebPage
https://bugs.webkit.org/show_bug.cgi?id=196750
<rdar://problem/49755738>

Reviewed by Youenn Fablet.

Tests of the new method will be covered by the internal counterpart.

* UIProcess/WebFrameProxy.cpp:
(WebKit::WebFrameProxy::loadData):
* UIProcess/WebFrameProxy.h:
Add a comment.
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::runJavaScriptInMainFrame):
(WebKit::WebPageProxy::runJavaScriptInMainFrameScriptWorld):
Merge the above two runJavaScriptInMainFrame*.
(WebKit::WebPageProxy::runJavaScriptInFrame):
* UIProcess/WebPageProxy.h:
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::loadDataInFrame):
Add an assertion.
(WebKit::WebPage::runJavaScript):
(WebKit::WebPage::runJavaScriptInMainFrameScriptWorld):
(WebKit::WebPage::runJavaScriptInFrame):
(WebKit::WebPage::runJavaScriptInMainFrame): Deleted.
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:


Canonical link: https://commits.webkit.org/211066@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@244148 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
Jiewen Tan committed Apr 10, 2019
1 parent f603adc commit 03413bb969b4259d3b743bca35e35c573fcfed41
Showing 8 changed files with 61 additions and 26 deletions.
@@ -1,3 +1,33 @@
2019-04-10 Jiewen Tan <jiewen_tan@apple.com>

Add runJavaScriptInFrame for WebPageProxy/WebPage
https://bugs.webkit.org/show_bug.cgi?id=196750
<rdar://problem/49755738>

Reviewed by Youenn Fablet.

Tests of the new method will be covered by the internal counterpart.

* UIProcess/WebFrameProxy.cpp:
(WebKit::WebFrameProxy::loadData):
* UIProcess/WebFrameProxy.h:
Add a comment.
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::runJavaScriptInMainFrame):
(WebKit::WebPageProxy::runJavaScriptInMainFrameScriptWorld):
Merge the above two runJavaScriptInMainFrame*.
(WebKit::WebPageProxy::runJavaScriptInFrame):
* UIProcess/WebPageProxy.h:
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::loadDataInFrame):
Add an assertion.
(WebKit::WebPage::runJavaScript):
(WebKit::WebPage::runJavaScriptInMainFrameScriptWorld):
(WebKit::WebPage::runJavaScriptInFrame):
(WebKit::WebPage::runJavaScriptInMainFrame): Deleted.
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:

2019-04-10 Chris Dumez <cdumez@apple.com>

Unable to run system Safari with trunk WebKit
@@ -88,6 +88,7 @@ void WebFrameProxy::loadURL(const URL& url)

void WebFrameProxy::loadData(const IPC::DataReference& data, const String& MIMEType, const String& encodingName, const URL& baseURL)
{
ASSERT(!isMainFrame());
if (!m_page)
return;

@@ -81,6 +81,7 @@ class WebFrameProxy : public API::ObjectImpl<API::Object::Type::Frame> {
FrameLoadState& frameLoadState() { return m_frameLoadState; }

void loadURL(const URL&);
// Sub frames only. For main frames, use WebPageProxy::loadData.
void loadData(const IPC::DataReference&, const String& MIMEType, const String& encodingName, const URL& baseURL);
void stopLoading() const;

@@ -3550,19 +3550,10 @@ void WebPageProxy::launchInitialProcessIfNecessary()

void WebPageProxy::runJavaScriptInMainFrame(const String& script, bool forceUserGesture, WTF::Function<void (API::SerializedScriptValue*, bool hadException, const ExceptionDetails&, CallbackBase::Error)>&& callbackFunction)
{
// For backward-compatibility support running script in a WebView which has not done any loads yets.
launchInitialProcessIfNecessary();

if (!hasRunningProcess()) {
callbackFunction(nullptr, false, { }, CallbackBase::Error::Unknown);
return;
}

auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
m_process->send(Messages::WebPage::RunJavaScriptInMainFrame(script, forceUserGesture, callbackID), m_pageID);
runJavaScriptInMainFrameScriptWorld(script, forceUserGesture, WTF::nullopt, WTFMove(callbackFunction));
}

void WebPageProxy::runJavaScriptInMainFrameScriptWorld(const String& script, bool forceUserGesture, const String& worldName, WTF::Function<void(API::SerializedScriptValue*, bool hadException, const ExceptionDetails&, CallbackBase::Error)>&& callbackFunction)
void WebPageProxy::runJavaScriptInMainFrameScriptWorld(const String& script, bool forceUserGesture, const Optional<String>& worldName, WTF::Function<void(API::SerializedScriptValue*, bool hadException, const ExceptionDetails&, CallbackBase::Error)>&& callbackFunction)
{
// For backward-compatibility support running script in a WebView which has not done any loads yets.
launchInitialProcessIfNecessary();
@@ -3576,6 +3567,13 @@ void WebPageProxy::runJavaScriptInMainFrameScriptWorld(const String& script, boo
m_process->send(Messages::WebPage::RunJavaScriptInMainFrameScriptWorld(script, forceUserGesture, worldName, callbackID), m_pageID);
}

void WebPageProxy::runJavaScriptInFrame(uint64_t frameID, const String& script, bool forceUserGesture, WTF::Function<void(API::SerializedScriptValue*, bool hadException, const ExceptionDetails&, CallbackBase::Error)>&& callbackFunction)
{
ASSERT(mainFrame()->frameID() != frameID);
auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
m_process->send(Messages::WebPage::RunJavaScriptInFrame(frameID, script, forceUserGesture, callbackID), m_pageID);
}

void WebPageProxy::getRenderTreeExternalRepresentation(WTF::Function<void (const String&, CallbackBase::Error)>&& callbackFunction)
{
if (!hasRunningProcess()) {
@@ -1001,7 +1001,9 @@ class WebPageProxy : public API::ObjectImpl<API::Object::Type::Page>
void getSourceForFrame(WebFrameProxy*, WTF::Function<void (const String&, CallbackBase::Error)>&&);
void getWebArchiveOfFrame(WebFrameProxy*, Function<void (API::Data*, CallbackBase::Error)>&&);
void runJavaScriptInMainFrame(const String&, bool, WTF::Function<void (API::SerializedScriptValue*, bool hadException, const WebCore::ExceptionDetails&, CallbackBase::Error)>&& callbackFunction);
void runJavaScriptInMainFrameScriptWorld(const String&, bool, const String& worldName, WTF::Function<void(API::SerializedScriptValue*, bool hadException, const WebCore::ExceptionDetails&, CallbackBase::Error)>&& callbackFunction);
void runJavaScriptInMainFrameScriptWorld(const String&, bool, const Optional<String>& worldName, WTF::Function<void(API::SerializedScriptValue*, bool hadException, const WebCore::ExceptionDetails&, CallbackBase::Error)>&& callbackFunction);
// For sub frames.
void runJavaScriptInFrame(uint64_t frameID, const String& script, bool forceUserGesture, WTF::Function<void(API::SerializedScriptValue*, bool hadException, const WebCore::ExceptionDetails&, CallbackBase::Error)>&& callbackFunction);
void forceRepaint(RefPtr<VoidCallback>&&);

float headerHeight(WebFrameProxy&);
@@ -1438,6 +1438,7 @@ void WebPage::loadDataInFrame(IPC::DataReference&& data, String&& MIMEType, Stri
WebFrame* frame = WebProcess::singleton().webFrame(frameID);
if (!frame)
return;
ASSERT(mainWebFrame() != frame);

auto sharedBuffer = SharedBuffer::create(reinterpret_cast<const char*>(data.data()), data.size());
ResourceResponse response(baseURL, MIMEType, sharedBuffer->size(), encodingName);
@@ -3286,7 +3287,7 @@ KeyboardUIMode WebPage::keyboardUIMode()
return static_cast<KeyboardUIMode>((fullKeyboardAccessEnabled ? KeyboardAccessFull : KeyboardAccessDefault) | (m_tabToLinks ? KeyboardAccessTabsToLinks : 0));
}

void WebPage::runJavaScript(const String& script, bool forceUserGesture, Optional<String> worldName, CallbackID callbackID)
void WebPage::runJavaScript(WebFrame* frame, const String& script, bool forceUserGesture, const Optional<String>& worldName, CallbackID callbackID)
{
// NOTE: We need to be careful when running scripts that the objects we depend on don't
// disappear during script execution.
@@ -3296,11 +3297,11 @@ void WebPage::runJavaScript(const String& script, bool forceUserGesture, Optiona
bool hadException = true;
ExceptionDetails details;
auto* world = worldName ? InjectedBundleScriptWorld::find(worldName.value()) : &InjectedBundleScriptWorld::normalWorld();
if (world) {
if (JSValue resultValue = m_mainFrame->coreFrame()->script().executeUserAgentScriptInWorld(world->coreWorld(), script, forceUserGesture, &details)) {
if (frame && frame->coreFrame() && world) {
if (JSValue resultValue = frame->coreFrame()->script().executeUserAgentScriptInWorld(world->coreWorld(), script, forceUserGesture, &details)) {
hadException = false;
serializedResultValue = SerializedScriptValue::create(m_mainFrame->jsContextForWorld(world),
toRef(m_mainFrame->coreFrame()->script().globalObject(world->coreWorld())->globalExec(), resultValue), nullptr);
serializedResultValue = SerializedScriptValue::create(frame->jsContextForWorld(world),
toRef(frame->coreFrame()->script().globalObject(world->coreWorld())->globalExec(), resultValue), nullptr);
}
}

@@ -3310,14 +3311,16 @@ void WebPage::runJavaScript(const String& script, bool forceUserGesture, Optiona
send(Messages::WebPageProxy::ScriptValueCallback(dataReference, hadException, details, callbackID));
}

void WebPage::runJavaScriptInMainFrame(const String& script, bool forceUserGesture, CallbackID callbackID)
void WebPage::runJavaScriptInMainFrameScriptWorld(const String& script, bool forceUserGesture, const Optional<String>& worldName, CallbackID callbackID)
{
runJavaScript(script, forceUserGesture, WTF::nullopt, callbackID);
runJavaScript(mainWebFrame(), script, forceUserGesture, worldName, callbackID);
}

void WebPage::runJavaScriptInMainFrameScriptWorld(const String& script, bool forceUserGesture, const String& worldName, CallbackID callbackID)
void WebPage::runJavaScriptInFrame(uint64_t frameID, const String& script, bool forceUserGesture, CallbackID callbackID)
{
runJavaScript(script, forceUserGesture, worldName, callbackID);
WebFrame* frame = WebProcess::singleton().webFrame(frameID);
ASSERT(mainWebFrame() != frame);
runJavaScript(frame, script, forceUserGesture, WTF::nullopt, callbackID);
}

void WebPage::getContentsAsString(CallbackID callbackID)
@@ -1345,9 +1345,9 @@ class WebPage : public API::ObjectImpl<API::Object::Type::BundlePage>, public IP
void getSelectionAsWebArchiveData(CallbackID);
void getSourceForFrame(uint64_t frameID, CallbackID);
void getWebArchiveOfFrame(uint64_t frameID, CallbackID);
void runJavaScript(const String&, bool forceUserGesture, Optional<String> worldName, CallbackID);
void runJavaScriptInMainFrame(const String&, bool forceUserGesture, CallbackID);
void runJavaScriptInMainFrameScriptWorld(const String&, bool forceUserGesture, const String& worldName, CallbackID);
void runJavaScript(WebFrame*, const String&, bool forceUserGesture, const Optional<String>& worldName, CallbackID);
void runJavaScriptInMainFrameScriptWorld(const String&, bool forceUserGesture, const Optional<String>& worldName, CallbackID);
void runJavaScriptInFrame(uint64_t frameID, const String&, bool forceUserGesture, CallbackID);
void forceRepaint(CallbackID);
void takeSnapshot(WebCore::IntRect snapshotRect, WebCore::IntSize bitmapSize, uint32_t options, CallbackID);

@@ -197,8 +197,8 @@ messages -> WebPage LegacyReceiver {
GetSelectionAsWebArchiveData(WebKit::CallbackID callbackID)
GetSourceForFrame(uint64_t frameID, WebKit::CallbackID callbackID)
GetWebArchiveOfFrame(uint64_t frameID, WebKit::CallbackID callbackID)
RunJavaScriptInMainFrame(String script, bool forceUserGesture, WebKit::CallbackID callbackID)
RunJavaScriptInMainFrameScriptWorld(String script, bool forceUserGesture, String worldName, WebKit::CallbackID callbackID)
RunJavaScriptInMainFrameScriptWorld(String script, bool forceUserGesture, Optional<String> worldName, WebKit::CallbackID callbackID)
RunJavaScriptInFrame(uint64_t frameID, String script, bool forceUserGesture, WebKit::CallbackID callbackID)
ForceRepaint(WebKit::CallbackID callbackID)

#if PLATFORM(COCOA)

0 comments on commit 03413bb

Please sign in to comment.