| 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_embedder.h" | 5 #include "content/browser/browser_plugin/browser_plugin_embedder.h" |
| 6 | 6 |
| 7 #include "base/values.h" | 7 #include "base/values.h" |
| 8 #include "content/browser/browser_plugin/browser_plugin_guest.h" | 8 #include "content/browser/browser_plugin/browser_plugin_guest.h" |
| 9 #include "content/browser/renderer_host/render_view_host_impl.h" | 9 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 10 #include "content/browser/web_contents/web_contents_impl.h" | 10 #include "content/browser/web_contents/web_contents_impl.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 void BrowserPluginEmbedder::DidSendScreenRects() { | 76 void BrowserPluginEmbedder::DidSendScreenRects() { |
| 77 GetBrowserPluginGuestManager()->ForEachGuest( | 77 GetBrowserPluginGuestManager()->ForEachGuest( |
| 78 GetWebContents(), base::Bind( | 78 GetWebContents(), base::Bind( |
| 79 &BrowserPluginEmbedder::DidSendScreenRectsCallback, | 79 &BrowserPluginEmbedder::DidSendScreenRectsCallback, |
| 80 base::Unretained(this))); | 80 base::Unretained(this))); |
| 81 } | 81 } |
| 82 | 82 |
| 83 bool BrowserPluginEmbedder::OnMessageReceived(const IPC::Message& message) { | 83 bool BrowserPluginEmbedder::OnMessageReceived(const IPC::Message& message) { |
| 84 bool handled = true; | 84 bool handled = true; |
| 85 IPC_BEGIN_MESSAGE_MAP(BrowserPluginEmbedder, message) | 85 IPC_BEGIN_MESSAGE_MAP(BrowserPluginEmbedder, message) |
| 86 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_AllocateInstanceID, | |
| 87 OnAllocateInstanceID) | |
| 88 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Attach, OnAttach) | 86 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Attach, OnAttach) |
| 89 IPC_MESSAGE_HANDLER_GENERIC(DragHostMsg_UpdateDragCursor, | 87 IPC_MESSAGE_HANDLER_GENERIC(DragHostMsg_UpdateDragCursor, |
| 90 OnUpdateDragCursor(&handled)); | 88 OnUpdateDragCursor(&handled)); |
| 91 IPC_MESSAGE_UNHANDLED(handled = false) | 89 IPC_MESSAGE_UNHANDLED(handled = false) |
| 92 IPC_END_MESSAGE_MAP() | 90 IPC_END_MESSAGE_MAP() |
| 93 return handled; | 91 return handled; |
| 94 } | 92 } |
| 95 | 93 |
| 96 void BrowserPluginEmbedder::DragSourceEndedAt(int client_x, int client_y, | 94 void BrowserPluginEmbedder::DragSourceEndedAt(int client_x, int client_y, |
| 97 int screen_x, int screen_y, blink::WebDragOperation operation) { | 95 int screen_x, int screen_y, blink::WebDragOperation operation) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 110 if (guest_started_drag_.get()) | 108 if (guest_started_drag_.get()) |
| 111 guest_started_drag_->EndSystemDrag(); | 109 guest_started_drag_->EndSystemDrag(); |
| 112 guest_started_drag_.reset(); | 110 guest_started_drag_.reset(); |
| 113 guest_dragging_over_.reset(); | 111 guest_dragging_over_.reset(); |
| 114 } | 112 } |
| 115 | 113 |
| 116 void BrowserPluginEmbedder::OnUpdateDragCursor(bool* handled) { | 114 void BrowserPluginEmbedder::OnUpdateDragCursor(bool* handled) { |
| 117 *handled = (guest_dragging_over_.get() != NULL); | 115 *handled = (guest_dragging_over_.get() != NULL); |
| 118 } | 116 } |
| 119 | 117 |
| 120 void BrowserPluginEmbedder::OnAllocateInstanceID(int request_id) { | |
| 121 int instance_id = GetBrowserPluginGuestManager()->GetNextInstanceID(); | |
| 122 Send(new BrowserPluginMsg_AllocateInstanceID_ACK( | |
| 123 routing_id(), request_id, instance_id)); | |
| 124 } | |
| 125 | |
| 126 void BrowserPluginEmbedder::OnGuestCallback( | 118 void BrowserPluginEmbedder::OnGuestCallback( |
| 127 int instance_id, | 119 int instance_id, |
| 128 const BrowserPluginHostMsg_Attach_Params& params, | 120 const BrowserPluginHostMsg_Attach_Params& params, |
| 129 const base::DictionaryValue* extra_params, | 121 const base::DictionaryValue* extra_params, |
| 130 WebContents* guest_web_contents) { | 122 WebContents* guest_web_contents) { |
| 131 BrowserPluginGuest* guest = guest_web_contents ? | 123 BrowserPluginGuest* guest = guest_web_contents ? |
| 132 static_cast<WebContentsImpl*>(guest_web_contents)-> | 124 static_cast<WebContentsImpl*>(guest_web_contents)-> |
| 133 GetBrowserPluginGuest() : NULL; | 125 GetBrowserPluginGuest() : NULL; |
| 126 if (!guest) { |
| 127 scoped_ptr<base::DictionaryValue> copy_extra_params( |
| 128 extra_params->DeepCopy()); |
| 129 guest_web_contents = GetBrowserPluginGuestManager()->CreateGuest( |
| 130 GetWebContents()->GetSiteInstance(), |
| 131 instance_id, |
| 132 copy_extra_params.Pass()); |
| 133 guest = guest_web_contents |
| 134 ? static_cast<WebContentsImpl*>(guest_web_contents) |
| 135 ->GetBrowserPluginGuest() |
| 136 : NULL; |
| 137 } |
| 138 |
| 134 if (guest) { | 139 if (guest) { |
| 135 // There is an implicit order expectation here: | 140 // There is an implicit order expectation here: |
| 136 // 1. The content embedder is made aware of the attachment. | 141 // 1. The content embedder is made aware of the attachment. |
| 137 // 2. BrowserPluginGuest::Attach is called. | 142 // 2. BrowserPluginGuest::Attach is called. |
| 138 // 3. The content embedder issues queued events if any that happened | 143 // 3. The content embedder issues queued events if any that happened |
| 139 // prior to attachment. | 144 // prior to attachment. |
| 140 GetContentClient()->browser()->GuestWebContentsAttached( | 145 GetContentClient()->browser()->GuestWebContentsAttached( |
| 141 guest->GetWebContents(), | 146 guest->GetWebContents(), |
| 142 GetWebContents(), | 147 GetWebContents(), |
| 143 *extra_params); | 148 *extra_params); |
| 144 guest->Attach(GetWebContents(), params, *extra_params); | 149 guest->Attach(GetWebContents(), params, *extra_params); |
| 145 return; | |
| 146 } | |
| 147 | |
| 148 scoped_ptr<base::DictionaryValue> copy_extra_params(extra_params->DeepCopy()); | |
| 149 guest_web_contents = GetBrowserPluginGuestManager()->CreateGuest( | |
| 150 GetWebContents()->GetSiteInstance(), | |
| 151 instance_id, | |
| 152 params.storage_partition_id, | |
| 153 params.persist_storage, | |
| 154 copy_extra_params.Pass()); | |
| 155 guest = guest_web_contents ? | |
| 156 static_cast<WebContentsImpl*>(guest_web_contents)-> | |
| 157 GetBrowserPluginGuest() : NULL; | |
| 158 if (guest) { | |
| 159 GetContentClient()->browser()->GuestWebContentsAttached( | |
| 160 guest->GetWebContents(), | |
| 161 GetWebContents(), | |
| 162 *extra_params); | |
| 163 guest->Initialize(params, GetWebContents()); | |
| 164 } | 150 } |
| 165 } | 151 } |
| 166 | 152 |
| 167 void BrowserPluginEmbedder::OnAttach( | 153 void BrowserPluginEmbedder::OnAttach( |
| 168 int instance_id, | 154 int instance_id, |
| 169 const BrowserPluginHostMsg_Attach_Params& params, | 155 const BrowserPluginHostMsg_Attach_Params& params, |
| 170 const base::DictionaryValue& extra_params) { | 156 const base::DictionaryValue& extra_params) { |
| 171 GetBrowserPluginGuestManager()->MaybeGetGuestByInstanceIDOrKill( | 157 GetBrowserPluginGuestManager()->MaybeGetGuestByInstanceIDOrKill( |
| 172 instance_id, GetWebContents()->GetRenderProcessHost()->GetID(), | 158 instance_id, GetWebContents()->GetRenderProcessHost()->GetID(), |
| 173 base::Bind(&BrowserPluginEmbedder::OnGuestCallback, | 159 base::Bind(&BrowserPluginEmbedder::OnGuestCallback, |
| 174 base::Unretained(this), | 160 base::Unretained(this), |
| 175 instance_id, | 161 instance_id, |
| 176 params, | 162 params, |
| 177 &extra_params)); | 163 &extra_params)); |
| 178 } | 164 } |
| 179 | 165 |
| 180 } // namespace content | 166 } // namespace content |
| OLD | NEW |