.: [BlackBerry] Implementing the NetworkInfo API for BB port
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 3 Oct 2012 21:11:10 +0000 (21:11 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 3 Oct 2012 21:11:10 +0000 (21:11 +0000)
https://bugs.webkit.org/show_bug.cgi?id=98273

Patch by Otto Derek Cheung <otcheung@rim.com> on 2012-10-03
Reviewed by Rob Buis.

Adding references to new classes added to support BlackBerry's
NetworkInfo implementation.

* Source/cmake/OptionsBlackBerry.cmake:

Source/WebKit: [BlackBerry] Implementing the NetworkInfo API for BB port
https://bugs.webkit.org/show_bug.cgi?id=98273

Patch by Otto Derek Cheung <otcheung@rim.com> on 2012-10-03
Reviewed by Rob Buis.

Adding new classes to support NetworkInfo API in the
BlackBerry Port.

* PlatformBlackBerry.cmake:

Source/WebKit/blackberry: [BlackBerry] Implementing the NetworkInfo API for BB port
https://bugs.webkit.org/show_bug.cgi?id=98273

Patch by Otto Derek Cheung <otcheung@rim.com> on 2012-10-03
Reviewed by Rob Buis.

Adding new class NetworkInfoClientBlackBerry to implement
NetworkInfoClient for the BlackBerry port.

* Api/WebPage.cpp:
(BlackBerry::WebKit::WebPagePrivate::init):
* WebCoreSupport/NetworkInfoClientBlackBerry.cpp: Added.
(WebCore):
(WebCore::NetworkInfoClientBlackBerry::NetworkInfoClientBlackBerry):
(WebCore::NetworkInfoClientBlackBerry::startUpdating):
(WebCore::NetworkInfoClientBlackBerry::stopUpdating):
(WebCore::NetworkInfoClientBlackBerry::bandwidth):
(WebCore::NetworkInfoClientBlackBerry::metered):
(WebCore::NetworkInfoClientBlackBerry::onCurrentNetworkChange):
(WebCore::NetworkInfoClientBlackBerry::onCurrentCellularTypeChange):
* WebCoreSupport/NetworkInfoClientBlackBerry.h: Added.
(WebKit):
(WebCore):
(NetworkInfoClientBlackBerry):
(WebCore::NetworkInfoClientBlackBerry::~NetworkInfoClientBlackBerry):

Tools: [BlackBerry] Implementing the NetworkInfo API for BB port
https://bugs.webkit.org/show_bug.cgi?id=98273

Patch by Otto Derek Cheung <otcheung@rim.com> on 2012-10-03
Reviewed by Rob Buis.

Enabling NetworkInfo API for the BlackBerry port.

* Scripts/webkitperl/FeatureList.pm:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@130320 268f45cc-cd09-0410-ab3c-d52691b4dbfc

ChangeLog
Source/WebKit/ChangeLog
Source/WebKit/PlatformBlackBerry.cmake
Source/WebKit/blackberry/Api/WebPage.cpp
Source/WebKit/blackberry/ChangeLog
Source/WebKit/blackberry/WebCoreSupport/NetworkInfoClientBlackBerry.cpp [new file with mode: 0644]
Source/WebKit/blackberry/WebCoreSupport/NetworkInfoClientBlackBerry.h [new file with mode: 0644]
Source/cmake/OptionsBlackBerry.cmake
Tools/ChangeLog
Tools/Scripts/webkitperl/FeatureList.pm

index 7a42fa9..170a671 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2012-10-03  Otto Derek Cheung  <otcheung@rim.com>
+
+        [BlackBerry] Implementing the NetworkInfo API for BB port 
+        https://bugs.webkit.org/show_bug.cgi?id=98273
+
+        Reviewed by Rob Buis.
+
+        Adding references to new classes added to support BlackBerry's
+        NetworkInfo implementation.
+
+        * Source/cmake/OptionsBlackBerry.cmake:
+
 2012-10-01  Keishi Hattori  <keishi@webkit.org>
 
         Calendar picker should use zero as default step base
index fc77ecc..871bb59 100644 (file)
@@ -1,3 +1,15 @@
+2012-10-03  Otto Derek Cheung  <otcheung@rim.com>
+
+        [BlackBerry] Implementing the NetworkInfo API for BB port
+        https://bugs.webkit.org/show_bug.cgi?id=98273
+
+        Reviewed by Rob Buis.
+
+        Adding new classes to support NetworkInfo API in the
+        BlackBerry Port.
+
+        * PlatformBlackBerry.cmake:
+
 2012-10-02  Krzysztof Czech  <k.czech@samsung.com>
 
         [EFL] Add file EWKTestEnvironment.cpp to build system.
index 7fdb7ec..19f6f04 100644 (file)
@@ -17,6 +17,7 @@ LIST(APPEND WebKit_INCLUDE_DIRECTORIES
     "${WEBCORE_DIR}/platform/network/blackberry"
     "${WEBCORE_DIR}/Modules/geolocation"
     "${WEBCORE_DIR}/Modules/notifications"
+    "${WEBCORE_DIR}/Modules/networkinfo"
     "${WEBCORE_DIR}/Modules/vibration"
     "${WEBCORE_DIR}/Modules/websockets"
     "${WEBKIT_DIR}/blackberry/Api"
@@ -88,6 +89,7 @@ LIST(APPEND WebKit_SOURCES
     blackberry/WebCoreSupport/IconDatabaseClientBlackBerry.cpp
     blackberry/WebCoreSupport/InspectorClientBlackBerry.cpp
     blackberry/WebCoreSupport/JavaScriptDebuggerBlackBerry.cpp
+    blackberry/WebCoreSupport/NetworkInfoClientBlackBerry.cpp
     blackberry/WebCoreSupport/NotificationPresenterImpl.cpp
     blackberry/WebCoreSupport/VibrationClientBlackBerry.cpp
     blackberry/WebCoreSupport/PagePopupBlackBerry.cpp
index 7f7e6b7..933647b 100644 (file)
@@ -80,6 +80,9 @@
 #include "JavaScriptDebuggerBlackBerry.h"
 #include "JavaScriptVariant_p.h"
 #include "LayerWebKitThread.h"
+#if ENABLE(NETWORK_INFO)
+#include "NetworkInfoClientBlackBerry.h"
+#endif
 #include "NetworkManager.h"
 #include "NodeRenderStyle.h"
 #if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS)
@@ -548,6 +551,10 @@ void WebPagePrivate::init(const WebString& pageGroupName)
     WebCore::provideNotification(m_page, NotificationPresenterImpl::instance());
 #endif
 
+#if ENABLE(NETWORK_INFO)
+    WebCore::provideNetworkInfoTo(m_page, new WebCore::NetworkInfoClientBlackBerry(this));
+#endif
+
     m_page->setCustomHTMLTokenizerChunkSize(256);
     m_page->setCustomHTMLTokenizerTimeDelay(0.3);
 
index 773db1b..878a07b 100644 (file)
@@ -1,3 +1,30 @@
+2012-10-03  Otto Derek Cheung  <otcheung@rim.com>
+
+        [BlackBerry] Implementing the NetworkInfo API for BB port
+        https://bugs.webkit.org/show_bug.cgi?id=98273
+
+        Reviewed by Rob Buis.
+
+        Adding new class NetworkInfoClientBlackBerry to implement
+        NetworkInfoClient for the BlackBerry port.
+
+        * Api/WebPage.cpp:
+        (BlackBerry::WebKit::WebPagePrivate::init):
+        * WebCoreSupport/NetworkInfoClientBlackBerry.cpp: Added.
+        (WebCore):
+        (WebCore::NetworkInfoClientBlackBerry::NetworkInfoClientBlackBerry):
+        (WebCore::NetworkInfoClientBlackBerry::startUpdating):
+        (WebCore::NetworkInfoClientBlackBerry::stopUpdating):
+        (WebCore::NetworkInfoClientBlackBerry::bandwidth):
+        (WebCore::NetworkInfoClientBlackBerry::metered):
+        (WebCore::NetworkInfoClientBlackBerry::onCurrentNetworkChange):
+        (WebCore::NetworkInfoClientBlackBerry::onCurrentCellularTypeChange):
+        * WebCoreSupport/NetworkInfoClientBlackBerry.h: Added.
+        (WebKit):
+        (WebCore):
+        (NetworkInfoClientBlackBerry):
+        (WebCore::NetworkInfoClientBlackBerry::~NetworkInfoClientBlackBerry):
+
 2012-10-02  Anders Carlsson  <andersca@apple.com>
 
         Change most GraphicsLayer::create calls to use the version that takes a GraphicsLayerFactory
diff --git a/Source/WebKit/blackberry/WebCoreSupport/NetworkInfoClientBlackBerry.cpp b/Source/WebKit/blackberry/WebCoreSupport/NetworkInfoClientBlackBerry.cpp
new file mode 100644 (file)
index 0000000..f62e426
--- /dev/null
@@ -0,0 +1,114 @@
+/*
+ * Copyright (C) 2012 Research In Motion Limited. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "config.h"
+#include "NetworkInfoClientBlackBerry.h"
+
+#include "Event.h"
+#include "NetworkInfo.h"
+#include "WebPage_p.h"
+
+#include <math.h>
+
+namespace WebCore {
+
+static const double  networkSpeedNone = 0; // 0 Mb/s
+static const double  networkSpeedEthernet = 20; // 20 Mb/s
+static const double  networkSpeedWifi = 20; // 20 Mb/s
+static const double  networkSpeed2G = 60 / 1024; // 60 kb/s
+static const double  networkSpeed3G = 7; // 7 Mb/s
+static const double  networkSpeed4G = 50; // 50 Mb/s
+static const double  networkSpeedDefault = INFINITY; // w3c draft states it should be infinity
+
+NetworkInfoClientBlackBerry::NetworkInfoClientBlackBerry(BlackBerry::WebKit::WebPagePrivate* webPagePrivate)
+    : m_webPagePrivate(webPagePrivate)
+    , m_controller(0)
+    , m_isActive(false)
+{
+}
+
+void NetworkInfoClientBlackBerry::startUpdating()
+{
+    if (!m_isActive)
+        // Add ourselves to listener so our values get updated whenever PPS calls.
+        BlackBerry::Platform::NetworkInfo::instance()->addListener(this);
+    m_isActive = true;
+}
+
+void NetworkInfoClientBlackBerry::stopUpdating()
+{
+    if (m_isActive)
+        BlackBerry::Platform::NetworkInfo::instance()->removeListener(this);
+    m_isActive = false;
+}
+
+double NetworkInfoClientBlackBerry::bandwidth() const
+{
+    switch (BlackBerry::Platform::NetworkInfo::instance()->getCurrentNetworkType()) {
+    case BlackBerry::Platform::NetworkTypeWifi:
+        return networkSpeedWifi;
+    case BlackBerry::Platform::NetworkTypeCellular:
+        switch (BlackBerry::Platform::NetworkInfo::instance()->getCurrentCellularType()) {
+        case BlackBerry::Platform::CellularTypeEDGE:
+            return networkSpeed2G;
+        case BlackBerry::Platform::CellularTypeEVDO:
+        case BlackBerry::Platform::CellularTypeUMTS:
+            return networkSpeed3G;
+        case BlackBerry::Platform::CellularTypeLTE:
+            return networkSpeed4G;
+        case BlackBerry::Platform::CellularTypeUnknown:
+            return networkSpeedDefault;
+        }
+        break;
+    case BlackBerry::Platform::NetworkTypeWired:
+        return networkSpeedEthernet;
+    case BlackBerry::Platform::NetworkTypeNone:
+        return networkSpeedNone;
+    default:
+        break;
+    }
+
+    return networkSpeedDefault;
+}
+
+bool NetworkInfoClientBlackBerry::metered() const
+{
+    BlackBerry::Platform::InternalNetworkConnectionType cellType = BlackBerry::Platform::NetworkInfo::instance()->getCurrentNetworkType();
+    if (cellType == BlackBerry::Platform::NetworkTypeCellular || cellType == BlackBerry::Platform::NetworkTypeBB)
+        return true;
+    return false;
+}
+
+void NetworkInfoClientBlackBerry::onCurrentNetworkTypeChange(BlackBerry::Platform::InternalNetworkConnectionType newInternalNetworkType)
+{
+    if (m_isActive) {
+        RefPtr<NetworkInfo> newNetworkInfo = NetworkInfo::create(bandwidth(), metered());
+        NetworkInfoController::from(m_webPagePrivate->m_page)->didChangeNetworkInformation(eventNames().webkitnetworkinfochangeEvent , newNetworkInfo.get());
+    }
+}
+
+void NetworkInfoClientBlackBerry::onCurrentCellularTypeChange(BlackBerry::Platform::InternalCellularConnectionType newCellularType)
+{
+    // Only dispatch to listeners if the current type is cellular.
+    if (BlackBerry::Platform::NetworkInfo::instance()->getCurrentNetworkType() == BlackBerry::Platform::NetworkTypeCellular && m_isActive) {
+        RefPtr<NetworkInfo> newNetworkInfo = NetworkInfo::create(bandwidth(), metered());
+        NetworkInfoController::from(m_webPagePrivate->m_page)->didChangeNetworkInformation(eventNames().webkitnetworkinfochangeEvent , newNetworkInfo.get());
+    }
+}
+
+}
diff --git a/Source/WebKit/blackberry/WebCoreSupport/NetworkInfoClientBlackBerry.h b/Source/WebKit/blackberry/WebCoreSupport/NetworkInfoClientBlackBerry.h
new file mode 100644 (file)
index 0000000..c5b5dac
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2012 Research In Motion Limited. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef NetworkInfoClientBlackBerry_h
+#define NetworkInfoClientBlackBerry_h
+
+#include "NetworkInfoClient.h"
+#include "NetworkInfoController.h"
+
+#include <BlackBerryPlatformNetworkInfo.h>
+
+namespace BlackBerry {
+namespace WebKit {
+class WebPagePrivate;
+}
+}
+
+namespace WebCore {
+
+class NetworkInfoClientBlackBerry : public NetworkInfoClient, public BlackBerry::Platform::NetworkInfoListener {
+public:
+
+    NetworkInfoClientBlackBerry(BlackBerry::WebKit::WebPagePrivate*);
+    ~NetworkInfoClientBlackBerry() { }
+
+    void startUpdating();
+    void stopUpdating();
+    double bandwidth() const;
+    bool metered() const;
+
+    void onCurrentNetworkTypeChange(BlackBerry::Platform::InternalNetworkConnectionType newNetworkType);
+    void onCurrentCellularTypeChange(BlackBerry::Platform::InternalCellularConnectionType newCellularType);
+
+private:
+    BlackBerry::WebKit::WebPagePrivate* m_webPagePrivate;
+    NetworkInfoController* m_controller;
+    bool m_isActive;
+};
+}
+
+#endif
index 9685c02..d20579d 100644 (file)
@@ -155,6 +155,7 @@ WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_LLINT ON)
 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_MEDIA_STREAM ON)
 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_MICRODATA ON)
 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_NAVIGATOR_CONTENT_UTILS ON)
+WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_NETWORK_INFO ON)
 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_NOTIFICATIONS ON)
 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_ORIENTATION_EVENTS ON)
 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_PAGE_POPUP ON)
index 131cda0..8cda93c 100644 (file)
@@ -1,3 +1,14 @@
+2012-10-03  Otto Derek Cheung  <otcheung@rim.com>
+
+        [BlackBerry] Implementing the NetworkInfo API for BB port
+        https://bugs.webkit.org/show_bug.cgi?id=98273
+
+        Reviewed by Rob Buis.
+
+        Enabling NetworkInfo API for the BlackBerry port.
+
+        * Scripts/webkitperl/FeatureList.pm:
+
 2012-10-03  Anders Carlsson  <andersca@apple.com>
 
         Exception thrown when running accessibility/container-node-delete-causes-crash.html test
index 2e9a147..5bdf0d3 100644 (file)
@@ -332,7 +332,7 @@ my @features = (
       define => "ENABLE_NETSCAPE_PLUGIN_API", default => 1, value => \$netscapePluginAPISupport },
 
     { option => "network-info", desc => "Toggle Network Info support",
-      define => "ENABLE_NETWORK_INFO", default => isEfl(), value => \$networkInfoSupport },
+      define => "ENABLE_NETWORK_INFO", default => (isEfl() || isBlackBerry()), value => \$networkInfoSupport },
 
     { option => "notifications", desc => "Toggle Notifications support",
       define => "ENABLE_NOTIFICATIONS", default => isBlackBerry(), value => \$notificationsSupport },