Changeset 160809 in webkit


Ignore:
Timestamp:
Dec 18, 2013, 4:52:47 PM (12 years ago)
Author:
mitz@apple.com
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.

Location:
trunk/Source/WebKit2
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r160803 r160809  
     12013-12-18  Dan Bernstein  <mitz@apple.com>
     2
     3        [Cocoa] Allow the web process plug-in to intercept resource requests
     4        https://bugs.webkit.org/show_bug.cgi?id=125959
     5
     6        Reviewed by Anders Carlsson.
     7
     8        * WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInLoadDelegate.h: Declared new
     9        delegate method.
     10        * WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInBrowserContextController.mm:
     11        (willSendRequestForFrame): Implemented this WKBundlePageResourceClient callback by calling
     12        the load delegate.
     13        (setUpResourceLoadClient): Added. Initializes the resource load client with the above
     14        function.
     15        (-[WKWebProcessPlugInBrowserContextController setLoadDelegate:]): Added calls to initialize
     16        and clear the resource load client.
     17
    1182013-12-18  Yongjun Zhang  <yongjun_zhang@apple.com>
    219
  • trunk/Source/WebKit2/WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInLoadDelegate.h

    r160616 r160809  
    3131@protocol WKWebProcessPlugInLoadDelegate <NSObject>
    3232@optional
     33
     34// Frame loading
     35
    3336- (void)webProcessPlugInBrowserContextController:(WKWebProcessPlugInBrowserContextController*)controller didStartProvisionalLoadForFrame:(WKWebProcessPlugInFrame *)frame;
    3437- (void)webProcessPlugInBrowserContextController:(WKWebProcessPlugInBrowserContextController*)controller didFinishLoadForFrame:(WKWebProcessPlugInFrame *)frame;
    3538- (void)webProcessPlugInBrowserContextController:(WKWebProcessPlugInBrowserContextController*)controller globalObjectIsAvailableForFrame:(WKWebProcessPlugInFrame *)frame inScriptWorld:(WKWebProcessPlugInScriptWorld *)scriptWorld;
     39
     40// Resource loading
     41
     42- (NSURLRequest *)webProcessPlugInBrowserContextController:(WKWebProcessPlugInBrowserContextController *)controller frame:(WKWebProcessPlugInFrame *)frame willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse;
     43
    3644@end
  • trunk/Source/WebKit2/WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInBrowserContextController.mm

    r160803 r160809  
    3838#import "WKRemoteObjectRegistryInternal.h"
    3939#import "WKRetainPtr.h"
     40#import "WKURLRequestNS.h"
    4041#import "WKWebProcessPluginFrameInternal.h"
    4142#import "WKWebProcessPlugInInternal.h"
     
    100101}
    101102
     103static WKURLRequestRef willSendRequestForFrame(WKBundlePageRef page, WKBundleFrameRef frame, uint64_t, WKURLRequestRef request, WKURLResponseRef redirectResponse, const void* clientInfo)
     104{
     105    WKWebProcessPlugInBrowserContextController *pluginContextController = (WKWebProcessPlugInBrowserContextController *)clientInfo;
     106    auto loadDelegate = pluginContextController->_loadDelegate.get();
     107
     108    if ([loadDelegate respondsToSelector:@selector(webProcessPlugInBrowserContextController:frame:willSendRequest:redirectResponse:)]) {
     109        NSURLRequest *originalRequest = toImpl(request)->resourceRequest().nsURLRequest(DoNotUpdateHTTPBody);
     110        RetainPtr<NSURLRequest> substituteRequest = [loadDelegate webProcessPlugInBrowserContextController:pluginContextController frame:wrapper(*toImpl(frame)) willSendRequest:originalRequest
     111            redirectResponse:toImpl(redirectResponse)->resourceResponse().nsURLResponse()];
     112
     113        if (substituteRequest != originalRequest)
     114            return substituteRequest ? WKURLRequestCreateWithNSURLRequest(substituteRequest.get()) : nullptr;
     115    }
     116
     117    WKRetain(request);
     118    return request;
     119}
     120
     121static void setUpResourceLoadClient(WKWebProcessPlugInBrowserContextController *contextController, WebPage& page)
     122{
     123    WKBundlePageResourceLoadClientV1 client;
     124    memset(&client, 0, sizeof(client));
     125
     126    client.base.version = 1;
     127    client.base.clientInfo = contextController;
     128    client.willSendRequestForFrame = willSendRequestForFrame;
     129
     130    page.initializeInjectedBundleResourceLoadClient(&client.base);
     131}
     132
    102133- (id <WKWebProcessPlugInLoadDelegate>)loadDelegate
    103134{
     
    109140    _loadDelegate = loadDelegate;
    110141
    111     if (loadDelegate)
     142    if (loadDelegate) {
    112143        setUpPageLoaderClient(self, *_page);
    113     else
     144        setUpResourceLoadClient(self, *_page);
     145    } else {
    114146        _page->initializeInjectedBundleLoaderClient(nullptr);
     147        _page->initializeInjectedBundleResourceLoadClient(nullptr);
     148    }
    115149}
    116150
Note: See TracChangeset for help on using the changeset viewer.