Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(80)

Side by Side Diff: content/renderer/browser_plugin/browser_plugin.cc

Issue 10829225: Browser Plugin: Add HTML5-like postMessage support (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge with ToT. Added subframe targeting + test. Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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
341 &param); 351 &param);
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.
nasko 2012/10/02 17:52:31 If this is the case, can we DCHECK that it is inde
Fady Samuel 2012/10/02 22:04:08 Done.
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 if (source_render_view) {
371 source_frame = source_render_view->GetFrameByMappedID(
372 source_frame_id);
373 }
374 }
375 WebKit::WebFrame* target_frame = render_view_->webview()->mainFrame();
nasko 2012/10/02 17:52:31 Why are we using the top level frame as the target
Fady Samuel 2012/10/02 22:04:08 I'm not sure it matters? We only use target_frame
376 WebKit::WebDOMEvent event =
377 target_frame->document().createEvent("MessageEvent");
378 WebKit::WebDOMMessageEvent msg_event = event.to<WebKit::WebDOMMessageEvent>();
379 msg_event.initMessageEvent("message",
380 // |canBubble| and |cancellable| are always false
381 false, false,
382 WebKit::WebSerializedScriptValue::fromString(data),
383 source_origin, source_frame, "");
384 // TODO(fsamuel): Does it make sense to do an origin check here? When
385 // the guest replies back to the embedder, the embedder cannot possibly
386 // navigate away to a different origin because the guest's lifetime
387 // is tied to the embedder's lifetime. If the embedder navigates away,
388 // the guest is cleaned up.
389 container()->element().dispatchEvent(msg_event);
390 }
391
392 void BrowserPlugin::GuestContentWindowReady(int guest_routing_id) {
393 DCHECK(guest_routing_id != MSG_ROUTING_NONE);
394 guest_routing_id_ = guest_routing_id;
395 }
396
351 void BrowserPlugin::SetAcceptTouchEvents(bool accept) { 397 void BrowserPlugin::SetAcceptTouchEvents(bool accept) {
352 if (container()) 398 if (container())
353 container()->setIsAcceptingTouchEvents(accept); 399 container()->setIsAcceptingTouchEvents(accept);
354 } 400 }
355 401
356 bool BrowserPlugin::HasListeners(const std::string& event_name) { 402 bool BrowserPlugin::HasListeners(const std::string& event_name) {
357 return event_listener_map_.find(event_name) != event_listener_map_.end(); 403 return event_listener_map_.find(event_name) != event_listener_map_.end();
358 } 404 }
359 405
360 bool BrowserPlugin::AddEventListener(const std::string& event_name, 406 bool BrowserPlugin::AddEventListener(const std::string& event_name,
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 void* notify_data) { 664 void* notify_data) {
619 } 665 }
620 666
621 void BrowserPlugin::didFailLoadingFrameRequest( 667 void BrowserPlugin::didFailLoadingFrameRequest(
622 const WebKit::WebURL& url, 668 const WebKit::WebURL& url,
623 void* notify_data, 669 void* notify_data,
624 const WebKit::WebURLError& error) { 670 const WebKit::WebURLError& error) {
625 } 671 }
626 672
627 } // namespace content 673 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698