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/renderer/browser_plugin/browser_plugin.h" | 5 #include "content/renderer/browser_plugin/browser_plugin.h" |
6 | 6 |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #if defined (OS_WIN) | 9 #if defined (OS_WIN) |
10 #include "base/sys_info.h" | 10 #include "base/sys_info.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 const WebPluginParams& params) | 57 const WebPluginParams& params) |
58 : instance_id_(instance_id), | 58 : instance_id_(instance_id), |
59 render_view_(render_view), | 59 render_view_(render_view), |
60 container_(NULL), | 60 container_(NULL), |
61 damage_buffer_(NULL), | 61 damage_buffer_(NULL), |
62 sad_guest_(NULL), | 62 sad_guest_(NULL), |
63 guest_crashed_(false), | 63 guest_crashed_(false), |
64 resize_pending_(false), | 64 resize_pending_(false), |
65 navigate_src_sent_(false), | 65 navigate_src_sent_(false), |
66 process_id_(-1), | 66 process_id_(-1), |
67 persist_storage_(false) { | 67 persist_storage_(false), |
| 68 guest_routing_id_(MSG_ROUTING_NONE) { |
68 BrowserPluginManager::Get()->AddBrowserPlugin(instance_id, this); | 69 BrowserPluginManager::Get()->AddBrowserPlugin(instance_id, this); |
69 bindings_.reset(new BrowserPluginBindings(this)); | 70 bindings_.reset(new BrowserPluginBindings(this)); |
70 | 71 |
71 ParseAttributes(params); | 72 ParseAttributes(params); |
72 } | 73 } |
73 | 74 |
74 BrowserPlugin::~BrowserPlugin() { | 75 BrowserPlugin::~BrowserPlugin() { |
75 if (damage_buffer_) | 76 if (damage_buffer_) |
76 FreeDamageBuffer(); | 77 FreeDamageBuffer(); |
77 RemoveEventListeners(); | 78 RemoveEventListeners(); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 // guest's |src| to empty value, resize and then set the |src| to a | 126 // guest's |src| to empty value, resize and then set the |src| to a |
126 // non-empty value). | 127 // non-empty value). |
127 // Additionally, once this instance has navigated, the storage partition | 128 // Additionally, once this instance has navigated, the storage partition |
128 // cannot be changed, so this value is used for enforcing this. | 129 // cannot be changed, so this value is used for enforcing this. |
129 navigate_src_sent_ = true; | 130 navigate_src_sent_ = true; |
130 } | 131 } |
131 src_ = src; | 132 src_ = src; |
132 guest_crashed_ = false; | 133 guest_crashed_ = false; |
133 } | 134 } |
134 | 135 |
| 136 NPObject* BrowserPlugin::GetContentWindow() const { |
| 137 if (guest_routing_id_ == MSG_ROUTING_NONE) |
| 138 return NULL; |
| 139 RenderViewImpl* guest_render_view = static_cast<RenderViewImpl*>( |
| 140 ChildThread::current()->ResolveRoute(guest_routing_id_)); |
| 141 WebKit::WebFrame* guest_frame = guest_render_view->GetWebView()->mainFrame(); |
| 142 return guest_frame->windowObject(); |
| 143 } |
| 144 |
135 std::string BrowserPlugin::GetPartitionAttribute() const { | 145 std::string BrowserPlugin::GetPartitionAttribute() const { |
136 std::string value; | 146 std::string value; |
137 if (persist_storage_) | 147 if (persist_storage_) |
138 value.append(kPersistPrefix); | 148 value.append(kPersistPrefix); |
139 | 149 |
140 value.append(storage_partition_id_); | 150 value.append(storage_partition_id_); |
141 return value; | 151 return value; |
142 } | 152 } |
143 | 153 |
144 bool BrowserPlugin::SetPartitionAttribute(const std::string& partition_id, | 154 bool BrowserPlugin::SetPartitionAttribute(const std::string& partition_id, |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 ¶m); | 351 ¶m); |
342 } | 352 } |
343 } | 353 } |
344 | 354 |
345 void BrowserPlugin::AdvanceFocus(bool reverse) { | 355 void BrowserPlugin::AdvanceFocus(bool reverse) { |
346 // We do not have a RenderView when we are testing. | 356 // We do not have a RenderView when we are testing. |
347 if (render_view_) | 357 if (render_view_) |
348 render_view_->GetWebView()->advanceFocus(reverse); | 358 render_view_->GetWebView()->advanceFocus(reverse); |
349 } | 359 } |
350 | 360 |
| 361 void BrowserPlugin::ReceiveMessage(int source_routing_id, |
| 362 const string16& source_origin, |
| 363 int source_frame_id, |
| 364 const string16& data) { |
| 365 // This is a swapped out RenderViewImpl for the guest in the embedder process. |
| 366 WebKit::WebFrame* source_frame = NULL; |
| 367 if (source_routing_id != MSG_ROUTING_NONE) { |
| 368 RenderViewImpl* source_render_view = static_cast<RenderViewImpl*>( |
| 369 ChildThread::current()->ResolveRoute(source_routing_id)); |
| 370 DCHECK(source_render_view->is_swapped_out()); |
| 371 if (source_render_view) { |
| 372 // TODO(fsamuel, nasko): Lookup based on the frame id, once |
| 373 // http://crbug.com/153701 is fixed and we can rely on having frame tree |
| 374 // updates again. |
| 375 source_frame = source_render_view->webview()->mainFrame(); |
| 376 } |
| 377 } |
| 378 WebKit::WebFrame* target_frame = render_view_->webview()->mainFrame(); |
| 379 WebKit::WebDOMEvent event = |
| 380 target_frame->document().createEvent("MessageEvent"); |
| 381 WebKit::WebDOMMessageEvent msg_event = event.to<WebKit::WebDOMMessageEvent>(); |
| 382 msg_event.initMessageEvent("message", |
| 383 // |canBubble| and |cancellable| are always false |
| 384 false, false, |
| 385 WebKit::WebSerializedScriptValue::fromString(data), |
| 386 source_origin, source_frame, ""); |
| 387 // TODO(fsamuel): Does it make sense to do an origin check here? When |
| 388 // the guest replies back to the embedder, the embedder cannot possibly |
| 389 // navigate away to a different origin because the guest's lifetime |
| 390 // is tied to the embedder's lifetime. If the embedder navigates away, |
| 391 // the guest is cleaned up. |
| 392 container()->element().dispatchEvent(msg_event); |
| 393 } |
| 394 |
| 395 void BrowserPlugin::GuestContentWindowReady(int guest_routing_id) { |
| 396 DCHECK(guest_routing_id != MSG_ROUTING_NONE); |
| 397 guest_routing_id_ = guest_routing_id; |
| 398 } |
| 399 |
351 void BrowserPlugin::SetAcceptTouchEvents(bool accept) { | 400 void BrowserPlugin::SetAcceptTouchEvents(bool accept) { |
352 if (container()) | 401 if (container()) |
353 container()->setIsAcceptingTouchEvents(accept); | 402 container()->setIsAcceptingTouchEvents(accept); |
354 } | 403 } |
355 | 404 |
356 bool BrowserPlugin::HasListeners(const std::string& event_name) { | 405 bool BrowserPlugin::HasListeners(const std::string& event_name) { |
357 return event_listener_map_.find(event_name) != event_listener_map_.end(); | 406 return event_listener_map_.find(event_name) != event_listener_map_.end(); |
358 } | 407 } |
359 | 408 |
360 bool BrowserPlugin::AddEventListener(const std::string& event_name, | 409 bool BrowserPlugin::AddEventListener(const std::string& event_name, |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
618 void* notify_data) { | 667 void* notify_data) { |
619 } | 668 } |
620 | 669 |
621 void BrowserPlugin::didFailLoadingFrameRequest( | 670 void BrowserPlugin::didFailLoadingFrameRequest( |
622 const WebKit::WebURL& url, | 671 const WebKit::WebURL& url, |
623 void* notify_data, | 672 void* notify_data, |
624 const WebKit::WebURLError& error) { | 673 const WebKit::WebURLError& error) { |
625 } | 674 } |
626 | 675 |
627 } // namespace content | 676 } // namespace content |
OLD | NEW |