diff options
author | fsamuel@chromium.org <fsamuel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-16 05:02:38 +0000 |
---|---|---|
committer | fsamuel@chromium.org <fsamuel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-16 05:02:38 +0000 |
commit | 922bd4ab867a05ddb6f3a3a6f3d0e8fe14d1696a (patch) | |
tree | 60d1ec1761b4009dabdfa154c57de6f2d036f430 | |
parent | e325a01b0a2914cdc208cea00758c26b3779c59a (diff) | |
download | chromium_src-922bd4ab867a05ddb6f3a3a6f3d0e8fe14d1696a.zip chromium_src-922bd4ab867a05ddb6f3a3a6f3d0e8fe14d1696a.tar.gz chromium_src-922bd4ab867a05ddb6f3a3a6f3d0e8fe14d1696a.tar.bz2 |
<webview>: Move download permission to chrome
BUG=330264
Review URL: https://codereview.chromium.org/235923003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@264117 0039d316-1c4b-4281-b951-d872f2087c98
9 files changed, 89 insertions, 49 deletions
diff --git a/chrome/browser/guestview/webview/webview_guest.cc b/chrome/browser/guestview/webview/webview_guest.cc index 9aef09d..6889074 100644 --- a/chrome/browser/guestview/webview/webview_guest.cc +++ b/chrome/browser/guestview/webview/webview_guest.cc @@ -77,8 +77,6 @@ static std::string TerminationStatusToString(base::TerminationStatus status) { static std::string PermissionTypeToString(BrowserPluginPermissionType type) { switch (type) { - case BROWSER_PLUGIN_PERMISSION_TYPE_DOWNLOAD: - return webview::kPermissionTypeDownload; case BROWSER_PLUGIN_PERMISSION_TYPE_NEW_WINDOW: return webview::kPermissionTypeNewWindow; case BROWSER_PLUGIN_PERMISSION_TYPE_POINTER_LOCK: @@ -91,6 +89,8 @@ static std::string PermissionTypeToString(BrowserPluginPermissionType type) { default: { WebViewPermissionType webview = static_cast<WebViewPermissionType>(type); switch (webview) { + case WEB_VIEW_PERMISSION_TYPE_DOWNLOAD: + return webview::kPermissionTypeDownload; case WEB_VIEW_PERMISSION_TYPE_GEOLOCATION: return webview::kPermissionTypeGeolocation; case WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN: @@ -193,10 +193,6 @@ void WebViewGuest::RecordUserInitiatedUMA(const PermissionResponseInfo& info, // scenario would be: an embedder allows geolocation request but doesn't // have geolocation access on its own. switch (info.permission_type) { - case BROWSER_PLUGIN_PERMISSION_TYPE_DOWNLOAD: - content::RecordAction( - UserMetricsAction("BrowserPlugin.PermissionAllow.Download")); - break; case BROWSER_PLUGIN_PERMISSION_TYPE_POINTER_LOCK: content::RecordAction( UserMetricsAction("BrowserPlugin.PermissionAllow.PointerLock")); @@ -226,6 +222,10 @@ void WebViewGuest::RecordUserInitiatedUMA(const PermissionResponseInfo& info, content::RecordAction( UserMetricsAction("WebView.PermissionAllow.Media")); break; + case WEB_VIEW_PERMISSION_TYPE_DOWNLOAD: + content::RecordAction( + UserMetricsAction("WebView.PermissionAllow.Download")); + break; default: break; } @@ -233,10 +233,6 @@ void WebViewGuest::RecordUserInitiatedUMA(const PermissionResponseInfo& info, } } else { switch (info.permission_type) { - case BROWSER_PLUGIN_PERMISSION_TYPE_DOWNLOAD: - content::RecordAction( - UserMetricsAction("BrowserPlugin.PermissionDeny.Download")); - break; case BROWSER_PLUGIN_PERMISSION_TYPE_POINTER_LOCK: content::RecordAction( UserMetricsAction("BrowserPlugin.PermissionDeny.PointerLock")); @@ -266,6 +262,10 @@ void WebViewGuest::RecordUserInitiatedUMA(const PermissionResponseInfo& info, content::RecordAction( UserMetricsAction("WebView.PermissionDeny.Media")); break; + case WEB_VIEW_PERMISSION_TYPE_DOWNLOAD: + content::RecordAction( + UserMetricsAction("WebView.PermissionDeny.Download")); + break; default: break; } @@ -609,6 +609,13 @@ void WebViewGuest::OnWebViewMediaPermissionResponse( RequestMediaAccessPermission(embedder_web_contents(), request, callback); } +void WebViewGuest::OnWebViewDownloadPermissionResponse( + const base::Callback<void(bool)>& callback, + bool allow, + const std::string& user_input) { + callback.Run(allow && attached()); +} + WebViewGuest::SetPermissionResult WebViewGuest::SetPermission( int request_id, PermissionResponseAction action, @@ -871,6 +878,24 @@ void WebViewGuest::RequestMediaAccessPermission( false /* allowed_by_default */); } +void WebViewGuest::CanDownload( + const std::string& request_method, + const GURL& url, + const base::Callback<void(bool)>& callback) { + base::DictionaryValue request_info; + request_info.Set( + guestview::kUrl, + base::Value::CreateStringValue(url.spec())); + RequestPermission( + static_cast<BrowserPluginPermissionType>( + WEB_VIEW_PERMISSION_TYPE_DOWNLOAD), + request_info, + base::Bind(&WebViewGuest::OnWebViewDownloadPermissionResponse, + base::Unretained(this), + callback), + false /* allowed_by_default */); +} + #if defined(OS_CHROMEOS) void WebViewGuest::OnAccessibilityStatusChanged( const chromeos::AccessibilityStatusEventDetails& details) { diff --git a/chrome/browser/guestview/webview/webview_guest.h b/chrome/browser/guestview/webview/webview_guest.h index 8561275..0a076b1 100644 --- a/chrome/browser/guestview/webview/webview_guest.h +++ b/chrome/browser/guestview/webview/webview_guest.h @@ -84,6 +84,9 @@ class WebViewGuest : public GuestView, virtual void RequestMediaAccessPermission( const content::MediaStreamRequest& request, const content::MediaResponseCallback& callback) OVERRIDE; + virtual void CanDownload(const std::string& request_method, + const GURL& url, + const base::Callback<void(bool)>& callback) OVERRIDE; // NotificationObserver implementation. virtual void Observe(int type, @@ -132,6 +135,11 @@ class WebViewGuest : public GuestView, bool allow, const std::string& user_input); + void OnWebViewDownloadPermissionResponse( + const base::Callback<void(bool)>& callback, + bool allow, + const std::string& user_input); + enum PermissionResponseAction { DENY, ALLOW, diff --git a/chrome/browser/guestview/webview/webview_permission_types.h b/chrome/browser/guestview/webview/webview_permission_types.h index c9421a1..053c9b8 100644 --- a/chrome/browser/guestview/webview/webview_permission_types.h +++ b/chrome/browser/guestview/webview/webview_permission_types.h @@ -15,6 +15,8 @@ enum WebViewPermissionType { // Media access (audio/video) permission request type. WEB_VIEW_PERMISSION_TYPE_MEDIA, + + WEB_VIEW_PERMISSION_TYPE_DOWNLOAD }; #endif // CHROME_BROWSER_GUESTVIEW_WEBVIEW_WEBVIEW_PERMISSION_TYPES_H_ diff --git a/content/browser/browser_plugin/browser_plugin_guest.cc b/content/browser/browser_plugin/browser_plugin_guest.cc index fa639dc..c397642 100644 --- a/content/browser/browser_plugin/browser_plugin_guest.cc +++ b/content/browser/browser_plugin/browser_plugin_guest.cc @@ -88,25 +88,6 @@ class BrowserPluginGuest::PermissionRequest : base::WeakPtr<BrowserPluginGuest> guest_; }; -class BrowserPluginGuest::DownloadRequest : public PermissionRequest { - public: - DownloadRequest(const base::WeakPtr<BrowserPluginGuest>& guest, - const base::Callback<void(bool)>& callback) - : PermissionRequest(guest), - callback_(callback) { - RecordAction( - base::UserMetricsAction("BrowserPlugin.Guest.PermissionRequest.Download")); - } - virtual void RespondImpl(bool should_allow, - const std::string& user_input) OVERRIDE { - callback_.Run(should_allow); - } - - private: - virtual ~DownloadRequest() {} - base::Callback<void(bool)> callback_; -}; - class BrowserPluginGuest::NewWindowRequest : public PermissionRequest { public: NewWindowRequest(const base::WeakPtr<BrowserPluginGuest>& guest, @@ -216,18 +197,17 @@ std::string JavaScriptMessageTypeToString(JavaScriptMessageType message_type) { } // Called on IO thread. -static std::string RetrieveDownloadURLFromRequestId( - RenderViewHost* render_view_host, +static GURL RetrieveDownloadURLFromRequestId( + int render_process_id, int url_request_id) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - int render_process_id = render_view_host->GetProcess()->GetID(); GlobalRequestID global_id(render_process_id, url_request_id); net::URLRequest* url_request = ResourceDispatcherHostImpl::Get()->GetURLRequest(global_id); if (url_request) - return url_request->url().possibly_invalid_spec(); - return ""; + return url_request->url(); + return GURL(); } } // namespace @@ -672,10 +652,15 @@ void BrowserPluginGuest::CanDownload( int request_id, const std::string& request_method, const base::Callback<void(bool)>& callback) { + if (!delegate_) { + callback.Run(false); + return; + } + BrowserThread::PostTaskAndReplyWithResult( BrowserThread::IO, FROM_HERE, base::Bind(&RetrieveDownloadURLFromRequestId, - render_view_host, request_id), + render_view_host->GetProcess()->GetID(), request_id), base::Bind(&BrowserPluginGuest::DidRetrieveDownloadURLFromRequestId, weak_ptr_factory_.GetWeakPtr(), request_method, @@ -1742,21 +1727,13 @@ void BrowserPluginGuest::OnImeCompositionRangeChanged( void BrowserPluginGuest::DidRetrieveDownloadURLFromRequestId( const std::string& request_method, const base::Callback<void(bool)>& callback, - const std::string& url) { - if (url.empty()) { + const GURL& url) { + if (!url.is_valid()) { callback.Run(false); return; } - base::DictionaryValue request_info; - request_info.Set(browser_plugin::kRequestMethod, - base::Value::CreateStringValue(request_method)); - request_info.Set(browser_plugin::kURL, base::Value::CreateStringValue(url)); - - RequestPermission(BROWSER_PLUGIN_PERMISSION_TYPE_DOWNLOAD, - new DownloadRequest(weak_ptr_factory_.GetWeakPtr(), - callback), - request_info); + delegate_->CanDownload(request_method, url, callback); } } // namespace content diff --git a/content/browser/browser_plugin/browser_plugin_guest.h b/content/browser/browser_plugin/browser_plugin_guest.h index a982e49..f3e3e5f 100644 --- a/content/browser/browser_plugin/browser_plugin_guest.h +++ b/content/browser/browser_plugin/browser_plugin_guest.h @@ -508,7 +508,7 @@ class CONTENT_EXPORT BrowserPluginGuest void DidRetrieveDownloadURLFromRequestId( const std::string& request_method, const base::Callback<void(bool)>& callback, - const std::string& url); + const GURL& url); // Forwards all messages from the |pending_messages_| queue to the embedder. void SendQueuedMessages(); diff --git a/content/public/browser/browser_plugin_guest_delegate.cc b/content/public/browser/browser_plugin_guest_delegate.cc index 820b243..d51d12a 100644 --- a/content/public/browser/browser_plugin_guest_delegate.cc +++ b/content/public/browser/browser_plugin_guest_delegate.cc @@ -33,4 +33,11 @@ void BrowserPluginGuestDelegate::RequestMediaAccessPermission( scoped_ptr<MediaStreamUI>()); } +void BrowserPluginGuestDelegate::CanDownload( + const std::string& request_method, + const GURL& url, + const base::Callback<void(bool)>& callback) { + callback.Run(true); +} + } // namespace content diff --git a/content/public/browser/browser_plugin_guest_delegate.h b/content/public/browser/browser_plugin_guest_delegate.h index b9de596..573658b 100644 --- a/content/public/browser/browser_plugin_guest_delegate.h +++ b/content/public/browser/browser_plugin_guest_delegate.h @@ -110,6 +110,11 @@ class CONTENT_EXPORT BrowserPluginGuestDelegate { const MediaStreamRequest& request, const MediaResponseCallback& callback); + // Asks the delegate if the given tab can download. + // Invoking the |callback| synchronously is OK. + virtual void CanDownload(const std::string& request_method, + const GURL& url, + const base::Callback<void(bool)>& callback); }; } // namespace content diff --git a/content/public/common/browser_plugin_permission_type.h b/content/public/common/browser_plugin_permission_type.h index d9584ae..9b487cd 100644 --- a/content/public/common/browser_plugin_permission_type.h +++ b/content/public/common/browser_plugin_permission_type.h @@ -9,8 +9,6 @@ enum BrowserPluginPermissionType { // Unknown type of permission request. BROWSER_PLUGIN_PERMISSION_TYPE_UNKNOWN, - BROWSER_PLUGIN_PERMISSION_TYPE_DOWNLOAD, - BROWSER_PLUGIN_PERMISSION_TYPE_POINTER_LOCK, // New window requests. diff --git a/tools/metrics/actions/actions.xml b/tools/metrics/actions/actions.xml index b876b99..12ae45e 100644 --- a/tools/metrics/actions/actions.xml +++ b/tools/metrics/actions/actions.xml @@ -1712,6 +1712,7 @@ should be able to be added at any place in this file. <action name="BrowserPlugin.PermissionAllow.Download"> <owner>Please list the metric's owners. Add more owner tags as needed.</owner> <description>Please enter the description of this user action.</description> + <obsolete>This permission has been moved to the chrome layer.</obsolete> </action> <action name="BrowserPlugin.PermissionAllow.Geolocation"> @@ -1744,6 +1745,7 @@ should be able to be added at any place in this file. <action name="BrowserPlugin.PermissionDeny.Download"> <owner>Please list the metric's owners. Add more owner tags as needed.</owner> <description>Please enter the description of this user action.</description> + <obsolete>This permission has been moved to the chrome layer.</obsolete> </action> <action name="BrowserPlugin.PermissionDeny.Geolocation"> @@ -10712,6 +10714,14 @@ should be able to be added at any place in this file. <description>Please enter the description of this user action.</description> </action> +<action name="WebView.PermissionAllow.Download"> + <owner>fsamuel@chromium.org</owner> + <owner>lazyboy@chromium.org</owner> + <description> + Tracks when the download permission is explicitly allowed on a webview. + </description> +</action> + <action name="WebView.PermissionAllow.Geolocation"> <owner>fsamuel@chromium.org</owner> <owner>lazyboy@chromium.org</owner> @@ -10728,6 +10738,14 @@ should be able to be added at any place in this file. </description> </action> +<action name="WebView.PermissionDeny.Download"> + <owner>fsamuel@chromium.org</owner> + <owner>lazyboy@chromium.org</owner> + <description> + Tracks when the download permission is explicitly denied on a webview. + </description> +</action> + <action name="WebView.PermissionDeny.Geolocation"> <owner>fsamuel@chromium.org</owner> <owner>lazyboy@chromium.org</owner> |