Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/renderer/browser_plugin/browser_plugin.h" | 5 #include "content/renderer/browser_plugin/browser_plugin.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/json/json_string_value_serializer.h" | 8 #include "base/json/json_string_value_serializer.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 79 paint_ack_received_(true), | 79 paint_ack_received_(true), |
| 80 last_device_scale_factor_(1.0f), | 80 last_device_scale_factor_(1.0f), |
| 81 sad_guest_(NULL), | 81 sad_guest_(NULL), |
| 82 guest_crashed_(false), | 82 guest_crashed_(false), |
| 83 is_auto_size_state_dirty_(false), | 83 is_auto_size_state_dirty_(false), |
| 84 persist_storage_(false), | 84 persist_storage_(false), |
| 85 valid_partition_id_(true), | 85 valid_partition_id_(true), |
| 86 content_window_routing_id_(MSG_ROUTING_NONE), | 86 content_window_routing_id_(MSG_ROUTING_NONE), |
| 87 plugin_focused_(false), | 87 plugin_focused_(false), |
| 88 visible_(true), | 88 visible_(true), |
| 89 opaque_(true), | |
| 90 before_first_navigation_(true), | 89 before_first_navigation_(true), |
| 91 mouse_locked_(false), | 90 mouse_locked_(false), |
| 92 browser_plugin_manager_(render_view->GetBrowserPluginManager()), | 91 browser_plugin_manager_(render_view->GetBrowserPluginManager()), |
| 93 compositing_enabled_(false), | 92 compositing_enabled_(false), |
| 94 embedder_frame_url_(frame->document().url()), | 93 embedder_frame_url_(frame->document().url()), |
| 95 weak_ptr_factory_(this) { | 94 weak_ptr_factory_(this) { |
| 96 } | 95 } |
| 97 | 96 |
| 98 BrowserPlugin::~BrowserPlugin() { | 97 BrowserPlugin::~BrowserPlugin() { |
| 99 // If the BrowserPlugin has never navigated then the browser process and | 98 // If the BrowserPlugin has never navigated then the browser process and |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 175 return false; | 174 return false; |
| 176 | 175 |
| 177 return container()->element().hasAttribute( | 176 return container()->element().hasAttribute( |
| 178 blink::WebString::fromUTF8(attribute_name)); | 177 blink::WebString::fromUTF8(attribute_name)); |
| 179 } | 178 } |
| 180 | 179 |
| 181 std::string BrowserPlugin::GetNameAttribute() const { | 180 std::string BrowserPlugin::GetNameAttribute() const { |
| 182 return GetDOMAttributeValue(browser_plugin::kAttributeName); | 181 return GetDOMAttributeValue(browser_plugin::kAttributeName); |
| 183 } | 182 } |
| 184 | 183 |
| 184 bool BrowserPlugin::GetAllowTransparencyAttribute() const { | |
| 185 return HasDOMAttribute(browser_plugin::kAttributeAllowTransparency); | |
| 186 } | |
| 187 | |
| 185 std::string BrowserPlugin::GetSrcAttribute() const { | 188 std::string BrowserPlugin::GetSrcAttribute() const { |
| 186 return GetDOMAttributeValue(browser_plugin::kAttributeSrc); | 189 return GetDOMAttributeValue(browser_plugin::kAttributeSrc); |
| 187 } | 190 } |
| 188 | 191 |
| 189 bool BrowserPlugin::GetAutoSizeAttribute() const { | 192 bool BrowserPlugin::GetAutoSizeAttribute() const { |
| 190 return HasDOMAttribute(browser_plugin::kAttributeAutoSize); | 193 return HasDOMAttribute(browser_plugin::kAttributeAutoSize); |
| 191 } | 194 } |
| 192 | 195 |
| 193 int BrowserPlugin::GetMaxHeightAttribute() const { | 196 int BrowserPlugin::GetMaxHeightAttribute() const { |
| 194 int max_height; | 197 int max_height; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 252 | 255 |
| 253 void BrowserPlugin::ParseNameAttribute() { | 256 void BrowserPlugin::ParseNameAttribute() { |
| 254 if (!HasGuestInstanceID()) | 257 if (!HasGuestInstanceID()) |
| 255 return; | 258 return; |
| 256 browser_plugin_manager()->Send( | 259 browser_plugin_manager()->Send( |
| 257 new BrowserPluginHostMsg_SetName(render_view_routing_id_, | 260 new BrowserPluginHostMsg_SetName(render_view_routing_id_, |
| 258 guest_instance_id_, | 261 guest_instance_id_, |
| 259 GetNameAttribute())); | 262 GetNameAttribute())); |
| 260 } | 263 } |
| 261 | 264 |
| 265 void BrowserPlugin::ParseAllowTransparencyAttribute() { | |
| 266 if (!HasGuestInstanceID()) | |
| 267 return; | |
| 268 | |
| 269 bool opaque = !GetAllowTransparencyAttribute(); | |
| 270 | |
| 271 paint_ack_received_ = false; | |
|
alexst (slow to review)
2013/11/28 21:44:57
Why did you need to change this?
Fady Samuel
2013/12/02 18:30:04
Experimenting. Forgot to remove it. Removed now.
| |
| 272 | |
| 273 if (compositing_helper_) | |
| 274 compositing_helper_->SetContentsOpaque(opaque); | |
| 275 | |
| 276 browser_plugin_manager()->Send(new BrowserPluginHostMsg_SetContentsOpaque( | |
| 277 render_view_routing_id_, | |
| 278 guest_instance_id_, | |
| 279 opaque)); | |
| 280 } | |
| 281 | |
| 262 bool BrowserPlugin::ParseSrcAttribute(std::string* error_message) { | 282 bool BrowserPlugin::ParseSrcAttribute(std::string* error_message) { |
| 263 if (!valid_partition_id_) { | 283 if (!valid_partition_id_) { |
| 264 *error_message = browser_plugin::kErrorInvalidPartition; | 284 *error_message = browser_plugin::kErrorInvalidPartition; |
| 265 return false; | 285 return false; |
| 266 } | 286 } |
| 267 std::string src = GetSrcAttribute(); | 287 std::string src = GetSrcAttribute(); |
| 268 if (src.empty()) | 288 if (src.empty()) |
| 269 return true; | 289 return true; |
| 270 | 290 |
| 271 // If we haven't created the guest yet, do so now. We will navigate it right | 291 // If we haven't created the guest yet, do so now. We will navigate it right |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 365 std::map<std::string, base::Value*> props; | 385 std::map<std::string, base::Value*> props; |
| 366 props[browser_plugin::kWindowID] = | 386 props[browser_plugin::kWindowID] = |
| 367 new base::FundamentalValue(guest_instance_id); | 387 new base::FundamentalValue(guest_instance_id); |
| 368 TriggerEvent(browser_plugin::kEventInternalInstanceIDAllocated, &props); | 388 TriggerEvent(browser_plugin::kEventInternalInstanceIDAllocated, &props); |
| 369 } | 389 } |
| 370 | 390 |
| 371 void BrowserPlugin::Attach(scoped_ptr<base::DictionaryValue> extra_params) { | 391 void BrowserPlugin::Attach(scoped_ptr<base::DictionaryValue> extra_params) { |
| 372 BrowserPluginHostMsg_Attach_Params attach_params; | 392 BrowserPluginHostMsg_Attach_Params attach_params; |
| 373 attach_params.focused = ShouldGuestBeFocused(); | 393 attach_params.focused = ShouldGuestBeFocused(); |
| 374 attach_params.visible = visible_; | 394 attach_params.visible = visible_; |
| 375 attach_params.opaque = opaque_; | 395 attach_params.opaque = !GetAllowTransparencyAttribute(); |
| 376 attach_params.name = GetNameAttribute(); | 396 attach_params.name = GetNameAttribute(); |
| 377 attach_params.storage_partition_id = storage_partition_id_; | 397 attach_params.storage_partition_id = storage_partition_id_; |
| 378 attach_params.persist_storage = persist_storage_; | 398 attach_params.persist_storage = persist_storage_; |
| 379 attach_params.src = GetSrcAttribute(); | 399 attach_params.src = GetSrcAttribute(); |
| 380 attach_params.embedder_frame_url = embedder_frame_url_; | 400 attach_params.embedder_frame_url = embedder_frame_url_; |
| 381 GetDamageBufferWithSizeParams(&attach_params.auto_size_params, | 401 GetDamageBufferWithSizeParams(&attach_params.auto_size_params, |
| 382 &attach_params.resize_guest_params, | 402 &attach_params.resize_guest_params, |
| 383 false); | 403 false); |
| 384 | 404 |
| 385 browser_plugin_manager()->Send( | 405 browser_plugin_manager()->Send( |
| 386 new BrowserPluginHostMsg_Attach(render_view_routing_id_, | 406 new BrowserPluginHostMsg_Attach(render_view_routing_id_, |
| 387 guest_instance_id_, attach_params, | 407 guest_instance_id_, attach_params, |
| 388 *extra_params)); | 408 *extra_params)); |
| 389 } | 409 } |
| 390 | 410 |
| 391 void BrowserPlugin::DidCommitCompositorFrame() { | 411 void BrowserPlugin::DidCommitCompositorFrame() { |
| 392 if (compositing_helper_.get()) | 412 if (compositing_helper_.get()) |
| 393 compositing_helper_->DidCommitCompositorFrame(); | 413 compositing_helper_->DidCommitCompositorFrame(); |
| 394 } | 414 } |
| 395 | 415 |
| 396 void BrowserPlugin::SetContentsOpaque(bool opaque) { | |
| 397 if (opaque_ == opaque) | |
| 398 return; | |
| 399 | |
| 400 opaque_ = opaque; | |
| 401 if (!HasGuestInstanceID()) | |
| 402 return; | |
| 403 | |
| 404 if (compositing_helper_) | |
| 405 compositing_helper_->SetContentsOpaque(opaque_); | |
| 406 | |
| 407 browser_plugin_manager()->Send(new BrowserPluginHostMsg_SetContentsOpaque( | |
| 408 render_view_routing_id_, | |
| 409 guest_instance_id_, | |
| 410 opaque_)); | |
| 411 } | |
| 412 | |
| 413 void BrowserPlugin::OnAdvanceFocus(int guest_instance_id, bool reverse) { | 416 void BrowserPlugin::OnAdvanceFocus(int guest_instance_id, bool reverse) { |
| 414 DCHECK(render_view_.get()); | 417 DCHECK(render_view_.get()); |
| 415 render_view_->GetWebView()->advanceFocus(reverse); | 418 render_view_->GetWebView()->advanceFocus(reverse); |
| 416 } | 419 } |
| 417 | 420 |
| 418 void BrowserPlugin::OnAttachACK( | 421 void BrowserPlugin::OnAttachACK( |
| 419 int guest_instance_id, | 422 int guest_instance_id, |
| 420 const BrowserPluginMsg_Attach_ACK_Params& params) { | 423 const BrowserPluginMsg_Attach_ACK_Params& params) { |
| 421 // Update BrowserPlugin attributes to match the state of the guest. | 424 // Update BrowserPlugin attributes to match the state of the guest. |
| 422 if (!params.name.empty()) | 425 if (!params.name.empty()) |
| (...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 911 plugin_rect(), | 914 plugin_rect(), |
| 912 true /* needs_repaint */); | 915 true /* needs_repaint */); |
| 913 paint_ack_received_ = false; | 916 paint_ack_received_ = false; |
| 914 browser_plugin_manager()->Send(new BrowserPluginHostMsg_ResizeGuest( | 917 browser_plugin_manager()->Send(new BrowserPluginHostMsg_ResizeGuest( |
| 915 render_view_routing_id_, | 918 render_view_routing_id_, |
| 916 guest_instance_id_, | 919 guest_instance_id_, |
| 917 params)); | 920 params)); |
| 918 } | 921 } |
| 919 } | 922 } |
| 920 compositing_helper_->EnableCompositing(enable); | 923 compositing_helper_->EnableCompositing(enable); |
| 921 compositing_helper_->SetContentsOpaque(opaque_); | 924 compositing_helper_->SetContentsOpaque(!GetAllowTransparencyAttribute()); |
| 922 } | 925 } |
| 923 | 926 |
| 924 void BrowserPlugin::destroy() { | 927 void BrowserPlugin::destroy() { |
| 925 // If the plugin was initialized then it has a valid |npp_| identifier, and | 928 // If the plugin was initialized then it has a valid |npp_| identifier, and |
| 926 // the |container_| must clear references to the plugin's script objects. | 929 // the |container_| must clear references to the plugin's script objects. |
| 927 DCHECK(!npp_ || container_); | 930 DCHECK(!npp_ || container_); |
| 928 if (container_) | 931 if (container_) |
| 929 container_->clearScriptObjects(); | 932 container_->clearScriptObjects(); |
| 930 | 933 |
| 931 // The BrowserPlugin's WebPluginContainer is deleted immediately after this | 934 // The BrowserPlugin's WebPluginContainer is deleted immediately after this |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1333 const blink::WebMouseEvent& event) { | 1336 const blink::WebMouseEvent& event) { |
| 1334 browser_plugin_manager()->Send( | 1337 browser_plugin_manager()->Send( |
| 1335 new BrowserPluginHostMsg_HandleInputEvent(render_view_routing_id_, | 1338 new BrowserPluginHostMsg_HandleInputEvent(render_view_routing_id_, |
| 1336 guest_instance_id_, | 1339 guest_instance_id_, |
| 1337 plugin_rect_, | 1340 plugin_rect_, |
| 1338 &event)); | 1341 &event)); |
| 1339 return true; | 1342 return true; |
| 1340 } | 1343 } |
| 1341 | 1344 |
| 1342 } // namespace content | 1345 } // namespace content |
| OLD | NEW |