diff options
author | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-07 00:32:22 +0000 |
---|---|---|
committer | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-07 00:32:22 +0000 |
commit | f7bbda81940376c6b64e0c3dc8ed189788d3a72e (patch) | |
tree | 4b01caf08b4187ddc4c8e06f27cbab6a76863bac | |
parent | 0e09059564a1ff139b1c65e5e54773f5782375ee (diff) | |
download | chromium_src-f7bbda81940376c6b64e0c3dc8ed189788d3a72e.zip chromium_src-f7bbda81940376c6b64e0c3dc8ed189788d3a72e.tar.gz chromium_src-f7bbda81940376c6b64e0c3dc8ed189788d3a72e.tar.bz2 |
Implement user consent InfoBar for screen capturing.
Support for screen capturing using getUserMedia() was added
in r180502 (behind a flag), but there were no notifications
to let the user know that the screen is being captured. This
CL dds InfoBar that is shown whenever a page requests screen
capturing and lets the user approve or deny the request.
BUG=134249
TBR=brettw@chromium.org (gypi changes)
Review URL: https://chromiumcodereview.appspot.com/12022024
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@181112 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/app/generated_resources.grd | 3 | ||||
-rw-r--r-- | chrome/browser/api/infobars/infobar_delegate.cc | 5 | ||||
-rw-r--r-- | chrome/browser/api/infobars/infobar_delegate.h | 2 | ||||
-rw-r--r-- | chrome/browser/media/media_stream_devices_controller.cc | 15 | ||||
-rw-r--r-- | chrome/browser/media/media_stream_devices_controller.h | 1 | ||||
-rw-r--r-- | chrome/browser/ui/browser.cc | 14 | ||||
-rw-r--r-- | chrome/browser/ui/screen_capture_infobar_delegate.cc | 102 | ||||
-rw-r--r-- | chrome/browser/ui/screen_capture_infobar_delegate.h | 49 | ||||
-rw-r--r-- | chrome/chrome_browser_ui.gypi | 2 |
9 files changed, 176 insertions, 17 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd index dd49078..f22f1e9 100644 --- a/chrome/app/generated_resources.grd +++ b/chrome/app/generated_resources.grd @@ -15367,6 +15367,9 @@ Some features may be unavailable. Please check that the profile exists and you <message name="IDS_MEDIA_CAPTURE_VIDEO" desc="Label for a camera element in a device list."> Camera: <ph name="DEVICE_NAME">$1<ex>Built-in camera</ex></ph> </message> + <message name="IDS_MEDIA_CAPTURE_SCREEN" desc="Text on the info bar that's shown when screen capturing is requrested by the tab."> + <ph name="HOST">$1<ex>html5rocks.com</ex></ph> wants to capture the content of your screen. + </message> <message name="IDS_MEDIA_CAPTURE_ALLOW" desc="Label for a button that grants access to a web page, so they can use a camera and/or a microphone."> Allow </message> diff --git a/chrome/browser/api/infobars/infobar_delegate.cc b/chrome/browser/api/infobars/infobar_delegate.cc index c0bf61d..ff49dc1 100644 --- a/chrome/browser/api/infobars/infobar_delegate.cc +++ b/chrome/browser/api/infobars/infobar_delegate.cc @@ -73,6 +73,11 @@ RegisterProtocolHandlerInfoBarDelegate* return NULL; } +ScreenCaptureInfoBarDelegate* + InfoBarDelegate::AsScreenCaptureInfoBarDelegate() { + return NULL; +} + ThemeInstalledInfoBarDelegate* InfoBarDelegate::AsThemePreviewInfobarDelegate() { return NULL; diff --git a/chrome/browser/api/infobars/infobar_delegate.h b/chrome/browser/api/infobars/infobar_delegate.h index 185bda8..a743b0c 100644 --- a/chrome/browser/api/infobars/infobar_delegate.h +++ b/chrome/browser/api/infobars/infobar_delegate.h @@ -20,6 +20,7 @@ class MediaStreamInfoBarDelegate; class PluginInstallerInfoBarDelegate; class RegisterProtocolHandlerInfoBarDelegate; class SavePasswordInfoBarDelegate; +class ScreenCaptureInfoBarDelegate; class ThemeInstalledInfoBarDelegate; class ThreeDAPIInfoBarDelegate; class TranslateInfoBarDelegate; @@ -100,6 +101,7 @@ class InfoBarDelegate { virtual MediaStreamInfoBarDelegate* AsMediaStreamInfoBarDelegate(); virtual RegisterProtocolHandlerInfoBarDelegate* AsRegisterProtocolHandlerInfoBarDelegate(); + virtual ScreenCaptureInfoBarDelegate* AsScreenCaptureInfoBarDelegate(); virtual ThemeInstalledInfoBarDelegate* AsThemePreviewInfobarDelegate(); virtual ThreeDAPIInfoBarDelegate* AsThreeDAPIInfoBarDelegate(); virtual TranslateInfoBarDelegate* AsTranslateInfoBarDelegate(); diff --git a/chrome/browser/media/media_stream_devices_controller.cc b/chrome/browser/media/media_stream_devices_controller.cc index f9262ec..e07b7cc 100644 --- a/chrome/browser/media/media_stream_devices_controller.cc +++ b/chrome/browser/media/media_stream_devices_controller.cc @@ -48,9 +48,7 @@ MediaStreamDevicesController::MediaStreamDevicesController( microphone_requested_( request.audio_type == content::MEDIA_DEVICE_AUDIO_CAPTURE), webcam_requested_( - request.video_type == content::MEDIA_DEVICE_VIDEO_CAPTURE), - screen_capture_requested_( - request.video_type == content::MEDIA_SCREEN_VIDEO_CAPTURE) { + request.video_type == content::MEDIA_DEVICE_VIDEO_CAPTURE) { // Don't call GetDevicePolicy from the initializer list since the // implementation depends on member variables. if (microphone_requested_ && @@ -164,14 +162,6 @@ void MediaStreamDevicesController::Accept(bool update_content_setting) { SetPermission(true); } - if (screen_capture_requested_ && - CommandLine::ForCurrentProcess()->HasSwitch( - switches::kEnableUserMediaScreenCapturing)) { - // Add screen capturer source if it was requested. - devices.push_back(content::MediaStreamDevice( - content::MEDIA_SCREEN_VIDEO_CAPTURE, "", "Screen")); - } - callback_.Run(devices); } @@ -234,9 +224,6 @@ bool MediaStreamDevicesController::IsRequestAllowedByDefault() const { // settings allow the request by default. } - // TODO(sergeyu): Add content setting and UI notifications for screen - // capturing and use them when screen_capture_requested_==true. - return true; } diff --git a/chrome/browser/media/media_stream_devices_controller.h b/chrome/browser/media/media_stream_devices_controller.h index 0b8fa7b..4139a42 100644 --- a/chrome/browser/media/media_stream_devices_controller.h +++ b/chrome/browser/media/media_stream_devices_controller.h @@ -93,7 +93,6 @@ class MediaStreamDevicesController { bool microphone_requested_; bool webcam_requested_; - bool screen_capture_requested_; DISALLOW_COPY_AND_ASSIGN(MediaStreamDevicesController); }; diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc index 071d8bd..e81eebc 100644 --- a/chrome/browser/ui/browser.cc +++ b/chrome/browser/ui/browser.cc @@ -62,7 +62,6 @@ #include "chrome/browser/intents/web_intents_reporting.h" #include "chrome/browser/intents/web_intents_util.h" #include "chrome/browser/lifetime/application_lifetime.h" -#include "chrome/browser/media/media_stream_devices_controller.h" #include "chrome/browser/net/url_fixer_upper.h" #include "chrome/browser/notifications/notification_ui_manager.h" #include "chrome/browser/pepper_broker_infobar_delegate.h" @@ -120,6 +119,7 @@ #include "chrome/browser/ui/intents/web_intent_picker_controller.h" #include "chrome/browser/ui/media_stream_infobar_delegate.h" #include "chrome/browser/ui/omnibox/location_bar.h" +#include "chrome/browser/ui/screen_capture_infobar_delegate.h" #include "chrome/browser/ui/search/search.h" #include "chrome/browser/ui/search/search_delegate.h" #include "chrome/browser/ui/search/search_model.h" @@ -1688,7 +1688,17 @@ void Browser::RequestMediaAccessPermission( content::WebContents* web_contents, const content::MediaStreamRequest& request, const content::MediaResponseCallback& callback) { - MediaStreamInfoBarDelegate::Create(web_contents, request, callback); + // The case when microphone access is requested together with screen capturing + // is not supported yet. Just check requested video type to decide which + // infobar to show. + // + // TODO(sergeyu): Add support for video stream with microphone, e.g. refactor + // MediaStreamDevicesController to use a single infobar for both permissions, + // or maybe show two infobars. + if (request.video_type == content::MEDIA_SCREEN_VIDEO_CAPTURE) + ScreenCaptureInfoBarDelegate::Create(web_contents, request, callback); + else + MediaStreamInfoBarDelegate::Create(web_contents, request, callback); } bool Browser::RequestPpapiBrokerPermission( diff --git a/chrome/browser/ui/screen_capture_infobar_delegate.cc b/chrome/browser/ui/screen_capture_infobar_delegate.cc new file mode 100644 index 0000000..da44c94 --- /dev/null +++ b/chrome/browser/ui/screen_capture_infobar_delegate.cc @@ -0,0 +1,102 @@ +// Copyright (c) 2013 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 "chrome/browser/ui/screen_capture_infobar_delegate.h" + +#include "base/command_line.h" +#include "base/utf_string_conversions.h" +#include "chrome/browser/api/infobars/infobar_service.h" +#include "chrome/common/chrome_switches.h" +#include "grit/generated_resources.h" +#include "ui/base/l10n/l10n_util.h" + +// static +void ScreenCaptureInfoBarDelegate::Create( + content::WebContents* web_contents, + const content::MediaStreamRequest& request, + const content::MediaResponseCallback& callback) { + bool screen_capture_enabled = CommandLine::ForCurrentProcess()->HasSwitch( + switches::kEnableUserMediaScreenCapturing); + // Deny request automatically in the following cases: + // 1. Screen capturing is not enabled via command line switch. + // 2. Audio capture was requested (it's not supported yet). + // 3. Request from a page that was not loaded from a secure origin. + if (!screen_capture_enabled || + request.audio_type != content::MEDIA_NO_SERVICE || + !request.security_origin.SchemeIsSecure()) { + callback.Run(content::MediaStreamDevices()); + return; + } + + InfoBarService* infobar_service = + InfoBarService::FromWebContents(web_contents); + infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( + new ScreenCaptureInfoBarDelegate(infobar_service, request, callback))); +} + +ScreenCaptureInfoBarDelegate::ScreenCaptureInfoBarDelegate( + InfoBarService* infobar_service, + const content::MediaStreamRequest& request, + const content::MediaResponseCallback& callback) + : ConfirmInfoBarDelegate(infobar_service), + request_(request), + callback_(callback) { + DCHECK_EQ(content::MEDIA_SCREEN_VIDEO_CAPTURE, request.video_type); +} + +ScreenCaptureInfoBarDelegate::~ScreenCaptureInfoBarDelegate() { +} + +// Needed to avoid having more than one infobar with the same request. +bool ScreenCaptureInfoBarDelegate::EqualsDelegate( + InfoBarDelegate* delegate) const { + ScreenCaptureInfoBarDelegate* other = + delegate->AsScreenCaptureInfoBarDelegate(); + return other && other->request_.security_origin == request_.security_origin; +} + +void ScreenCaptureInfoBarDelegate::InfoBarDismissed() { + Deny(); +} + +InfoBarDelegate::Type ScreenCaptureInfoBarDelegate::GetInfoBarType() const { + return PAGE_ACTION_TYPE; +} + +ScreenCaptureInfoBarDelegate* + ScreenCaptureInfoBarDelegate::AsScreenCaptureInfoBarDelegate() { + return this; +} + +string16 ScreenCaptureInfoBarDelegate::GetMessageText() const { + return l10n_util::GetStringFUTF16( + IDS_MEDIA_CAPTURE_SCREEN, + UTF8ToUTF16(request_.security_origin.spec())); +} + +string16 ScreenCaptureInfoBarDelegate::GetButtonLabel( + InfoBarButton button) const { + return l10n_util::GetStringUTF16((button == BUTTON_OK) ? + IDS_MEDIA_CAPTURE_ALLOW : IDS_MEDIA_CAPTURE_DENY); +} + +bool ScreenCaptureInfoBarDelegate::Accept() { + content::MediaStreamDevices devices; + + // Add screen capturer source if it was requested. + devices.push_back(content::MediaStreamDevice( + content::MEDIA_SCREEN_VIDEO_CAPTURE, std::string(), "Screen")); + + callback_.Run(devices); + return true; +} + +bool ScreenCaptureInfoBarDelegate::Cancel() { + Deny(); + return true; +} + +void ScreenCaptureInfoBarDelegate::Deny() { + callback_.Run(content::MediaStreamDevices()); +} diff --git a/chrome/browser/ui/screen_capture_infobar_delegate.h b/chrome/browser/ui/screen_capture_infobar_delegate.h new file mode 100644 index 0000000..de091d4 --- /dev/null +++ b/chrome/browser/ui/screen_capture_infobar_delegate.h @@ -0,0 +1,49 @@ +// Copyright (c) 2013 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 CHROME_BROWSER_UI_SCREEN_CAPTURE_INFOBAR_DELEGATE_H_ +#define CHROME_BROWSER_UI_SCREEN_CAPTURE_INFOBAR_DELEGATE_H_ + +#include "base/compiler_specific.h" +#include "chrome/browser/api/infobars/confirm_infobar_delegate.h" +#include "content/public/browser/web_contents_delegate.h" +#include "content/public/common/media_stream_request.h" + +class InfoBarService; + +class ScreenCaptureInfoBarDelegate : public ConfirmInfoBarDelegate { + public: + static void Create( + content::WebContents* web_contents, + const content::MediaStreamRequest& request, + const content::MediaResponseCallback& callback); + + virtual ~ScreenCaptureInfoBarDelegate(); + + private: + ScreenCaptureInfoBarDelegate( + InfoBarService* infobar_service, + const content::MediaStreamRequest& request, + const content::MediaResponseCallback& callback); + + // Base class: ConfirmInfoBarDelegate. + virtual bool EqualsDelegate(InfoBarDelegate* delegate) const OVERRIDE; + virtual void InfoBarDismissed() OVERRIDE; + virtual Type GetInfoBarType() const OVERRIDE; + virtual ScreenCaptureInfoBarDelegate* + AsScreenCaptureInfoBarDelegate() OVERRIDE; + virtual string16 GetMessageText() const OVERRIDE; + virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; + virtual bool Accept() OVERRIDE; + virtual bool Cancel() OVERRIDE; + + void Deny(); + + const content::MediaStreamRequest request_; + const content::MediaResponseCallback callback_; + + DISALLOW_COPY_AND_ASSIGN(ScreenCaptureInfoBarDelegate); +}; + +#endif // CHROME_BROWSER_UI_SCREEN_CAPTURE_INFOBAR_DELEGATE_H_ diff --git a/chrome/chrome_browser_ui.gypi b/chrome/chrome_browser_ui.gypi index 103a458..2e99746 100644 --- a/chrome/chrome_browser_ui.gypi +++ b/chrome/chrome_browser_ui.gypi @@ -1248,6 +1248,8 @@ 'browser/ui/sad_tab_helper.cc', 'browser/ui/sad_tab_helper.h', 'browser/ui/sad_tab_types.h', + 'browser/ui/screen_capture_infobar_delegate.cc', + 'browser/ui/screen_capture_infobar_delegate.h', 'browser/ui/search/other_device_menu_controller.cc', 'browser/ui/search/other_device_menu_controller.h', 'browser/ui/search/search.cc', |