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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: content/renderer/browser_plugin/browser_plugin.cc
diff --git a/content/renderer/browser_plugin/browser_plugin.cc b/content/renderer/browser_plugin/browser_plugin.cc
index 712c41a93f060738323e498f6fa612bbd476bcd5..abee6b87a34bf82fc148554fe64c4945cdcc42cc 100644
--- a/content/renderer/browser_plugin/browser_plugin.cc
+++ b/content/renderer/browser_plugin/browser_plugin.cc
@@ -64,7 +64,8 @@ BrowserPlugin::BrowserPlugin(
resize_pending_(false),
navigate_src_sent_(false),
process_id_(-1),
- persist_storage_(false) {
+ persist_storage_(false),
+ guest_routing_id_(MSG_ROUTING_NONE) {
BrowserPluginManager::Get()->AddBrowserPlugin(instance_id, this);
bindings_.reset(new BrowserPluginBindings(this));
@@ -132,6 +133,15 @@ void BrowserPlugin::SetSrcAttribute(const std::string& src) {
guest_crashed_ = false;
}
+NPObject* BrowserPlugin::GetContentWindow() const {
+ if (guest_routing_id_ == MSG_ROUTING_NONE)
+ return NULL;
+ RenderViewImpl* guest_render_view = static_cast<RenderViewImpl*>(
+ ChildThread::current()->ResolveRoute(guest_routing_id_));
+ WebKit::WebFrame* guest_frame = guest_render_view->GetWebView()->mainFrame();
+ return guest_frame->windowObject();
+}
+
std::string BrowserPlugin::GetPartitionAttribute() const {
std::string value;
if (persist_storage_)
@@ -348,6 +358,42 @@ void BrowserPlugin::AdvanceFocus(bool reverse) {
render_view_->GetWebView()->advanceFocus(reverse);
}
+void BrowserPlugin::ReceiveMessage(int source_routing_id,
+ const string16& source_origin,
+ int source_frame_id,
+ const string16& data) {
+ // 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.
+ WebKit::WebFrame* source_frame = NULL;
+ if (source_routing_id != MSG_ROUTING_NONE) {
+ RenderViewImpl* source_render_view = static_cast<RenderViewImpl*>(
+ ChildThread::current()->ResolveRoute(source_routing_id));
+ if (source_render_view) {
+ source_frame = source_render_view->GetFrameByMappedID(
+ source_frame_id);
+ }
+ }
+ 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
+ WebKit::WebDOMEvent event =
+ target_frame->document().createEvent("MessageEvent");
+ WebKit::WebDOMMessageEvent msg_event = event.to<WebKit::WebDOMMessageEvent>();
+ msg_event.initMessageEvent("message",
+ // |canBubble| and |cancellable| are always false
+ false, false,
+ WebKit::WebSerializedScriptValue::fromString(data),
+ source_origin, source_frame, "");
+ // TODO(fsamuel): Does it make sense to do an origin check here? When
+ // the guest replies back to the embedder, the embedder cannot possibly
+ // navigate away to a different origin because the guest's lifetime
+ // is tied to the embedder's lifetime. If the embedder navigates away,
+ // the guest is cleaned up.
+ container()->element().dispatchEvent(msg_event);
+}
+
+void BrowserPlugin::GuestContentWindowReady(int guest_routing_id) {
+ DCHECK(guest_routing_id != MSG_ROUTING_NONE);
+ guest_routing_id_ = guest_routing_id;
+}
+
void BrowserPlugin::SetAcceptTouchEvents(bool accept) {
if (container())
container()->setIsAcceptingTouchEvents(accept);

Powered by Google App Engine
This is Rietveld 408576698