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

Side by Side Diff: content/browser/browser_plugin/browser_plugin_guest.cc

Issue 11093080: <webview>: First stab at implementing media permission request for guests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add todo for auto deny when no listeners attached. Created 8 years 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
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 "content/browser/browser_plugin/browser_plugin_guest.h" 5 #include "content/browser/browser_plugin/browser_plugin_guest.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "content/browser/browser_plugin/browser_plugin_embedder.h" 10 #include "content/browser/browser_plugin/browser_plugin_embedder.h"
11 #include "content/browser/browser_plugin/browser_plugin_guest_helper.h" 11 #include "content/browser/browser_plugin/browser_plugin_guest_helper.h"
12 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" 12 #include "content/browser/browser_plugin/browser_plugin_host_factory.h"
13 #include "content/browser/renderer_host/render_view_host_impl.h" 13 #include "content/browser/renderer_host/render_view_host_impl.h"
14 #include "content/browser/renderer_host/render_widget_host_impl.h" 14 #include "content/browser/renderer_host/render_widget_host_impl.h"
15 #include "content/browser/web_contents/web_contents_impl.h" 15 #include "content/browser/web_contents/web_contents_impl.h"
16 #include "content/common/browser_plugin_messages.h" 16 #include "content/common/browser_plugin_messages.h"
17 #include "content/common/view_messages.h" 17 #include "content/common/view_messages.h"
18 #include "content/port/browser/render_view_host_delegate_view.h" 18 #include "content/port/browser/render_view_host_delegate_view.h"
19 #include "content/public/browser/notification_service.h" 19 #include "content/public/browser/notification_service.h"
20 #include "content/public/browser/notification_types.h" 20 #include "content/public/browser/notification_types.h"
21 #include "content/public/browser/render_process_host.h" 21 #include "content/public/browser/render_process_host.h"
22 #include "content/public/browser/render_widget_host_view.h" 22 #include "content/public/browser/render_widget_host_view.h"
23 #include "content/public/browser/resource_request_details.h" 23 #include "content/public/browser/resource_request_details.h"
24 #include "content/public/browser/user_metrics.h" 24 #include "content/public/browser/user_metrics.h"
25 #include "content/public/browser/web_contents_view.h" 25 #include "content/public/browser/web_contents_view.h"
26 #include "content/public/common/media_stream_request.h"
26 #include "content/public/common/result_codes.h" 27 #include "content/public/common/result_codes.h"
27 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" 28 #include "content/browser/browser_plugin/browser_plugin_host_factory.h"
28 #include "net/base/net_errors.h" 29 #include "net/base/net_errors.h"
29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" 30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h"
30 #include "ui/surface/transport_dib.h" 31 #include "ui/surface/transport_dib.h"
32 #include "webkit/glue/resource_type.h"
31 #include "webkit/glue/webdropdata.h" 33 #include "webkit/glue/webdropdata.h"
32 #include "webkit/glue/resource_type.h"
33 34
34 namespace content { 35 namespace content {
35 36
36 // static 37 // static
37 BrowserPluginHostFactory* BrowserPluginGuest::factory_ = NULL; 38 BrowserPluginHostFactory* BrowserPluginGuest::factory_ = NULL;
38 39
39 namespace { 40 namespace {
40 const int kGuestHangTimeoutMs = 5000; 41 const int kGuestHangTimeoutMs = 5000;
42 const int kNumMaxOutstandingMediaRequests = 1024;
41 } 43 }
42 44
43 BrowserPluginGuest::BrowserPluginGuest( 45 BrowserPluginGuest::BrowserPluginGuest(
44 int instance_id, 46 int instance_id,
45 WebContentsImpl* web_contents, 47 WebContentsImpl* web_contents,
46 const BrowserPluginHostMsg_CreateGuest_Params& params) 48 const BrowserPluginHostMsg_CreateGuest_Params& params)
47 : WebContentsObserver(web_contents), 49 : WebContentsObserver(web_contents),
48 embedder_web_contents_(NULL), 50 embedder_web_contents_(NULL),
49 instance_id_(instance_id), 51 instance_id_(instance_id),
50 #if defined(OS_WIN) 52 #if defined(OS_WIN)
51 damage_buffer_size_(0), 53 damage_buffer_size_(0),
52 remote_damage_buffer_handle_(0), 54 remote_damage_buffer_handle_(0),
53 #endif 55 #endif
54 damage_buffer_scale_factor_(1.0f), 56 damage_buffer_scale_factor_(1.0f),
55 pending_update_counter_(0), 57 pending_update_counter_(0),
56 guest_hang_timeout_( 58 guest_hang_timeout_(
57 base::TimeDelta::FromMilliseconds(kGuestHangTimeoutMs)), 59 base::TimeDelta::FromMilliseconds(kGuestHangTimeoutMs)),
58 focused_(params.focused), 60 focused_(params.focused),
59 visible_(params.visible), 61 visible_(params.visible),
60 auto_size_enabled_(params.auto_size_params.enable), 62 auto_size_enabled_(params.auto_size_params.enable),
61 max_auto_size_(params.auto_size_params.max_size), 63 max_auto_size_(params.auto_size_params.max_size),
62 min_auto_size_(params.auto_size_params.min_size) { 64 min_auto_size_(params.auto_size_params.min_size),
65 current_media_access_request_id_(0) {
63 DCHECK(web_contents); 66 DCHECK(web_contents);
64 } 67 }
65 68
66 void BrowserPluginGuest::InstallHelper( 69 void BrowserPluginGuest::InstallHelper(
67 content::RenderViewHost* render_view_host) { 70 content::RenderViewHost* render_view_host) {
68 // |render_view_host| manages the ownership of this BrowserPluginGuestHelper. 71 // |render_view_host| manages the ownership of this BrowserPluginGuestHelper.
69 new BrowserPluginGuestHelper(this, render_view_host); 72 new BrowserPluginGuestHelper(this, render_view_host);
70 73
71 notification_registrar_.Add( 74 notification_registrar_.Add(
72 this, content::NOTIFICATION_RESOURCE_RECEIVED_REDIRECT, 75 this, content::NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 const FileChooserParams& params) { 155 const FileChooserParams& params) {
153 embedder_web_contents_->GetDelegate()->RunFileChooser(web_contents, params); 156 embedder_web_contents_->GetDelegate()->RunFileChooser(web_contents, params);
154 } 157 }
155 158
156 bool BrowserPluginGuest::ShouldFocusPageAfterCrash() { 159 bool BrowserPluginGuest::ShouldFocusPageAfterCrash() {
157 // Rather than managing focus in WebContentsImpl::RenderViewReady, we will 160 // Rather than managing focus in WebContentsImpl::RenderViewReady, we will
158 // manage the focus ourselves. 161 // manage the focus ourselves.
159 return false; 162 return false;
160 } 163 }
161 164
165 void BrowserPluginGuest::RequestMediaAccessPermission(
166 WebContents* web_contents,
167 const content::MediaStreamRequest* request,
168 const content::MediaResponseCallback& callback) {
169 if (media_requests_map_.size() >= kNumMaxOutstandingMediaRequests) {
170 // Deny the media request.
171 callback.Run(content::MediaStreamDevices());
172 return;
173 }
174 int request_id = current_media_access_request_id_++;
175 media_requests_map_.insert(
176 std::make_pair(request_id,
177 std::make_pair(*request, callback)));
178
179 SendMessageToEmbedder(new BrowserPluginMsg_RequestMediaAccess(
180 embedder_routing_id(), instance_id(), request_id));
181 }
182
162 void BrowserPluginGuest::SetIsAcceptingTouchEvents(bool accept) { 183 void BrowserPluginGuest::SetIsAcceptingTouchEvents(bool accept) {
163 SendMessageToEmbedder( 184 SendMessageToEmbedder(
164 new BrowserPluginMsg_ShouldAcceptTouchEvents(embedder_routing_id(), 185 new BrowserPluginMsg_ShouldAcceptTouchEvents(embedder_routing_id(),
165 instance_id(), 186 instance_id(),
166 accept)); 187 accept));
167 } 188 }
168 189
169 void BrowserPluginGuest::SetVisibility(bool embedder_visible, bool visible) { 190 void BrowserPluginGuest::SetVisibility(bool embedder_visible, bool visible) {
170 visible_ = visible; 191 visible_ = visible;
171 if (embedder_visible && visible) 192 if (embedder_visible && visible)
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 damage_buffer = TransportDIB::Map(params.damage_buffer_handle); 318 damage_buffer = TransportDIB::Map(params.damage_buffer_handle);
298 #elif defined(OS_ANDROID) 319 #elif defined(OS_ANDROID)
299 damage_buffer = TransportDIB::Map(params.damage_buffer_id); 320 damage_buffer = TransportDIB::Map(params.damage_buffer_id);
300 #elif defined(OS_POSIX) 321 #elif defined(OS_POSIX)
301 damage_buffer = TransportDIB::Map(params.damage_buffer_id.shmkey); 322 damage_buffer = TransportDIB::Map(params.damage_buffer_id.shmkey);
302 #endif // defined(OS_POSIX) 323 #endif // defined(OS_POSIX)
303 DCHECK(damage_buffer); 324 DCHECK(damage_buffer);
304 return damage_buffer; 325 return damage_buffer;
305 } 326 }
306 327
328 void BrowserPluginGuest::AllowMediaAccess(WebContents* embedder_web_contents,
329 int request_id,
330 bool should_allow) {
331 MediaStreamRequestsMap::iterator media_request_iter =
332 media_requests_map_.find(request_id);
333 if (media_request_iter == media_requests_map_.end()) {
334 LOG(INFO) << "Not a valid request id";
335 return;
336 }
337 const content::MediaStreamRequest& request = media_request_iter->second.first;
338 const content::MediaResponseCallback& callback =
339 media_request_iter->second.second;
340
341 if (should_allow) {
342 WebContentsImpl* embedder_web_contents_impl =
343 static_cast<WebContentsImpl*>(embedder_web_contents);
344 // Re-route the request to the embedder's WebContents; the guest gets the
345 // permission this way.
346 embedder_web_contents_impl->RequestMediaAccessPermission(
Charlie Reis 2012/12/07 19:16:25 Ah, is the security check in here, then? Maybe my
lazyboy 2012/12/07 22:50:44 OK.
347 &request, callback);
348 } else {
349 // Deny the request.
350 callback.Run(content::MediaStreamDevices());
351 }
352 media_requests_map_.erase(media_request_iter);
353 }
354
307 void BrowserPluginGuest::SetDamageBuffer( 355 void BrowserPluginGuest::SetDamageBuffer(
308 TransportDIB* damage_buffer, 356 TransportDIB* damage_buffer,
309 #if defined(OS_WIN) 357 #if defined(OS_WIN)
310 int damage_buffer_size, 358 int damage_buffer_size,
311 TransportDIB::Handle remote_handle, 359 TransportDIB::Handle remote_handle,
312 #endif 360 #endif
313 const gfx::Size& damage_view_size, 361 const gfx::Size& damage_view_size,
314 float scale_factor) { 362 float scale_factor) {
315 // Sanity check: Verify that we've correctly shared the damage buffer memory 363 // Sanity check: Verify that we've correctly shared the damage buffer memory
316 // between the embedder and browser processes. 364 // between the embedder and browser processes.
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 default: 703 default:
656 break; 704 break;
657 } 705 }
658 } 706 }
659 707
660 void BrowserPluginGuest::SendMessageToEmbedder(IPC::Message* msg) { 708 void BrowserPluginGuest::SendMessageToEmbedder(IPC::Message* msg) {
661 embedder_web_contents_->Send(msg); 709 embedder_web_contents_->Send(msg);
662 } 710 }
663 711
664 } // namespace content 712 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698