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/browser_plugin/browser_plugin_host_factory.h" | 9 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" |
10 #include "content/browser/renderer_host/render_view_host_impl.h" | 10 #include "content/browser/renderer_host/render_view_host_impl.h" |
11 #include "content/browser/web_contents/web_contents_impl.h" | 11 #include "content/browser/web_contents/web_contents_impl.h" |
12 #include "content/common/browser_plugin/browser_plugin_constants.h" | 12 #include "content/common/browser_plugin/browser_plugin_constants.h" |
13 #include "content/common/browser_plugin/browser_plugin_messages.h" | 13 #include "content/common/browser_plugin/browser_plugin_messages.h" |
14 #include "content/common/drag_messages.h" | 14 #include "content/common/drag_messages.h" |
15 #include "content/common/gpu/gpu_messages.h" | 15 #include "content/common/gpu/gpu_messages.h" |
16 #include "content/public/browser/browser_context.h" | 16 #include "content/public/browser/browser_context.h" |
17 #include "content/public/browser/browser_plugin_guest_manager.h" | 17 #include "content/public/browser/browser_plugin_guest_manager.h" |
18 #include "content/public/browser/content_browser_client.h" | 18 #include "content/public/browser/content_browser_client.h" |
19 #include "content/public/browser/native_web_keyboard_event.h" | 19 #include "content/public/browser/native_web_keyboard_event.h" |
20 #include "content/public/browser/render_view_host.h" | 20 #include "content/public/browser/render_view_host.h" |
21 #include "content/public/browser/user_metrics.h" | 21 #include "content/public/browser/user_metrics.h" |
22 #include "content/public/common/content_switches.h" | 22 #include "content/public/common/content_switches.h" |
23 #include "content/public/common/result_codes.h" | 23 #include "content/public/common/result_codes.h" |
24 #include "content/public/common/url_constants.h" | 24 #include "content/public/common/url_constants.h" |
25 #include "net/base/escape.h" | 25 #include "net/base/escape.h" |
26 #include "ui/events/keycodes/keyboard_codes.h" | 26 #include "ui/events/keycodes/keyboard_codes.h" |
27 | 27 |
28 | |
Fady Samuel
2014/06/03 16:36:34
Remove extra space.
lazyboy
2014/06/03 19:17:58
Done.
| |
28 namespace content { | 29 namespace content { |
29 | 30 |
30 // static | 31 // static |
31 BrowserPluginHostFactory* BrowserPluginEmbedder::factory_ = NULL; | 32 BrowserPluginHostFactory* BrowserPluginEmbedder::factory_ = NULL; |
32 | 33 |
33 BrowserPluginEmbedder::BrowserPluginEmbedder(WebContentsImpl* web_contents) | 34 BrowserPluginEmbedder::BrowserPluginEmbedder(WebContentsImpl* web_contents) |
34 : WebContentsObserver(web_contents), | 35 : WebContentsObserver(web_contents), |
35 weak_ptr_factory_(this) { | 36 weak_ptr_factory_(this) { |
36 } | 37 } |
37 | 38 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
99 GetBrowserPluginGuestManager()->ForEachGuest( | 100 GetBrowserPluginGuestManager()->ForEachGuest( |
100 GetWebContents(), base::Bind( | 101 GetWebContents(), base::Bind( |
101 &BrowserPluginEmbedder::SetZoomLevelCallback, | 102 &BrowserPluginEmbedder::SetZoomLevelCallback, |
102 base::Unretained(this), | 103 base::Unretained(this), |
103 level)); | 104 level)); |
104 } | 105 } |
105 | 106 |
106 bool BrowserPluginEmbedder::OnMessageReceived(const IPC::Message& message) { | 107 bool BrowserPluginEmbedder::OnMessageReceived(const IPC::Message& message) { |
107 bool handled = true; | 108 bool handled = true; |
108 IPC_BEGIN_MESSAGE_MAP(BrowserPluginEmbedder, message) | 109 IPC_BEGIN_MESSAGE_MAP(BrowserPluginEmbedder, message) |
109 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_AllocateInstanceID, | |
110 OnAllocateInstanceID) | |
111 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Attach, OnAttach) | 110 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Attach, OnAttach) |
112 IPC_MESSAGE_HANDLER_GENERIC(DragHostMsg_UpdateDragCursor, | 111 IPC_MESSAGE_HANDLER_GENERIC(DragHostMsg_UpdateDragCursor, |
113 OnUpdateDragCursor(&handled)); | 112 OnUpdateDragCursor(&handled)); |
114 IPC_MESSAGE_UNHANDLED(handled = false) | 113 IPC_MESSAGE_UNHANDLED(handled = false) |
115 IPC_END_MESSAGE_MAP() | 114 IPC_END_MESSAGE_MAP() |
116 return handled; | 115 return handled; |
117 } | 116 } |
118 | 117 |
119 void BrowserPluginEmbedder::DragSourceEndedAt(int client_x, int client_y, | 118 void BrowserPluginEmbedder::DragSourceEndedAt(int client_x, int client_y, |
120 int screen_x, int screen_y, blink::WebDragOperation operation) { | 119 int screen_x, int screen_y, blink::WebDragOperation operation) { |
(...skipping 12 matching lines...) Expand all Loading... | |
133 if (guest_started_drag_.get()) | 132 if (guest_started_drag_.get()) |
134 guest_started_drag_->EndSystemDrag(); | 133 guest_started_drag_->EndSystemDrag(); |
135 guest_started_drag_.reset(); | 134 guest_started_drag_.reset(); |
136 guest_dragging_over_.reset(); | 135 guest_dragging_over_.reset(); |
137 } | 136 } |
138 | 137 |
139 void BrowserPluginEmbedder::OnUpdateDragCursor(bool* handled) { | 138 void BrowserPluginEmbedder::OnUpdateDragCursor(bool* handled) { |
140 *handled = (guest_dragging_over_.get() != NULL); | 139 *handled = (guest_dragging_over_.get() != NULL); |
141 } | 140 } |
142 | 141 |
143 void BrowserPluginEmbedder::OnAllocateInstanceID(int request_id) { | |
144 int instance_id = GetBrowserPluginGuestManager()->GetNextInstanceID(); | |
145 Send(new BrowserPluginMsg_AllocateInstanceID_ACK( | |
146 routing_id(), request_id, instance_id)); | |
147 } | |
148 | |
149 void BrowserPluginEmbedder::OnGuestCallback( | 142 void BrowserPluginEmbedder::OnGuestCallback( |
150 int instance_id, | 143 int instance_id, |
151 const BrowserPluginHostMsg_Attach_Params& params, | 144 const BrowserPluginHostMsg_Attach_Params& params, |
152 const base::DictionaryValue* extra_params, | 145 const base::DictionaryValue* extra_params, |
153 WebContents* guest_web_contents) { | 146 WebContents* guest_web_contents) { |
154 BrowserPluginGuest* guest = guest_web_contents ? | 147 BrowserPluginGuest* guest = guest_web_contents ? |
155 static_cast<WebContentsImpl*>(guest_web_contents)-> | 148 static_cast<WebContentsImpl*>(guest_web_contents)-> |
156 GetBrowserPluginGuest() : NULL; | 149 GetBrowserPluginGuest() : NULL; |
150 printf("OnGuestCallback: guest [%p]\n", guest); | |
151 if (!guest) { | |
152 scoped_ptr<base::DictionaryValue> copy_extra_params( | |
153 extra_params->DeepCopy()); | |
154 guest_web_contents = GetBrowserPluginGuestManager()->CreateGuest( | |
155 GetWebContents()->GetSiteInstance(), | |
156 instance_id, | |
157 copy_extra_params.Pass()); | |
158 guest = guest_web_contents ? | |
159 static_cast<WebContentsImpl*>(guest_web_contents)-> | |
160 GetBrowserPluginGuest() : NULL; | |
161 } | |
162 | |
157 if (guest) { | 163 if (guest) { |
158 // There is an implicit order expectation here: | 164 // There is an implicit order expectation here: |
159 // 1. The content embedder is made aware of the attachment. | 165 // 1. The content embedder is made aware of the attachment. |
160 // 2. BrowserPluginGuest::Attach is called. | 166 // 2. BrowserPluginGuest::Attach is called. |
161 // 3. The content embedder issues queued events if any that happened | 167 // 3. The content embedder issues queued events if any that happened |
162 // prior to attachment. | 168 // prior to attachment. |
163 GetContentClient()->browser()->GuestWebContentsAttached( | 169 GetContentClient()->browser()->GuestWebContentsAttached( |
164 guest->GetWebContents(), | 170 guest->GetWebContents(), |
165 GetWebContents(), | 171 GetWebContents(), |
166 *extra_params); | 172 *extra_params); |
167 guest->Attach(GetWebContents(), params, *extra_params); | 173 guest->Attach(GetWebContents(), params, *extra_params); |
168 return; | |
169 } | |
170 | |
171 scoped_ptr<base::DictionaryValue> copy_extra_params(extra_params->DeepCopy()); | |
172 guest_web_contents = GetBrowserPluginGuestManager()->CreateGuest( | |
173 GetWebContents()->GetSiteInstance(), | |
174 instance_id, | |
175 params.storage_partition_id, | |
176 params.persist_storage, | |
177 copy_extra_params.Pass()); | |
178 guest = guest_web_contents ? | |
179 static_cast<WebContentsImpl*>(guest_web_contents)-> | |
180 GetBrowserPluginGuest() : NULL; | |
181 if (guest) { | |
182 GetContentClient()->browser()->GuestWebContentsAttached( | |
183 guest->GetWebContents(), | |
184 GetWebContents(), | |
185 *extra_params); | |
186 guest->Initialize(params, GetWebContents()); | |
187 } | 174 } |
188 } | 175 } |
189 | 176 |
190 void BrowserPluginEmbedder::OnAttach( | 177 void BrowserPluginEmbedder::OnAttach( |
191 int instance_id, | 178 int instance_id, |
192 const BrowserPluginHostMsg_Attach_Params& params, | 179 const BrowserPluginHostMsg_Attach_Params& params, |
193 const base::DictionaryValue& extra_params) { | 180 const base::DictionaryValue& extra_params) { |
194 GetBrowserPluginGuestManager()->MaybeGetGuestByInstanceIDOrKill( | 181 GetBrowserPluginGuestManager()->MaybeGetGuestByInstanceIDOrKill( |
195 instance_id, GetWebContents()->GetRenderProcessHost()->GetID(), | 182 instance_id, GetWebContents()->GetRenderProcessHost()->GetID(), |
196 base::Bind(&BrowserPluginEmbedder::OnGuestCallback, | 183 base::Bind(&BrowserPluginEmbedder::OnGuestCallback, |
197 base::Unretained(this), | 184 base::Unretained(this), |
198 instance_id, | 185 instance_id, |
199 params, | 186 params, |
200 &extra_params)); | 187 &extra_params)); |
201 } | 188 } |
202 | 189 |
203 } // namespace content | 190 } // namespace content |
OLD | NEW |