Title: [160809] trunk/Source/WebKit2
- Revision
- 160809
- Author
- [email protected]
- Date
- 2013-12-18 16:52:47 -0800 (Wed, 18 Dec 2013)
Log Message
[Cocoa] Allow the web process plug-in to intercept resource requests
https://bugs.webkit.org/show_bug.cgi?id=125959
Reviewed by Anders Carlsson.
* WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInLoadDelegate.h: Declared new
delegate method.
* WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInBrowserContextController.mm:
(willSendRequestForFrame): Implemented this WKBundlePageResourceClient callback by calling
the load delegate.
(setUpResourceLoadClient): Added. Initializes the resource load client with the above
function.
(-[WKWebProcessPlugInBrowserContextController setLoadDelegate:]): Added calls to initialize
and clear the resource load client.
Modified Paths
Diff
Modified: trunk/Source/WebKit2/ChangeLog (160808 => 160809)
--- trunk/Source/WebKit2/ChangeLog 2013-12-19 00:48:54 UTC (rev 160808)
+++ trunk/Source/WebKit2/ChangeLog 2013-12-19 00:52:47 UTC (rev 160809)
@@ -1,3 +1,20 @@
+2013-12-18 Dan Bernstein <[email protected]>
+
+ [Cocoa] Allow the web process plug-in to intercept resource requests
+ https://bugs.webkit.org/show_bug.cgi?id=125959
+
+ Reviewed by Anders Carlsson.
+
+ * WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInLoadDelegate.h: Declared new
+ delegate method.
+ * WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInBrowserContextController.mm:
+ (willSendRequestForFrame): Implemented this WKBundlePageResourceClient callback by calling
+ the load delegate.
+ (setUpResourceLoadClient): Added. Initializes the resource load client with the above
+ function.
+ (-[WKWebProcessPlugInBrowserContextController setLoadDelegate:]): Added calls to initialize
+ and clear the resource load client.
+
2013-12-18 Yongjun Zhang <[email protected]>
https://bugs.webkit.org/show_bug.cgi?id=125941
Modified: trunk/Source/WebKit2/WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInLoadDelegate.h (160808 => 160809)
--- trunk/Source/WebKit2/WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInLoadDelegate.h 2013-12-19 00:48:54 UTC (rev 160808)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInLoadDelegate.h 2013-12-19 00:52:47 UTC (rev 160809)
@@ -30,7 +30,15 @@
@protocol WKWebProcessPlugInLoadDelegate <NSObject>
@optional
+
+// Frame loading
+
- (void)webProcessPlugInBrowserContextController:(WKWebProcessPlugInBrowserContextController*)controller didStartProvisionalLoadForFrame:(WKWebProcessPlugInFrame *)frame;
- (void)webProcessPlugInBrowserContextController:(WKWebProcessPlugInBrowserContextController*)controller didFinishLoadForFrame:(WKWebProcessPlugInFrame *)frame;
- (void)webProcessPlugInBrowserContextController:(WKWebProcessPlugInBrowserContextController*)controller globalObjectIsAvailableForFrame:(WKWebProcessPlugInFrame *)frame inScriptWorld:(WKWebProcessPlugInScriptWorld *)scriptWorld;
+
+// Resource loading
+
+- (NSURLRequest *)webProcessPlugInBrowserContextController:(WKWebProcessPlugInBrowserContextController *)controller frame:(WKWebProcessPlugInFrame *)frame willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse;
+
@end
Modified: trunk/Source/WebKit2/WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInBrowserContextController.mm (160808 => 160809)
--- trunk/Source/WebKit2/WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInBrowserContextController.mm 2013-12-19 00:48:54 UTC (rev 160808)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInBrowserContextController.mm 2013-12-19 00:52:47 UTC (rev 160809)
@@ -37,6 +37,7 @@
#import "WKDOMInternals.h"
#import "WKRemoteObjectRegistryInternal.h"
#import "WKRetainPtr.h"
+#import "WKURLRequestNS.h"
#import "WKWebProcessPluginFrameInternal.h"
#import "WKWebProcessPlugInInternal.h"
#import "WKWebProcessPlugInLoadDelegate.h"
@@ -99,6 +100,36 @@
page.initializeInjectedBundleLoaderClient(&client.base);
}
+static WKURLRequestRef willSendRequestForFrame(WKBundlePageRef page, WKBundleFrameRef frame, uint64_t, WKURLRequestRef request, WKURLResponseRef redirectResponse, const void* clientInfo)
+{
+ WKWebProcessPlugInBrowserContextController *pluginContextController = (WKWebProcessPlugInBrowserContextController *)clientInfo;
+ auto loadDelegate = pluginContextController->_loadDelegate.get();
+
+ if ([loadDelegate respondsToSelector:@selector(webProcessPlugInBrowserContextController:frame:willSendRequest:redirectResponse:)]) {
+ NSURLRequest *originalRequest = toImpl(request)->resourceRequest().nsURLRequest(DoNotUpdateHTTPBody);
+ RetainPtr<NSURLRequest> substituteRequest = [loadDelegate webProcessPlugInBrowserContextController:pluginContextController frame:wrapper(*toImpl(frame)) willSendRequest:originalRequest
+ redirectResponse:toImpl(redirectResponse)->resourceResponse().nsURLResponse()];
+
+ if (substituteRequest != originalRequest)
+ return substituteRequest ? WKURLRequestCreateWithNSURLRequest(substituteRequest.get()) : nullptr;
+ }
+
+ WKRetain(request);
+ return request;
+}
+
+static void setUpResourceLoadClient(WKWebProcessPlugInBrowserContextController *contextController, WebPage& page)
+{
+ WKBundlePageResourceLoadClientV1 client;
+ memset(&client, 0, sizeof(client));
+
+ client.base.version = 1;
+ client.base.clientInfo = contextController;
+ client.willSendRequestForFrame = willSendRequestForFrame;
+
+ page.initializeInjectedBundleResourceLoadClient(&client.base);
+}
+
- (id <WKWebProcessPlugInLoadDelegate>)loadDelegate
{
return _loadDelegate.getAutoreleased();
@@ -108,10 +139,13 @@
{
_loadDelegate = loadDelegate;
- if (loadDelegate)
+ if (loadDelegate) {
setUpPageLoaderClient(self, *_page);
- else
+ setUpResourceLoadClient(self, *_page);
+ } else {
_page->initializeInjectedBundleLoaderClient(nullptr);
+ _page->initializeInjectedBundleResourceLoadClient(nullptr);
+ }
}
- (void)dealloc
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes