| 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/content_constants_internal.h" | 17 #include "content/common/content_constants_internal.h" |
| 18 #include "content/common/view_messages.h" | 18 #include "content/common/view_messages.h" |
| 19 #include "content/port/browser/render_view_host_delegate_view.h" | 19 #include "content/port/browser/render_view_host_delegate_view.h" |
| 20 #include "content/public/browser/notification_service.h" | 20 #include "content/public/browser/notification_service.h" |
| 21 #include "content/public/browser/notification_types.h" | 21 #include "content/public/browser/notification_types.h" |
| 22 #include "content/public/browser/render_process_host.h" | 22 #include "content/public/browser/render_process_host.h" |
| 23 #include "content/public/browser/render_widget_host_view.h" | 23 #include "content/public/browser/render_widget_host_view.h" |
| 24 #include "content/public/browser/resource_request_details.h" | 24 #include "content/public/browser/resource_request_details.h" |
| 25 #include "content/public/browser/user_metrics.h" | 25 #include "content/public/browser/user_metrics.h" |
| 26 #include "content/public/browser/web_contents_view.h" | 26 #include "content/public/browser/web_contents_view.h" |
| 27 #include "content/public/common/media_stream_request.h" |
| 27 #include "content/public/common/result_codes.h" | 28 #include "content/public/common/result_codes.h" |
| 28 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" | 29 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" |
| 29 #include "net/base/net_errors.h" | 30 #include "net/base/net_errors.h" |
| 30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" | 31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" |
| 31 #include "ui/surface/transport_dib.h" | 32 #include "ui/surface/transport_dib.h" |
| 33 #include "webkit/glue/resource_type.h" |
| 32 #include "webkit/glue/webdropdata.h" | 34 #include "webkit/glue/webdropdata.h" |
| 33 #include "webkit/glue/resource_type.h" | |
| 34 | 35 |
| 35 namespace content { | 36 namespace content { |
| 36 | 37 |
| 37 // static | 38 // static |
| 38 BrowserPluginHostFactory* BrowserPluginGuest::factory_ = NULL; | 39 BrowserPluginHostFactory* BrowserPluginGuest::factory_ = NULL; |
| 39 | 40 |
| 41 namespace { |
| 42 const int kNumMaxOutstandingMediaRequests = 1024; |
| 43 } |
| 44 |
| 40 BrowserPluginGuest::BrowserPluginGuest( | 45 BrowserPluginGuest::BrowserPluginGuest( |
| 41 int instance_id, | 46 int instance_id, |
| 42 WebContentsImpl* web_contents, | 47 WebContentsImpl* web_contents, |
| 43 const BrowserPluginHostMsg_CreateGuest_Params& params) | 48 const BrowserPluginHostMsg_CreateGuest_Params& params) |
| 44 : WebContentsObserver(web_contents), | 49 : WebContentsObserver(web_contents), |
| 45 embedder_web_contents_(NULL), | 50 embedder_web_contents_(NULL), |
| 46 instance_id_(instance_id), | 51 instance_id_(instance_id), |
| 47 #if defined(OS_WIN) | 52 #if defined(OS_WIN) |
| 48 damage_buffer_size_(0), | 53 damage_buffer_size_(0), |
| 49 remote_damage_buffer_handle_(0), | 54 remote_damage_buffer_handle_(0), |
| 50 #endif | 55 #endif |
| 51 damage_buffer_scale_factor_(1.0f), | 56 damage_buffer_scale_factor_(1.0f), |
| 52 pending_update_counter_(0), | 57 pending_update_counter_(0), |
| 53 guest_hang_timeout_( | 58 guest_hang_timeout_( |
| 54 base::TimeDelta::FromMilliseconds(kHungRendererDelayMs)), | 59 base::TimeDelta::FromMilliseconds(kHungRendererDelayMs)), |
| 55 focused_(params.focused), | 60 focused_(params.focused), |
| 56 visible_(params.visible), | 61 visible_(params.visible), |
| 57 auto_size_enabled_(params.auto_size_params.enable), | 62 auto_size_enabled_(params.auto_size_params.enable), |
| 58 max_auto_size_(params.auto_size_params.max_size), | 63 max_auto_size_(params.auto_size_params.max_size), |
| 59 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) { |
| 60 DCHECK(web_contents); | 66 DCHECK(web_contents); |
| 61 } | 67 } |
| 62 | 68 |
| 63 void BrowserPluginGuest::InstallHelper( | 69 void BrowserPluginGuest::InstallHelper( |
| 64 content::RenderViewHost* render_view_host) { | 70 content::RenderViewHost* render_view_host) { |
| 65 // |render_view_host| manages the ownership of this BrowserPluginGuestHelper. | 71 // |render_view_host| manages the ownership of this BrowserPluginGuestHelper. |
| 66 new BrowserPluginGuestHelper(this, render_view_host); | 72 new BrowserPluginGuestHelper(this, render_view_host); |
| 67 | 73 |
| 68 notification_registrar_.Add( | 74 notification_registrar_.Add( |
| 69 this, content::NOTIFICATION_RESOURCE_RECEIVED_REDIRECT, | 75 this, content::NOTIFICATION_RESOURCE_RECEIVED_REDIRECT, |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 const FileChooserParams& params) { | 168 const FileChooserParams& params) { |
| 163 embedder_web_contents_->GetDelegate()->RunFileChooser(web_contents, params); | 169 embedder_web_contents_->GetDelegate()->RunFileChooser(web_contents, params); |
| 164 } | 170 } |
| 165 | 171 |
| 166 bool BrowserPluginGuest::ShouldFocusPageAfterCrash() { | 172 bool BrowserPluginGuest::ShouldFocusPageAfterCrash() { |
| 167 // Rather than managing focus in WebContentsImpl::RenderViewReady, we will | 173 // Rather than managing focus in WebContentsImpl::RenderViewReady, we will |
| 168 // manage the focus ourselves. | 174 // manage the focus ourselves. |
| 169 return false; | 175 return false; |
| 170 } | 176 } |
| 171 | 177 |
| 178 void BrowserPluginGuest::RequestMediaAccessPermission( |
| 179 WebContents* web_contents, |
| 180 const content::MediaStreamRequest* request, |
| 181 const content::MediaResponseCallback& callback) { |
| 182 if (media_requests_map_.size() >= kNumMaxOutstandingMediaRequests) { |
| 183 // Deny the media request. |
| 184 callback.Run(content::MediaStreamDevices()); |
| 185 return; |
| 186 } |
| 187 int request_id = current_media_access_request_id_++; |
| 188 media_requests_map_.insert( |
| 189 std::make_pair(request_id, |
| 190 std::make_pair(*request, callback))); |
| 191 |
| 192 SendMessageToEmbedder(new BrowserPluginMsg_RequestMediaAccess( |
| 193 embedder_routing_id(), instance_id(), request_id, |
| 194 request->security_origin)); |
| 195 } |
| 196 |
| 172 void BrowserPluginGuest::SetIsAcceptingTouchEvents(bool accept) { | 197 void BrowserPluginGuest::SetIsAcceptingTouchEvents(bool accept) { |
| 173 SendMessageToEmbedder( | 198 SendMessageToEmbedder( |
| 174 new BrowserPluginMsg_ShouldAcceptTouchEvents(embedder_routing_id(), | 199 new BrowserPluginMsg_ShouldAcceptTouchEvents(embedder_routing_id(), |
| 175 instance_id(), | 200 instance_id(), |
| 176 accept)); | 201 accept)); |
| 177 } | 202 } |
| 178 | 203 |
| 179 void BrowserPluginGuest::SetVisibility(bool embedder_visible, bool visible) { | 204 void BrowserPluginGuest::SetVisibility(bool embedder_visible, bool visible) { |
| 180 visible_ = visible; | 205 visible_ = visible; |
| 181 if (embedder_visible && visible) | 206 if (embedder_visible && visible) |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 damage_buffer = TransportDIB::Map(params.damage_buffer_handle); | 332 damage_buffer = TransportDIB::Map(params.damage_buffer_handle); |
| 308 #elif defined(OS_ANDROID) | 333 #elif defined(OS_ANDROID) |
| 309 damage_buffer = TransportDIB::Map(params.damage_buffer_id); | 334 damage_buffer = TransportDIB::Map(params.damage_buffer_id); |
| 310 #elif defined(OS_POSIX) | 335 #elif defined(OS_POSIX) |
| 311 damage_buffer = TransportDIB::Map(params.damage_buffer_id.shmkey); | 336 damage_buffer = TransportDIB::Map(params.damage_buffer_id.shmkey); |
| 312 #endif // defined(OS_POSIX) | 337 #endif // defined(OS_POSIX) |
| 313 DCHECK(damage_buffer); | 338 DCHECK(damage_buffer); |
| 314 return damage_buffer; | 339 return damage_buffer; |
| 315 } | 340 } |
| 316 | 341 |
| 342 void BrowserPluginGuest::AllowMediaAccess(WebContents* embedder_web_contents, |
| 343 int request_id, |
| 344 bool should_allow) { |
| 345 MediaStreamRequestsMap::iterator media_request_iter = |
| 346 media_requests_map_.find(request_id); |
| 347 if (media_request_iter == media_requests_map_.end()) { |
| 348 LOG(INFO) << "Not a valid request id"; |
| 349 return; |
| 350 } |
| 351 const content::MediaStreamRequest& request = media_request_iter->second.first; |
| 352 const content::MediaResponseCallback& callback = |
| 353 media_request_iter->second.second; |
| 354 |
| 355 if (should_allow) { |
| 356 WebContentsImpl* embedder_web_contents_impl = |
| 357 static_cast<WebContentsImpl*>(embedder_web_contents); |
| 358 // Re-route the request to the embedder's WebContents; the guest gets the |
| 359 // permission this way. |
| 360 embedder_web_contents_impl->RequestMediaAccessPermission( |
| 361 &request, callback); |
| 362 } else { |
| 363 // Deny the request. |
| 364 callback.Run(content::MediaStreamDevices()); |
| 365 } |
| 366 media_requests_map_.erase(media_request_iter); |
| 367 } |
| 368 |
| 317 void BrowserPluginGuest::SetDamageBuffer( | 369 void BrowserPluginGuest::SetDamageBuffer( |
| 318 TransportDIB* damage_buffer, | 370 TransportDIB* damage_buffer, |
| 319 #if defined(OS_WIN) | 371 #if defined(OS_WIN) |
| 320 int damage_buffer_size, | 372 int damage_buffer_size, |
| 321 TransportDIB::Handle remote_handle, | 373 TransportDIB::Handle remote_handle, |
| 322 #endif | 374 #endif |
| 323 const gfx::Size& damage_view_size, | 375 const gfx::Size& damage_view_size, |
| 324 float scale_factor) { | 376 float scale_factor) { |
| 325 // Sanity check: Verify that we've correctly shared the damage buffer memory | 377 // Sanity check: Verify that we've correctly shared the damage buffer memory |
| 326 // between the embedder and browser processes. | 378 // between the embedder and browser processes. |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 636 default: | 688 default: |
| 637 break; | 689 break; |
| 638 } | 690 } |
| 639 } | 691 } |
| 640 | 692 |
| 641 void BrowserPluginGuest::SendMessageToEmbedder(IPC::Message* msg) { | 693 void BrowserPluginGuest::SendMessageToEmbedder(IPC::Message* msg) { |
| 642 embedder_web_contents_->Send(msg); | 694 embedder_web_contents_->Send(msg); |
| 643 } | 695 } |
| 644 | 696 |
| 645 } // namespace content | 697 } // namespace content |
| OLD | NEW |