WebKit2: Should be able to call into injected bundle to ask if we should allow resour...
authorbweinstein@apple.com <bweinstein@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 6 Jan 2011 19:27:23 +0000 (19:27 +0000)
committerbweinstein@apple.com <bweinstein@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 6 Jan 2011 19:27:23 +0000 (19:27 +0000)
https://bugs.webkit.org/show_bug.cgi?id=51969

Reviewed by Ada Chan.

Tools:

Add shouldLoadResourceForFrame to WTR::InjectedBundlePage.

* WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp:
(WTR::InjectedBundlePage::InjectedBundlePage):
(WTR::InjectedBundlePage::shouldLoadResourceForFrame): Stub implementation.
* WebKitTestRunner/InjectedBundle/InjectedBundlePage.h:

WebKit2:

Add the ability to call into the injected bundle to ask if we should allow resource loads.
If the injected bundle says we should cancel, we clear out the ResourceRequest that was
passed into willSendRequest, which cancels the resource load.

* WebProcess/InjectedBundle/API/c/WKBundlePage.h: Add the new callback for allowing/cancelling
    resource loads.
* WebProcess/InjectedBundle/InjectedBundlePageLoaderClient.cpp:
(WebKit::InjectedBundlePageLoaderClient::shouldLoadResourceForFrame): Calls through to the client.
* WebProcess/InjectedBundle/InjectedBundlePageLoaderClient.h:
* WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:
(WebKit::WebFrameLoaderClient::dispatchWillSendRequest): Ask the InjectedBundlePageLoaderClient if we
    should load the resource or not.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@75174 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Tools/ChangeLog
Tools/WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp
Tools/WebKitTestRunner/InjectedBundle/InjectedBundlePage.h
WebKit2/ChangeLog
WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePage.h
WebKit2/WebProcess/InjectedBundle/InjectedBundlePageLoaderClient.cpp
WebKit2/WebProcess/InjectedBundle/InjectedBundlePageLoaderClient.h
WebKit2/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp

index b1c397c3590786a3ac5e598eb807ec31b23b3fa8..7c607d7d8f7d284b321686de0ec77f2e0812a158 100644 (file)
@@ -1,3 +1,17 @@
+2011-01-05  Brian Weinstein  <bweinstein@apple.com>
+
+        Reviewed by Ada Chan.
+
+        WebKit2: Should be able to call into injected bundle to ask if we should allow resource loads
+        https://bugs.webkit.org/show_bug.cgi?id=51969
+        
+        Add shouldLoadResourceForFrame to WTR::InjectedBundlePage.
+
+        * WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp:
+        (WTR::InjectedBundlePage::InjectedBundlePage):
+        (WTR::InjectedBundlePage::shouldLoadResourceForFrame): Stub implementation.
+        * WebKitTestRunner/InjectedBundle/InjectedBundlePage.h:
+
 2011-01-06  James Robinson  <jamesr@chromium.org>
 
         Reviewed by Simon Fraser.
index da79b19be03a72f84bde64a156adc9aeacf4a5ca..765ff370a010e27d9b28d31191c1d141e879b093 100644 (file)
@@ -190,7 +190,8 @@ InjectedBundlePage::InjectedBundlePage(WKBundlePageRef page)
         didClearWindowForFrame,
         didCancelClientRedirectForFrame,
         willPerformClientRedirectForFrame,
-        didHandleOnloadEventsForFrame
+        didHandleOnloadEventsForFrame,
+        shouldLoadResourceForFrame
     };
     WKBundlePageSetLoaderClient(m_page, &loaderClient);
 
@@ -322,6 +323,11 @@ void InjectedBundlePage::didRunInsecureContentForFrame(WKBundlePageRef page, WKB
     static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->didRunInsecureContentForFrame(frame);
 }
 
+bool InjectedBundlePage::shouldLoadResourceForFrame(WKBundlePageRef page, WKBundleFrameRef frame, WKURLRef, const void* clientInfo)
+{
+    return static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->shouldLoadResourceForFrame(frame);
+}
+
 
 void InjectedBundlePage::didStartProvisionalLoadForFrame(WKBundleFrameRef frame)
 {
@@ -561,6 +567,11 @@ void InjectedBundlePage::didRunInsecureContentForFrame(WKBundleFrameRef frame)
 {
 }
 
+bool InjectedBundlePage::shouldLoadResourceForFrame(WKBundleFrameRef frame)
+{
+    return true;
+}
+
 // UI Client Callbacks
 
 void InjectedBundlePage::willAddMessageToConsole(WKBundlePageRef page, WKStringRef message, uint32_t lineNumber, const void *clientInfo)
index cb1c27be4aa04b237953dfa6c9cd34594cedbd95..ac9fbc36e3259d45c540bc9d77966341f29e10ca 100644 (file)
@@ -64,6 +64,7 @@ private:
     static void didHandleOnloadEventsForFrame(WKBundlePageRef, WKBundleFrameRef, const void*);
     static void didDisplayInsecureContentForFrame(WKBundlePageRef, WKBundleFrameRef, WKTypeRef*, const void*);
     static void didRunInsecureContentForFrame(WKBundlePageRef, WKBundleFrameRef, WKTypeRef*, const void*);
+    static bool shouldLoadResourceForFrame(WKBundlePageRef, WKBundleFrameRef, WKURLRef, const void*);
     void didStartProvisionalLoadForFrame(WKBundleFrameRef);
     void didReceiveServerRedirectForProvisionalLoadForFrame(WKBundleFrameRef);
     void didFailProvisionalLoadWithErrorForFrame(WKBundleFrameRef, WKErrorRef);
@@ -79,6 +80,7 @@ private:
     void didHandleOnloadEventsForFrame(WKBundleFrameRef);
     void didDisplayInsecureContentForFrame(WKBundleFrameRef);
     void didRunInsecureContentForFrame(WKBundleFrameRef);
+    bool shouldLoadResourceForFrame(WKBundleFrameRef);
 
     // UI Client
     static void willAddMessageToConsole(WKBundlePageRef, WKStringRef message, uint32_t lineNumber, const void* clientInfo);
index 3dab6489a815d92cf6a58dca5cfd728a2eb0bf9d..79f05af7ad51add250471f81cead517853f49c38 100644 (file)
@@ -1,3 +1,23 @@
+2011-01-05  Brian Weinstein  <bweinstein@apple.com>
+
+        Reviewed by Ada Chan.
+
+        WebKit2: Should be able to call into injected bundle to ask if we should allow resource loads
+        https://bugs.webkit.org/show_bug.cgi?id=51969
+        
+        Add the ability to call into the injected bundle to ask if we should allow resource loads.
+        If the injected bundle says we should cancel, we clear out the ResourceRequest that was
+        passed into willSendRequest, which cancels the resource load.
+
+        * WebProcess/InjectedBundle/API/c/WKBundlePage.h: Add the new callback for allowing/cancelling
+            resource loads.
+        * WebProcess/InjectedBundle/InjectedBundlePageLoaderClient.cpp:
+        (WebKit::InjectedBundlePageLoaderClient::shouldLoadResourceForFrame): Calls through to the client.
+        * WebProcess/InjectedBundle/InjectedBundlePageLoaderClient.h:
+        * WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:
+        (WebKit::WebFrameLoaderClient::dispatchWillSendRequest): Ask the InjectedBundlePageLoaderClient if we
+            should load the resource or not.
+
 2011-01-06  Jeff Miller  <jeffm@apple.com>
 
         Reviewed by Darin Adler.
index 6c700993d63e3048b026d3dabec1070676d05732..6c6ed3a329aa548a444602084e13693f0fe355bb 100644 (file)
@@ -87,6 +87,7 @@ typedef void (*WKBundlePageDidClearWindowObjectForFrameCallback)(WKBundlePageRef
 typedef void (*WKBundlePageDidCancelClientRedirectForFrameCallback)(WKBundlePageRef page, WKBundleFrameRef frame, const void *clientInfo);
 typedef void (*WKBundlePageWillPerformClientRedirectForFrameCallback)(WKBundlePageRef page, WKBundleFrameRef frame, WKURLRef url, double delay, double date, const void *clientInfo);
 typedef void (*WKBundlePageDidHandleOnloadEventsForFrameCallback)(WKBundlePageRef page, WKBundleFrameRef frame, const void *clientInfo);
+typedef bool (*WKBundlePageShouldLoadResourceForFrameCallback)(WKBundlePageRef page, WKBundleFrameRef frame, WKURLRef url, const void *clientInfo);
 
 
 struct WKBundlePageLoaderClient {
@@ -112,6 +113,7 @@ struct WKBundlePageLoaderClient {
     WKBundlePageDidCancelClientRedirectForFrameCallback                 didCancelClientRedirectForFrame;
     WKBundlePageWillPerformClientRedirectForFrameCallback               willPerformClientRedirectForFrame;
     WKBundlePageDidHandleOnloadEventsForFrameCallback                   didHandleOnloadEventsForFrame;
+    WKBundlePageShouldLoadResourceForFrameCallback                      shouldLoadResourceForFrame;
 };
 typedef struct WKBundlePageLoaderClient WKBundlePageLoaderClient;
 
index a02cf8a03a0ac4572a38a355bb3d185e9af06115..2df2ffd73899cafa22e69aa4e4808a2b8a241ddf 100644 (file)
@@ -175,6 +175,14 @@ void InjectedBundlePageLoaderClient::didRunInsecureContentForFrame(WebPage* page
     userData = adoptRef(toImpl(userDataToPass));
 }
 
+bool InjectedBundlePageLoaderClient::shouldLoadResourceForFrame(WebPage* page, WebFrame* frame, const String& subResourceURL)
+{
+    if (!m_client.shouldLoadResourceForFrame)
+        return true;
+
+    return m_client.shouldLoadResourceForFrame(toAPI(page), toAPI(frame), toURLRef(subResourceURL.impl()), m_client.clientInfo);
+}
+
 void InjectedBundlePageLoaderClient::didClearWindowObjectForFrame(WebPage* page, WebFrame* frame, DOMWrapperWorld* world)
 {
     if (!m_client.didClearWindowObjectForFrame)
index c9bba7cfcee6998cdb78543c665baca5aa375ab3..e983b488fd5aa6c41f29f90e0dec78c54f6e25ce 100644 (file)
@@ -60,6 +60,8 @@ public:
     void didDisplayInsecureContentForFrame(WebPage*, WebFrame*, RefPtr<APIObject>& userData);
     void didRunInsecureContentForFrame(WebPage*, WebFrame*, RefPtr<APIObject>& userData);
 
+    bool shouldLoadResourceForFrame(WebPage*, WebFrame*, const String&);
+
     void didClearWindowObjectForFrame(WebPage*, WebFrame*, WebCore::DOMWrapperWorld*);
     void didCancelClientRedirectForFrame(WebPage*, WebFrame*);
     void willPerformClientRedirectForFrame(WebPage*, WebFrame*, const String& url, double delay, double date);
index 3adbe243a85e6466c99467ae94819d0c2a7a6f6d..49ce240772e3b7ab1197c3b42fba38cdc92ecb50 100644 (file)
@@ -156,6 +156,12 @@ void WebFrameLoaderClient::dispatchWillSendRequest(DocumentLoader*, unsigned lon
     if (!webPage)
         return;
 
+    if (!webPage->injectedBundleLoaderClient().shouldLoadResourceForFrame(webPage, m_frame, request.url().string())) {
+        request = ResourceRequest();
+        // FIXME: We should probably send a message saying we cancelled the request for the resource.
+        return;
+    }
+
     webPage->send(Messages::WebPageProxy::DidSendRequestForResource(m_frame->frameID(), identifier, request, redirectResponse));
 }