diff options
author | grunell <grunell@chromium.org> | 2014-09-17 17:09:43 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-09-18 00:09:55 +0000 |
commit | 657d4d8c7d26c89c0846479ac322931bfaba4f86 (patch) | |
tree | 2a853ed570eb321b1f0a77fc8afe656a0f0e0210 /extensions | |
parent | ee83dcef7d2552d2221ac5be9f8ac831942ba670 (diff) | |
download | chromium_src-657d4d8c7d26c89c0846479ac322931bfaba4f86.zip chromium_src-657d4d8c7d26c89c0846479ac322931bfaba4f86.tar.gz chromium_src-657d4d8c7d26c89c0846479ac322931bfaba4f86.tar.bz2 |
Check media permissions through RenderFrameHostDelegate.
* Add function CheckMediaAccessPermission on RenderFrameHostDelegate, WebContentsDelegate, classes implementing those and chain it to MediaCaptureDevicesDispatcher::CheckMediaAccessPermission through the different paths. (Essentially add this function side-by-side with RequestMediaAccessPermission.)
* Change MediaStreamManager to use this function for checking permission when determining if device labels should be visible.
BUG=406094
Review URL: https://codereview.chromium.org/562263002
Cr-Commit-Position: refs/heads/master@{#295379}
Diffstat (limited to 'extensions')
20 files changed, 133 insertions, 12 deletions
diff --git a/extensions/browser/app_window/app_delegate.h b/extensions/browser/app_window/app_delegate.h index 7b247af..2d5fa1d 100644 --- a/extensions/browser/app_window/app_delegate.h +++ b/extensions/browser/app_window/app_delegate.h @@ -63,6 +63,10 @@ class AppDelegate { const content::MediaStreamRequest& request, const content::MediaResponseCallback& callback, const Extension* extension) = 0; + virtual bool CheckMediaAccessPermission(content::WebContents* web_contents, + const GURL& security_origin, + content::MediaStreamType type, + const Extension* extension) = 0; virtual int PreferredIconSize() = 0; virtual gfx::ImageSkia GetAppDefaultIcon() = 0; diff --git a/extensions/browser/app_window/app_web_contents_helper.cc b/extensions/browser/app_window/app_web_contents_helper.cc index 54153ac..fb66479 100644 --- a/extensions/browser/app_window/app_web_contents_helper.cc +++ b/extensions/browser/app_window/app_web_contents_helper.cc @@ -97,6 +97,17 @@ void AppWebContentsHelper::RequestMediaAccessPermission( web_contents_, request, callback, extension); } +bool AppWebContentsHelper::CheckMediaAccessPermission( + const GURL& security_origin, + content::MediaStreamType type) const { + const Extension* extension = GetExtension(); + if (!extension) + return false; + + return app_delegate_->CheckMediaAccessPermission( + web_contents_, security_origin, type, extension); +} + const Extension* AppWebContentsHelper::GetExtension() const { return ExtensionRegistry::Get(browser_context_) ->enabled_extensions() diff --git a/extensions/browser/app_window/app_web_contents_helper.h b/extensions/browser/app_window/app_web_contents_helper.h index 3d17851..ea4f13e 100644 --- a/extensions/browser/app_window/app_web_contents_helper.h +++ b/extensions/browser/app_window/app_web_contents_helper.h @@ -48,6 +48,11 @@ class AppWebContentsHelper { const content::MediaStreamRequest& request, const content::MediaResponseCallback& callback) const; + // Checks permission to use the camera or microphone. See + // WebContentsDelegate. + bool CheckMediaAccessPermission(const GURL& security_origin, + content::MediaStreamType type) const; + private: const Extension* GetExtension() const; diff --git a/extensions/browser/app_window/app_window.cc b/extensions/browser/app_window/app_window.cc index 3218a24..1cc9ae2 100644 --- a/extensions/browser/app_window/app_window.cc +++ b/extensions/browser/app_window/app_window.cc @@ -346,6 +346,13 @@ void AppWindow::RequestMediaAccessPermission( helper_->RequestMediaAccessPermission(request, callback); } +bool AppWindow::CheckMediaAccessPermission(content::WebContents* web_contents, + const GURL& security_origin, + content::MediaStreamType type) { + DCHECK_EQ(AppWindow::web_contents(), web_contents); + return helper_->CheckMediaAccessPermission(security_origin, type); +} + WebContents* AppWindow::OpenURLFromTab(WebContents* source, const content::OpenURLParams& params) { DCHECK_EQ(web_contents(), source); diff --git a/extensions/browser/app_window/app_window.h b/extensions/browser/app_window/app_window.h index 7b84ed7..3cef2ed 100644 --- a/extensions/browser/app_window/app_window.h +++ b/extensions/browser/app_window/app_window.h @@ -382,6 +382,10 @@ class AppWindow : public content::WebContentsDelegate, content::WebContents* web_contents, const content::MediaStreamRequest& request, const content::MediaResponseCallback& callback) OVERRIDE; + virtual bool CheckMediaAccessPermission( + content::WebContents* web_contents, + const GURL& security_origin, + content::MediaStreamType type) OVERRIDE; virtual content::WebContents* OpenURLFromTab( content::WebContents* source, const content::OpenURLParams& params) OVERRIDE; diff --git a/extensions/browser/extension_host.cc b/extensions/browser/extension_host.cc index 2f0572e..3920e47 100644 --- a/extensions/browser/extension_host.cc +++ b/extensions/browser/extension_host.cc @@ -428,6 +428,14 @@ void ExtensionHost::RequestMediaAccessPermission( web_contents, request, callback, extension()); } +bool ExtensionHost::CheckMediaAccessPermission( + content::WebContents* web_contents, + const GURL& security_origin, + content::MediaStreamType type) { + return delegate_->CheckMediaAccessPermission( + web_contents, security_origin, type, extension()); +} + bool ExtensionHost::IsNeverVisible(content::WebContents* web_contents) { ViewType view_type = extensions::GetViewType(web_contents); return view_type == extensions::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE; diff --git a/extensions/browser/extension_host.h b/extensions/browser/extension_host.h index 24bd9ba..548e8f8 100644 --- a/extensions/browser/extension_host.h +++ b/extensions/browser/extension_host.h @@ -101,6 +101,10 @@ class ExtensionHost : public content::WebContentsDelegate, content::WebContents* web_contents, const content::MediaStreamRequest& request, const content::MediaResponseCallback& callback) OVERRIDE; + virtual bool CheckMediaAccessPermission( + content::WebContents* web_contents, + const GURL& security_origin, + content::MediaStreamType type) OVERRIDE; virtual bool IsNeverVisible(content::WebContents* web_contents) OVERRIDE; // content::NotificationObserver diff --git a/extensions/browser/extension_host_delegate.h b/extensions/browser/extension_host_delegate.h index 0bf52a4..b14580d 100644 --- a/extensions/browser/extension_host_delegate.h +++ b/extensions/browser/extension_host_delegate.h @@ -56,6 +56,14 @@ class ExtensionHostDelegate { const content::MediaStreamRequest& request, const content::MediaResponseCallback& callback, const Extension* extension) = 0; + + // Checks if we have permission to access the microphone or camera. Note that + // this does not query the user. |type| must be MEDIA_DEVICE_AUDIO_CAPTURE + // or MEDIA_DEVICE_VIDEO_CAPTURE. + virtual bool CheckMediaAccessPermission(content::WebContents* web_contents, + const GURL& security_origin, + content::MediaStreamType type, + const Extension* extension) = 0; }; } // namespace extensions diff --git a/extensions/browser/guest_view/web_view/web_view_guest.cc b/extensions/browser/guest_view/web_view/web_view_guest.cc index 0522514..bfc29f5 100644 --- a/extensions/browser/guest_view/web_view/web_view_guest.cc +++ b/extensions/browser/guest_view/web_view/web_view_guest.cc @@ -791,6 +791,13 @@ void WebViewGuest::RequestMediaAccessPermission( callback); } +bool WebViewGuest::CheckMediaAccessPermission(content::WebContents* source, + const GURL& security_origin, + content::MediaStreamType type) { + return web_view_permission_helper_->CheckMediaAccessPermission( + source, security_origin, type); +} + void WebViewGuest::CanDownload( content::RenderViewHost* render_view_host, const GURL& url, diff --git a/extensions/browser/guest_view/web_view/web_view_guest.h b/extensions/browser/guest_view/web_view/web_view_guest.h index 926a67b..f593213 100644 --- a/extensions/browser/guest_view/web_view/web_view_guest.h +++ b/extensions/browser/guest_view/web_view/web_view_guest.h @@ -121,6 +121,10 @@ class WebViewGuest : public GuestView<WebViewGuest>, content::WebContents* source, const content::MediaStreamRequest& request, const content::MediaResponseCallback& callback) OVERRIDE; + virtual bool CheckMediaAccessPermission( + content::WebContents* source, + const GURL& security_origin, + content::MediaStreamType type) OVERRIDE; virtual void CanDownload(content::RenderViewHost* render_view_host, const GURL& url, const std::string& request_method, diff --git a/extensions/browser/guest_view/web_view/web_view_permission_helper.cc b/extensions/browser/guest_view/web_view/web_view_permission_helper.cc index 079282b..d713279 100644 --- a/extensions/browser/guest_view/web_view/web_view_permission_helper.cc +++ b/extensions/browser/guest_view/web_view/web_view_permission_helper.cc @@ -180,10 +180,18 @@ void WebViewPermissionHelper::RequestMediaAccessPermission( content::WebContents* source, const content::MediaStreamRequest& request, const content::MediaResponseCallback& callback) { - web_view_permission_helper_delegate_-> RequestMediaAccessPermission( + web_view_permission_helper_delegate_->RequestMediaAccessPermission( source, request, callback); } +bool WebViewPermissionHelper::CheckMediaAccessPermission( + content::WebContents* source, + const GURL& security_origin, + content::MediaStreamType type) { + return web_view_permission_helper_delegate_->CheckMediaAccessPermission( + source, security_origin, type); +} + void WebViewPermissionHelper::CanDownload( content::RenderViewHost* render_view_host, const GURL& url, diff --git a/extensions/browser/guest_view/web_view/web_view_permission_helper.h b/extensions/browser/guest_view/web_view/web_view_permission_helper.h index db9f1ab..8fb9037 100644 --- a/extensions/browser/guest_view/web_view/web_view_permission_helper.h +++ b/extensions/browser/guest_view/web_view/web_view_permission_helper.h @@ -60,6 +60,9 @@ class WebViewPermissionHelper content::WebContents* source, const content::MediaStreamRequest& request, const content::MediaResponseCallback& callback); + bool CheckMediaAccessPermission(content::WebContents* source, + const GURL& security_origin, + content::MediaStreamType type); void CanDownload(content::RenderViewHost* render_view_host, const GURL& url, const std::string& request_method, diff --git a/extensions/browser/guest_view/web_view/web_view_permission_helper_delegate.cc b/extensions/browser/guest_view/web_view/web_view_permission_helper_delegate.cc index 1ce7c28..4fbbef8 100644 --- a/extensions/browser/guest_view/web_view/web_view_permission_helper_delegate.cc +++ b/extensions/browser/guest_view/web_view/web_view_permission_helper_delegate.cc @@ -18,4 +18,12 @@ WebViewPermissionHelperDelegate::WebViewPermissionHelperDelegate( WebViewPermissionHelperDelegate::~WebViewPermissionHelperDelegate() { } +bool WebViewPermissionHelperDelegate::CheckMediaAccessPermission( + content::WebContents* source, + const GURL& security_origin, + content::MediaStreamType type) { + // Defensive default implementation for privacy reasons. + return false; +} + } // namespace extensions diff --git a/extensions/browser/guest_view/web_view/web_view_permission_helper_delegate.h b/extensions/browser/guest_view/web_view/web_view_permission_helper_delegate.h index b43b73a..d919105 100644 --- a/extensions/browser/guest_view/web_view/web_view_permission_helper_delegate.h +++ b/extensions/browser/guest_view/web_view/web_view_permission_helper_delegate.h @@ -25,6 +25,10 @@ class WebViewPermissionHelperDelegate : public content::WebContentsObserver { const content::MediaStreamRequest& request, const content::MediaResponseCallback& callback) {} + virtual bool CheckMediaAccessPermission(content::WebContents* source, + const GURL& security_origin, + content::MediaStreamType type); + virtual void CanDownload( content::RenderViewHost* render_view_host, const GURL& url, diff --git a/extensions/shell/browser/media_capture_util.cc b/extensions/shell/browser/media_capture_util.cc index 364e19d..30e3fb6 100644 --- a/extensions/shell/browser/media_capture_util.cc +++ b/extensions/shell/browser/media_capture_util.cc @@ -42,14 +42,9 @@ void GrantMediaStreamRequest(content::WebContents* web_contents, request.video_type == content::MEDIA_DEVICE_VIDEO_CAPTURE); MediaStreamDevices devices; - const PermissionsData* permissions_data = extension->permissions_data(); if (request.audio_type == content::MEDIA_DEVICE_AUDIO_CAPTURE) { - // app_shell has no UI surface to show an error, and on an embedded device - // it's better to crash than to have a feature not work. - CHECK(permissions_data->HasAPIPermission(APIPermission::kAudioCapture)) - << "Audio capture request but no audioCapture permission in manifest."; - + VerifyMediaAccessPermission(request.audio_type, extension); const MediaStreamDevice* device = GetRequestedDeviceOrDefault( MediaCaptureDevices::GetInstance()->GetAudioCaptureDevices(), request.requested_audio_device_id); @@ -58,10 +53,7 @@ void GrantMediaStreamRequest(content::WebContents* web_contents, } if (request.video_type == content::MEDIA_DEVICE_VIDEO_CAPTURE) { - // See APIPermission::kAudioCapture check above. - CHECK(permissions_data->HasAPIPermission(APIPermission::kVideoCapture)) - << "Video capture request but no videoCapture permission in manifest."; - + VerifyMediaAccessPermission(request.video_type, extension); const MediaStreamDevice* device = GetRequestedDeviceOrDefault( MediaCaptureDevices::GetInstance()->GetVideoCaptureDevices(), request.requested_video_device_id); @@ -77,5 +69,20 @@ void GrantMediaStreamRequest(content::WebContents* web_contents, ui.Pass()); } +void VerifyMediaAccessPermission(content::MediaStreamType type, + const Extension* extension) { + const PermissionsData* permissions_data = extension->permissions_data(); + if (type == content::MEDIA_DEVICE_AUDIO_CAPTURE) { + // app_shell has no UI surface to show an error, and on an embedded device + // it's better to crash than to have a feature not work. + CHECK(permissions_data->HasAPIPermission(APIPermission::kAudioCapture)) + << "Audio capture request but no audioCapture permission in manifest."; + } else { + DCHECK(type == content::MEDIA_DEVICE_VIDEO_CAPTURE); + CHECK(permissions_data->HasAPIPermission(APIPermission::kVideoCapture)) + << "Video capture request but no videoCapture permission in manifest."; + } +} + } // namespace media_capture_util } // namespace extensions diff --git a/extensions/shell/browser/media_capture_util.h b/extensions/shell/browser/media_capture_util.h index f254071..b1b15ba 100644 --- a/extensions/shell/browser/media_capture_util.h +++ b/extensions/shell/browser/media_capture_util.h @@ -28,6 +28,10 @@ void GrantMediaStreamRequest(content::WebContents* web_contents, const content::MediaResponseCallback& callback, const Extension* extension); +// Verifies that the extension has permission for |type|. If not, crash. +void VerifyMediaAccessPermission(content::MediaStreamType type, + const Extension* extension); + } // namespace media_capture_util } // namespace extensions diff --git a/extensions/shell/browser/shell_app_delegate.cc b/extensions/shell/browser/shell_app_delegate.cc index 4380d6a..483da67 100644 --- a/extensions/shell/browser/shell_app_delegate.cc +++ b/extensions/shell/browser/shell_app_delegate.cc @@ -62,6 +62,15 @@ void ShellAppDelegate::RequestMediaAccessPermission( web_contents, request, callback, extension); } +bool ShellAppDelegate::CheckMediaAccessPermission( + content::WebContents* web_contents, + const GURL& security_origin, + content::MediaStreamType type, + const Extension* extension) { + media_capture_util::VerifyMediaAccessPermission(type, extension); + return true; +} + int ShellAppDelegate::PreferredIconSize() { return extension_misc::EXTENSION_ICON_SMALL; } diff --git a/extensions/shell/browser/shell_app_delegate.h b/extensions/shell/browser/shell_app_delegate.h index 6e58e17..b842edb 100644 --- a/extensions/shell/browser/shell_app_delegate.h +++ b/extensions/shell/browser/shell_app_delegate.h @@ -40,6 +40,10 @@ class ShellAppDelegate : public AppDelegate { const content::MediaStreamRequest& request, const content::MediaResponseCallback& callback, const Extension* extension) OVERRIDE; + virtual bool CheckMediaAccessPermission(content::WebContents* web_contents, + const GURL& security_origin, + content::MediaStreamType type, + const Extension* extension) OVERRIDE; virtual int PreferredIconSize() OVERRIDE; virtual gfx::ImageSkia GetAppDefaultIcon() OVERRIDE; virtual void SetWebContentsBlocked(content::WebContents* web_contents, diff --git a/extensions/shell/browser/shell_extension_host_delegate.cc b/extensions/shell/browser/shell_extension_host_delegate.cc index 0053c64..a02d604 100644 --- a/extensions/shell/browser/shell_extension_host_delegate.cc +++ b/extensions/shell/browser/shell_extension_host_delegate.cc @@ -52,5 +52,13 @@ void ShellExtensionHostDelegate::ProcessMediaAccessRequest( web_contents, request, callback, extension); } -} // namespace extensions +bool ShellExtensionHostDelegate::CheckMediaAccessPermission( + content::WebContents* web_contents, + const GURL& security_origin, + content::MediaStreamType type, + const Extension* extension) { + media_capture_util::VerifyMediaAccessPermission(type, extension); + return true; +} +} // namespace extensions diff --git a/extensions/shell/browser/shell_extension_host_delegate.h b/extensions/shell/browser/shell_extension_host_delegate.h index 759a465..d7265f3 100644 --- a/extensions/shell/browser/shell_extension_host_delegate.h +++ b/extensions/shell/browser/shell_extension_host_delegate.h @@ -33,6 +33,10 @@ class ShellExtensionHostDelegate : public ExtensionHostDelegate { const content::MediaStreamRequest& request, const content::MediaResponseCallback& callback, const Extension* extension) OVERRIDE; + virtual bool CheckMediaAccessPermission(content::WebContents* web_contents, + const GURL& security_origin, + content::MediaStreamType type, + const Extension* extension) OVERRIDE; private: DISALLOW_COPY_AND_ASSIGN(ShellExtensionHostDelegate); |