Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1673)

Unified Diff: android_webview/java/src/org/chromium/android_webview/permission/AwGeolocationCallback.java

Issue 1277563002: Cherry-pick: Deny the geolocation permission request by default. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2454
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: android_webview/java/src/org/chromium/android_webview/permission/AwGeolocationCallback.java
diff --git a/android_webview/java/src/org/chromium/android_webview/permission/AwGeolocationCallback.java b/android_webview/java/src/org/chromium/android_webview/permission/AwGeolocationCallback.java
new file mode 100644
index 0000000000000000000000000000000000000000..ef084f7c2807aa21a3bba30b58e67af804debbfb
--- /dev/null
+++ b/android_webview/java/src/org/chromium/android_webview/permission/AwGeolocationCallback.java
@@ -0,0 +1,76 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.android_webview.permission;
+
+import android.webkit.GeolocationPermissions;
+
+import org.chromium.android_webview.AwContents;
+import org.chromium.base.Log;
+import org.chromium.base.ThreadUtils;
+import org.chromium.content.common.CleanupReference;
+
+import java.lang.ref.WeakReference;
+
+/**
+ * This class implements GeolocationPermissions.Callback, and will be sent to
+ * WebView applications through WebChromeClient.onGeolocationPermissionsShowPrompt().
+ */
+public class AwGeolocationCallback implements GeolocationPermissions.Callback {
+ private static final String TAG = "cr.Geolocation";
+
+ private CleanupRunable mCleanupRunable;
+ private CleanupReference mCleanupReference;
+
+ private static class CleanupRunable implements Runnable {
+ private WeakReference<AwContents> mAwContents;
+ private boolean mAllow;
+ private boolean mRetain;
+ private String mOrigin;
+
+ public CleanupRunable(AwContents awContents, String origin) {
+ mAwContents = new WeakReference<AwContents>(awContents);
+ mOrigin = origin;
+ }
+
+ @Override
+ public void run() {
+ assert ThreadUtils.runningOnUiThread();
+ AwContents awContents = mAwContents.get();
+ if (awContents == null) return;
+ if (mRetain) {
+ if (mAllow) {
+ awContents.getGeolocationPermissions().allow(mOrigin);
+ } else {
+ awContents.getGeolocationPermissions().deny(mOrigin);
+ }
+ }
+ awContents.invokeGeolocationCallback(mAllow, mOrigin);
+ }
+
+ public void setResponse(String origin, boolean allow, boolean retain) {
+ mOrigin = origin;
+ mAllow = allow;
+ mRetain = retain;
+ }
+ }
+
+ public AwGeolocationCallback(String origin, AwContents awContents) {
+ mCleanupRunable = new CleanupRunable(awContents, origin);
+ mCleanupReference = new CleanupReference(this, mCleanupRunable);
+ }
+
+ @Override
+ public void invoke(String origin, boolean allow, boolean retain) {
+ if (mCleanupRunable == null || mCleanupReference == null) {
+ Log.w(TAG, "Response for this geolocation request has been received."
+ + " Ignoring subsequent responses");
+ return;
+ }
+ mCleanupRunable.setResponse(origin, allow, retain);
+ mCleanupReference.cleanupNow();
+ mCleanupReference = null;
+ mCleanupRunable = null;
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698