summaryrefslogtreecommitdiff
path: root/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebPage.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebPage.cpp')
-rw-r--r--Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebPage.cpp351
1 files changed, 304 insertions, 47 deletions
diff --git a/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebPage.cpp b/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebPage.cpp
index 272c9ed2f..37da10e7b 100644
--- a/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebPage.cpp
+++ b/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebPage.cpp
@@ -20,28 +20,38 @@
#include "config.h"
#include "WebKitWebPage.h"
+#include "APIArray.h"
+#include "APIDictionary.h"
#include "ImageOptions.h"
-#include "ImmutableDictionary.h"
#include "InjectedBundle.h"
#include "WKBundleAPICast.h"
#include "WKBundleFrame.h"
+#include "WebContextMenuItem.h"
#include "WebImage.h"
+#include "WebKitConsoleMessagePrivate.h"
+#include "WebKitContextMenuPrivate.h"
#include "WebKitDOMDocumentPrivate.h"
+#include "WebKitDOMElementPrivate.h"
#include "WebKitFramePrivate.h"
#include "WebKitMarshal.h"
#include "WebKitPrivate.h"
#include "WebKitScriptWorldPrivate.h"
#include "WebKitURIRequestPrivate.h"
#include "WebKitURIResponsePrivate.h"
+#include "WebKitWebEditorPrivate.h"
+#include "WebKitWebHitTestResultPrivate.h"
#include "WebKitWebPagePrivate.h"
#include "WebProcess.h"
#include <WebCore/Document.h>
#include <WebCore/DocumentLoader.h>
#include <WebCore/Frame.h>
+#include <WebCore/FrameDestructionObserver.h>
#include <WebCore/FrameView.h>
+#include <WebCore/MainFrame.h>
#include <glib/gi18n-lib.h>
#include <wtf/NeverDestroyed.h>
#include <wtf/text/CString.h>
+#include <wtf/text/StringBuilder.h>
using namespace WebKit;
using namespace WebCore;
@@ -49,6 +59,9 @@ using namespace WebCore;
enum {
DOCUMENT_LOADED,
SEND_REQUEST,
+ CONTEXT_MENU,
+ CONSOLE_MESSAGE_SENT,
+ FORM_CONTROLS_ASSOCIATED,
LAST_SIGNAL
};
@@ -63,13 +76,37 @@ struct _WebKitWebPagePrivate {
WebPage* webPage;
CString uri;
+
+ GRefPtr<WebKitWebEditor> webEditor;
};
static guint signals[LAST_SIGNAL] = { 0, };
WEBKIT_DEFINE_TYPE(WebKitWebPage, webkit_web_page, G_TYPE_OBJECT)
-typedef HashMap<WebFrame*, GRefPtr<WebKitFrame>> WebFrameMap;
+static void webFrameDestroyed(WebFrame*);
+
+class WebKitFrameWrapper final: public FrameDestructionObserver {
+public:
+ WebKitFrameWrapper(WebFrame& webFrame)
+ : FrameDestructionObserver(webFrame.coreFrame())
+ , m_webkitFrame(adoptGRef(webkitFrameCreate(&webFrame)))
+ {
+ }
+
+ WebKitFrame* webkitFrame() const { return m_webkitFrame.get(); }
+
+private:
+ void frameDestroyed() override
+ {
+ FrameDestructionObserver::frameDestroyed();
+ webFrameDestroyed(webkitFrameGetWebFrame(m_webkitFrame.get()));
+ }
+
+ GRefPtr<WebKitFrame> m_webkitFrame;
+};
+
+typedef HashMap<WebFrame*, std::unique_ptr<WebKitFrameWrapper>> WebFrameMap;
static WebFrameMap& webFrameMap()
{
@@ -79,19 +116,24 @@ static WebFrameMap& webFrameMap()
static WebKitFrame* webkitFrameGetOrCreate(WebFrame* webFrame)
{
- GRefPtr<WebKitFrame> frame = webFrameMap().get(webFrame);
- if (frame)
- return frame.get();
-
- frame = adoptGRef(webkitFrameCreate(webFrame));
- webFrameMap().set(webFrame, frame);
+ auto wrapperPtr = webFrameMap().get(webFrame);
+ if (wrapperPtr)
+ return wrapperPtr->webkitFrame();
+
+ std::unique_ptr<WebKitFrameWrapper> wrapper = std::make_unique<WebKitFrameWrapper>(*webFrame);
+ wrapperPtr = wrapper.get();
+ webFrameMap().set(webFrame, WTFMove(wrapper));
+ return wrapperPtr->webkitFrame();
+}
- return frame.get();
+static void webFrameDestroyed(WebFrame* webFrame)
+{
+ webFrameMap().remove(webFrame);
}
-static CString getProvisionalURLForFrame(WebFrame* webFrame)
+static CString getDocumentLoaderURL(DocumentLoader* documentLoader)
{
- DocumentLoader* documentLoader = webFrame->coreFrame()->loader().provisionalDocumentLoader();
+ ASSERT(documentLoader);
if (!documentLoader->unreachableURL().isEmpty())
return documentLoader->unreachableURL().string().utf8();
@@ -107,23 +149,29 @@ static void webkitWebPageSetURI(WebKitWebPage* webPage, const CString& uri)
g_object_notify(G_OBJECT(webPage), "uri");
}
+static void webkitWebPageDidSendConsoleMessage(WebKitWebPage* webPage, MessageSource source, MessageLevel level, const String& message, unsigned lineNumber, const String& sourceID)
+{
+ WebKitConsoleMessage consoleMessage(source, level, message, lineNumber, sourceID);
+ g_signal_emit(webPage, signals[CONSOLE_MESSAGE_SENT], 0, &consoleMessage);
+}
+
static void didStartProvisionalLoadForFrame(WKBundlePageRef, WKBundleFrameRef frame, WKTypeRef*, const void *clientInfo)
{
if (!WKBundleFrameIsMainFrame(frame))
return;
- webkitWebPageSetURI(WEBKIT_WEB_PAGE(clientInfo), getProvisionalURLForFrame(toImpl(frame)));
+ webkitWebPageSetURI(WEBKIT_WEB_PAGE(clientInfo), getDocumentLoaderURL(toImpl(frame)->coreFrame()->loader().provisionalDocumentLoader()));
}
-static void didReceiveServerRedirectForProvisionalLoadForFrame(WKBundlePageRef page, WKBundleFrameRef frame, WKTypeRef* userData, const void *clientInfo)
+static void didReceiveServerRedirectForProvisionalLoadForFrame(WKBundlePageRef, WKBundleFrameRef frame, WKTypeRef* /* userData */, const void *clientInfo)
{
if (!WKBundleFrameIsMainFrame(frame))
return;
- webkitWebPageSetURI(WEBKIT_WEB_PAGE(clientInfo), getProvisionalURLForFrame(toImpl(frame)));
+ webkitWebPageSetURI(WEBKIT_WEB_PAGE(clientInfo), getDocumentLoaderURL(toImpl(frame)->coreFrame()->loader().provisionalDocumentLoader()));
}
-static void didSameDocumentNavigationForFrame(WKBundlePageRef page, WKBundleFrameRef frame, WKSameDocumentNavigationType type, WKTypeRef* userData, const void *clientInfo)
+static void didSameDocumentNavigationForFrame(WKBundlePageRef, WKBundleFrameRef frame, WKSameDocumentNavigationType, WKTypeRef* /* userData */, const void *clientInfo)
{
if (!WKBundleFrameIsMainFrame(frame))
return;
@@ -131,17 +179,20 @@ static void didSameDocumentNavigationForFrame(WKBundlePageRef page, WKBundleFram
webkitWebPageSetURI(WEBKIT_WEB_PAGE(clientInfo), toImpl(frame)->coreFrame()->document()->url().string().utf8());
}
-static void didFinishDocumentLoadForFrame(WKBundlePageRef, WKBundleFrameRef frame, WKTypeRef*, const void *clientInfo)
+static void didCommitLoadForFrame(WKBundlePageRef, WKBundleFrameRef frame, WKTypeRef* /* userData */, const void* clientInfo)
{
if (!WKBundleFrameIsMainFrame(frame))
return;
- g_signal_emit(WEBKIT_WEB_PAGE(clientInfo), signals[DOCUMENT_LOADED], 0);
+ webkitWebPageSetURI(WEBKIT_WEB_PAGE(clientInfo), getDocumentLoaderURL(toImpl(frame)->coreFrame()->loader().documentLoader()));
}
-static void willDestroyFrame(WKBundlePageRef, WKBundleFrameRef frame, const void *clientInfo)
+static void didFinishDocumentLoadForFrame(WKBundlePageRef, WKBundleFrameRef frame, WKTypeRef*, const void *clientInfo)
{
- webFrameMap().remove(toImpl(frame));
+ if (!WKBundleFrameIsMainFrame(frame))
+ return;
+
+ g_signal_emit(WEBKIT_WEB_PAGE(clientInfo), signals[DOCUMENT_LOADED], 0);
}
static void didClearWindowObjectForFrame(WKBundlePageRef, WKBundleFrameRef frame, WKBundleScriptWorldRef wkWorld, const void* clientInfo)
@@ -150,14 +201,14 @@ static void didClearWindowObjectForFrame(WKBundlePageRef, WKBundleFrameRef frame
webkitScriptWorldWindowObjectCleared(world, WEBKIT_WEB_PAGE(clientInfo), webkitFrameGetOrCreate(toImpl(frame)));
}
-static void didInitiateLoadForResource(WKBundlePageRef page, WKBundleFrameRef frame, uint64_t identifier, WKURLRequestRef request, bool pageLoadIsProvisional, const void*)
+static void didInitiateLoadForResource(WKBundlePageRef page, WKBundleFrameRef frame, uint64_t identifier, WKURLRequestRef request, bool /* pageLoadIsProvisional */, const void*)
{
- ImmutableDictionary::MapType message;
+ API::Dictionary::MapType message;
message.set(String::fromUTF8("Page"), toImpl(page));
message.set(String::fromUTF8("Frame"), toImpl(frame));
message.set(String::fromUTF8("Identifier"), API::UInt64::create(identifier));
message.set(String::fromUTF8("Request"), toImpl(request));
- WebProcess::shared().injectedBundle()->postMessage(String::fromUTF8("WebPage.DidInitiateLoadForResource"), ImmutableDictionary::create(std::move(message)).get());
+ WebProcess::singleton().injectedBundle()->postMessage(String::fromUTF8("WebPage.DidInitiateLoadForResource"), API::Dictionary::create(WTFMove(message)).ptr());
}
static WKURLRequestRef willSendRequestForFrame(WKBundlePageRef page, WKBundleFrameRef, uint64_t identifier, WKURLRequestRef wkRequest, WKURLResponseRef wkRedirectResponse, const void* clientInfo)
@@ -174,54 +225,145 @@ static WKURLRequestRef willSendRequestForFrame(WKBundlePageRef page, WKBundleFra
ResourceRequest resourceRequest;
webkitURIRequestGetResourceRequest(request.get(), resourceRequest);
resourceRequest.setInitiatingPageID(toImpl(page)->pageID());
- RefPtr<API::URLRequest> newRequest = API::URLRequest::create(resourceRequest);
+ Ref<API::URLRequest> newRequest = API::URLRequest::create(resourceRequest);
- ImmutableDictionary::MapType message;
+ API::Dictionary::MapType message;
message.set(String::fromUTF8("Page"), toImpl(page));
message.set(String::fromUTF8("Identifier"), API::UInt64::create(identifier));
- message.set(String::fromUTF8("Request"), newRequest.get());
+ message.set(String::fromUTF8("Request"), newRequest.ptr());
if (!redirectResourceResponse.isNull())
message.set(String::fromUTF8("RedirectResponse"), toImpl(wkRedirectResponse));
- WebProcess::shared().injectedBundle()->postMessage(String::fromUTF8("WebPage.DidSendRequestForResource"), ImmutableDictionary::create(std::move(message)).get());
+ WebProcess::singleton().injectedBundle()->postMessage(String::fromUTF8("WebPage.DidSendRequestForResource"), API::Dictionary::create(WTFMove(message)).ptr());
- return toAPI(newRequest.release().leakRef());
+ return toAPI(&newRequest.leakRef());
}
-static void didReceiveResponseForResource(WKBundlePageRef page, WKBundleFrameRef, uint64_t identifier, WKURLResponseRef response, const void*)
+static void didReceiveResponseForResource(WKBundlePageRef page, WKBundleFrameRef, uint64_t identifier, WKURLResponseRef response, const void* clientInfo)
{
- ImmutableDictionary::MapType message;
+ API::Dictionary::MapType message;
message.set(String::fromUTF8("Page"), toImpl(page));
message.set(String::fromUTF8("Identifier"), API::UInt64::create(identifier));
message.set(String::fromUTF8("Response"), toImpl(response));
- WebProcess::shared().injectedBundle()->postMessage(String::fromUTF8("WebPage.DidReceiveResponseForResource"), ImmutableDictionary::create(std::move(message)).get());
+ WebProcess::singleton().injectedBundle()->postMessage(String::fromUTF8("WebPage.DidReceiveResponseForResource"), API::Dictionary::create(WTFMove(message)).ptr());
+
+ // Post on the console as well to be consistent with the inspector.
+ const ResourceResponse& resourceResponse = toImpl(response)->resourceResponse();
+ if (resourceResponse.httpStatusCode() >= 400) {
+ StringBuilder errorMessage;
+ errorMessage.appendLiteral("Failed to load resource: the server responded with a status of ");
+ errorMessage.appendNumber(resourceResponse.httpStatusCode());
+ errorMessage.appendLiteral(" (");
+ errorMessage.append(resourceResponse.httpStatusText());
+ errorMessage.append(')');
+ webkitWebPageDidSendConsoleMessage(WEBKIT_WEB_PAGE(clientInfo), MessageSource::Network, MessageLevel::Error, errorMessage.toString(), 0, resourceResponse.url().string());
+ }
}
static void didReceiveContentLengthForResource(WKBundlePageRef page, WKBundleFrameRef, uint64_t identifier, uint64_t length, const void*)
{
- ImmutableDictionary::MapType message;
+ API::Dictionary::MapType message;
message.set(String::fromUTF8("Page"), toImpl(page));
message.set(String::fromUTF8("Identifier"), API::UInt64::create(identifier));
message.set(String::fromUTF8("ContentLength"), API::UInt64::create(length));
- WebProcess::shared().injectedBundle()->postMessage(String::fromUTF8("WebPage.DidReceiveContentLengthForResource"), ImmutableDictionary::create(std::move(message)).get());
+ WebProcess::singleton().injectedBundle()->postMessage(String::fromUTF8("WebPage.DidReceiveContentLengthForResource"), API::Dictionary::create(WTFMove(message)).ptr());
}
static void didFinishLoadForResource(WKBundlePageRef page, WKBundleFrameRef, uint64_t identifier, const void*)
{
- ImmutableDictionary::MapType message;
+ API::Dictionary::MapType message;
message.set(String::fromUTF8("Page"), toImpl(page));
message.set(String::fromUTF8("Identifier"), API::UInt64::create(identifier));
- WebProcess::shared().injectedBundle()->postMessage(String::fromUTF8("WebPage.DidFinishLoadForResource"), ImmutableDictionary::create(std::move(message)).get());
+ WebProcess::singleton().injectedBundle()->postMessage(String::fromUTF8("WebPage.DidFinishLoadForResource"), API::Dictionary::create(WTFMove(message)).ptr());
}
-static void didFailLoadForResource(WKBundlePageRef page, WKBundleFrameRef, uint64_t identifier, WKErrorRef error, const void*)
+static void didFailLoadForResource(WKBundlePageRef page, WKBundleFrameRef, uint64_t identifier, WKErrorRef error, const void* clientInfo)
{
- ImmutableDictionary::MapType message;
+ API::Dictionary::MapType message;
message.set(String::fromUTF8("Page"), toImpl(page));
message.set(String::fromUTF8("Identifier"), API::UInt64::create(identifier));
message.set(String::fromUTF8("Error"), toImpl(error));
- WebProcess::shared().injectedBundle()->postMessage(String::fromUTF8("WebPage.DidFailLoadForResource"), ImmutableDictionary::create(std::move(message)).get());
+ WebProcess::singleton().injectedBundle()->postMessage(String::fromUTF8("WebPage.DidFailLoadForResource"), API::Dictionary::create(WTFMove(message)).ptr());
+
+ // Post on the console as well to be consistent with the inspector.
+ const ResourceError& resourceError = toImpl(error)->platformError();
+ if (!resourceError.isCancellation()) {
+ StringBuilder errorMessage;
+ errorMessage.appendLiteral("Failed to load resource");
+ if (!resourceError.localizedDescription().isEmpty()) {
+ errorMessage.appendLiteral(": ");
+ errorMessage.append(resourceError.localizedDescription());
+ }
+ webkitWebPageDidSendConsoleMessage(WEBKIT_WEB_PAGE(clientInfo), MessageSource::Network, MessageLevel::Error, errorMessage.toString(), 0, resourceError.failingURL());
+ }
}
+class PageContextMenuClient final : public API::InjectedBundle::PageContextMenuClient {
+public:
+ explicit PageContextMenuClient(WebKitWebPage* webPage)
+ : m_webPage(webPage)
+ {
+ }
+
+private:
+ bool getCustomMenuFromDefaultItems(WebPage&, const WebCore::HitTestResult& hitTestResult, const Vector<WebCore::ContextMenuItem>& defaultMenu, Vector<WebContextMenuItemData>& newMenu, RefPtr<API::Object>& userData) override
+ {
+ GRefPtr<WebKitContextMenu> contextMenu = adoptGRef(webkitContextMenuCreate(kitItems(defaultMenu)));
+ GRefPtr<WebKitWebHitTestResult> webHitTestResult = adoptGRef(webkitWebHitTestResultCreate(hitTestResult));
+ gboolean returnValue;
+ g_signal_emit(m_webPage, signals[CONTEXT_MENU], 0, contextMenu.get(), webHitTestResult.get(), &returnValue);
+ if (GVariant* variant = webkit_context_menu_get_user_data(contextMenu.get())) {
+ GUniquePtr<gchar> dataString(g_variant_print(variant, TRUE));
+ userData = API::String::create(String::fromUTF8(dataString.get()));
+ }
+
+ if (!returnValue)
+ return false;
+
+ webkitContextMenuPopulate(contextMenu.get(), newMenu);
+ return true;
+ }
+
+ WebKitWebPage* m_webPage;
+};
+
+class PageUIClient final : public API::InjectedBundle::PageUIClient {
+public:
+ explicit PageUIClient(WebKitWebPage* webPage)
+ : m_webPage(webPage)
+ {
+ }
+
+private:
+ void willAddMessageToConsole(WebPage*, MessageSource source, MessageLevel level, const String& message, unsigned lineNumber, unsigned /*columnNumber*/, const String& sourceID) override
+ {
+ webkitWebPageDidSendConsoleMessage(m_webPage, source, level, message, lineNumber, sourceID);
+ }
+
+ WebKitWebPage* m_webPage;
+};
+
+class FormClient final : public API::InjectedBundle::FormClient {
+public:
+ explicit FormClient(WebKitWebPage* webPage)
+ : m_webPage(webPage)
+ {
+ }
+
+ void didAssociateFormControls(WebPage*, const Vector<RefPtr<Element>>& elements) override
+ {
+ GRefPtr<GPtrArray> formElements = adoptGRef(g_ptr_array_sized_new(elements.size()));
+ for (size_t i = 0; i < elements.size(); ++i)
+ g_ptr_array_add(formElements.get(), WebKit::kit(elements[i].get()));
+
+ g_signal_emit(m_webPage, signals[FORM_CONTROLS_ASSOCIATED], 0, formElements.get());
+ }
+
+ bool shouldNotifyOnFormChanges(WebPage*) override { return true; }
+
+private:
+ WebKitWebPage* m_webPage;
+};
+
static void webkitWebPageGetProperty(GObject* object, guint propId, GValue* value, GParamSpec* paramSpec)
{
WebKitWebPage* webPage = WEBKIT_WEB_PAGE(object);
@@ -304,6 +446,89 @@ static void webkit_web_page_class_init(WebKitWebPageClass* klass)
G_TYPE_BOOLEAN, 2,
WEBKIT_TYPE_URI_REQUEST,
WEBKIT_TYPE_URI_RESPONSE);
+
+ /**
+ * WebKitWebPage::context-menu:
+ * @web_page: the #WebKitWebPage on which the signal is emitted
+ * @context_menu: the proposed #WebKitContextMenu
+ * @hit_test_result: a #WebKitWebHitTestResult
+ *
+ * Emmited before a context menu is displayed in the UI Process to
+ * give the application a chance to customize the proposed menu,
+ * build its own context menu or pass user data to the UI Process.
+ * This signal is useful when the information available in the UI Process
+ * is not enough to build or customize the context menu, for example, to
+ * add menu entries depending on the #WebKitDOMNode at the coordinates of the
+ * @hit_test_result. Otherwise, it's recommened to use #WebKitWebView::context-menu
+ * signal instead.
+ *
+ * Returns: %TRUE if the proposed @context_menu has been modified, or %FALSE otherwise.
+ *
+ * Since: 2.8
+ */
+ signals[CONTEXT_MENU] = g_signal_new(
+ "context-menu",
+ G_TYPE_FROM_CLASS(klass),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ g_signal_accumulator_true_handled, 0,
+ webkit_marshal_BOOLEAN__OBJECT_OBJECT,
+ G_TYPE_BOOLEAN, 2,
+ WEBKIT_TYPE_CONTEXT_MENU,
+ WEBKIT_TYPE_WEB_HIT_TEST_RESULT);
+
+ /**
+ * WebKitWebPage::console-message-sent:
+ * @web_page: the #WebKitWebPage on which the signal is emitted
+ * @console_message: the #WebKitConsoleMessage
+ *
+ * Emmited when a message is sent to the console. This can be a message
+ * produced by the use of JavaScript console API, a javascript exception,
+ * a security error or other errors, warnings, debug or log messages.
+ * The @console_message contains information of the message.
+ *
+ * Since: 2.12
+ */
+ signals[CONSOLE_MESSAGE_SENT] = g_signal_new(
+ "console-message-sent",
+ G_TYPE_FROM_CLASS(klass),
+ G_SIGNAL_RUN_LAST,
+ 0, 0, nullptr,
+ g_cclosure_marshal_VOID__BOXED,
+ G_TYPE_NONE, 1,
+ WEBKIT_TYPE_CONSOLE_MESSAGE | G_SIGNAL_TYPE_STATIC_SCOPE);
+
+ /**
+ * WebKitWebPage::form-controls-associated:
+ * @web_page: the #WebKitWebPage on which the signal is emitted
+ * @elements: (element-type WebKitDOMElement) (transfer none): a #GPtrArray of
+ * #WebKitDOMElement with the list of forms in the page
+ *
+ * Emitted after form elements (or form associated elements) are associated to a particular web
+ * page. This is useful to implement form autofilling for web pages where form fields are added
+ * dynamically. This signal might be emitted multiple times for the same web page.
+ *
+ * Note that this signal could be also emitted when form controls are moved between forms. In
+ * that case, the @elements array carries the list of those elements which have moved.
+ *
+ * Clients should take a reference to the members of the @elements array if it is desired to
+ * keep them alive after the signal handler returns.
+ *
+ * Since: 2.16
+ */
+ signals[FORM_CONTROLS_ASSOCIATED] = g_signal_new(
+ "form-controls-associated",
+ G_TYPE_FROM_CLASS(klass),
+ G_SIGNAL_RUN_LAST,
+ 0, 0, nullptr,
+ g_cclosure_marshal_VOID__BOXED,
+ G_TYPE_NONE, 1,
+ G_TYPE_PTR_ARRAY);
+}
+
+WebPage* webkitWebPageGetPage(WebKitWebPage *webPage)
+{
+ return webPage->priv->webPage;
}
WebKitWebPage* webkitWebPageCreate(WebPage* webPage)
@@ -311,15 +536,15 @@ WebKitWebPage* webkitWebPageCreate(WebPage* webPage)
WebKitWebPage* page = WEBKIT_WEB_PAGE(g_object_new(WEBKIT_TYPE_WEB_PAGE, NULL));
page->priv->webPage = webPage;
- WKBundlePageLoaderClientV7 loaderClient = {
+ WKBundlePageLoaderClientV6 loaderClient = {
{
- 7, // version
+ 6, // version
page, // clientInfo
},
didStartProvisionalLoadForFrame,
didReceiveServerRedirectForProvisionalLoadForFrame,
0, // didFailProvisionalLoadWithErrorForFrame
- 0, // didCommitLoadForFrame
+ didCommitLoadForFrame,
didFinishDocumentLoadForFrame,
0, // didFinishLoadForFrame
0, // didFailLoadWithErrorForFrame
@@ -327,7 +552,7 @@ WebKitWebPage* webkitWebPageCreate(WebPage* webPage)
0, // didReceiveTitleForFrame
0, // didFirstLayoutForFrame
0, // didFirstVisuallyNonEmptyLayoutForFrame
- 0, // didRemoveFrameFromHierarchy
+ 0, // didRemoveFrameFromHierarchy,
0, // didDisplayInsecureContentForFrame
0, // didRunInsecureContentForFrame
didClearWindowObjectForFrame,
@@ -350,7 +575,6 @@ WebKitWebPage* webkitWebPageCreate(WebPage* webPage)
0, // featuresUsedInPage
0, // willLoadURLRequest
0, // willLoadDataRequest
- willDestroyFrame
};
WKBundlePageSetPageLoaderClient(toAPI(webPage), &loaderClient.base);
@@ -370,15 +594,20 @@ WebKitWebPage* webkitWebPageCreate(WebPage* webPage)
};
WKBundlePageSetResourceLoadClient(toAPI(webPage), &resourceLoadClient.base);
+ webPage->setInjectedBundleContextMenuClient(std::make_unique<PageContextMenuClient>(page));
+ webPage->setInjectedBundleUIClient(std::make_unique<PageUIClient>(page));
+ webPage->setInjectedBundleFormClient(std::make_unique<FormClient>(page));
+
return page;
}
-void webkitWebPageDidReceiveMessage(WebKitWebPage* page, const String& messageName, ImmutableDictionary& message)
+void webkitWebPageDidReceiveMessage(WebKitWebPage* page, const String& messageName, API::Dictionary& message)
{
if (messageName == String("GetSnapshot")) {
SnapshotOptions snapshotOptions = static_cast<SnapshotOptions>(static_cast<API::UInt64*>(message.get("SnapshotOptions"))->value());
uint64_t callbackID = static_cast<API::UInt64*>(message.get("CallbackID"))->value();
SnapshotRegion region = static_cast<SnapshotRegion>(static_cast<API::UInt64*>(message.get("SnapshotRegion"))->value());
+ bool transparentBackground = static_cast<API::Boolean*>(message.get("TransparentBackground"))->value();
RefPtr<WebImage> snapshotImage;
WebPage* webPage = page->priv->webPage;
@@ -394,15 +623,23 @@ void webkitWebPageDidReceiveMessage(WebKitWebPage* page, const String& messageNa
default:
ASSERT_NOT_REACHED();
}
- if (!snapshotRect.isEmpty())
+ if (!snapshotRect.isEmpty()) {
+ Color savedBackgroundColor;
+ if (transparentBackground) {
+ savedBackgroundColor = frameView->baseBackgroundColor();
+ frameView->setBaseBackgroundColor(Color::transparent);
+ }
snapshotImage = webPage->scaledSnapshotWithOptions(snapshotRect, 1, snapshotOptions | SnapshotOptionsShareable);
+ if (transparentBackground)
+ frameView->setBaseBackgroundColor(savedBackgroundColor);
+ }
}
- ImmutableDictionary::MapType messageReply;
+ API::Dictionary::MapType messageReply;
messageReply.set("Page", webPage);
messageReply.set("CallbackID", API::UInt64::create(callbackID));
messageReply.set("Snapshot", snapshotImage);
- WebProcess::shared().injectedBundle()->postMessage("WebPage.DidGetSnapshot", ImmutableDictionary::create(std::move(messageReply)).get());
+ WebProcess::singleton().injectedBundle()->postMessage("WebPage.DidGetSnapshot", API::Dictionary::create(WTFMove(messageReply)).ptr());
} else
ASSERT_NOT_REACHED();
}
@@ -420,7 +657,7 @@ WebKitDOMDocument* webkit_web_page_get_dom_document(WebKitWebPage* webPage)
{
g_return_val_if_fail(WEBKIT_IS_WEB_PAGE(webPage), 0);
- Frame* coreFrame = webPage->priv->webPage->mainFrame();
+ MainFrame* coreFrame = webPage->priv->webPage->mainFrame();
if (!coreFrame)
return 0;
@@ -477,3 +714,23 @@ WebKitFrame* webkit_web_page_get_main_frame(WebKitWebPage* webPage)
return webkitFrameGetOrCreate(webPage->priv->webPage->mainWebFrame());
}
+
+/**
+ * webkit_web_page_get_editor:
+ * @web_page: a #WebKitWebPage
+ *
+ * Gets the #WebKitWebEditor of a #WebKitWebPage.
+ *
+ * Returns: (transfer none): the #WebKitWebEditor
+ *
+ * Since: 2.10
+ */
+WebKitWebEditor* webkit_web_page_get_editor(WebKitWebPage* webPage)
+{
+ g_return_val_if_fail(WEBKIT_IS_WEB_PAGE(webPage), nullptr);
+
+ if (!webPage->priv->webEditor)
+ webPage->priv->webEditor = adoptGRef(webkitWebEditorCreate(webPage));
+
+ return webPage->priv->webEditor.get();
+}