Chromium Code Reviews| OLD | NEW |
|---|---|
| 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, |
| 73 content::Source<content::WebContents>(web_contents())); | 76 content::Source<content::WebContents>(web_contents())); |
| 74 } | 77 } |
| 75 | 78 |
| 76 BrowserPluginGuest::~BrowserPluginGuest() { | 79 BrowserPluginGuest::~BrowserPluginGuest() { |
| 80 media_requests_map_.clear(); | |
|
Fady Samuel
2012/12/05 22:47:31
I believe this is unnecessary.
lazyboy
2012/12/06 00:05:52
Removed.
| |
| 77 } | 81 } |
| 78 | 82 |
| 79 // static | 83 // static |
| 80 BrowserPluginGuest* BrowserPluginGuest::Create( | 84 BrowserPluginGuest* BrowserPluginGuest::Create( |
| 81 int instance_id, | 85 int instance_id, |
| 82 WebContentsImpl* web_contents, | 86 WebContentsImpl* web_contents, |
| 83 const BrowserPluginHostMsg_CreateGuest_Params& params) { | 87 const BrowserPluginHostMsg_CreateGuest_Params& params) { |
| 84 RecordAction(UserMetricsAction("BrowserPlugin.Guest.Create")); | 88 RecordAction(UserMetricsAction("BrowserPlugin.Guest.Create")); |
| 85 if (factory_) { | 89 if (factory_) { |
| 86 return factory_->CreateBrowserPluginGuest(instance_id, | 90 return factory_->CreateBrowserPluginGuest(instance_id, |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 152 const FileChooserParams& params) { | 156 const FileChooserParams& params) { |
| 153 embedder_web_contents_->GetDelegate()->RunFileChooser(web_contents, params); | 157 embedder_web_contents_->GetDelegate()->RunFileChooser(web_contents, params); |
| 154 } | 158 } |
| 155 | 159 |
| 156 bool BrowserPluginGuest::ShouldFocusPageAfterCrash() { | 160 bool BrowserPluginGuest::ShouldFocusPageAfterCrash() { |
| 157 // Rather than managing focus in WebContentsImpl::RenderViewReady, we will | 161 // Rather than managing focus in WebContentsImpl::RenderViewReady, we will |
| 158 // manage the focus ourselves. | 162 // manage the focus ourselves. |
| 159 return false; | 163 return false; |
| 160 } | 164 } |
| 161 | 165 |
| 166 void BrowserPluginGuest::RequestMediaAccessPermission( | |
| 167 WebContents* web_contents, | |
| 168 const content::MediaStreamRequest* request, | |
| 169 const content::MediaResponseCallback& callback) { | |
| 170 if (media_requests_map_.size() >= kNumMaxOutstandingMediaRequests) { | |
| 171 // Deny the media request. | |
| 172 callback.Run(content::MediaStreamDevices()); | |
| 173 return; | |
| 174 } | |
| 175 int request_id = current_media_access_request_id_++; | |
| 176 media_requests_map_.insert( | |
| 177 std::make_pair(request_id, | |
| 178 std::make_pair(*request, callback))); | |
| 179 | |
| 180 SendMessageToEmbedder(new BrowserPluginMsg_RequestMediaAccess( | |
| 181 embedder_routing_id(), instance_id(), request_id)); | |
| 182 } | |
| 183 | |
| 162 void BrowserPluginGuest::SetIsAcceptingTouchEvents(bool accept) { | 184 void BrowserPluginGuest::SetIsAcceptingTouchEvents(bool accept) { |
| 163 SendMessageToEmbedder( | 185 SendMessageToEmbedder( |
| 164 new BrowserPluginMsg_ShouldAcceptTouchEvents(embedder_routing_id(), | 186 new BrowserPluginMsg_ShouldAcceptTouchEvents(embedder_routing_id(), |
| 165 instance_id(), | 187 instance_id(), |
| 166 accept)); | 188 accept)); |
| 167 } | 189 } |
| 168 | 190 |
| 169 void BrowserPluginGuest::SetVisibility(bool embedder_visible, bool visible) { | 191 void BrowserPluginGuest::SetVisibility(bool embedder_visible, bool visible) { |
| 170 visible_ = visible; | 192 visible_ = visible; |
| 171 if (embedder_visible && visible) | 193 if (embedder_visible && visible) |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 297 damage_buffer = TransportDIB::Map(params.damage_buffer_handle); | 319 damage_buffer = TransportDIB::Map(params.damage_buffer_handle); |
| 298 #elif defined(OS_ANDROID) | 320 #elif defined(OS_ANDROID) |
| 299 damage_buffer = TransportDIB::Map(params.damage_buffer_id); | 321 damage_buffer = TransportDIB::Map(params.damage_buffer_id); |
| 300 #elif defined(OS_POSIX) | 322 #elif defined(OS_POSIX) |
| 301 damage_buffer = TransportDIB::Map(params.damage_buffer_id.shmkey); | 323 damage_buffer = TransportDIB::Map(params.damage_buffer_id.shmkey); |
| 302 #endif // defined(OS_POSIX) | 324 #endif // defined(OS_POSIX) |
| 303 DCHECK(damage_buffer); | 325 DCHECK(damage_buffer); |
| 304 return damage_buffer; | 326 return damage_buffer; |
| 305 } | 327 } |
| 306 | 328 |
| 329 void BrowserPluginGuest::AllowMediaAccess(WebContents* embedder_web_contents, | |
| 330 int request_id, | |
| 331 bool should_allow) { | |
| 332 MediaStreamRequestsMap::iterator media_request_iter = | |
| 333 media_requests_map_.find(request_id); | |
| 334 if (media_request_iter == media_requests_map_.end()) { | |
| 335 LOG(INFO) << "Not a valid request id"; | |
| 336 return; | |
| 337 } | |
| 338 const content::MediaStreamRequest& request = media_request_iter->second.first; | |
| 339 const content::MediaResponseCallback& callback = | |
| 340 media_request_iter->second.second; | |
| 341 | |
| 342 if (should_allow) { | |
| 343 WebContentsImpl* embedder_web_contents_impl = | |
| 344 static_cast<WebContentsImpl*>(embedder_web_contents); | |
| 345 // Re-route the request to the embedder's WebContents; the guest gets the | |
| 346 // permission this way. | |
| 347 embedder_web_contents_impl->RequestMediaAccessPermission( | |
| 348 &request, callback); | |
| 349 } else { | |
| 350 // Deny the request. | |
| 351 callback.Run(content::MediaStreamDevices()); | |
| 352 } | |
| 353 media_requests_map_.erase(media_request_iter); | |
| 354 } | |
| 355 | |
| 307 void BrowserPluginGuest::SetDamageBuffer( | 356 void BrowserPluginGuest::SetDamageBuffer( |
| 308 TransportDIB* damage_buffer, | 357 TransportDIB* damage_buffer, |
| 309 #if defined(OS_WIN) | 358 #if defined(OS_WIN) |
| 310 int damage_buffer_size, | 359 int damage_buffer_size, |
| 311 TransportDIB::Handle remote_handle, | 360 TransportDIB::Handle remote_handle, |
| 312 #endif | 361 #endif |
| 313 const gfx::Size& damage_view_size, | 362 const gfx::Size& damage_view_size, |
| 314 float scale_factor) { | 363 float scale_factor) { |
| 315 // Sanity check: Verify that we've correctly shared the damage buffer memory | 364 // Sanity check: Verify that we've correctly shared the damage buffer memory |
| 316 // between the embedder and browser processes. | 365 // between the embedder and browser processes. |
| (...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 655 default: | 704 default: |
| 656 break; | 705 break; |
| 657 } | 706 } |
| 658 } | 707 } |
| 659 | 708 |
| 660 void BrowserPluginGuest::SendMessageToEmbedder(IPC::Message* msg) { | 709 void BrowserPluginGuest::SendMessageToEmbedder(IPC::Message* msg) { |
| 661 embedder_web_contents_->Send(msg); | 710 embedder_web_contents_->Send(msg); |
| 662 } | 711 } |
| 663 | 712 |
| 664 } // namespace content | 713 } // namespace content |
| OLD | NEW |