| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package com.android.webview.chromium; | 5 package com.android.webview.chromium; |
| 6 | 6 |
| 7 import android.webkit.GeolocationPermissions; | 7 import android.webkit.GeolocationPermissions; |
| 8 import android.webkit.ValueCallback; | 8 import android.webkit.ValueCallback; |
| 9 | 9 |
| 10 import org.chromium.android_webview.AwGeolocationPermissions; | 10 import org.chromium.android_webview.AwGeolocationPermissions; |
| 11 import org.chromium.base.ThreadUtils; |
| 11 | 12 |
| 12 import java.util.Set; | 13 import java.util.Set; |
| 13 | 14 |
| 14 /** | 15 /** |
| 15 * Chromium implementation of GeolocationPermissions -- forwards calls to the | 16 * Chromium implementation of GeolocationPermissions -- forwards calls to the |
| 16 * chromium internal implementation. | 17 * chromium internal implementation. |
| 17 */ | 18 */ |
| 18 final class GeolocationPermissionsAdapter extends GeolocationPermissions { | 19 final class GeolocationPermissionsAdapter extends GeolocationPermissions { |
| 19 private AwGeolocationPermissions mChromeGeolocationPermissions; | 20 private final WebViewChromiumFactoryProvider mFactory; |
| 21 private final AwGeolocationPermissions mChromeGeolocationPermissions; |
| 20 | 22 |
| 21 public GeolocationPermissionsAdapter(AwGeolocationPermissions chromeGeolocat
ionPermissions) { | 23 public GeolocationPermissionsAdapter(WebViewChromiumFactoryProvider factory, |
| 24 AwGeolocationPermissions chromeGeolocationPermissions) { |
| 25 mFactory = factory; |
| 22 mChromeGeolocationPermissions = chromeGeolocationPermissions; | 26 mChromeGeolocationPermissions = chromeGeolocationPermissions; |
| 23 } | 27 } |
| 24 | 28 |
| 25 @Override | 29 @Override |
| 26 public void allow(String origin) { | 30 public void allow(final String origin) { |
| 31 if (checkNeedsPost()) { |
| 32 mFactory.addTask(new Runnable() { |
| 33 @Override |
| 34 public void run() { |
| 35 mChromeGeolocationPermissions.allow(origin); |
| 36 } |
| 37 |
| 38 }); |
| 39 return; |
| 40 } |
| 27 mChromeGeolocationPermissions.allow(origin); | 41 mChromeGeolocationPermissions.allow(origin); |
| 28 } | 42 } |
| 29 | 43 |
| 30 @Override | 44 @Override |
| 31 public void clear(String origin) { | 45 public void clear(final String origin) { |
| 46 if (checkNeedsPost()) { |
| 47 mFactory.addTask(new Runnable() { |
| 48 @Override |
| 49 public void run() { |
| 50 mChromeGeolocationPermissions.clear(origin); |
| 51 } |
| 52 |
| 53 }); |
| 54 return; |
| 55 } |
| 32 mChromeGeolocationPermissions.clear(origin); | 56 mChromeGeolocationPermissions.clear(origin); |
| 33 } | 57 } |
| 34 | 58 |
| 35 @Override | 59 @Override |
| 36 public void clearAll() { | 60 public void clearAll() { |
| 61 if (checkNeedsPost()) { |
| 62 mFactory.addTask(new Runnable() { |
| 63 @Override |
| 64 public void run() { |
| 65 mChromeGeolocationPermissions.clearAll(); |
| 66 } |
| 67 |
| 68 }); |
| 69 return; |
| 70 } |
| 37 mChromeGeolocationPermissions.clearAll(); | 71 mChromeGeolocationPermissions.clearAll(); |
| 38 } | 72 } |
| 39 | 73 |
| 40 @Override | 74 @Override |
| 41 public void getAllowed(String origin, ValueCallback<Boolean> callback) { | 75 public void getAllowed(final String origin, final ValueCallback<Boolean> cal
lback) { |
| 76 if (checkNeedsPost()) { |
| 77 mFactory.addTask(new Runnable() { |
| 78 @Override |
| 79 public void run() { |
| 80 mChromeGeolocationPermissions.getAllowed(origin, callback); |
| 81 } |
| 82 |
| 83 }); |
| 84 return; |
| 85 } |
| 42 mChromeGeolocationPermissions.getAllowed(origin, callback); | 86 mChromeGeolocationPermissions.getAllowed(origin, callback); |
| 43 } | 87 } |
| 44 | 88 |
| 45 @Override | 89 @Override |
| 46 public void getOrigins(ValueCallback<Set<String>> callback) { | 90 public void getOrigins(final ValueCallback<Set<String>> callback) { |
| 91 if (checkNeedsPost()) { |
| 92 mFactory.addTask(new Runnable() { |
| 93 @Override |
| 94 public void run() { |
| 95 mChromeGeolocationPermissions.getOrigins(callback); |
| 96 } |
| 97 |
| 98 }); |
| 99 return; |
| 100 } |
| 47 mChromeGeolocationPermissions.getOrigins(callback); | 101 mChromeGeolocationPermissions.getOrigins(callback); |
| 48 } | 102 } |
| 103 |
| 104 private static boolean checkNeedsPost() { |
| 105 // Init is guaranteed to have happened if a GeolocationPermissionsAdapte
r is created, so do |
| 106 // not need to check WebViewChromiumFactoryProvider.hasStarted. |
| 107 return !ThreadUtils.runningOnUiThread(); |
| 108 } |
| 49 } | 109 } |
| OLD | NEW |