Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(96)

Side by Side Diff: chrome/browser/media/media_capture_devices_dispatcher.cc

Issue 12843009: Replace screen capture confirmation infobar with a message box. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/media/media_capture_devices_dispatcher.h ('k') | chrome/browser/ui/browser.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "chrome/browser/media/media_capture_devices_dispatcher.h" 5 #include "chrome/browser/media/media_capture_devices_dispatcher.h"
6 6
7 #include "base/command_line.h"
8 #include "base/logging.h"
7 #include "base/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
10 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/media/audio_stream_indicator.h" 11 #include "chrome/browser/media/audio_stream_indicator.h"
9 #include "chrome/browser/media/media_stream_capture_indicator.h" 12 #include "chrome/browser/media/media_stream_capture_indicator.h"
10 #include "chrome/browser/prefs/scoped_user_pref_update.h" 13 #include "chrome/browser/prefs/scoped_user_pref_update.h"
11 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/ui/media_stream_infobar_delegate.h"
16 #include "chrome/browser/ui/simple_message_box.h"
17 #include "chrome/common/chrome_switches.h"
12 #include "chrome/common/pref_names.h" 18 #include "chrome/common/pref_names.h"
13 #include "components/user_prefs/pref_registry_syncable.h" 19 #include "components/user_prefs/pref_registry_syncable.h"
14 #include "content/public/browser/browser_thread.h" 20 #include "content/public/browser/browser_thread.h"
15 #include "content/public/browser/media_devices_monitor.h" 21 #include "content/public/browser/media_devices_monitor.h"
16 #include "content/public/common/media_stream_request.h" 22 #include "content/public/common/media_stream_request.h"
23 #include "grit/generated_resources.h"
24 #include "ui/base/l10n/l10n_util.h"
17 25
18 using content::BrowserThread; 26 using content::BrowserThread;
19 using content::MediaStreamDevices; 27 using content::MediaStreamDevices;
20 28
21 namespace { 29 namespace {
22 30
23 const content::MediaStreamDevice* FindDefaultDeviceWithId( 31 const content::MediaStreamDevice* FindDefaultDeviceWithId(
24 const content::MediaStreamDevices& devices, 32 const content::MediaStreamDevices& devices,
25 const std::string& device_id) { 33 const std::string& device_id) {
26 if (devices.empty()) 34 if (devices.empty())
27 return NULL; 35 return NULL;
28 36
29 content::MediaStreamDevices::const_iterator iter = devices.begin(); 37 content::MediaStreamDevices::const_iterator iter = devices.begin();
30 for (; iter != devices.end(); ++iter) { 38 for (; iter != devices.end(); ++iter) {
31 if (iter->id == device_id) { 39 if (iter->id == device_id) {
32 return &(*iter); 40 return &(*iter);
33 } 41 }
34 } 42 }
35 43
36 return &(*devices.begin()); 44 return &(*devices.begin());
37 }; 45 };
38 46
47 // This is a short-term solution to allow testing of the the Screen Capture API
48 // with Google Hangouts in M27.
49 // TODO(sergeyu): Remove this whitelist as soon as possible.
50 bool IsOriginWhitelistedForScreenCapture(const GURL& origin) {
51 #if defined(OFFICIAL_BUILD)
52 return origin.spec() == "https://staging.talkgadget.google.com/" ||
53 origin.spec() == "https://plus.google.com/";
54 #else
55 return false;
56 #endif
57 }
58
39 } // namespace 59 } // namespace
40 60
41
42 MediaCaptureDevicesDispatcher* MediaCaptureDevicesDispatcher::GetInstance() { 61 MediaCaptureDevicesDispatcher* MediaCaptureDevicesDispatcher::GetInstance() {
43 return Singleton<MediaCaptureDevicesDispatcher>::get(); 62 return Singleton<MediaCaptureDevicesDispatcher>::get();
44 } 63 }
45 64
46 MediaCaptureDevicesDispatcher::MediaCaptureDevicesDispatcher() 65 MediaCaptureDevicesDispatcher::MediaCaptureDevicesDispatcher()
47 : devices_enumerated_(false), 66 : devices_enumerated_(false),
48 media_stream_capture_indicator_(new MediaStreamCaptureIndicator()), 67 media_stream_capture_indicator_(new MediaStreamCaptureIndicator()),
49 audio_stream_indicator_(new AudioStreamIndicator()) {} 68 audio_stream_indicator_(new AudioStreamIndicator()) {}
50 69
51 MediaCaptureDevicesDispatcher::~MediaCaptureDevicesDispatcher() {} 70 MediaCaptureDevicesDispatcher::~MediaCaptureDevicesDispatcher() {}
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 107 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
89 if (!devices_enumerated_) { 108 if (!devices_enumerated_) {
90 BrowserThread::PostTask( 109 BrowserThread::PostTask(
91 BrowserThread::IO, FROM_HERE, 110 BrowserThread::IO, FROM_HERE,
92 base::Bind(&content::EnsureMonitorCaptureDevices)); 111 base::Bind(&content::EnsureMonitorCaptureDevices));
93 devices_enumerated_ = true; 112 devices_enumerated_ = true;
94 } 113 }
95 return video_devices_; 114 return video_devices_;
96 } 115 }
97 116
117 void MediaCaptureDevicesDispatcher::RequestAccess(
118 content::WebContents* web_contents,
119 const content::MediaStreamRequest& request,
120 const content::MediaResponseCallback& callback) {
121 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
122
123 // Handle regular media requests first.
124 if (request.video_type != content::MEDIA_SCREEN_VIDEO_CAPTURE) {
125 MediaStreamInfoBarDelegate::Create(web_contents, request, callback);
126 return;
127 }
128
129 content::MediaStreamDevices devices;
130
131 bool screen_capture_enabled = CommandLine::ForCurrentProcess()->HasSwitch(
Peter Kasting 2013/03/23 19:08:40 Nit: Just for readability you might want to break
Sergey Ulanov 2013/03/23 19:16:05 Done.
132 switches::kEnableUserMediaScreenCapturing) ||
133 IsOriginWhitelistedForScreenCapture(request.security_origin);
134 // Deny request automatically in the following cases:
135 // 1. Screen capturing is not enabled via command line switch.
136 // 2. Audio capture was requested (it's not supported yet).
137 // 3. Request from a page that was not loaded from a secure origin.
138 if (screen_capture_enabled &&
139 request.audio_type == content::MEDIA_NO_SERVICE &&
140 request.security_origin.SchemeIsSecure()) {
141 string16 application_name = UTF8ToUTF16(request.security_origin.spec());
142 chrome::MessageBoxResult result = chrome::ShowMessageBox(
143 NULL,
144 l10n_util::GetStringFUTF16(IDS_MEDIA_SCREEN_CAPTURE_CONFIRMATION_TITLE,
145 application_name),
146 l10n_util::GetStringFUTF16(IDS_MEDIA_SCREEN_CAPTURE_CONFIRMATION_TEXT,
147 application_name),
148 chrome::MESSAGE_BOX_TYPE_QUESTION);
149
Peter Kasting 2013/03/23 19:08:40 Nit: Extra blank line
Sergey Ulanov 2013/03/23 19:16:05 Done.
150 if (result == chrome::MESSAGE_BOX_RESULT_YES) {
151 devices.push_back(content::MediaStreamDevice(
152 content::MEDIA_SCREEN_VIDEO_CAPTURE, std::string(), "Screen"));
153 }
154 }
155
156 callback.Run(devices);
157 }
158
98 void MediaCaptureDevicesDispatcher::GetDefaultDevicesForProfile( 159 void MediaCaptureDevicesDispatcher::GetDefaultDevicesForProfile(
99 Profile* profile, 160 Profile* profile,
100 bool audio, 161 bool audio,
101 bool video, 162 bool video,
102 content::MediaStreamDevices* devices) { 163 content::MediaStreamDevices* devices) {
103 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 164 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
104 DCHECK(audio || video); 165 DCHECK(audio || video);
105 166
106 PrefService* prefs = profile->GetPrefs(); 167 PrefService* prefs = profile->GetPrefs();
107 std::string default_device; 168 std::string default_device;
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 int render_process_id, 294 int render_process_id,
234 int render_view_id, 295 int render_view_id,
235 const content::MediaStreamDevice& device, 296 const content::MediaStreamDevice& device,
236 content::MediaRequestState state) { 297 content::MediaRequestState state) {
237 FOR_EACH_OBSERVER(Observer, observers_, 298 FOR_EACH_OBSERVER(Observer, observers_,
238 OnRequestUpdate(render_process_id, 299 OnRequestUpdate(render_process_id,
239 render_view_id, 300 render_view_id,
240 device, 301 device,
241 state)); 302 state));
242 } 303 }
OLDNEW
« no previous file with comments | « chrome/browser/media/media_capture_devices_dispatcher.h ('k') | chrome/browser/ui/browser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698