summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKristian Monsen <kristianm@google.com>2011-05-09 16:04:34 +0100
committerKristian Monsen <kristianm@google.com>2011-05-10 14:13:16 +0100
commitcbb59db7ee1743fdd147c5cbdb179870bf08f849 (patch)
tree30d6f84984f578395311b96883ce1042b7624e66
parent2f6a27f69d079f14858f9d6b38227b53d54bffca (diff)
downloadframeworks_base-cbb59db7ee1743fdd147c5cbdb179870bf08f849.zip
frameworks_base-cbb59db7ee1743fdd147c5cbdb179870bf08f849.tar.gz
frameworks_base-cbb59db7ee1743fdd147c5cbdb179870bf08f849.tar.bz2
Enable platform notifications for chrome http stack
Change-Id: I386aef25010c95b15fb6a8edc96e59e538540306
-rw-r--r--core/java/android/webkit/JniUtil.java6
-rw-r--r--core/java/android/webkit/WebView.java47
2 files changed, 44 insertions, 9 deletions
diff --git a/core/java/android/webkit/JniUtil.java b/core/java/android/webkit/JniUtil.java
index 62b415c..b5d4933 100644
--- a/core/java/android/webkit/JniUtil.java
+++ b/core/java/android/webkit/JniUtil.java
@@ -48,6 +48,12 @@ class JniUtil {
initialized = true;
}
+ protected static synchronized Context getContext() {
+ if (!initialized)
+ return null;
+ return sContext;
+ }
+
/**
* Called by JNI. Gets the application's database directory, excluding the trailing slash.
* @return String The application's database directory
diff --git a/core/java/android/webkit/WebView.java b/core/java/android/webkit/WebView.java
index 0504532..7a0c3a0 100644
--- a/core/java/android/webkit/WebView.java
+++ b/core/java/android/webkit/WebView.java
@@ -822,6 +822,8 @@ public class WebView extends AbsoluteLayout
private WebViewCore.AutoFillData mAutoFillData;
+ private static boolean sNotificationsEnabled = true;
+
/**
* URI scheme for telephone number
*/
@@ -1024,24 +1026,38 @@ public class WebView extends AbsoluteLayout
}
/*
- * A variable to track if there is a receiver added for PROXY_CHANGE_ACTION
+ * Receiver for PROXY_CHANGE_ACTION, will be null when it is not added handling broadcasts.
*/
- private static boolean sProxyReceiverAdded;
+ private static ProxyReceiver sProxyReceiver;
+ /*
+ * @param context This method expects this to be a valid context
+ */
private static synchronized void setupProxyListener(Context context) {
- if (sProxyReceiverAdded) {
+ if (sProxyReceiver != null || sNotificationsEnabled == false) {
return;
}
IntentFilter filter = new IntentFilter();
filter.addAction(Proxy.PROXY_CHANGE_ACTION);
+ sProxyReceiver = new ProxyReceiver();
Intent currentProxy = context.getApplicationContext().registerReceiver(
- new ProxyReceiver(), filter);
- sProxyReceiverAdded = true;
+ sProxyReceiver, filter);
if (currentProxy != null) {
handleProxyBroadcast(currentProxy);
}
}
+ /*
+ * @param context This method expects this to be a valid context
+ */
+ private static synchronized void disableProxyListener(Context context) {
+ if (sProxyReceiver == null)
+ return;
+
+ context.getApplicationContext().unregisterReceiver(sProxyReceiver);
+ sProxyReceiver = null;
+ }
+
private static void handleProxyBroadcast(Intent intent) {
ProxyProperties proxyProperties = (ProxyProperties)intent.getExtra(Proxy.EXTRA_PROXY_INFO);
if (proxyProperties == null || proxyProperties.getHost() == null) {
@@ -1530,19 +1546,32 @@ public class WebView extends AbsoluteLayout
/**
* Enables platform notifications of data state and proxy changes.
+ * Notifications are enabled by default.
*/
public static void enablePlatformNotifications() {
checkThread();
- Network.enablePlatformNotifications();
+ synchronized (WebView.class) {
+ Network.enablePlatformNotifications();
+ sNotificationsEnabled = true;
+ Context context = JniUtil.getContext();
+ if (context != null)
+ setupProxyListener(context);
+ }
}
/**
- * If platform notifications are enabled, this should be called
- * from the Activity's onPause() or onStop().
+ * Disables platform notifications of data state and proxy changes.
+ * Notifications are enabled by default.
*/
public static void disablePlatformNotifications() {
checkThread();
- Network.disablePlatformNotifications();
+ synchronized (WebView.class) {
+ Network.disablePlatformNotifications();
+ sNotificationsEnabled = false;
+ Context context = JniUtil.getContext();
+ if (context != null)
+ disableProxyListener(context);
+ }
}
/**