Changeset 74000 in webkit


Ignore:
Timestamp:
Dec 13, 2010 9:49:20 PM (13 years ago)
Author:
weinig@apple.com
Message:

WebKit2: Need to be able to set the application name for the user agent for a WKPage
https://bugs.webkit.org/show_bug.cgi?id=51011

Reviewed by Anders Carlsson.

Fixes:

WebKit2: Need to be able to set the application name for the user agent for a WKPage
<rdar://problem/8564532>
WebKit2: Need to be able to get the computed user agent for a WKPage
<rdar://problem/8637285>

Moves user agent computation to the UIProcess and just passes it to the WebProcess
when it has changed.

  • Shared/WebPageCreationParameters.cpp:

(WebKit::WebPageCreationParameters::encode):
(WebKit::WebPageCreationParameters::decode):

  • Shared/WebPageCreationParameters.h:

Add a user agent to the creation parameters.

  • UIProcess/API/C/WKPage.cpp:

(WKPageCopyUserAgent):
(WKPageCopyApplicationNameForUserAgent):
(WKPageSetApplicationNameForUserAgent):
(WKPageSetCustomUserAgent):

  • UIProcess/API/C/WKPage.h:

Add new API to set the application name and access the computed user agent.

  • UIProcess/WebPageProxy.cpp:

(WebKit::WebPageProxy::WebPageProxy):
(WebKit::WebPageProxy::close):
(WebKit::WebPageProxy::setUserAgent):
(WebKit::WebPageProxy::setApplicationNameForUserAgent):
(WebKit::WebPageProxy::setCustomUserAgent):
(WebKit::WebPageProxy::processDidCrash):
(WebKit::WebPageProxy::creationParameters):

  • UIProcess/WebPageProxy.h:

(WebKit::WebPageProxy::userAgent):
(WebKit::WebPageProxy::applicationNameForUserAgent):

  • UIProcess/mac/WebPageProxyMac.mm: Added.
  • WebProcess/WebPage/WebPage.cpp:

(WebKit::WebPage::WebPage):
(WebKit::WebPage::setUserAgent):

  • WebProcess/WebPage/WebPage.h:

(WebKit::WebPage::userAgent):

  • WebProcess/WebPage/WebPage.messages.in:

Pipe through user agent.

(WebKit::callGestalt):
(WebKit::macOSXVersionString):
(WebKit::userVisibleWebKitVersionString):
(WebKit::WebPageProxy::standardUserAgent):

  • UIProcess/win/WebPageProxyWin.cpp: Added.

(WebKit::windowsVersion):
(WebKit::userVisibleWebKitVersionString):
(WebKit::WebPageProxy::standardUserAgent):
Port standardUserAgent computation from WebKit1.

  • UIProcess/qt/WebPageProxyQt.cpp: Added.

(WebKit::WebPageProxy::standardUserAgent):
Stub out the user agent so there is no change in behavior.

  • WebKit2.pro:
  • WebKit2.xcodeproj/project.pbxproj:
  • win/WebKit2.vcproj:

Add new file.

Location:
trunk/WebKit2
Files:
3 added
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebKit2/ChangeLog

    r73992 r74000  
     12010-12-13  Sam Weinig  <sam@webkit.org>
     2
     3        Reviewed by Anders Carlsson.
     4
     5        WebKit2: Need to be able to set the application name for the user agent for a WKPage
     6        https://bugs.webkit.org/show_bug.cgi?id=51011
     7
     8        Fixes:
     9            WebKit2: Need to be able to set the application name for the user agent for a WKPage
     10            <rdar://problem/8564532>
     11            WebKit2: Need to be able to get the computed user agent for a WKPage
     12            <rdar://problem/8637285>
     13
     14        Moves user agent computation to the UIProcess and just passes it to the WebProcess
     15        when it has changed.
     16
     17        * Shared/WebPageCreationParameters.cpp:
     18        (WebKit::WebPageCreationParameters::encode):
     19        (WebKit::WebPageCreationParameters::decode):
     20        * Shared/WebPageCreationParameters.h:
     21        Add a user agent to the creation parameters.
     22
     23        * UIProcess/API/C/WKPage.cpp:
     24        (WKPageCopyUserAgent):
     25        (WKPageCopyApplicationNameForUserAgent):
     26        (WKPageSetApplicationNameForUserAgent):
     27        (WKPageSetCustomUserAgent):
     28        * UIProcess/API/C/WKPage.h:
     29        Add new API to set the application name and access the computed user agent.
     30
     31        * UIProcess/WebPageProxy.cpp:
     32        (WebKit::WebPageProxy::WebPageProxy):
     33        (WebKit::WebPageProxy::close):
     34        (WebKit::WebPageProxy::setUserAgent):
     35        (WebKit::WebPageProxy::setApplicationNameForUserAgent):
     36        (WebKit::WebPageProxy::setCustomUserAgent):
     37        (WebKit::WebPageProxy::processDidCrash):
     38        (WebKit::WebPageProxy::creationParameters):
     39        * UIProcess/WebPageProxy.h:
     40        (WebKit::WebPageProxy::userAgent):
     41        (WebKit::WebPageProxy::applicationNameForUserAgent):
     42        * UIProcess/mac/WebPageProxyMac.mm: Added.
     43        * WebProcess/WebPage/WebPage.cpp:
     44        (WebKit::WebPage::WebPage):
     45        (WebKit::WebPage::setUserAgent):
     46        * WebProcess/WebPage/WebPage.h:
     47        (WebKit::WebPage::userAgent):
     48        * WebProcess/WebPage/WebPage.messages.in:
     49        Pipe through user agent.
     50
     51        (WebKit::callGestalt):
     52        (WebKit::macOSXVersionString):
     53        (WebKit::userVisibleWebKitVersionString):
     54        (WebKit::WebPageProxy::standardUserAgent):
     55        * UIProcess/win/WebPageProxyWin.cpp: Added.
     56        (WebKit::windowsVersion):
     57        (WebKit::userVisibleWebKitVersionString):
     58        (WebKit::WebPageProxy::standardUserAgent):
     59        Port standardUserAgent computation from WebKit1.
     60
     61        * UIProcess/qt/WebPageProxyQt.cpp: Added.
     62        (WebKit::WebPageProxy::standardUserAgent):
     63        Stub out the user agent so there is no change in behavior.
     64
     65        * WebKit2.pro:
     66        * WebKit2.xcodeproj/project.pbxproj:
     67        * win/WebKit2.vcproj:
     68        Add new file.
     69
    1702010-12-13  Brady Eidson  <beidson@apple.com>
    271
  • trunk/WebKit2/Shared/WebPageCreationParameters.cpp

    r73666 r74000  
    3838    encoder->encode(drawsBackground);
    3939    encoder->encode(drawsTransparentBackground);
     40    encoder->encode(userAgent);
    4041
    4142#if PLATFORM(WIN)
     
    5859    if (!decoder->decode(parameters.drawsTransparentBackground))
    5960        return false;
     61    if (!decoder->decode(parameters.userAgent))
     62        return false;
    6063
    6164#if PLATFORM(WIN)
  • trunk/WebKit2/Shared/WebPageCreationParameters.h

    r73666 r74000  
    3131#include "WebPreferencesStore.h"
    3232#include <WebCore/IntSize.h>
     33#include <wtf/text/WTFString.h>
    3334
    3435namespace CoreIPC {
     
    5152    bool drawsTransparentBackground;
    5253
     54    String userAgent;
     55
    5356#if PLATFORM(WIN)
    5457    HWND nativeWindow;
  • trunk/WebKit2/UIProcess/API/C/WKPage.cpp

    r73965 r74000  
    165165}
    166166
     167WKStringRef WKPageCopyUserAgent(WKPageRef pageRef)
     168{
     169    return toCopiedAPI(toImpl(pageRef)->userAgent());
     170}
     171
     172WKStringRef WKPageCopyApplicationNameForUserAgent(WKPageRef pageRef)
     173{
     174    return toCopiedAPI(toImpl(pageRef)->applicationNameForUserAgent());
     175}
     176
     177void WKPageSetApplicationNameForUserAgent(WKPageRef pageRef, WKStringRef applicationNameRef)
     178{
     179    toImpl(pageRef)->setApplicationNameForUserAgent(toWTFString(applicationNameRef));
     180}
     181
    167182WKStringRef WKPageCopyCustomUserAgent(WKPageRef pageRef)
    168183{
     
    172187void WKPageSetCustomUserAgent(WKPageRef pageRef, WKStringRef userAgentRef)
    173188{
    174     toImpl(pageRef)->setCustomUserAgent(toImpl(userAgentRef)->string());
     189    toImpl(pageRef)->setCustomUserAgent(toWTFString(userAgentRef));
    175190}
    176191
  • trunk/WebKit2/UIProcess/API/C/WKPage.h

    r73986 r74000  
    252252#endif
    253253
     254WK_EXPORT WKStringRef WKPageCopyUserAgent(WKPageRef page);
     255
     256WK_EXPORT WKStringRef WKPageCopyApplicationNameForUserAgent(WKPageRef page);
     257WK_EXPORT void WKPageSetApplicationNameForUserAgent(WKPageRef page, WKStringRef applicationName);
     258
    254259WK_EXPORT WKStringRef WKPageCopyCustomUserAgent(WKPageRef page);
    255260WK_EXPORT void WKPageSetCustomUserAgent(WKPageRef page, WKStringRef userAgent);
  • trunk/WebKit2/UIProcess/WebPageProxy.cpp

    r73986 r74000  
    9191    , m_pageGroup(pageGroup)
    9292    , m_mainFrame(0)
     93    , m_userAgent(standardUserAgent())
    9394    , m_estimatedProgress(0.0)
    9495    , m_isInWindow(false)
     
    224225    m_mainFrame = 0;
    225226
    226     m_customUserAgent = String();
    227 
    228227#if ENABLE(INSPECTOR)
    229228    if (m_inspector) {
     
    604603}
    605604
    606 void WebPageProxy::setCustomUserAgent(const String& userAgent)
    607 {
    608     if (!isValid())
    609         return;
    610 
    611     if (m_customUserAgent == userAgent || (m_customUserAgent.isEmpty() && userAgent.isEmpty()))
    612         return;
    613 
    614     m_customUserAgent = userAgent;
    615     process()->send(Messages::WebPage::SetCustomUserAgent(userAgent), m_pageID);
     605void WebPageProxy::setUserAgent(const String& userAgent)
     606{
     607    if (m_userAgent == userAgent)
     608        return;
     609    m_userAgent = userAgent;
     610
     611    if (!isValid())
     612        return;
     613    process()->send(Messages::WebPage::SetUserAgent(m_userAgent), m_pageID);
     614}
     615
     616void WebPageProxy::setApplicationNameForUserAgent(const String& applicationName)
     617{
     618    if (m_applicationNameForUserAgent == applicationName)
     619        return;
     620
     621    m_applicationNameForUserAgent = applicationName;
     622    if (!m_customUserAgent.isEmpty())
     623        return;
     624
     625    setUserAgent(standardUserAgent(m_applicationNameForUserAgent));
     626}
     627
     628void WebPageProxy::setCustomUserAgent(const String& customUserAgent)
     629{
     630    if (m_customUserAgent == customUserAgent)
     631        return;
     632
     633    m_customUserAgent = customUserAgent;
     634
     635    if (m_customUserAgent.isEmpty()) {
     636        setUserAgent(standardUserAgent(m_applicationNameForUserAgent));
     637        return;
     638    }
     639
     640    setUserAgent(m_customUserAgent);
    616641}
    617642
     
    15831608#endif
    15841609
    1585     m_customUserAgent = String();
    15861610    m_pageTitle = String();
    15871611    m_toolTip = String();
     
    16161640    parameters.drawsBackground = m_drawsBackground;
    16171641    parameters.drawsTransparentBackground = m_drawsTransparentBackground;
     1642    parameters.userAgent = userAgent();
    16181643
    16191644#if PLATFORM(WIN)
  • trunk/WebKit2/UIProcess/WebPageProxy.h

    r73986 r74000  
    196196    const String& pageTitle() const { return m_pageTitle; }
    197197    const String& toolTip() const { return m_toolTip; }
     198
     199    void setUserAgent(const String&);
     200    const String& userAgent() const { return m_userAgent; }
     201    void setApplicationNameForUserAgent(const String&);
     202    const String& applicationNameForUserAgent() const { return m_applicationNameForUserAgent; }
     203    void setCustomUserAgent(const String&);
    198204    const String& customUserAgent() const { return m_customUserAgent; }
    199205
    200206    double estimatedProgress() const { return m_estimatedProgress; }
    201 
    202     void setCustomUserAgent(const String&);
    203207
    204208    void terminateProcess();
     
    398402#endif
    399403
     404    static String standardUserAgent(const String& applicationName = String());
     405
    400406    PageClient* m_pageClient;
    401407    WebLoaderClient m_loaderClient;
     
    413419    String m_pageTitle;
    414420
     421    String m_userAgent;
     422    String m_applicationNameForUserAgent;
    415423    String m_customUserAgent;
    416424
  • trunk/WebKit2/WebKit2.pro

    r73986 r74000  
    546546    UIProcess/qt/WebContextQt.cpp \
    547547    UIProcess/qt/WebInspectorProxyQt.cpp \
     548    UIProcess/qt/WebPageProxyQt.cpp \
    548549    UIProcess/qt/WebPopupMenuProxyQt.cpp \
    549550    UIProcess/qt/WebPreferencesQt.cpp \
  • trunk/WebKit2/WebKit2.xcodeproj/project.pbxproj

    r73986 r74000  
    440440                BC8452A81162C80900CAB9B5 /* DrawingArea.h in Headers */ = {isa = PBXBuildFile; fileRef = BC8452A61162C80900CAB9B5 /* DrawingArea.h */; };
    441441                BC84EB1812A7100C0083F2DA /* WebPreferencesMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = BC84EB1712A7100C0083F2DA /* WebPreferencesMac.mm */; };
     442                BC857E8712B71EBB00EDEB2E /* WebPageProxyMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = BC857E8512B71EBB00EDEB2E /* WebPageProxyMac.mm */; };
    442443                BC8699B5116AADAA002A925B /* WKView.h in Headers */ = {isa = PBXBuildFile; fileRef = BC8699B2116AADAA002A925B /* WKView.h */; settings = {ATTRIBUTES = (Public, ); }; };
    443444                BC8699B6116AADAA002A925B /* WKView.mm in Sources */ = {isa = PBXBuildFile; fileRef = BC8699B3116AADAA002A925B /* WKView.mm */; };
     
    10861087                BC8452A61162C80900CAB9B5 /* DrawingArea.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DrawingArea.h; sourceTree = "<group>"; };
    10871088                BC84EB1712A7100C0083F2DA /* WebPreferencesMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebPreferencesMac.mm; sourceTree = "<group>"; };
     1089                BC857E8512B71EBB00EDEB2E /* WebPageProxyMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebPageProxyMac.mm; sourceTree = "<group>"; };
    10881090                BC8699B2116AADAA002A925B /* WKView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKView.h; sourceTree = "<group>"; };
    10891091                BC8699B3116AADAA002A925B /* WKView.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKView.mm; sourceTree = "<group>"; };
     
    22502252                                51ACBB9F127A8F2C00D203B9 /* WebContextMenuProxyMac.mm */,
    22512253                                1CA8B935127C774E00576C2B /* WebInspectorProxyMac.mm */,
     2254                                BC857E8512B71EBB00EDEB2E /* WebPageProxyMac.mm */,
    22522255                                BC5750951268F3C6006F0F12 /* WebPopupMenuProxyMac.h */,
    22532256                                BC5750961268F3C6006F0F12 /* WebPopupMenuProxyMac.mm */,
     
    31033106                                F62A76B612B1B25F0005F1B6 /* WebDatabaseManagerMessageReceiver.cpp in Sources */,
    31043107                                F62A76B812B1B25F0005F1B6 /* WebDatabaseManagerProxyMessageReceiver.cpp in Sources */,
     3108                                BC857E8712B71EBB00EDEB2E /* WebPageProxyMac.mm in Sources */,
    31053109                        );
    31063110                        runOnlyForDeploymentPostprocessing = 0;
  • trunk/WebKit2/WebProcess/WebPage/WebPage.cpp

    r73803 r74000  
    160160    setDrawsTransparentBackground(parameters.drawsTransparentBackground);
    161161
     162    m_userAgent = parameters.userAgent;
     163
    162164#ifndef NDEBUG
    163165    webPageCounter.increment();
     
    861863}
    862864
    863 void WebPage::setCustomUserAgent(const String& customUserAgent)
    864 {
    865     m_customUserAgent = customUserAgent;
    866 }
    867 
    868 String WebPage::userAgent() const
    869 {
    870     if (!m_customUserAgent.isEmpty())
    871         return m_customUserAgent;
    872 
    873     // FIXME: This should be based on an application name.
    874     return "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6; en-us) AppleWebKit/531.4 (KHTML, like Gecko) Version/4.0.3 Safari/531.4";
     865void WebPage::setUserAgent(const String& userAgent)
     866{
     867    m_userAgent = userAgent;
    875868}
    876869
  • trunk/WebKit2/WebProcess/WebPage/WebPage.h

    r73803 r74000  
    127127#endif
    128128    void show();
    129     String userAgent() const;
     129    String userAgent() const { return m_userAgent; }
    130130    WebCore::IntRect windowResizerRect() const;
    131131    bool tabsToLinks() const { return m_tabToLinks; }
     
    302302
    303303    void didReceivePolicyDecision(uint64_t frameID, uint64_t listenerID, uint32_t policyAction, uint64_t downloadID);
    304     void setCustomUserAgent(const String&);
     304    void setUserAgent(const String&);
    305305
    306306#if PLATFORM(MAC)
     
    333333    RefPtr<WebPageGroupProxy> m_pageGroup;
    334334
    335     String m_customUserAgent;
     335    String m_userAgent;
    336336
    337337    WebCore::IntSize m_viewSize;
  • trunk/WebKit2/WebProcess/WebPage/WebPage.messages.in

    r73803 r74000  
    5858    PreferencesDidChange(WebKit::WebPreferencesStore store)
    5959
    60     SetCustomUserAgent(WTF::String customUserAgent)
     60    SetUserAgent(WTF::String userAgent)
    6161
    6262#if ENABLE(TILED_BACKING_STORE)
  • trunk/WebKit2/win/WebKit2.vcproj

    r73986 r74000  
    24672467                                </File>
    24682468                                <File
     2469                                        RelativePath="..\UIProcess\win\WebPageProxyWin.cpp"
     2470                                        >
     2471                                </File>
     2472                                <File
    24692473                                        RelativePath="..\UIProcess\win\WebPopupMenuProxyWin.cpp"
    24702474                                        >
Note: See TracChangeset for help on using the changeset viewer.