diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-13 16:49:01 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-13 16:49:01 +0000 |
commit | 487974a82e46f4b716f4f893f3f47a9b0884611b (patch) | |
tree | 3cb49c41576cd8fea67ef4e1564bdf3830167f85 /android_webview | |
parent | ac592955fdf45e9bb3a8b8b8b462091faf0d631b (diff) | |
download | chromium_src-487974a82e46f4b716f4f893f3f47a9b0884611b.zip chromium_src-487974a82e46f4b716f4f893f3f47a9b0884611b.tar.gz chromium_src-487974a82e46f4b716f4f893f3f47a9b0884611b.tar.bz2 |
Simplify geolocation permission request in the Content API.
This is the model I used for notifications and will use for other features as they move from RenderView to RenderFrame.
BUG=304341
R=avi@chromium.org, mkosiba@chromium.org
Review URL: https://codereview.chromium.org/330143002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@277038 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'android_webview')
13 files changed, 72 insertions, 119 deletions
diff --git a/android_webview/browser/aw_browser_context.cc b/android_webview/browser/aw_browser_context.cc index 660e662..92df40b 100644 --- a/android_webview/browser/aw_browser_context.cc +++ b/android_webview/browser/aw_browser_context.cc @@ -300,15 +300,6 @@ AwBrowserContext::GetDownloadManagerDelegate() { return &download_manager_delegate_; } -content::GeolocationPermissionContext* -AwBrowserContext::GetGeolocationPermissionContext() { - if (!geolocation_permission_context_.get()) { - geolocation_permission_context_ = - native_factory_->CreateGeolocationPermission(this); - } - return geolocation_permission_context_.get(); -} - content::BrowserPluginGuestManager* AwBrowserContext::GetGuestManager() { return NULL; } diff --git a/android_webview/browser/aw_browser_context.h b/android_webview/browser/aw_browser_context.h index 63793c5..5e1e2f6 100644 --- a/android_webview/browser/aw_browser_context.h +++ b/android_webview/browser/aw_browser_context.h @@ -16,7 +16,6 @@ #include "components/visitedlink/browser/visitedlink_delegate.h" #include "content/public/browser/browser_context.h" #include "content/public/browser/content_browser_client.h" -#include "content/public/browser/geolocation_permission_context.h" #include "net/url_request/url_request_job_factory.h" class GURL; @@ -125,8 +124,6 @@ class AwBrowserContext : public content::BrowserContext, virtual content::ResourceContext* GetResourceContext() OVERRIDE; virtual content::DownloadManagerDelegate* GetDownloadManagerDelegate() OVERRIDE; - virtual content::GeolocationPermissionContext* - GetGeolocationPermissionContext() OVERRIDE; virtual content::BrowserPluginGuestManager* GetGuestManager() OVERRIDE; virtual quota::SpecialStoragePolicy* GetSpecialStoragePolicy() OVERRIDE; virtual content::PushMessagingService* GetPushMessagingService() OVERRIDE; @@ -144,8 +141,6 @@ class AwBrowserContext : public content::BrowserContext, JniDependencyFactory* native_factory_; scoped_refptr<net::CookieStore> cookie_store_; scoped_refptr<AwURLRequestContextGetter> url_request_context_getter_; - scoped_refptr<content::GeolocationPermissionContext> - geolocation_permission_context_; scoped_refptr<AwQuotaManagerBridge> quota_manager_bridge_; scoped_ptr<AwFormDatabaseService> form_database_service_; diff --git a/android_webview/browser/aw_content_browser_client.cc b/android_webview/browser/aw_content_browser_client.cc index 7c3dc65..bb48653 100644 --- a/android_webview/browser/aw_content_browser_client.cc +++ b/android_webview/browser/aw_content_browser_client.cc @@ -386,6 +386,25 @@ void AwContentBrowserClient::ShowDesktopNotification( NOTREACHED() << "Android WebView does not support desktop notifications."; } +void AwContentBrowserClient::RequestGeolocationPermission( + content::WebContents* web_contents, + int bridge_id, + const GURL& requesting_frame, + bool user_gesture, + base::Callback<void(bool)> result_callback, + base::Closure* cancel_callback) { + AwContentsClientBridgeBase* client = + AwContentsClientBridgeBase::FromWebContents(web_contents); + if (client) { + client->RequestGeolocationPermission( + web_contents, requesting_frame, result_callback, cancel_callback); + } else { + LOG(WARNING) << "Failed to find the associated bridge for geolocation " + << "permission request."; + result_callback.Run(false); + } +} + bool AwContentBrowserClient::CanCreateWindow( const GURL& opener_url, const GURL& opener_top_level_frame_url, diff --git a/android_webview/browser/aw_content_browser_client.h b/android_webview/browser/aw_content_browser_client.h index bf4abd2..bee7034 100644 --- a/android_webview/browser/aw_content_browser_client.h +++ b/android_webview/browser/aw_content_browser_client.h @@ -119,6 +119,13 @@ class AwContentBrowserClient : public content::ContentBrowserClient { content::RenderFrameHost* render_frame_host, content::DesktopNotificationDelegate* delegate, base::Closure* cancel_callback) OVERRIDE; + virtual void RequestGeolocationPermission( + content::WebContents* web_contents, + int bridge_id, + const GURL& requesting_frame, + bool user_gesture, + base::Callback<void(bool)> result_callback, + base::Closure* cancel_callback) OVERRIDE; virtual bool CanCreateWindow(const GURL& opener_url, const GURL& opener_top_level_frame_url, const GURL& source_origin, diff --git a/android_webview/browser/aw_contents_client_bridge_base.h b/android_webview/browser/aw_contents_client_bridge_base.h index a24aa4b..1ce1542 100644 --- a/android_webview/browser/aw_contents_client_bridge_base.h +++ b/android_webview/browser/aw_contents_client_bridge_base.h @@ -65,6 +65,12 @@ class AwContentsClientBridgeBase { = 0; virtual bool ShouldOverrideUrlLoading(const base::string16& url) = 0; + + virtual void RequestGeolocationPermission( + content::WebContents* web_contents, + const GURL& requesting_frame, + base::Callback<void(bool)> result_callback, + base::Closure* cancel_callback) = 0; }; } // namespace android_webview diff --git a/android_webview/browser/jni_dependency_factory.h b/android_webview/browser/jni_dependency_factory.h index d0b6f72..983ef2a 100644 --- a/android_webview/browser/jni_dependency_factory.h +++ b/android_webview/browser/jni_dependency_factory.h @@ -9,7 +9,6 @@ namespace content { class ExternalVideoSurfaceContainer; -class GeolocationPermissionContext; class WebContents; class WebContentsViewDelegate; } // namespace content @@ -27,8 +26,6 @@ class JniDependencyFactory { virtual scoped_refptr<AwQuotaManagerBridge> CreateAwQuotaManagerBridge( AwBrowserContext* browser_context) = 0; - virtual content::GeolocationPermissionContext* CreateGeolocationPermission( - AwBrowserContext* browser_context) = 0; virtual content::WebContentsViewDelegate* CreateViewDelegate( content::WebContents* web_contents) = 0; virtual AwWebPreferencesPopulater* CreateWebPreferencesPopulater() = 0; diff --git a/android_webview/lib/main/aw_main_delegate.cc b/android_webview/lib/main/aw_main_delegate.cc index 1acb2a6..9f6d91c 100644 --- a/android_webview/lib/main/aw_main_delegate.cc +++ b/android_webview/lib/main/aw_main_delegate.cc @@ -10,7 +10,6 @@ #include "android_webview/browser/scoped_allow_wait_for_legacy_web_view_api.h" #include "android_webview/common/aw_switches.h" #include "android_webview/lib/aw_browser_dependency_factory_impl.h" -#include "android_webview/native/aw_geolocation_permission_context.h" #include "android_webview/native/aw_quota_manager_bridge_impl.h" #include "android_webview/native/aw_web_contents_view_delegate.h" #include "android_webview/native/aw_web_preferences_populater_impl.h" @@ -148,12 +147,6 @@ scoped_refptr<AwQuotaManagerBridge> AwMainDelegate::CreateAwQuotaManagerBridge( return AwQuotaManagerBridgeImpl::Create(browser_context); } -content::GeolocationPermissionContext* - AwMainDelegate::CreateGeolocationPermission( - AwBrowserContext* browser_context) { - return AwGeolocationPermissionContext::Create(browser_context); -} - content::WebContentsViewDelegate* AwMainDelegate::CreateViewDelegate( content::WebContents* web_contents) { return AwWebContentsViewDelegate::Create(web_contents); diff --git a/android_webview/lib/main/aw_main_delegate.h b/android_webview/lib/main/aw_main_delegate.h index 93a116c..856d699 100644 --- a/android_webview/lib/main/aw_main_delegate.h +++ b/android_webview/lib/main/aw_main_delegate.h @@ -45,8 +45,6 @@ class AwMainDelegate : public content::ContentMainDelegate, // JniDependencyFactory implementation. virtual scoped_refptr<AwQuotaManagerBridge> CreateAwQuotaManagerBridge( AwBrowserContext* browser_context) OVERRIDE; - virtual content::GeolocationPermissionContext* CreateGeolocationPermission( - AwBrowserContext* browser_context) OVERRIDE; virtual content::WebContentsViewDelegate* CreateViewDelegate( content::WebContents* web_contents) OVERRIDE; virtual AwWebPreferencesPopulater* CreateWebPreferencesPopulater() OVERRIDE; diff --git a/android_webview/native/aw_contents_client_bridge.cc b/android_webview/native/aw_contents_client_bridge.cc index efb5a85..a241e40 100644 --- a/android_webview/native/aw_contents_client_bridge.cc +++ b/android_webview/native/aw_contents_client_bridge.cc @@ -5,11 +5,15 @@ #include "android_webview/native/aw_contents_client_bridge.h" #include "android_webview/common/devtools_instrumentation.h" +#include "android_webview/native/aw_contents.h" #include "base/android/jni_android.h" #include "base/android/jni_array.h" #include "base/android/jni_string.h" #include "base/callback_helpers.h" #include "content/public/browser/browser_thread.h" +#include "content/public/browser/render_process_host.h" +#include "content/public/browser/render_view_host.h" +#include "content/public/browser/web_contents.h" #include "jni/AwContentsClientBridge_jni.h" #include "net/android/keystore_openssl.h" #include "net/cert/x509_certificate.h" @@ -42,6 +46,15 @@ void RecordClientCertificateKey( client_cert.get(), private_key.get()); } +void CancelGeolocationPermission(int render_process_id, + int render_view_id, + const GURL& requesting_frame) { + AwContents* aw_contents = AwContents::FromID( + render_process_id, render_view_id); + if (aw_contents) + aw_contents->HideGeolocationPrompt(requesting_frame); +} + } // namespace AwContentsClientBridge::AwContentsClientBridge(JNIEnv* env, jobject obj) @@ -336,6 +349,28 @@ bool AwContentsClientBridge::ShouldOverrideUrlLoading( jurl.obj()); } +void AwContentsClientBridge::RequestGeolocationPermission( + content::WebContents* web_contents, + const GURL& requesting_frame, + base::Callback<void(bool)> result_callback, + base::Closure* cancel_callback) { + AwContents* aw_contents = AwContents::FromWebContents(web_contents); + if (!aw_contents) { + result_callback.Run(false); + return; + } + + if (cancel_callback) { + *cancel_callback = base::Bind( + CancelGeolocationPermission, + web_contents->GetRenderProcessHost()->GetID(), + web_contents->GetRenderViewHost()->GetRoutingID(), + requesting_frame); + } + + aw_contents->ShowGeolocationPrompt(requesting_frame, result_callback); +} + void AwContentsClientBridge::ConfirmJsResult(JNIEnv* env, jobject, int id, diff --git a/android_webview/native/aw_contents_client_bridge.h b/android_webview/native/aw_contents_client_bridge.h index 3c97f33..cb51ec1 100644 --- a/android_webview/native/aw_contents_client_bridge.h +++ b/android_webview/native/aw_contents_client_bridge.h @@ -55,6 +55,11 @@ class AwContentsClientBridge : public AwContentsClientBridgeBase { const content::JavaScriptDialogManager::DialogClosedCallback& callback) OVERRIDE; virtual bool ShouldOverrideUrlLoading(const base::string16& url) OVERRIDE; + virtual void RequestGeolocationPermission( + content::WebContents* web_contents, + const GURL& requesting_frame, + base::Callback<void(bool)> result_callback, + base::Closure* cancel_callback) OVERRIDE; // Methods called from Java. void ProceedSslError(JNIEnv* env, jobject obj, jboolean proceed, jint id); diff --git a/android_webview/native/aw_geolocation_permission_context.cc b/android_webview/native/aw_geolocation_permission_context.cc deleted file mode 100644 index 11d9140..0000000 --- a/android_webview/native/aw_geolocation_permission_context.cc +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright (c) 2012 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. - -#include "android_webview/native/aw_geolocation_permission_context.h" - -#include "android_webview/native/aw_contents.h" -#include "base/bind.h" -#include "base/callback.h" -#include "content/public/browser/browser_thread.h" -#include "content/public/browser/render_view_host.h" -#include "content/public/browser/web_contents.h" - -namespace android_webview { - -AwGeolocationPermissionContext::~AwGeolocationPermissionContext() { -} - -void AwGeolocationPermissionContext::RequestGeolocationPermission( - content::WebContents* web_contents, - int bridge_id, - const GURL& requesting_frame, - bool user_gesture, - base::Callback<void(bool)> callback) { - AwContents* aw_contents = AwContents::FromWebContents(web_contents); - if (!aw_contents) { - callback.Run(false); - return; - } - aw_contents->ShowGeolocationPrompt(requesting_frame, callback); -} - -// static -content::GeolocationPermissionContext* -AwGeolocationPermissionContext::Create(AwBrowserContext* browser_context) { - return new AwGeolocationPermissionContext(); -} - -void AwGeolocationPermissionContext::CancelGeolocationPermissionRequest( - content::WebContents* web_contents, - int bridge_id, - const GURL& requesting_frame) { - AwContents* aw_contents = AwContents::FromWebContents(web_contents); - if (aw_contents) { - aw_contents->HideGeolocationPrompt(requesting_frame); - } -} - -} // namespace android_webview diff --git a/android_webview/native/aw_geolocation_permission_context.h b/android_webview/native/aw_geolocation_permission_context.h deleted file mode 100644 index 2ad18a6..0000000 --- a/android_webview/native/aw_geolocation_permission_context.h +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright (c) 2012 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. - -#ifndef ANDROID_WEBVIEW_NATIVE_AW_GEOLOCATION_PERMISSION_CONTEXT_H_ -#define ANDROID_WEBVIEW_NATIVE_AW_GEOLOCATION_PERMISSION_CONTEXT_H_ - -#include "content/public/browser/geolocation_permission_context.h" - -class GURL; - -namespace android_webview { - -class AwBrowserContext; - -class AwGeolocationPermissionContext : - public content::GeolocationPermissionContext { - public: - static content::GeolocationPermissionContext* Create( - AwBrowserContext* browser_context); - - // content::GeolocationPermissionContext implementation - virtual void RequestGeolocationPermission( - content::WebContents* web_contents, - int bridge_id, - const GURL& requesting_frame, - bool user_gesture, - base::Callback<void(bool)> callback) OVERRIDE; - virtual void CancelGeolocationPermissionRequest( - content::WebContents* web_contents, - int bridge_id, - const GURL& requesting_frame) OVERRIDE; - - protected: - virtual ~AwGeolocationPermissionContext(); - - private: -}; - -} // namespace android_webview - -#endif // ANDROID_WEBVIEW_NATIVE_AW_GEOLOCATION_PERMISSION_CONTEXT_H_ diff --git a/android_webview/native/webview_native.gyp b/android_webview/native/webview_native.gyp index 67aa94e..48a2a40 100644 --- a/android_webview/native/webview_native.gyp +++ b/android_webview/native/webview_native.gyp @@ -52,8 +52,6 @@ 'aw_dev_tools_server.h', 'aw_form_database.cc', 'aw_form_database.h', - 'aw_geolocation_permission_context.cc', - 'aw_geolocation_permission_context.h', 'aw_http_auth_handler.cc', 'aw_http_auth_handler.h', 'aw_pdf_exporter.cc', |