summaryrefslogtreecommitdiffstats
path: root/WebKit
diff options
context:
space:
mode:
authorAndrei Popescu <andreip@google.com>2010-01-14 19:19:31 +0000
committerAndrei Popescu <andreip@google.com>2010-01-15 20:05:20 +0000
commit488dcd54e257a3a18d92e5ec1897511dfb05482c (patch)
tree2b94289fcc32af6b379329f0d147a6e146e9496f /WebKit
parent3498801a958b3c41f61e136faad545d1ed71f9f6 (diff)
downloadexternal_webkit-488dcd54e257a3a18d92e5ec1897511dfb05482c.zip
external_webkit-488dcd54e257a3a18d92e5ec1897511dfb05482c.tar.gz
external_webkit-488dcd54e257a3a18d92e5ec1897511dfb05482c.tar.bz2
Add navigator.networkType to allow apps to detect the connection type.
The online event is fired when the networkType changes. Bug: 2368650
Diffstat (limited to 'WebKit')
-rw-r--r--WebKit/android/jni/JavaBridge.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/WebKit/android/jni/JavaBridge.cpp b/WebKit/android/jni/JavaBridge.cpp
index 049a7da..9e83d6a 100644
--- a/WebKit/android/jni/JavaBridge.cpp
+++ b/WebKit/android/jni/JavaBridge.cpp
@@ -27,8 +27,11 @@
#include <config.h>
#include <wtf/Platform.h>
+#include <wtf/StdLibExtras.h>
+#include "AtomicString.h"
#include "Cache.h"
+#include "Connection.h"
#include "CookieClient.h"
#include "JavaSharedClient.h"
#include "KeyGeneratorClient.h"
@@ -96,6 +99,7 @@ public:
static void SharedTimerFired(JNIEnv* env, jobject);
static void SetCacheSize(JNIEnv* env, jobject obj, jint bytes);
static void SetNetworkOnLine(JNIEnv* env, jobject obj, jboolean online);
+ static void SetNetworkType(JNIEnv* env, jobject obj, jstring type, jstring subtype);
static void SetDeferringTimers(JNIEnv* env, jobject obj, jboolean defer);
static void ServiceFuncPtrQueue(JNIEnv*);
static void UpdatePluginDirectories(JNIEnv* env, jobject obj, jobjectArray array, jboolean reload);
@@ -344,6 +348,29 @@ void JavaBridge::SetNetworkOnLine(JNIEnv* env, jobject obj, jboolean online)
WebCore::networkStateNotifier().networkStateChange(online);
}
+void JavaBridge::SetNetworkType(JNIEnv* env, jobject obj, jstring javatype, jstring javasubtype)
+{
+ DEFINE_STATIC_LOCAL(AtomicString, wifi, ("wifi"));
+ DEFINE_STATIC_LOCAL(AtomicString, mobile, ("mobile"));
+ DEFINE_STATIC_LOCAL(AtomicString, mobileSupl, ("mobile_supl"));
+ DEFINE_STATIC_LOCAL(AtomicString, gprs, ("gprs"));
+ DEFINE_STATIC_LOCAL(AtomicString, edge, ("edge"));
+ DEFINE_STATIC_LOCAL(AtomicString, umts, ("umts"));
+
+ String type = to_string(env, javatype);
+ String subtype = to_string(env, javasubtype);
+ Connection::ConnectionType connectionType = Connection::Unknown;
+ if (type == wifi)
+ connectionType = Connection::WiFi;
+ else if (type == mobile || type == mobileSupl) {
+ if (subtype == edge || subtype == gprs)
+ connectionType = Connection::Cell_2G;
+ else if (subtype == umts)
+ connectionType = Connection::Cell_3G;
+ }
+ WebCore::networkStateNotifier().networkTypeChange(connectionType);
+}
+
void JavaBridge::ServiceFuncPtrQueue(JNIEnv*)
{
JavaSharedClient::ServiceFunctionPtrQueue();
@@ -383,6 +410,8 @@ static JNINativeMethod gWebCoreJavaBridgeMethods[] = {
(void*) JavaBridge::SetCacheSize },
{ "setNetworkOnLine", "(Z)V",
(void*) JavaBridge::SetNetworkOnLine },
+ { "setNetworkType", "(Ljava/lang/String;Ljava/lang/String;)V",
+ (void*) JavaBridge::SetNetworkType },
{ "nativeServiceFuncPtrQueue", "()V",
(void*) JavaBridge::ServiceFuncPtrQueue },
{ "nativeUpdatePluginDirectories", "([Ljava/lang/String;Z)V",