Title: [111209] trunk/Source/WebKit/blackberry
Revision
111209
Author
[email protected]
Date
2012-03-19 11:36:25 -0700 (Mon, 19 Mar 2012)

Log Message

[BlackBerry] Use BlackBerry::Platform::DeviceInfo to generate UserAgent
https://bugs.webkit.org/show_bug.cgi?id=81269

Generate the UserAgent lazily, using it as the default for the
WebSettings object. BlackBerry::Platform::DeviceInfo is used
to ensure the information is accurate to the specific device.

Remove the !isEmpty() assert when fetching the UA from the
WebSettings object, as it will now always be properly initialized.

Add a static initializer block to ensure defaultUserAgent() is
thread-safe from that moment onward.

Patch by Mike Lattanzio <[email protected]> on 2012-03-19
Reviewed by Rob Buis.

* Api/WebPage.cpp:
(WebKit):
(BlackBerry::WebKit::WebPagePrivate::init):
(BlackBerry::WebKit::WebPagePrivate::defaultUserAgent):
* Api/WebPage_p.h:
(WebPagePrivate):
* Api/WebSettings.cpp:
(BlackBerry::WebKit::WebSettings::setUserAgentString):
* Api/WebSettings.h:

Modified Paths

Diff

Modified: trunk/Source/WebKit/blackberry/Api/WebPage.cpp (111208 => 111209)


--- trunk/Source/WebKit/blackberry/Api/WebPage.cpp	2012-03-19 18:33:20 UTC (rev 111208)
+++ trunk/Source/WebKit/blackberry/Api/WebPage.cpp	2012-03-19 18:36:25 UTC (rev 111209)
@@ -102,6 +102,7 @@
 #if ENABLE(WEBDOM)
 #include "WebDOMDocument.h"
 #endif
+#include "WebKitVersion.h"
 #include "WebPageClient.h"
 #include "WebSocket.h"
 #include "npapi.h"
@@ -122,6 +123,7 @@
 #include "WebPageCompositor_p.h"
 #endif
 
+#include <BlackBerryPlatformDeviceInfo.h>
 #include <BlackBerryPlatformExecutableMessage.h>
 #include <BlackBerryPlatformITPolicy.h>
 #include <BlackBerryPlatformKeyboardEvent.h>
@@ -335,6 +337,12 @@
     , m_hasInRegionScrollableAreas(false)
     , m_updateDelegatedOverlaysDispatched(false)
 {
+    static bool isInitialized = false;
+    if (!isInitialized) {
+        isInitialized = true;
+        BlackBerry::Platform::DeviceInfo::instance();
+        defaultUserAgent();
+    }
 }
 
 WebPage::WebPage(WebPageClient* client, const WebString& pageGroupName, const Platform::IntRect& rect)
@@ -447,6 +455,7 @@
     m_page->setCustomHTMLTokenizerTimeDelay(0.3);
 
     m_webSettings = WebSettings::createFromStandardSettings();
+    m_webSettings->setUserAgentString(defaultUserAgent());
 
     // FIXME: We explicitly call setDelegate() instead of passing ourself in createFromStandardSettings()
     // so that we only get one didChangeSettings() callback when we set the page group name. This causes us
@@ -5667,5 +5676,24 @@
     m_inPageSearchManager->frameUnloaded(frame);
 }
 
+const String& WebPagePrivate::defaultUserAgent()
+{
+    static String* defaultUserAgent = new String;
+    if (defaultUserAgent->isEmpty()) {
+        BlackBerry::Platform::DeviceInfo* info = BlackBerry::Platform::DeviceInfo::instance();
+        char uaBuffer[256];
+        int uaSize = snprintf(uaBuffer, 256, "Mozilla/5.0 (%s) AppleWebKit/%d.%d+ (KHTML, like Gecko) Version/%s %sSafari/%d.%d+",
+            info->family(), WEBKIT_MAJOR_VERSION, WEBKIT_MINOR_VERSION, info->osVersion(),
+            info->isMobile() ? "Mobile " : "", WEBKIT_MAJOR_VERSION, WEBKIT_MINOR_VERSION);
+
+        if (uaSize <= 0 || uaSize >= 256)
+            BLACKBERRY_CRASH();
+
+        defaultUserAgent->append(uaBuffer);
+    }
+
+    return *defaultUserAgent;
 }
+
 }
+}

Modified: trunk/Source/WebKit/blackberry/Api/WebPage_p.h (111208 => 111209)


--- trunk/Source/WebKit/blackberry/Api/WebPage_p.h	2012-03-19 18:33:20 UTC (rev 111208)
+++ trunk/Source/WebKit/blackberry/Api/WebPage_p.h	2012-03-19 18:36:25 UTC (rev 111209)
@@ -399,6 +399,7 @@
     static WebCore::RenderLayer* enclosingFixedPositionedAncestorOrSelfIfFixedPositioned(WebCore::RenderLayer*);
 
     static WebCore::IntSize defaultMaxLayoutSize();
+    static const String& defaultUserAgent();
 
     void setVisible(bool);
 #if ENABLE(PAGE_VISIBILITY_API)

Modified: trunk/Source/WebKit/blackberry/Api/WebSettings.cpp (111208 => 111209)


--- trunk/Source/WebKit/blackberry/Api/WebSettings.cpp	2012-03-19 18:33:20 UTC (rev 111208)
+++ trunk/Source/WebKit/blackberry/Api/WebSettings.cpp	2012-03-19 18:36:25 UTC (rev 111209)
@@ -396,17 +396,10 @@
 
 WebString WebSettings::userAgentString() const
 {
-    // FIXME: Is this the best place for this assertion. Why can't we just return an empty string
-    // and let the caller decide how to handle it?
-
-    // The default user agent string is empty. We rely upon the client to set this for us.
-    // We check this by asserting if the client has not done so before the first time it is needed.
-    String userAgentString = m_private->getString(BlackBerryUserAgentString);
-    ASSERT(!userAgentString.isEmpty());
-    return userAgentString;
+    return m_private->getString(BlackBerryUserAgentString);
 }
 
-void WebSettings::setUserAgentString(const char* userAgentString)
+void WebSettings::setUserAgentString(const WebString& userAgentString)
 {
     m_private->setString(BlackBerryUserAgentString, userAgentString);
 }

Modified: trunk/Source/WebKit/blackberry/Api/WebSettings.h (111208 => 111209)


--- trunk/Source/WebKit/blackberry/Api/WebSettings.h	2012-03-19 18:33:20 UTC (rev 111208)
+++ trunk/Source/WebKit/blackberry/Api/WebSettings.h	2012-03-19 18:36:25 UTC (rev 111209)
@@ -95,7 +95,7 @@
     bool downloadableBinaryFontsEnabled() const;
 
     WebString userAgentString() const;
-    void setUserAgentString(const char*);
+    void setUserAgentString(const WebString&);
 
     WebString defaultTextEncodingName() const;
     void setDefaultTextEncodingName(const char*);

Modified: trunk/Source/WebKit/blackberry/ChangeLog (111208 => 111209)


--- trunk/Source/WebKit/blackberry/ChangeLog	2012-03-19 18:33:20 UTC (rev 111208)
+++ trunk/Source/WebKit/blackberry/ChangeLog	2012-03-19 18:36:25 UTC (rev 111209)
@@ -1,3 +1,30 @@
+2012-03-19  Mike Lattanzio  <[email protected]>
+
+        [BlackBerry] Use BlackBerry::Platform::DeviceInfo to generate UserAgent
+        https://bugs.webkit.org/show_bug.cgi?id=81269
+
+        Generate the UserAgent lazily, using it as the default for the
+        WebSettings object. BlackBerry::Platform::DeviceInfo is used
+        to ensure the information is accurate to the specific device.
+
+        Remove the !isEmpty() assert when fetching the UA from the
+        WebSettings object, as it will now always be properly initialized.
+
+        Add a static initializer block to ensure defaultUserAgent() is
+        thread-safe from that moment onward.
+
+        Reviewed by Rob Buis.
+
+        * Api/WebPage.cpp:
+        (WebKit):
+        (BlackBerry::WebKit::WebPagePrivate::init):
+        (BlackBerry::WebKit::WebPagePrivate::defaultUserAgent):
+        * Api/WebPage_p.h:
+        (WebPagePrivate):
+        * Api/WebSettings.cpp:
+        (BlackBerry::WebKit::WebSettings::setUserAgentString):
+        * Api/WebSettings.h:
+
 2012-03-19  Mike Fenton  <[email protected]>
 
         [BlackBerry] Input fields with id of e-mail and url should be styled as such.
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to