Changeset 170330 in webkit


Ignore:
Timestamp:
Jun 23, 2014 4:15:10 PM (10 years ago)
Author:
commit-queue@webkit.org
Message:

Add SPI for Injected Bundle to provide user agent for a given URL.
https://bugs.webkit.org/show_bug.cgi?id=133562

Patch by Grant Kennell <gkennell@apple.com> on 2014-06-23
Reviewed by Sam Weinig.

  • WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInLoadDelegate.h: Added delegate method to WebProcess PluIn protocol to provide UserAgent per URL.
  • WebProcess/InjectedBundle/API/c/WKBundlePageLoaderClient.h: Added new typedef for function pointer for this new delegate call. Added new version (V8) of bundle loader client struct containing a function pointer of that new type.
  • WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInBrowserContextController.mm:

(userAgentForURL): Makes delegate call with the new method.
(setUpPageLoaderClient): Sets the struct's new function pointer to the new method.

  • WebProcess/InjectedBundle/InjectedBundlePageLoaderClient.cpp:

(WebKit::InjectedBundlePageLoaderClient::userAgentForURL):

  • WebProcess/InjectedBundle/InjectedBundlePageLoaderClient.h:
  • WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:

(WebKit::WebFrameLoaderClient::userAgent):

  • WebProcess/WebPage/WebPage.cpp:

(WebKit::WebPage::userAgent): Began using the new API to ask for user agent

instead of simply returning what had been stored.

  • WebProcess/WebPage/WebPage.h:

(WebKit::WebPage::userAgent): Deleted.

Location:
trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r170329 r170330  
     12014-06-23  Grant Kennell  <gkennell@apple.com>
     2
     3        Add SPI for Injected Bundle to provide user agent for a given URL.
     4        https://bugs.webkit.org/show_bug.cgi?id=133562
     5
     6        Reviewed by Sam Weinig.
     7
     8        * WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInLoadDelegate.h:
     9          Added delegate method to WebProcess PluIn protocol to provide UserAgent per URL.
     10        * WebProcess/InjectedBundle/API/c/WKBundlePageLoaderClient.h:
     11          Added new typedef for function pointer for this new delegate call.
     12          Added new version (V8) of bundle loader client struct containing
     13          a function pointer of that new type.
     14        * WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInBrowserContextController.mm:
     15        (userAgentForURL): Makes delegate call with the new method.
     16        (setUpPageLoaderClient): Sets the struct's new function pointer to the new method.
     17        * WebProcess/InjectedBundle/InjectedBundlePageLoaderClient.cpp:
     18        (WebKit::InjectedBundlePageLoaderClient::userAgentForURL):
     19        * WebProcess/InjectedBundle/InjectedBundlePageLoaderClient.h:
     20        * WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:
     21        (WebKit::WebFrameLoaderClient::userAgent):
     22        * WebProcess/WebPage/WebPage.cpp:
     23        (WebKit::WebPage::userAgent): Began using the new API to ask for user agent
     24          instead of simply returning what had been stored.
     25        * WebProcess/WebPage/WebPage.h:
     26        (WebKit::WebPage::userAgent): Deleted.
     27
    1282014-06-23  Commit Queue  <commit-queue@webkit.org>
    229
  • trunk/Source/WebKit2/WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInLoadDelegate.h

    r168541 r170330  
    5858- (void)webProcessPlugInBrowserContextController:(WKWebProcessPlugInBrowserContextController *)controller frame:(WKWebProcessPlugInFrame *)frame didFailLoadForResource:(uint64_t)resource error:(NSError *)error;
    5959
     60- (NSString *)webProcessPlugInBrowserContextController:(WKWebProcessPlugInBrowserContextController *)controller frame:(WKWebProcessPlugInFrame *)frame userAgentForURL:(NSURL *)url;
     61
    6062@end
  • trunk/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePageLoaderClient.h

    r168541 r170330  
    6363typedef void (*WKBundlePageWillLoadDataRequestCallback)(WKBundlePageRef page, WKURLRequestRef request, WKDataRef data, WKStringRef MIMEType, WKStringRef encodingName, WKURLRef unreachableURL, WKTypeRef userData, const void *clientInfo);
    6464typedef void (*WKBundlePageWillDestroyFrame)(WKBundlePageRef page, WKBundleFrameRef frame, const void *clientInfo);
     65typedef WKStringRef (*WKBundlePageUserAgentForURLCallback)(WKBundleFrameRef frame, WKURLRef url, const void *clientInfo);
    6566
    6667typedef struct WKBundlePageLoaderClientBase {
     
    407408} WKBundlePageLoaderClientV7;
    408409
    409 enum { kWKBundlePageLoaderClientCurrentVersion WK_ENUM_DEPRECATED("Use an explicit version number instead") = 7 };
     410typedef struct WKBundlePageLoaderClientV8 {
     411    WKBundlePageLoaderClientBase                                            base;
     412   
     413    // Version 0.
     414    WKBundlePageDidStartProvisionalLoadForFrameCallback                     didStartProvisionalLoadForFrame;
     415    WKBundlePageDidReceiveServerRedirectForProvisionalLoadForFrameCallback  didReceiveServerRedirectForProvisionalLoadForFrame;
     416    WKBundlePageDidFailProvisionalLoadWithErrorForFrameCallback             didFailProvisionalLoadWithErrorForFrame;
     417    WKBundlePageDidCommitLoadForFrameCallback                               didCommitLoadForFrame;
     418    WKBundlePageDidFinishDocumentLoadForFrameCallback                       didFinishDocumentLoadForFrame;
     419    WKBundlePageDidFinishLoadForFrameCallback                               didFinishLoadForFrame;
     420    WKBundlePageDidFailLoadWithErrorForFrameCallback                        didFailLoadWithErrorForFrame;
     421    WKBundlePageDidSameDocumentNavigationForFrameCallback                   didSameDocumentNavigationForFrame;
     422    WKBundlePageDidReceiveTitleForFrameCallback                             didReceiveTitleForFrame;
     423    WKBundlePageDidFirstLayoutForFrameCallback                              didFirstLayoutForFrame;
     424    WKBundlePageDidFirstVisuallyNonEmptyLayoutForFrameCallback              didFirstVisuallyNonEmptyLayoutForFrame;
     425    WKBundlePageDidRemoveFrameFromHierarchyCallback                         didRemoveFrameFromHierarchy;
     426    WKBundlePageDidDisplayInsecureContentForFrameCallback                   didDisplayInsecureContentForFrame;
     427    WKBundlePageDidRunInsecureContentForFrameCallback                       didRunInsecureContentForFrame;
     428    WKBundlePageDidClearWindowObjectForFrameCallback                        didClearWindowObjectForFrame;
     429    WKBundlePageDidCancelClientRedirectForFrameCallback                     didCancelClientRedirectForFrame;
     430    WKBundlePageWillPerformClientRedirectForFrameCallback                   willPerformClientRedirectForFrame;
     431    WKBundlePageDidHandleOnloadEventsForFrameCallback                       didHandleOnloadEventsForFrame;
     432   
     433    // Version 1.
     434    WKBundlePageDidLayoutForFrameCallback                                   didLayoutForFrame;
     435    void *                                                                  didNewFirstVisuallyNonEmptyLayout_unavailable;
     436    WKBundlePageDidDetectXSSForFrameCallback                                didDetectXSSForFrame;
     437    WKBundlePageShouldGoToBackForwardListItemCallback                       shouldGoToBackForwardListItem;
     438    WKBundlePageGlobalObjectIsAvailableForFrameCallback                     globalObjectIsAvailableForFrame;
     439    WKBundlePageWillDisconnectDOMWindowExtensionFromGlobalObjectCallback    willDisconnectDOMWindowExtensionFromGlobalObject;
     440    WKBundlePageDidReconnectDOMWindowExtensionToGlobalObjectCallback        didReconnectDOMWindowExtensionToGlobalObject;
     441    WKBundlePageWillDestroyGlobalObjectForDOMWindowExtensionCallback        willDestroyGlobalObjectForDOMWindowExtension;
     442   
     443    // Version 2
     444    WKBundlePageDidFinishProgressCallback                                   didFinishProgress;
     445    WKBundlePageShouldForceUniversalAccessFromLocalURLCallback              shouldForceUniversalAccessFromLocalURL;
     446   
     447    // Version 3
     448    void *                                                                  didReceiveIntentForFrame_unavailable;
     449    void *                                                                  registerIntentServiceForFrame_unavailable;
     450   
     451    // Version 4
     452    WKBundlePageDidLayoutCallback                                           didLayout;
     453   
     454    // Version 5
     455    WKBundlePageFeaturesUsedInPageCallback                                  featuresUsedInPage;
     456   
     457    // Version 6
     458    WKBundlePageWillLoadURLRequestCallback                                  willLoadURLRequest;
     459    WKBundlePageWillLoadDataRequestCallback                                 willLoadDataRequest;
     460   
     461    // Version 7
     462    WKBundlePageWillDestroyFrame                                            willDestroyFrame;
     463   
     464    // Version 8
     465    WKBundlePageUserAgentForURLCallback                                     userAgentForURL;
     466} WKBundlePageLoaderClientV8;
     467
     468enum { kWKBundlePageLoaderClientCurrentVersion WK_ENUM_DEPRECATED("Use an explicit version number instead") = 8 };
    410469typedef struct WKBundlePageLoaderClient {
    411470    int                                                                     version;
  • trunk/Source/WebKit2/WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInBrowserContextController.mm

    r169807 r170330  
    3939#import "WKNSDictionary.h"
    4040#import "WKNSError.h"
     41#import "WKNSString.h"
     42#import "WKNSURL.h"
    4143#import "WKNSURLRequest.h"
    4244#import "WKRenderingProgressEventsInternal.h"
    4345#import "WKRetainPtr.h"
     46#import "WKStringCF.h"
    4447#import "WKURLRequestNS.h"
    4548#import "WKWebProcessPluginFrameInternal.h"
     
    177180        [loadDelegate webProcessPlugInBrowserContextController:pluginContextController didHandleOnloadEventsForFrame:wrapper(*toImpl(frame))];
    178181}
     182
     183static WKStringRef userAgentForURL(WKBundleFrameRef frame, WKURLRef url, const void* clientInfo)
     184{
     185    WKWebProcessPlugInBrowserContextController *pluginContextController = (WKWebProcessPlugInBrowserContextController *)clientInfo;
     186    auto loadDelegate = pluginContextController->_loadDelegate.get();
     187   
     188    if ([loadDelegate respondsToSelector:@selector(webProcessPlugInBrowserContextController:frame:userAgentForURL:)]) {
     189        WKWebProcessPlugInFrame *newFrame = wrapper(*toImpl(frame));
     190        NSString *string = [loadDelegate webProcessPlugInBrowserContextController:pluginContextController frame:newFrame userAgentForURL:wrapper(*toImpl(url))];
     191        if (!string)
     192            return nullptr;
     193
     194        WKStringRef wkString = WKStringCreateWithCFString((CFStringRef)string);
     195        return wkString;
     196    }
     197   
     198    return nullptr;
     199}
     200
    179201static void setUpPageLoaderClient(WKWebProcessPlugInBrowserContextController *contextController, WebPage& page)
    180202{
    181     WKBundlePageLoaderClientV7 client;
     203    WKBundlePageLoaderClientV8 client;
    182204    memset(&client, 0, sizeof(client));
    183205
    184     client.base.version = 7;
     206    client.base.version = 8;
    185207    client.base.clientInfo = contextController;
    186208    client.didStartProvisionalLoadForFrame = didStartProvisionalLoadForFrame;
     
    194216    client.didHandleOnloadEventsForFrame = didHandleOnloadEventsForFrame;
    195217    client.didFirstVisuallyNonEmptyLayoutForFrame = didFirstVisuallyNonEmptyLayoutForFrame;
     218    client.userAgentForURL = userAgentForURL;
    196219
    197220    client.didLayoutForFrame = didLayoutForFrame;
  • trunk/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundlePageLoaderClient.cpp

    r160971 r170330  
    3030#include "APIData.h"
    3131#include "APIError.h"
     32#include "APIURL.h"
    3233#include "APIURLRequest.h"
    3334#include "InjectedBundleDOMWindowExtension.h"
     
    3536#include "WKAPICast.h"
    3637#include "WKBundleAPICast.h"
     38#include "WKSharedAPICast.h"
    3739#include <WebCore/SharedBuffer.h>
    3840#include <wtf/text/WTFString.h>
     
    352354    m_client.willDestroyFrame(toAPI(page), toAPI(frame), m_client.base.clientInfo);
    353355}
    354 
     356   
     357API::String* InjectedBundlePageLoaderClient::userAgentForURL(WebFrame* frame, API::URL* url) const
     358{
     359    if (!m_client.userAgentForURL)
     360        return nullptr;
     361    WKStringRef userAgent = m_client.userAgentForURL(toAPI(frame), toAPI(url), m_client.base.clientInfo);
     362    return toImpl(userAgent);
     363}
     364   
    355365} // namespace WebKit
  • trunk/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundlePageLoaderClient.h

    r160653 r170330  
    2828
    2929#include "APIClient.h"
     30#include "APIString.h"
     31#include "APIURL.h"
    3032#include "SameDocumentNavigationType.h"
    3133#include "WKBundlePage.h"
     
    3941
    4042template<> struct ClientTraits<WKBundlePageLoaderClientBase> {
    41     typedef std::tuple<WKBundlePageLoaderClientV0, WKBundlePageLoaderClientV1, WKBundlePageLoaderClientV2, WKBundlePageLoaderClientV3, WKBundlePageLoaderClientV4, WKBundlePageLoaderClientV5, WKBundlePageLoaderClientV6, WKBundlePageLoaderClientV7> Versions;
     43    typedef std::tuple<WKBundlePageLoaderClientV0, WKBundlePageLoaderClientV1, WKBundlePageLoaderClientV2, WKBundlePageLoaderClientV3, WKBundlePageLoaderClientV4, WKBundlePageLoaderClientV5, WKBundlePageLoaderClientV6, WKBundlePageLoaderClientV7, WKBundlePageLoaderClientV8> Versions;
    4244};
    4345}
     
    100102
    101103    void willDestroyFrame(WebPage*, WebFrame*);
     104    API::String* userAgentForURL(WebFrame*, API::URL*) const;
    102105};
    103106
  • trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp

    r170163 r170330  
    3737#include "NavigationActionData.h"
    3838#include "PluginView.h"
     39#include "WKBundleAPICast.h"
    3940#include "WebBackForwardListProxy.h"
    4041#include "WebContextMessages.h"
     
    11881189        return String();
    11891190
    1190     return webPage->userAgent(url);
     1191    return webPage->userAgent(m_frame, url);
    11911192}
    11921193
  • trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp

    r170325 r170330  
    5656#include "TelephoneNumberOverlayController.h"
    5757#include "VisitedLinkTableController.h"
     58#include "WKBundleAPICast.h"
     59#include "WKRetainPtr.h"
    5860#include "WKSharedAPICast.h"
     61#include "WKStringCF.h"
    5962#include "WebAlternativeTextClient.h"
    6063#include "WebBackForwardListItem.h"
     
    22722275}
    22732276
    2274 void WebPage::setUserAgent(const String& userAgent)
    2275 {
    2276     m_userAgent = userAgent;
    2277 }
    2278 
    2279 String WebPage::userAgent(const URL& url) const
    2280 {
    2281     String userAgent = platformUserAgent(url);
     2277String WebPage::userAgent(const URL& webCoreURL) const
     2278{
     2279    return userAgent(nullptr, webCoreURL);
     2280}
     2281
     2282String WebPage::userAgent(WebFrame* frame, const URL& webcoreURL) const
     2283{
     2284    if (frame && m_loaderClient.client().userAgentForURL) {
     2285        RefPtr<API::URL> url = API::URL::create(webcoreURL);
     2286
     2287        API::String* apiString = m_loaderClient.userAgentForURL(frame, url.get());
     2288        if (apiString)
     2289            return apiString->string();
     2290    }
     2291
     2292    String userAgent = platformUserAgent(webcoreURL);
    22822293    if (!userAgent.isEmpty())
    22832294        return userAgent;
    2284 
    22852295    return m_userAgent;
     2296}
     2297   
     2298void WebPage::setUserAgent(const String& userAgent)
     2299{
     2300    m_userAgent = userAgent;
    22862301}
    22872302
  • trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h

    r170325 r170330  
    256256    void show();
    257257    String userAgent(const WebCore::URL&) const;
     258    String userAgent(WebFrame*, const WebCore::URL&) const;
    258259    String platformUserAgent(const WebCore::URL&) const;
    259260    WebCore::IntRect windowResizerRect() const;
  • trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp

    r168961 r170330  
    269269    , m_world(AdoptWK, WKBundleScriptWorldCreateWorld())
    270270{
    271     WKBundlePageLoaderClientV7 loaderClient = {
    272         { 7, this },
     271    WKBundlePageLoaderClientV8 loaderClient = {
     272        { 8, this },
    273273        didStartProvisionalLoadForFrame,
    274274        didReceiveServerRedirectForProvisionalLoadForFrame,
     
    306306        0, // willLoadDataRequest
    307307        0, // willDestroyFrame
     308        0, // userAgentForURL
    308309    };
    309310    WKBundlePageSetPageLoaderClient(m_page, &loaderClient.base);
Note: See TracChangeset for help on using the changeset viewer.