| 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; |
| 41 } | 42 } |
| 42 | 43 |
| 43 BrowserPluginGuest::BrowserPluginGuest( | 44 BrowserPluginGuest::BrowserPluginGuest( |
| 44 int instance_id, | 45 int instance_id, |
| 45 WebContentsImpl* web_contents, | 46 WebContentsImpl* web_contents, |
| 46 RenderViewHost* render_view_host, | 47 RenderViewHost* render_view_host, |
| 47 const BrowserPluginHostMsg_CreateGuest_Params& params) | 48 const BrowserPluginHostMsg_CreateGuest_Params& params) |
| 48 : WebContentsObserver(web_contents), | 49 : WebContentsObserver(web_contents), |
| 49 embedder_web_contents_(NULL), | 50 embedder_web_contents_(NULL), |
| 50 instance_id_(instance_id), | 51 instance_id_(instance_id), |
| 51 #if defined(OS_WIN) | 52 #if defined(OS_WIN) |
| 52 damage_buffer_size_(0), | 53 damage_buffer_size_(0), |
| 53 #endif | 54 #endif |
| 54 damage_buffer_scale_factor_(1.0f), | 55 damage_buffer_scale_factor_(1.0f), |
| 55 pending_update_counter_(0), | 56 pending_update_counter_(0), |
| 56 guest_hang_timeout_( | 57 guest_hang_timeout_( |
| 57 base::TimeDelta::FromMilliseconds(kGuestHangTimeoutMs)), | 58 base::TimeDelta::FromMilliseconds(kGuestHangTimeoutMs)), |
| 58 focused_(params.focused), | 59 focused_(params.focused), |
| 59 visible_(params.visible), | 60 visible_(params.visible), |
| 60 auto_size_(params.auto_size.enable), | 61 auto_size_(params.auto_size.enable), |
| 61 max_auto_size_(params.auto_size.max_size), | 62 max_auto_size_(params.auto_size.max_size), |
| 62 min_auto_size_(params.auto_size.min_size) { | 63 min_auto_size_(params.auto_size.min_size), |
| 64 current_media_access_request_id_(0) { |
| 63 DCHECK(web_contents); | 65 DCHECK(web_contents); |
| 64 // |render_view_host| manages the ownership of this BrowserPluginGuestHelper. | 66 // |render_view_host| manages the ownership of this BrowserPluginGuestHelper. |
| 65 new BrowserPluginGuestHelper(this, render_view_host); | 67 new BrowserPluginGuestHelper(this, render_view_host); |
| 66 | 68 |
| 67 notification_registrar_.Add( | 69 notification_registrar_.Add( |
| 68 this, content::NOTIFICATION_RESOURCE_RECEIVED_REDIRECT, | 70 this, content::NOTIFICATION_RESOURCE_RECEIVED_REDIRECT, |
| 69 content::Source<content::WebContents>(web_contents)); | 71 content::Source<content::WebContents>(web_contents)); |
| 70 } | 72 } |
| 71 | 73 |
| 72 BrowserPluginGuest::~BrowserPluginGuest() { | 74 BrowserPluginGuest::~BrowserPluginGuest() { |
| 75 media_requests_map_.clear(); |
| 73 } | 76 } |
| 74 | 77 |
| 75 // static | 78 // static |
| 76 BrowserPluginGuest* BrowserPluginGuest::Create( | 79 BrowserPluginGuest* BrowserPluginGuest::Create( |
| 77 int instance_id, | 80 int instance_id, |
| 78 WebContentsImpl* web_contents, | 81 WebContentsImpl* web_contents, |
| 79 content::RenderViewHost* render_view_host, | 82 content::RenderViewHost* render_view_host, |
| 80 const BrowserPluginHostMsg_CreateGuest_Params& params) { | 83 const BrowserPluginHostMsg_CreateGuest_Params& params) { |
| 81 RecordAction(UserMetricsAction("BrowserPlugin.Guest.Create")); | 84 RecordAction(UserMetricsAction("BrowserPlugin.Guest.Create")); |
| 82 if (factory_) { | 85 if (factory_) { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 const FileChooserParams& params) { | 152 const FileChooserParams& params) { |
| 150 embedder_web_contents_->GetDelegate()->RunFileChooser(web_contents, params); | 153 embedder_web_contents_->GetDelegate()->RunFileChooser(web_contents, params); |
| 151 } | 154 } |
| 152 | 155 |
| 153 bool BrowserPluginGuest::ShouldFocusPageAfterCrash() { | 156 bool BrowserPluginGuest::ShouldFocusPageAfterCrash() { |
| 154 // Rather than managing focus in WebContentsImpl::RenderViewReady, we will | 157 // Rather than managing focus in WebContentsImpl::RenderViewReady, we will |
| 155 // manage the focus ourselves. | 158 // manage the focus ourselves. |
| 156 return false; | 159 return false; |
| 157 } | 160 } |
| 158 | 161 |
| 162 void BrowserPluginGuest::RequestMediaAccessPermission( |
| 163 WebContents* web_contents, |
| 164 const content::MediaStreamRequest* request, |
| 165 const content::MediaResponseCallback& callback) { |
| 166 int request_id = current_media_access_request_id_++; |
| 167 media_requests_map_.insert( |
| 168 std::make_pair(request_id, |
| 169 std::make_pair(*request, callback))); |
| 170 |
| 171 SendMessageToEmbedder(new BrowserPluginMsg_RequestMediaAccess(instance_id(), |
| 172 request_id)); |
| 173 } |
| 174 |
| 159 void BrowserPluginGuest::SetIsAcceptingTouchEvents(bool accept) { | 175 void BrowserPluginGuest::SetIsAcceptingTouchEvents(bool accept) { |
| 160 SendMessageToEmbedder( | 176 SendMessageToEmbedder( |
| 161 new BrowserPluginMsg_ShouldAcceptTouchEvents(instance_id(), accept)); | 177 new BrowserPluginMsg_ShouldAcceptTouchEvents(instance_id(), accept)); |
| 162 } | 178 } |
| 163 | 179 |
| 164 void BrowserPluginGuest::SetVisibility(bool embedder_visible, bool visible) { | 180 void BrowserPluginGuest::SetVisibility(bool embedder_visible, bool visible) { |
| 165 visible_ = visible; | 181 visible_ = visible; |
| 166 if (embedder_visible && visible) | 182 if (embedder_visible && visible) |
| 167 web_contents()->WasShown(); | 183 web_contents()->WasShown(); |
| 168 else | 184 else |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 damage_buffer = TransportDIB::Map(params.damage_buffer_handle); | 292 damage_buffer = TransportDIB::Map(params.damage_buffer_handle); |
| 277 #elif defined(OS_ANDROID) | 293 #elif defined(OS_ANDROID) |
| 278 damage_buffer = TransportDIB::Map(params.damage_buffer_id); | 294 damage_buffer = TransportDIB::Map(params.damage_buffer_id); |
| 279 #elif defined(OS_POSIX) | 295 #elif defined(OS_POSIX) |
| 280 damage_buffer = TransportDIB::Map(params.damage_buffer_id.shmkey); | 296 damage_buffer = TransportDIB::Map(params.damage_buffer_id.shmkey); |
| 281 #endif // defined(OS_POSIX) | 297 #endif // defined(OS_POSIX) |
| 282 DCHECK(damage_buffer); | 298 DCHECK(damage_buffer); |
| 283 return damage_buffer; | 299 return damage_buffer; |
| 284 } | 300 } |
| 285 | 301 |
| 302 void BrowserPluginGuest::AllowMediaAccess(WebContents* embedder_web_contents, |
| 303 int request_id, |
| 304 bool should_allow) { |
| 305 MediaStreamRequestsMap::iterator media_request_iter = |
| 306 media_requests_map_.find(request_id); |
| 307 if (media_request_iter == media_requests_map_.end()) { |
| 308 LOG(INFO) << "Not a valid request id"; |
| 309 return; |
| 310 } |
| 311 const content::MediaStreamRequest& request = media_request_iter->second.first; |
| 312 const content::MediaResponseCallback& callback = |
| 313 media_request_iter->second.second; |
| 314 |
| 315 if (should_allow) { |
| 316 WebContentsImpl* embedder_web_contents_impl = |
| 317 static_cast<WebContentsImpl*>(embedder_web_contents); |
| 318 // Re-route the request to the embedder's WebContents; the guest gets the |
| 319 // permission this way. |
| 320 embedder_web_contents_impl->RequestMediaAccessPermission( |
| 321 &request, callback); |
| 322 } else { |
| 323 // Deny the request. |
| 324 callback.Run(content::MediaStreamDevices()); |
| 325 } |
| 326 media_requests_map_.erase(media_request_iter); |
| 327 } |
| 328 |
| 286 void BrowserPluginGuest::SetDamageBuffer( | 329 void BrowserPluginGuest::SetDamageBuffer( |
| 287 TransportDIB* damage_buffer, | 330 TransportDIB* damage_buffer, |
| 288 #if defined(OS_WIN) | 331 #if defined(OS_WIN) |
| 289 int damage_buffer_size, | 332 int damage_buffer_size, |
| 290 #endif | 333 #endif |
| 291 const gfx::Size& damage_view_size, | 334 const gfx::Size& damage_view_size, |
| 292 float scale_factor) { | 335 float scale_factor) { |
| 293 // Sanity check: Verify that we've correctly shared the damage buffer memory | 336 // Sanity check: Verify that we've correctly shared the damage buffer memory |
| 294 // between the embedder and browser processes. | 337 // between the embedder and browser processes. |
| 295 DCHECK(*static_cast<unsigned int*>(damage_buffer->memory()) == 0xdeadbeef); | 338 DCHECK(*static_cast<unsigned int*>(damage_buffer->memory()) == 0xdeadbeef); |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 584 default: | 627 default: |
| 585 break; | 628 break; |
| 586 } | 629 } |
| 587 } | 630 } |
| 588 | 631 |
| 589 void BrowserPluginGuest::SendMessageToEmbedder(IPC::Message* msg) { | 632 void BrowserPluginGuest::SendMessageToEmbedder(IPC::Message* msg) { |
| 590 embedder_web_contents_->GetRenderProcessHost()->Send(msg); | 633 embedder_web_contents_->GetRenderProcessHost()->Send(msg); |
| 591 } | 634 } |
| 592 | 635 |
| 593 } // namespace content | 636 } // namespace content |
| OLD | NEW |