<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[218267] trunk/Source/WebKit2</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/218267">218267</a></dd>
<dt>Author</dt> <dd>carlosgc@webkit.org</dd>
<dt>Date</dt> <dd>2017-06-14 10:22:42 -0700 (Wed, 14 Jun 2017)</dd>
</dl>

<h3>Log Message</h3>
<pre>[GTK] Use API::InjectedBundle::ResourceLoadClient in WebKitWebPage
https://bugs.webkit.org/show_bug.cgi?id=173364

Reviewed by Michael Catanzaro.

Instead of the C API.

* WebProcess/InjectedBundle/API/gtk/WebKitWebPage.cpp:
(webkitWebPageCreate):
(didInitiateLoadForResource): Deleted.
(willSendRequestForFrame): Deleted.
(didReceiveResponseForResource): Deleted.
(didReceiveContentLengthForResource): Deleted.
(didFinishLoadForResource): Deleted.
(didFailLoadForResource): Deleted.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2WebProcessInjectedBundleAPIgtkWebKitWebPagecpp">trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebPage.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (218266 => 218267)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog   2017-06-14 17:10:28 UTC (rev 218266)
+++ trunk/Source/WebKit2/ChangeLog      2017-06-14 17:22:42 UTC (rev 218267)
</span><span class="lines">@@ -1,5 +1,23 @@
</span><span class="cx"> 2017-06-14  Carlos Garcia Campos  <cgarcia@igalia.com>
</span><span class="cx"> 
</span><ins>+        [GTK] Use API::InjectedBundle::ResourceLoadClient in WebKitWebPage
+        https://bugs.webkit.org/show_bug.cgi?id=173364
+
+        Reviewed by Michael Catanzaro.
+
+        Instead of the C API.
+
+        * WebProcess/InjectedBundle/API/gtk/WebKitWebPage.cpp:
+        (webkitWebPageCreate):
+        (didInitiateLoadForResource): Deleted.
+        (willSendRequestForFrame): Deleted.
+        (didReceiveResponseForResource): Deleted.
+        (didReceiveContentLengthForResource): Deleted.
+        (didFinishLoadForResource): Deleted.
+        (didFailLoadForResource): Deleted.
+
+2017-06-14  Carlos Garcia Campos  <cgarcia@igalia.com>
+
</ins><span class="cx">         Add API::InjectedBundle::ResourceLoadClient
</span><span class="cx">         https://bugs.webkit.org/show_bug.cgi?id=173362
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessInjectedBundleAPIgtkWebKitWebPagecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebPage.cpp (218266 => 218267)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebPage.cpp 2017-06-14 17:10:28 UTC (rev 218266)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebPage.cpp    2017-06-14 17:22:42 UTC (rev 218267)
</span><span class="lines">@@ -24,8 +24,6 @@
</span><span class="cx"> #include "APIDictionary.h"
</span><span class="cx"> #include "ImageOptions.h"
</span><span class="cx"> #include "InjectedBundle.h"
</span><del>-#include "WKBundleAPICast.h"
-#include "WKBundleFrame.h"
</del><span class="cx"> #include "WebContextMenuItem.h"
</span><span class="cx"> #include "WebImage.h"
</span><span class="cx"> #include "WebKitConsoleMessagePrivate.h"
</span><span class="lines">@@ -207,102 +205,109 @@
</span><span class="cx">     WebKitWebPage* m_webPage;
</span><span class="cx"> };
</span><span class="cx"> 
</span><del>-static void didInitiateLoadForResource(WKBundlePageRef page, WKBundleFrameRef frame, uint64_t identifier, WKURLRequestRef request, bool /* pageLoadIsProvisional */, const void*)
-{
-    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::singleton().injectedBundle()->postMessage(String::fromUTF8("WebPage.DidInitiateLoadForResource"), API::Dictionary::create(WTFMove(message)).ptr());
-}
</del><span class="cx"> 
</span><del>-static WKURLRequestRef willSendRequestForFrame(WKBundlePageRef page, WKBundleFrameRef, uint64_t identifier, WKURLRequestRef wkRequest, WKURLResponseRef wkRedirectResponse, const void* clientInfo)
-{
-    GRefPtr<WebKitURIRequest> request = adoptGRef(webkitURIRequestCreateForResourceRequest(toImpl(wkRequest)->resourceRequest()));
-    const ResourceResponse& redirectResourceResponse = toImpl(wkRedirectResponse)->resourceResponse();
-    GRefPtr<WebKitURIResponse> redirectResponse = !redirectResourceResponse.isNull() ? adoptGRef(webkitURIResponseCreateForResourceResponse(redirectResourceResponse)) : nullptr;
</del><ins>+class PageResourceLoadClient final : public API::InjectedBundle::ResourceLoadClient {
+public:
+    explicit PageResourceLoadClient(WebKitWebPage* webPage)
+        : m_webPage(webPage)
+    {
+    }
</ins><span class="cx"> 
</span><del>-    gboolean returnValue;
-    g_signal_emit(WEBKIT_WEB_PAGE(clientInfo), signals[SEND_REQUEST], 0, request.get(), redirectResponse.get(), &returnValue);
-    if (returnValue)
-        return 0;
</del><ins>+private:
+    void didInitiateLoadForResource(WebPage& page, WebFrame& frame, uint64_t identifier, const ResourceRequest& request, bool) override
+    {
+        API::Dictionary::MapType message;
+        message.set(String::fromUTF8("Page"), &page);
+        message.set(String::fromUTF8("Frame"), &frame);
+        message.set(String::fromUTF8("Identifier"), API::UInt64::create(identifier));
+        message.set(String::fromUTF8("Request"), API::URLRequest::create(request));
+        WebProcess::singleton().injectedBundle()->postMessage(String::fromUTF8("WebPage.DidInitiateLoadForResource"), API::Dictionary::create(WTFMove(message)).ptr());
+    }
</ins><span class="cx"> 
</span><del>-    ResourceRequest resourceRequest;
-    webkitURIRequestGetResourceRequest(request.get(), resourceRequest);
-    resourceRequest.setInitiatingPageID(toImpl(page)->pageID());
-    Ref<API::URLRequest> newRequest = API::URLRequest::create(resourceRequest);
</del><ins>+    void willSendRequestForFrame(WebPage& page, WebFrame&, uint64_t identifier, ResourceRequest& resourceRequest, const ResourceResponse& redirectResourceResponse) override
+    {
+        GRefPtr<WebKitURIRequest> request = adoptGRef(webkitURIRequestCreateForResourceRequest(resourceRequest));
+        GRefPtr<WebKitURIResponse> redirectResponse = !redirectResourceResponse.isNull() ? adoptGRef(webkitURIResponseCreateForResourceResponse(redirectResourceResponse)) : nullptr;
</ins><span class="cx"> 
</span><del>-    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.ptr());
-    if (!redirectResourceResponse.isNull())
-        message.set(String::fromUTF8("RedirectResponse"), toImpl(wkRedirectResponse));
-    WebProcess::singleton().injectedBundle()->postMessage(String::fromUTF8("WebPage.DidSendRequestForResource"), API::Dictionary::create(WTFMove(message)).ptr());
</del><ins>+        gboolean returnValue;
+        g_signal_emit(m_webPage, signals[SEND_REQUEST], 0, request.get(), redirectResponse.get(), &returnValue);
+        if (returnValue) {
+            resourceRequest = { };
+            return;
+        }
</ins><span class="cx"> 
</span><del>-    return toAPI(&newRequest.leakRef());
-}
</del><ins>+        webkitURIRequestGetResourceRequest(request.get(), resourceRequest);
+        resourceRequest.setInitiatingPageID(page.pageID());
</ins><span class="cx"> 
</span><del>-static void didReceiveResponseForResource(WKBundlePageRef page, WKBundleFrameRef, uint64_t identifier, WKURLResponseRef response, const void* clientInfo)
-{
-    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::singleton().injectedBundle()->postMessage(String::fromUTF8("WebPage.DidReceiveResponseForResource"), API::Dictionary::create(WTFMove(message)).ptr());
</del><ins>+        API::Dictionary::MapType message;
+        message.set(String::fromUTF8("Page"), &page);
+        message.set(String::fromUTF8("Identifier"), API::UInt64::create(identifier));
+        message.set(String::fromUTF8("Request"), API::URLRequest::create(resourceRequest));
+        if (!redirectResourceResponse.isNull())
+            message.set(String::fromUTF8("RedirectResponse"), API::URLResponse::create(redirectResourceResponse));
+        WebProcess::singleton().injectedBundle()->postMessage(String::fromUTF8("WebPage.DidSendRequestForResource"), API::Dictionary::create(WTFMove(message)).ptr());
+    }
</ins><span class="cx"> 
</span><del>-    // 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());
</del><ins>+    void didReceiveResponseForResource(WebPage& page, WebFrame&, uint64_t identifier, const ResourceResponse& response) override
+    {
+        API::Dictionary::MapType message;
+        message.set(String::fromUTF8("Page"), &page);
+        message.set(String::fromUTF8("Identifier"), API::UInt64::create(identifier));
+        message.set(String::fromUTF8("Response"), API::URLResponse::create(response));
+        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.
+        if (response.httpStatusCode() >= 400) {
+            StringBuilder errorMessage;
+            errorMessage.appendLiteral("Failed to load resource: the server responded with a status of ");
+            errorMessage.appendNumber(response.httpStatusCode());
+            errorMessage.appendLiteral(" (");
+            errorMessage.append(response.httpStatusText());
+            errorMessage.append(')');
+            webkitWebPageDidSendConsoleMessage(m_webPage, MessageSource::Network, MessageLevel::Error, errorMessage.toString(), 0, response.url().string());
+        }
</ins><span class="cx">     }
</span><del>-}
</del><span class="cx"> 
</span><del>-static void didReceiveContentLengthForResource(WKBundlePageRef page, WKBundleFrameRef, uint64_t identifier, uint64_t length, const void*)
-{
-    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::singleton().injectedBundle()->postMessage(String::fromUTF8("WebPage.DidReceiveContentLengthForResource"), API::Dictionary::create(WTFMove(message)).ptr());
-}
</del><ins>+    void didReceiveContentLengthForResource(WebPage& page, WebFrame&, uint64_t identifier, uint64_t contentLength) override
+    {
+        API::Dictionary::MapType message;
+        message.set(String::fromUTF8("Page"), &page);
+        message.set(String::fromUTF8("Identifier"), API::UInt64::create(identifier));
+        message.set(String::fromUTF8("ContentLength"), API::UInt64::create(contentLength));
+        WebProcess::singleton().injectedBundle()->postMessage(String::fromUTF8("WebPage.DidReceiveContentLengthForResource"), API::Dictionary::create(WTFMove(message)).ptr());
+    }
</ins><span class="cx"> 
</span><del>-static void didFinishLoadForResource(WKBundlePageRef page, WKBundleFrameRef, uint64_t identifier, const void*)
-{
-    API::Dictionary::MapType message;
-    message.set(String::fromUTF8("Page"), toImpl(page));
-    message.set(String::fromUTF8("Identifier"), API::UInt64::create(identifier));
-    WebProcess::singleton().injectedBundle()->postMessage(String::fromUTF8("WebPage.DidFinishLoadForResource"), API::Dictionary::create(WTFMove(message)).ptr());
-}
</del><ins>+    void didFinishLoadForResource(WebPage& page, WebFrame&, uint64_t identifier) override
+    {
+        API::Dictionary::MapType message;
+        message.set(String::fromUTF8("Page"), &page);
+        message.set(String::fromUTF8("Identifier"), API::UInt64::create(identifier));
+        WebProcess::singleton().injectedBundle()->postMessage(String::fromUTF8("WebPage.DidFinishLoadForResource"), API::Dictionary::create(WTFMove(message)).ptr());
+    }
</ins><span class="cx"> 
</span><del>-static void didFailLoadForResource(WKBundlePageRef page, WKBundleFrameRef, uint64_t identifier, WKErrorRef error, const void* clientInfo)
-{
-    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::singleton().injectedBundle()->postMessage(String::fromUTF8("WebPage.DidFailLoadForResource"), API::Dictionary::create(WTFMove(message)).ptr());
</del><ins>+    void didFailLoadForResource(WebPage& page, WebFrame&, uint64_t identifier, const ResourceError& error) override
+    {
+        API::Dictionary::MapType message;
+        message.set(String::fromUTF8("Page"), &page);
+        message.set(String::fromUTF8("Identifier"), API::UInt64::create(identifier));
+        message.set(String::fromUTF8("Error"), API::Error::create(error));
+        WebProcess::singleton().injectedBundle()->postMessage(String::fromUTF8("WebPage.DidFailLoadForResource"), API::Dictionary::create(WTFMove(message)).ptr());
</ins><span class="cx"> 
</span><del>-    // 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());
</del><ins>+        // Post on the console as well to be consistent with the inspector.
+        if (!error.isCancellation()) {
+            StringBuilder errorMessage;
+            errorMessage.appendLiteral("Failed to load resource");
+            if (!error.localizedDescription().isEmpty()) {
+                errorMessage.appendLiteral(": ");
+                errorMessage.append(error.localizedDescription());
+            }
+            webkitWebPageDidSendConsoleMessage(m_webPage, MessageSource::Network, MessageLevel::Error, errorMessage.toString(), 0, error.failingURL());
</ins><span class="cx">         }
</span><del>-        webkitWebPageDidSendConsoleMessage(WEBKIT_WEB_PAGE(clientInfo), MessageSource::Network, MessageLevel::Error, errorMessage.toString(), 0, resourceError.failingURL());
</del><span class="cx">     }
</span><del>-}
</del><span class="cx"> 
</span><ins>+    WebKitWebPage* m_webPage;
+};
+
</ins><span class="cx"> class PageContextMenuClient final : public API::InjectedBundle::PageContextMenuClient {
</span><span class="cx"> public:
</span><span class="cx">     explicit PageContextMenuClient(WebKitWebPage* webPage)
</span><span class="lines">@@ -542,22 +547,7 @@
</span><span class="cx">     WebKitWebPage* page = WEBKIT_WEB_PAGE(g_object_new(WEBKIT_TYPE_WEB_PAGE, NULL));
</span><span class="cx">     page->priv->webPage = webPage;
</span><span class="cx"> 
</span><del>-    WKBundlePageResourceLoadClientV1 resourceLoadClient = {
-        {
-            1, // version
-            page, // clientInfo
-        },
-        didInitiateLoadForResource,
-        willSendRequestForFrame,
-        didReceiveResponseForResource,
-        didReceiveContentLengthForResource,
-        didFinishLoadForResource,
-        didFailLoadForResource,
-        0, // shouldCacheResponse
-        0 // shouldUseCredentialStorage
-    };
-    WKBundlePageSetResourceLoadClient(toAPI(webPage), &resourceLoadClient.base);
-
</del><ins>+    webPage->setInjectedBundleResourceLoadClient(std::make_unique<PageResourceLoadClient>(page));
</ins><span class="cx">     webPage->setInjectedBundlePageLoaderClient(std::make_unique<PageLoaderClient>(page));
</span><span class="cx">     webPage->setInjectedBundleContextMenuClient(std::make_unique<PageContextMenuClient>(page));
</span><span class="cx">     webPage->setInjectedBundleUIClient(std::make_unique<PageUIClient>(page));
</span></span></pre>
</div>
</div>

</body>
</html>