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_guest_manager.h" | 9 #include "content/browser/browser_plugin/browser_plugin_guest_manager.h" |
10 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" | 10 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" |
(...skipping 13 matching lines...) Expand all Loading... |
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 namespace content { | 28 namespace content { |
29 | 29 |
30 // static | 30 // static |
31 BrowserPluginHostFactory* BrowserPluginEmbedder::factory_ = NULL; | 31 BrowserPluginHostFactory* BrowserPluginEmbedder::factory_ = NULL; |
32 | 32 |
33 BrowserPluginEmbedder::BrowserPluginEmbedder(WebContentsImpl* web_contents) | 33 BrowserPluginEmbedder::BrowserPluginEmbedder(WebContentsImpl* web_contents) |
34 : WebContentsObserver(web_contents) { | 34 : WebContentsObserver(web_contents), |
| 35 weak_ptr_factory_(this) { |
35 } | 36 } |
36 | 37 |
37 BrowserPluginEmbedder::~BrowserPluginEmbedder() { | 38 BrowserPluginEmbedder::~BrowserPluginEmbedder() { |
38 } | 39 } |
39 | 40 |
40 // static | 41 // static |
41 BrowserPluginEmbedder* BrowserPluginEmbedder::Create( | 42 BrowserPluginEmbedder* BrowserPluginEmbedder::Create( |
42 WebContentsImpl* web_contents) { | 43 WebContentsImpl* web_contents) { |
43 if (factory_) | 44 if (factory_) |
44 return factory_->CreateBrowserPluginEmbedder(web_contents); | 45 return factory_->CreateBrowserPluginEmbedder(web_contents); |
(...skipping 22 matching lines...) Expand all Loading... |
67 | 68 |
68 bool BrowserPluginEmbedder::DidSendScreenRectsCallback( | 69 bool BrowserPluginEmbedder::DidSendScreenRectsCallback( |
69 BrowserPluginGuest* guest) { | 70 BrowserPluginGuest* guest) { |
70 static_cast<RenderViewHostImpl*>( | 71 static_cast<RenderViewHostImpl*>( |
71 guest->GetWebContents()->GetRenderViewHost())->SendScreenRects(); | 72 guest->GetWebContents()->GetRenderViewHost())->SendScreenRects(); |
72 // Not handled => Iterate over all guests. | 73 // Not handled => Iterate over all guests. |
73 return false; | 74 return false; |
74 } | 75 } |
75 | 76 |
76 void BrowserPluginEmbedder::DidSendScreenRects() { | 77 void BrowserPluginEmbedder::DidSendScreenRects() { |
77 GetBrowserPluginGuestManager()->ForEachGuest(GetWebContents(), base::Bind( | 78 BrowserPluginGuestManager::FromBrowserContext( |
78 &BrowserPluginEmbedder::DidSendScreenRectsCallback, | 79 GetWebContents()->GetBrowserContext())->ForEachGuest( |
79 base::Unretained(this))); | 80 GetWebContents(), base::Bind( |
| 81 &BrowserPluginEmbedder::DidSendScreenRectsCallback, |
| 82 base::Unretained(this))); |
80 } | 83 } |
81 | 84 |
82 bool BrowserPluginEmbedder::UnlockMouseIfNecessaryCallback( | 85 bool BrowserPluginEmbedder::UnlockMouseIfNecessaryCallback( |
83 const NativeWebKeyboardEvent& event, | 86 const NativeWebKeyboardEvent& event, |
84 BrowserPluginGuest* guest) { | 87 BrowserPluginGuest* guest) { |
85 return guest->UnlockMouseIfNecessary(event); | 88 return guest->UnlockMouseIfNecessary(event); |
86 } | 89 } |
87 | 90 |
88 bool BrowserPluginEmbedder::HandleKeyboardEvent( | 91 bool BrowserPluginEmbedder::HandleKeyboardEvent( |
89 const NativeWebKeyboardEvent& event) { | 92 const NativeWebKeyboardEvent& event) { |
90 if ((event.type != blink::WebInputEvent::RawKeyDown) || | 93 if ((event.type != blink::WebInputEvent::RawKeyDown) || |
91 (event.windowsKeyCode != ui::VKEY_ESCAPE) || | 94 (event.windowsKeyCode != ui::VKEY_ESCAPE) || |
92 (event.modifiers & blink::WebInputEvent::InputModifiers)) { | 95 (event.modifiers & blink::WebInputEvent::InputModifiers)) { |
93 return false; | 96 return false; |
94 } | 97 } |
95 | 98 |
96 return GetBrowserPluginGuestManager()->ForEachGuest(GetWebContents(), | 99 return BrowserPluginGuestManager::FromBrowserContext( |
97 base::Bind(&BrowserPluginEmbedder::UnlockMouseIfNecessaryCallback, | 100 GetWebContents()->GetBrowserContext())->ForEachGuest( |
98 base::Unretained(this), | 101 GetWebContents(), |
99 event)); | 102 base::Bind(&BrowserPluginEmbedder::UnlockMouseIfNecessaryCallback, |
| 103 base::Unretained(this), |
| 104 event)); |
100 } | 105 } |
101 | 106 |
102 bool BrowserPluginEmbedder::SetZoomLevelCallback( | 107 bool BrowserPluginEmbedder::SetZoomLevelCallback( |
103 double level, BrowserPluginGuest* guest) { | 108 double level, BrowserPluginGuest* guest) { |
104 double zoom_factor = content::ZoomLevelToZoomFactor(level); | 109 double zoom_factor = content::ZoomLevelToZoomFactor(level); |
105 guest->SetZoom(zoom_factor); | 110 guest->SetZoom(zoom_factor); |
106 // Not handled => Iterate over all guests. | 111 // Not handled => Iterate over all guests. |
107 return false; | 112 return false; |
108 } | 113 } |
109 | 114 |
110 void BrowserPluginEmbedder::SetZoomLevel(double level) { | 115 void BrowserPluginEmbedder::SetZoomLevel(double level) { |
111 GetBrowserPluginGuestManager()->ForEachGuest(GetWebContents(), base::Bind( | 116 BrowserPluginGuestManager::FromBrowserContext( |
112 &BrowserPluginEmbedder::SetZoomLevelCallback, | 117 GetWebContents()->GetBrowserContext())->ForEachGuest( |
113 base::Unretained(this), | 118 GetWebContents(), base::Bind( |
114 level)); | 119 &BrowserPluginEmbedder::SetZoomLevelCallback, |
| 120 base::Unretained(this), |
| 121 level)); |
115 } | 122 } |
116 | 123 |
117 bool BrowserPluginEmbedder::OnMessageReceived(const IPC::Message& message) { | 124 bool BrowserPluginEmbedder::OnMessageReceived(const IPC::Message& message) { |
118 bool handled = true; | 125 bool handled = true; |
119 IPC_BEGIN_MESSAGE_MAP(BrowserPluginEmbedder, message) | 126 IPC_BEGIN_MESSAGE_MAP(BrowserPluginEmbedder, message) |
120 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_AllocateInstanceID, | 127 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_AllocateInstanceID, |
121 OnAllocateInstanceID) | 128 OnAllocateInstanceID) |
122 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Attach, OnAttach) | 129 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Attach, OnAttach) |
123 IPC_MESSAGE_HANDLER_GENERIC(DragHostMsg_UpdateDragCursor, | 130 IPC_MESSAGE_HANDLER_GENERIC(DragHostMsg_UpdateDragCursor, |
124 OnUpdateDragCursor(&handled)); | 131 OnUpdateDragCursor(&handled)); |
(...skipping 19 matching lines...) Expand all Loading... |
144 if (guest_started_drag_.get()) | 151 if (guest_started_drag_.get()) |
145 guest_started_drag_->EndSystemDrag(); | 152 guest_started_drag_->EndSystemDrag(); |
146 guest_started_drag_.reset(); | 153 guest_started_drag_.reset(); |
147 guest_dragging_over_.reset(); | 154 guest_dragging_over_.reset(); |
148 } | 155 } |
149 | 156 |
150 void BrowserPluginEmbedder::OnUpdateDragCursor(bool* handled) { | 157 void BrowserPluginEmbedder::OnUpdateDragCursor(bool* handled) { |
151 *handled = (guest_dragging_over_.get() != NULL); | 158 *handled = (guest_dragging_over_.get() != NULL); |
152 } | 159 } |
153 | 160 |
154 BrowserPluginGuestManager* | 161 void BrowserPluginEmbedder::AllocateInstanceIDResponse(int request_id, |
155 BrowserPluginEmbedder::GetBrowserPluginGuestManager() { | 162 int instance_id) { |
156 BrowserPluginGuestManager* guest_manager = | 163 Send(new BrowserPluginMsg_AllocateInstanceID_ACK( |
157 GetWebContents()->GetBrowserPluginGuestManager(); | 164 routing_id(), request_id, instance_id)); |
158 if (!guest_manager) { | |
159 guest_manager = BrowserPluginGuestManager::Create(); | |
160 GetWebContents()->GetBrowserContext()->SetUserData( | |
161 browser_plugin::kBrowserPluginGuestManagerKeyName, guest_manager); | |
162 } | |
163 return guest_manager; | |
164 } | 165 } |
165 | 166 |
166 void BrowserPluginEmbedder::OnAllocateInstanceID(int request_id) { | 167 void BrowserPluginEmbedder::OnAllocateInstanceID(int request_id, |
167 int instance_id = GetBrowserPluginGuestManager()->get_next_instance_id(); | 168 const std::string& src) { |
168 Send(new BrowserPluginMsg_AllocateInstanceID_ACK( | 169 BrowserPluginGuestManager::FromBrowserContext( |
169 routing_id(), request_id, instance_id)); | 170 GetWebContents()->GetBrowserContext())->RequestInstanceID( |
| 171 src, base::Bind(&BrowserPluginEmbedder::AllocateInstanceIDResponse, |
| 172 weak_ptr_factory_.GetWeakPtr(), |
| 173 request_id)); |
170 } | 174 } |
171 | 175 |
172 void BrowserPluginEmbedder::OnAttach( | 176 void BrowserPluginEmbedder::OnAttach( |
173 int instance_id, | 177 int instance_id, |
174 const BrowserPluginHostMsg_Attach_Params& params, | 178 const BrowserPluginHostMsg_Attach_Params& params, |
175 const base::DictionaryValue& extra_params) { | 179 const base::DictionaryValue& extra_params) { |
176 if (!GetBrowserPluginGuestManager()->CanEmbedderAccessInstanceIDMaybeKill( | 180 BrowserPluginGuestManager* guest_manager = |
| 181 BrowserPluginGuestManager::FromBrowserContext( |
| 182 GetWebContents()->GetBrowserContext()); |
| 183 if (!guest_manager->CanEmbedderAccessInstanceIDMaybeKill( |
177 GetWebContents()->GetRenderProcessHost()->GetID(), instance_id)) | 184 GetWebContents()->GetRenderProcessHost()->GetID(), instance_id)) |
178 return; | 185 return; |
179 | 186 |
180 BrowserPluginGuest* guest = | 187 BrowserPluginGuest* guest = |
181 GetBrowserPluginGuestManager()->GetGuestByInstanceID( | 188 guest_manager->GetGuestByInstanceID( |
182 instance_id, GetWebContents()->GetRenderProcessHost()->GetID()); | 189 instance_id, GetWebContents()->GetRenderProcessHost()->GetID()); |
183 | 190 |
184 if (guest) { | 191 if (guest) { |
185 // There is an implicit order expectation here: | 192 // There is an implicit order expectation here: |
186 // 1. The content embedder is made aware of the attachment. | 193 // 1. The content embedder is made aware of the attachment. |
187 // 2. BrowserPluginGuest::Attach is called. | 194 // 2. BrowserPluginGuest::Attach is called. |
188 // 3. The content embedder issues queued events if any that happened | 195 // 3. The content embedder issues queued events if any that happened |
189 // prior to attachment. | 196 // prior to attachment. |
190 GetContentClient()->browser()->GuestWebContentsAttached( | 197 GetContentClient()->browser()->GuestWebContentsAttached( |
191 guest->GetWebContents(), | 198 guest->GetWebContents(), |
192 GetWebContents(), | 199 GetWebContents(), |
193 extra_params); | 200 extra_params); |
194 guest->Attach(GetWebContents(), params, extra_params); | 201 guest->Attach(GetWebContents(), params, extra_params); |
195 return; | 202 return; |
196 } | 203 } |
197 | 204 |
198 scoped_ptr<base::DictionaryValue> copy_extra_params(extra_params.DeepCopy()); | 205 scoped_ptr<base::DictionaryValue> copy_extra_params(extra_params.DeepCopy()); |
199 guest = GetBrowserPluginGuestManager()->CreateGuest( | 206 guest = guest_manager->CreateGuest( |
200 GetWebContents()->GetSiteInstance(), | 207 GetWebContents()->GetSiteInstance(), |
201 instance_id, params, | 208 instance_id, params, |
202 copy_extra_params.Pass()); | 209 copy_extra_params.Pass()); |
203 if (guest) { | 210 if (guest) { |
204 GetContentClient()->browser()->GuestWebContentsAttached( | 211 GetContentClient()->browser()->GuestWebContentsAttached( |
205 guest->GetWebContents(), | 212 guest->GetWebContents(), |
206 GetWebContents(), | 213 GetWebContents(), |
207 extra_params); | 214 extra_params); |
208 guest->Initialize(params, GetWebContents()); | 215 guest->Initialize(params, GetWebContents()); |
209 } | 216 } |
210 } | 217 } |
211 | 218 |
212 } // namespace content | 219 } // namespace content |
OLD | NEW |