⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 232159 in webkit


Ignore:
Timestamp:
May 24, 2018, 12:23:15 PM (8 years ago)
Author:
Chris Dumez
Message:

Cache navigator.userAgent for performance
​https://bugs.webkit.org/show_bug.cgi?id=185952

Reviewed by Geoffrey Garen.

Cache navigator.userAgent for performance. Previously, we would ask the client 5 times
while loading apple.com.

  • page/Navigator.cpp:

(WebCore::Navigator::userAgent const):

  • page/Navigator.h:
  • page/NavigatorBase.h:
  • page/NavigatorID.idl:
  • page/WorkerNavigator.cpp:

(WebCore::WorkerNavigator::userAgent const):

  • page/WorkerNavigator.h:
Location:
trunk/Source/WebCore
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r232158 r232159  
     12018-05-24  Chris Dumez  <cdumez@apple.com>
     2
     3        Cache navigator.userAgent for performance
     4        https://bugs.webkit.org/show_bug.cgi?id=185952
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        Cache navigator.userAgent for performance. Previously, we would ask the client 5 times
     9        while loading apple.com.
     10
     11        * page/Navigator.cpp:
     12        (WebCore::Navigator::userAgent const):
     13        * page/Navigator.h:
     14        * page/NavigatorBase.h:
     15        * page/NavigatorID.idl:
     16        * page/WorkerNavigator.cpp:
     17        (WebCore::WorkerNavigator::userAgent const):
     18        * page/WorkerNavigator.h:
     19
    1202018-05-24  Chris Dumez  <cdumez@apple.com>
    221
  • trunk/Source/WebCore/page/Navigator.cpp

    r230007 r232159  
    7878}
    7979
    80 String Navigator::userAgent() const
     80const String& Navigator::userAgent() const
    8181{
    82     if (!m_frame)
    83         return String();
    84 
    85     // If the frame is already detached, FrameLoader::userAgent may malfunction, because it calls a client method
    86     // that uses frame's WebView (at least, in Mac WebKit).
    87     if (!m_frame->page())
    88         return String();
    89 
    90     return m_frame->loader().userAgent(m_frame->document()->url());
     82    if (m_userAgent.isNull() && m_frame && m_frame->page())
     83        m_userAgent = m_frame->loader().userAgent(m_frame->document()->url());
     84    return m_userAgent;
    9185}
    9286
  • trunk/Source/WebCore/page/Navigator.h

    r224321 r232159  
    4040    bool cookieEnabled() const;
    4141    bool javaEnabled() const;
    42     String userAgent() const final;
     42    const String& userAgent() const final;
    4343    bool onLine() const final;
    4444   
    … …  
    5454    mutable RefPtr<DOMPluginArray> m_plugins;
    5555    mutable RefPtr<DOMMimeTypeArray> m_mimeTypes;
     56    mutable String m_userAgent;
    5657};
    5758
  • trunk/Source/WebCore/page/NavigatorBase.h

    r227639 r232159  
    4343    static String appName();
    4444    String appVersion() const;
    45     virtual String userAgent() const = 0;
     45    virtual const String& userAgent() const = 0;
    4646    static String platform();
    4747
  • trunk/Source/WebCore/page/NavigatorID.idl

    r215403 r232159  
    3636    readonly attribute DOMString product;
    3737    [Exposed=Window] readonly attribute DOMString productSub;
    38     readonly attribute DOMString userAgent;
     38    [CachedAttribute] readonly attribute DOMString userAgent;
    3939    [Exposed=Window] readonly attribute DOMString vendor;
    4040    [Exposed=Window] readonly attribute DOMString vendorSub;
  • trunk/Source/WebCore/page/WorkerNavigator.cpp

    r224321 r232159  
    3737}
    3838
    39 String WorkerNavigator::userAgent() const
     39const String& WorkerNavigator::userAgent() const
    4040{
    4141    return m_userAgent;
  • trunk/Source/WebCore/page/WorkerNavigator.h

    r224321 r232159  
    3636    static Ref<WorkerNavigator> create(ScriptExecutionContext& context, const String& userAgent, bool isOnline) { return adoptRef(*new WorkerNavigator(context, userAgent, isOnline)); }
    3737
    38     String userAgent() const final;
     38    const String& userAgent() const final;
    3939    bool onLine() const final;
    4040    void setIsOnline(bool isOnline) { m_isOnline = isOnline; }
Note: See TracChangeset for help on using the changeset viewer.