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/renderer/browser_plugin/browser_plugin.h" | 5 #include "content/renderer/browser_plugin/browser_plugin_impl.h" |
6 | 6 |
7 #include "base/json/json_string_value_serializer.h" | 7 #include "base/json/json_string_value_serializer.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
12 #include "content/common/browser_plugin_messages.h" | 12 #include "content/common/browser_plugin_messages.h" |
13 #include "content/common/view_messages.h" | 13 #include "content/common/view_messages.h" |
14 #include "content/public/common/content_client.h" | 14 #include "content/public/common/content_client.h" |
| 15 #include "content/public/renderer/browser_plugin/browser_plugin_observer.h" |
15 #include "content/public/renderer/content_renderer_client.h" | 16 #include "content/public/renderer/content_renderer_client.h" |
16 #include "content/renderer/browser_plugin/browser_plugin_bindings.h" | 17 #include "content/renderer/browser_plugin/browser_plugin_bindings.h" |
17 #include "content/renderer/browser_plugin/browser_plugin_compositing_helper.h" | 18 #include "content/renderer/browser_plugin/browser_plugin_compositing_helper.h" |
18 #include "content/renderer/browser_plugin/browser_plugin_constants.h" | 19 #include "content/renderer/browser_plugin/browser_plugin_constants.h" |
19 #include "content/renderer/browser_plugin/browser_plugin_manager.h" | 20 #include "content/renderer/browser_plugin/browser_plugin_manager.h" |
20 #include "content/renderer/render_process_impl.h" | 21 #include "content/renderer/render_process_impl.h" |
21 #include "content/renderer/render_thread_impl.h" | 22 #include "content/renderer/render_thread_impl.h" |
22 #include "content/renderer/v8_value_converter_impl.h" | 23 #include "content/renderer/v8_value_converter_impl.h" |
23 #include "skia/ext/platform_canvas.h" | 24 #include "skia/ext/platform_canvas.h" |
24 #include "third_party/WebKit/Source/Platform/chromium/public/WebRect.h" | 25 #include "third_party/WebKit/Source/Platform/chromium/public/WebRect.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 } | 66 } |
66 NOTREACHED() << "Unknown Termination Status."; | 67 NOTREACHED() << "Unknown Termination Status."; |
67 return "unknown"; | 68 return "unknown"; |
68 } | 69 } |
69 | 70 |
70 static std::string GetInternalEventName(const char* event_name) { | 71 static std::string GetInternalEventName(const char* event_name) { |
71 return base::StringPrintf("-internal-%s", event_name); | 72 return base::StringPrintf("-internal-%s", event_name); |
72 } | 73 } |
73 } // namespace | 74 } // namespace |
74 | 75 |
75 BrowserPlugin::BrowserPlugin( | 76 BrowserPluginImpl::BrowserPluginImpl( |
76 RenderViewImpl* render_view, | 77 RenderViewImpl* render_view, |
77 WebKit::WebFrame* frame, | 78 WebKit::WebFrame* frame, |
78 const WebPluginParams& params) | 79 const WebPluginParams& params) |
79 : instance_id_(browser_plugin::kInstanceIDNone), | 80 : instance_id_(browser_plugin::kInstanceIDNone), |
80 render_view_(render_view->AsWeakPtr()), | 81 render_view_(render_view->AsWeakPtr()), |
81 render_view_routing_id_(render_view->GetRoutingID()), | 82 render_view_routing_id_(render_view->GetRoutingID()), |
82 container_(NULL), | 83 container_(NULL), |
83 damage_buffer_sequence_id_(0), | 84 damage_buffer_sequence_id_(0), |
84 resize_ack_received_(true), | 85 resize_ack_received_(true), |
85 sad_guest_(NULL), | 86 sad_guest_(NULL), |
86 guest_crashed_(false), | 87 guest_crashed_(false), |
87 navigate_src_sent_(false), | 88 navigate_src_sent_(false), |
88 auto_size_ack_pending_(false), | 89 auto_size_ack_pending_(false), |
89 guest_process_id_(-1), | 90 guest_process_id_(-1), |
90 guest_route_id_(-1), | 91 guest_route_id_(-1), |
91 persist_storage_(false), | 92 persist_storage_(false), |
92 valid_partition_id_(true), | 93 valid_partition_id_(true), |
93 content_window_routing_id_(MSG_ROUTING_NONE), | 94 content_window_routing_id_(MSG_ROUTING_NONE), |
94 plugin_focused_(false), | 95 plugin_focused_(false), |
95 visible_(true), | 96 visible_(true), |
96 size_changed_in_flight_(false), | 97 size_changed_in_flight_(false), |
97 allocate_instance_id_sent_(false), | 98 allocate_instance_id_sent_(false), |
98 browser_plugin_manager_(render_view->browser_plugin_manager()), | 99 browser_plugin_manager_(render_view->browser_plugin_manager()), |
99 current_nav_entry_index_(0), | 100 current_nav_entry_index_(0), |
100 nav_entry_count_(0), | 101 nav_entry_count_(0), |
101 compositing_enabled_(false), | 102 compositing_enabled_(false), |
102 ALLOW_THIS_IN_INITIALIZER_LIST( | 103 ALLOW_THIS_IN_INITIALIZER_LIST( |
103 weak_ptr_factory_(this)) { | 104 weak_ptr_factory_(this)) { |
| 105 GetContentClient()->renderer()->BrowserPluginCreated(this); |
104 } | 106 } |
105 | 107 |
106 BrowserPlugin::~BrowserPlugin() { | 108 BrowserPluginImpl::~BrowserPluginImpl() { |
107 // If the BrowserPlugin has never navigated then the browser process and | 109 // If the BrowserPlugin has never navigated then the browser process and |
108 // BrowserPluginManager don't know about it and so there is nothing to do | 110 // BrowserPluginManager don't know about it and so there is nothing to do |
109 // here. | 111 // here. |
110 if (!navigate_src_sent_) | 112 if (!navigate_src_sent_) |
111 return; | 113 return; |
112 browser_plugin_manager()->RemoveBrowserPlugin(instance_id_); | 114 browser_plugin_manager()->RemoveBrowserPlugin(instance_id_); |
113 browser_plugin_manager()->Send( | 115 browser_plugin_manager()->Send( |
114 new BrowserPluginHostMsg_PluginDestroyed(render_view_routing_id_, | 116 new BrowserPluginHostMsg_PluginDestroyed(render_view_routing_id_, |
115 instance_id_)); | 117 instance_id_)); |
116 } | 118 } |
117 | 119 |
118 bool BrowserPlugin::OnMessageReceived(const IPC::Message& message) { | 120 void BrowserPluginImpl::AddObserver(BrowserPluginObserver* observer) { |
| 121 observers_.AddObserver(observer); |
| 122 } |
| 123 |
| 124 void BrowserPluginImpl::RemoveObserver(BrowserPluginObserver* observer) { |
| 125 observers_.RemoveObserver(observer); |
| 126 } |
| 127 |
| 128 bool BrowserPluginImpl::OnMessageReceived(const IPC::Message& message) { |
119 bool handled = true; | 129 bool handled = true; |
120 IPC_BEGIN_MESSAGE_MAP(BrowserPlugin, message) | 130 IPC_BEGIN_MESSAGE_MAP(BrowserPluginImpl, message) |
121 IPC_MESSAGE_HANDLER(BrowserPluginMsg_AdvanceFocus, OnAdvanceFocus) | 131 IPC_MESSAGE_HANDLER(BrowserPluginMsg_AdvanceFocus, OnAdvanceFocus) |
122 IPC_MESSAGE_HANDLER(BrowserPluginMsg_BuffersSwapped, OnBuffersSwapped) | 132 IPC_MESSAGE_HANDLER(BrowserPluginMsg_BuffersSwapped, OnBuffersSwapped) |
| 133 IPC_MESSAGE_HANDLER(BrowserPluginMsg_ForwardMessage, OnForwardMessage) |
123 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestContentWindowReady, | 134 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestContentWindowReady, |
124 OnGuestContentWindowReady) | 135 OnGuestContentWindowReady) |
125 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestGone, OnGuestGone) | 136 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestGone, OnGuestGone) |
126 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestResponsive, OnGuestResponsive) | 137 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestResponsive, OnGuestResponsive) |
127 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestUnresponsive, OnGuestUnresponsive) | 138 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestUnresponsive, OnGuestUnresponsive) |
128 IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadAbort, OnLoadAbort) | 139 IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadAbort, OnLoadAbort) |
129 IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadCommit, OnLoadCommit) | 140 IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadCommit, OnLoadCommit) |
130 IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadRedirect, OnLoadRedirect) | 141 IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadRedirect, OnLoadRedirect) |
131 IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadStart, OnLoadStart) | 142 IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadStart, OnLoadStart) |
132 IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadStop, OnLoadStop) | 143 IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadStop, OnLoadStop) |
133 IPC_MESSAGE_HANDLER(BrowserPluginMsg_RequestPermission, OnRequestPermission) | 144 IPC_MESSAGE_HANDLER(BrowserPluginMsg_RequestPermission, OnRequestPermission) |
134 IPC_MESSAGE_HANDLER(BrowserPluginMsg_SetCursor, OnSetCursor) | 145 IPC_MESSAGE_HANDLER(BrowserPluginMsg_SetCursor, OnSetCursor) |
135 IPC_MESSAGE_HANDLER(BrowserPluginMsg_ShouldAcceptTouchEvents, | 146 IPC_MESSAGE_HANDLER(BrowserPluginMsg_ShouldAcceptTouchEvents, |
136 OnShouldAcceptTouchEvents) | 147 OnShouldAcceptTouchEvents) |
137 IPC_MESSAGE_HANDLER(BrowserPluginMsg_UpdatedName, OnUpdatedName) | 148 IPC_MESSAGE_HANDLER(BrowserPluginMsg_UpdatedName, OnUpdatedName) |
138 IPC_MESSAGE_HANDLER(BrowserPluginMsg_UpdateRect, OnUpdateRect) | 149 IPC_MESSAGE_HANDLER(BrowserPluginMsg_UpdateRect, OnUpdateRect) |
139 IPC_MESSAGE_UNHANDLED(handled = false) | 150 IPC_MESSAGE_UNHANDLED(handled = false) |
140 IPC_END_MESSAGE_MAP() | 151 IPC_END_MESSAGE_MAP() |
141 return handled; | 152 return handled; |
142 } | 153 } |
143 | 154 |
144 void BrowserPlugin::UpdateDOMAttribute(const std::string& attribute_name, | 155 std::string BrowserPluginImpl::GetNameAttribute() const { |
145 const std::string& attribute_value) { | |
146 if (!container()) | |
147 return; | |
148 | |
149 WebKit::WebElement element = container()->element(); | |
150 WebKit::WebString web_attribute_name = | |
151 WebKit::WebString::fromUTF8(attribute_name); | |
152 if (!HasDOMAttribute(attribute_name) || | |
153 (std::string(element.getAttribute(web_attribute_name).utf8()) != | |
154 attribute_value)) { | |
155 element.setAttribute(web_attribute_name, | |
156 WebKit::WebString::fromUTF8(attribute_value)); | |
157 } | |
158 } | |
159 | |
160 void BrowserPlugin::RemoveDOMAttribute(const std::string& attribute_name) { | |
161 if (!container()) | |
162 return; | |
163 | |
164 container()->element().removeAttribute( | |
165 WebKit::WebString::fromUTF8(attribute_name)); | |
166 } | |
167 | |
168 std::string BrowserPlugin::GetDOMAttributeValue( | |
169 const std::string& attribute_name) const { | |
170 if (!container()) | |
171 return ""; | |
172 | |
173 return container()->element().getAttribute( | |
174 WebKit::WebString::fromUTF8(attribute_name)).utf8(); | |
175 } | |
176 | |
177 bool BrowserPlugin::HasDOMAttribute(const std::string& attribute_name) const { | |
178 if (!container()) | |
179 return false; | |
180 | |
181 return container()->element().hasAttribute( | |
182 WebKit::WebString::fromUTF8(attribute_name)); | |
183 } | |
184 | |
185 std::string BrowserPlugin::GetNameAttribute() const { | |
186 return GetDOMAttributeValue(browser_plugin::kAttributeName); | 156 return GetDOMAttributeValue(browser_plugin::kAttributeName); |
187 } | 157 } |
188 | 158 |
189 std::string BrowserPlugin::GetSrcAttribute() const { | 159 std::string BrowserPluginImpl::GetSrcAttribute() const { |
190 return GetDOMAttributeValue(browser_plugin::kAttributeSrc); | 160 return GetDOMAttributeValue(browser_plugin::kAttributeSrc); |
191 } | 161 } |
192 | 162 |
193 bool BrowserPlugin::GetAutoSizeAttribute() const { | 163 bool BrowserPluginImpl::GetAutoSizeAttribute() const { |
194 return HasDOMAttribute(browser_plugin::kAttributeAutoSize); | 164 return HasDOMAttribute(browser_plugin::kAttributeAutoSize); |
195 } | 165 } |
196 | 166 |
197 int BrowserPlugin::GetMaxHeightAttribute() const { | 167 int BrowserPluginImpl::GetMaxHeightAttribute() const { |
198 int max_height; | 168 int max_height; |
199 base::StringToInt(GetDOMAttributeValue(browser_plugin::kAttributeMaxHeight), | 169 base::StringToInt(GetDOMAttributeValue(browser_plugin::kAttributeMaxHeight), |
200 &max_height); | 170 &max_height); |
201 return max_height; | 171 return max_height; |
202 } | 172 } |
203 | 173 |
204 int BrowserPlugin::GetMaxWidthAttribute() const { | 174 int BrowserPluginImpl::GetMaxWidthAttribute() const { |
205 int max_width; | 175 int max_width; |
206 base::StringToInt(GetDOMAttributeValue(browser_plugin::kAttributeMaxWidth), | 176 base::StringToInt(GetDOMAttributeValue(browser_plugin::kAttributeMaxWidth), |
207 &max_width); | 177 &max_width); |
208 return max_width; | 178 return max_width; |
209 } | 179 } |
210 | 180 |
211 int BrowserPlugin::GetMinHeightAttribute() const { | 181 int BrowserPluginImpl::GetMinHeightAttribute() const { |
212 int min_height; | 182 int min_height; |
213 base::StringToInt(GetDOMAttributeValue(browser_plugin::kAttributeMinHeight), | 183 base::StringToInt(GetDOMAttributeValue(browser_plugin::kAttributeMinHeight), |
214 &min_height); | 184 &min_height); |
215 return min_height; | 185 return min_height; |
216 } | 186 } |
217 | 187 |
218 int BrowserPlugin::GetMinWidthAttribute() const { | 188 int BrowserPluginImpl::GetMinWidthAttribute() const { |
219 int min_width; | 189 int min_width; |
220 base::StringToInt(GetDOMAttributeValue(browser_plugin::kAttributeMinWidth), | 190 base::StringToInt(GetDOMAttributeValue(browser_plugin::kAttributeMinWidth), |
221 &min_width); | 191 &min_width); |
222 return min_width; | 192 return min_width; |
223 } | 193 } |
224 | 194 |
225 int BrowserPlugin::GetAdjustedMaxHeight() const { | 195 int BrowserPluginImpl::GetAdjustedMaxHeight() const { |
226 int max_height = GetMaxHeightAttribute(); | 196 int max_height = GetMaxHeightAttribute(); |
227 return max_height ? max_height : height(); | 197 return max_height ? max_height : height(); |
228 } | 198 } |
229 | 199 |
230 int BrowserPlugin::GetAdjustedMaxWidth() const { | 200 int BrowserPluginImpl::GetAdjustedMaxWidth() const { |
231 int max_width = GetMaxWidthAttribute(); | 201 int max_width = GetMaxWidthAttribute(); |
232 return max_width ? max_width : width(); | 202 return max_width ? max_width : width(); |
233 } | 203 } |
234 | 204 |
235 int BrowserPlugin::GetAdjustedMinHeight() const { | 205 int BrowserPluginImpl::GetAdjustedMinHeight() const { |
236 int min_height = GetMinHeightAttribute(); | 206 int min_height = GetMinHeightAttribute(); |
237 // FrameView.cpp does not allow this value to be <= 0, so when the value is | 207 // FrameView.cpp does not allow this value to be <= 0, so when the value is |
238 // unset (or set to 0), we set it to the container size. | 208 // unset (or set to 0), we set it to the container size. |
239 min_height = min_height ? min_height : height(); | 209 min_height = min_height ? min_height : height(); |
240 // For autosize, minHeight should not be bigger than maxHeight. | 210 // For autosize, minHeight should not be bigger than maxHeight. |
241 return std::min(min_height, GetAdjustedMaxHeight()); | 211 return std::min(min_height, GetAdjustedMaxHeight()); |
242 } | 212 } |
243 | 213 |
244 int BrowserPlugin::GetAdjustedMinWidth() const { | 214 int BrowserPluginImpl::GetAdjustedMinWidth() const { |
245 int min_width = GetMinWidthAttribute(); | 215 int min_width = GetMinWidthAttribute(); |
246 // FrameView.cpp does not allow this value to be <= 0, so when the value is | 216 // FrameView.cpp does not allow this value to be <= 0, so when the value is |
247 // unset (or set to 0), we set it to the container size. | 217 // unset (or set to 0), we set it to the container size. |
248 min_width = min_width ? min_width : width(); | 218 min_width = min_width ? min_width : width(); |
249 // For autosize, minWidth should not be bigger than maxWidth. | 219 // For autosize, minWidth should not be bigger than maxWidth. |
250 return std::min(min_width, GetAdjustedMaxWidth()); | 220 return std::min(min_width, GetAdjustedMaxWidth()); |
251 } | 221 } |
252 | 222 |
253 std::string BrowserPlugin::GetPartitionAttribute() const { | 223 std::string BrowserPluginImpl::GetPartitionAttribute() const { |
254 return GetDOMAttributeValue(browser_plugin::kAttributePartition); | 224 return GetDOMAttributeValue(browser_plugin::kAttributePartition); |
255 } | 225 } |
256 | 226 |
257 void BrowserPlugin::ParseNameAttribute() { | 227 void BrowserPluginImpl::ParseNameAttribute() { |
258 if (!navigate_src_sent_) | 228 if (!navigate_src_sent_) |
259 return; | 229 return; |
260 browser_plugin_manager()->Send( | 230 browser_plugin_manager()->Send( |
261 new BrowserPluginHostMsg_SetName(render_view_routing_id_, | 231 new BrowserPluginHostMsg_SetName(render_view_routing_id_, |
262 instance_id_, | 232 instance_id_, |
263 GetNameAttribute())); | 233 GetNameAttribute())); |
264 } | 234 } |
265 | 235 |
266 bool BrowserPlugin::ParseSrcAttribute(std::string* error_message) { | 236 bool BrowserPluginImpl::ParseSrcAttribute(std::string* error_message) { |
267 if (!valid_partition_id_) { | 237 if (!valid_partition_id_) { |
268 *error_message = browser_plugin::kErrorInvalidPartition; | 238 *error_message = browser_plugin::kErrorInvalidPartition; |
269 return false; | 239 return false; |
270 } | 240 } |
271 std::string src = GetSrcAttribute(); | 241 std::string src = GetSrcAttribute(); |
272 if (src.empty()) | 242 if (src.empty()) |
273 return true; | 243 return true; |
274 | 244 |
275 // If we haven't created the guest yet, do so now. We will navigate it right | 245 // If we haven't created the guest yet, do so now. We will navigate it right |
276 // after creation. If |src| is empty, we can delay the creation until we | 246 // after creation. If |src| is empty, we can delay the creation until we |
(...skipping 15 matching lines...) Expand all Loading... |
292 return true; | 262 return true; |
293 } | 263 } |
294 | 264 |
295 browser_plugin_manager()->Send( | 265 browser_plugin_manager()->Send( |
296 new BrowserPluginHostMsg_NavigateGuest(render_view_routing_id_, | 266 new BrowserPluginHostMsg_NavigateGuest(render_view_routing_id_, |
297 instance_id_, | 267 instance_id_, |
298 src)); | 268 src)); |
299 return true; | 269 return true; |
300 } | 270 } |
301 | 271 |
302 void BrowserPlugin::ParseAutoSizeAttribute() { | 272 void BrowserPluginImpl::ParseAutoSizeAttribute() { |
303 auto_size_ack_pending_ = true; | 273 auto_size_ack_pending_ = true; |
304 last_view_size_ = plugin_rect_.size(); | 274 last_view_size_ = plugin_rect_.size(); |
305 UpdateGuestAutoSizeState(GetAutoSizeAttribute()); | 275 UpdateGuestAutoSizeState(GetAutoSizeAttribute()); |
306 } | 276 } |
307 | 277 |
308 void BrowserPlugin::PopulateAutoSizeParameters( | 278 void BrowserPluginImpl::PopulateAutoSizeParameters( |
309 BrowserPluginHostMsg_AutoSize_Params* params, bool current_auto_size) { | 279 BrowserPluginHostMsg_AutoSize_Params* params, bool current_auto_size) { |
310 params->enable = current_auto_size; | 280 params->enable = current_auto_size; |
311 // No need to populate the params if autosize is off. | 281 // No need to populate the params if autosize is off. |
312 if (current_auto_size) { | 282 if (current_auto_size) { |
313 params->max_size = gfx::Size(GetAdjustedMaxWidth(), GetAdjustedMaxHeight()); | 283 params->max_size = gfx::Size(GetAdjustedMaxWidth(), GetAdjustedMaxHeight()); |
314 params->min_size = gfx::Size(GetAdjustedMinWidth(), GetAdjustedMinHeight()); | 284 params->min_size = gfx::Size(GetAdjustedMinWidth(), GetAdjustedMinHeight()); |
315 } | 285 } |
316 } | 286 } |
317 | 287 |
318 void BrowserPlugin::UpdateGuestAutoSizeState(bool current_auto_size) { | 288 void BrowserPluginImpl::UpdateGuestAutoSizeState(bool current_auto_size) { |
319 // If we haven't yet heard back from the guest about the last resize request, | 289 // If we haven't yet heard back from the guest about the last resize request, |
320 // then we don't issue another request until we do in | 290 // then we don't issue another request until we do in |
321 // BrowserPlugin::UpdateRect. | 291 // BrowserPluginImpl::UpdateRect. |
322 if (!navigate_src_sent_ || !resize_ack_received_) | 292 if (!navigate_src_sent_ || !resize_ack_received_) |
323 return; | 293 return; |
324 BrowserPluginHostMsg_AutoSize_Params auto_size_params; | 294 BrowserPluginHostMsg_AutoSize_Params auto_size_params; |
325 BrowserPluginHostMsg_ResizeGuest_Params resize_guest_params; | 295 BrowserPluginHostMsg_ResizeGuest_Params resize_guest_params; |
326 if (current_auto_size) { | 296 if (current_auto_size) { |
327 GetDamageBufferWithSizeParams(&auto_size_params, &resize_guest_params); | 297 GetDamageBufferWithSizeParams(&auto_size_params, &resize_guest_params); |
328 } else { | 298 } else { |
329 GetDamageBufferWithSizeParams(NULL, &resize_guest_params); | 299 GetDamageBufferWithSizeParams(NULL, &resize_guest_params); |
330 } | 300 } |
331 resize_ack_received_ = false; | 301 resize_ack_received_ = false; |
332 browser_plugin_manager()->Send( | 302 browser_plugin_manager()->Send( |
333 new BrowserPluginHostMsg_SetAutoSize(render_view_routing_id_, | 303 new BrowserPluginHostMsg_SetAutoSize(render_view_routing_id_, |
334 instance_id_, | 304 instance_id_, |
335 auto_size_params, | 305 auto_size_params, |
336 resize_guest_params)); | 306 resize_guest_params)); |
337 } | 307 } |
338 | 308 |
339 void BrowserPlugin::SizeChangedDueToAutoSize(const gfx::Size& old_view_size) { | 309 void BrowserPluginImpl::SizeChangedDueToAutoSize( |
| 310 const gfx::Size& old_view_size) { |
340 size_changed_in_flight_ = false; | 311 size_changed_in_flight_ = false; |
341 | 312 |
342 std::map<std::string, base::Value*> props; | 313 std::map<std::string, base::Value*> props; |
343 props[browser_plugin::kOldHeight] = | 314 props[browser_plugin::kOldHeight] = |
344 new base::FundamentalValue(old_view_size.height()); | 315 new base::FundamentalValue(old_view_size.height()); |
345 props[browser_plugin::kOldWidth] = | 316 props[browser_plugin::kOldWidth] = |
346 new base::FundamentalValue(old_view_size.width()); | 317 new base::FundamentalValue(old_view_size.width()); |
347 props[browser_plugin::kNewHeight] = | 318 props[browser_plugin::kNewHeight] = |
348 new base::FundamentalValue(last_view_size_.height()); | 319 new base::FundamentalValue(last_view_size_.height()); |
349 props[browser_plugin::kNewWidth] = | 320 props[browser_plugin::kNewWidth] = |
350 new base::FundamentalValue(last_view_size_.width()); | 321 new base::FundamentalValue(last_view_size_.width()); |
351 TriggerEvent(browser_plugin::kEventSizeChanged, &props); | 322 TriggerEvent(browser_plugin::kEventSizeChanged, &props); |
352 } | 323 } |
353 | 324 |
354 // static | 325 // static |
355 bool BrowserPlugin::UsesDamageBuffer( | 326 bool BrowserPluginImpl::UsesDamageBuffer( |
356 const BrowserPluginMsg_UpdateRect_Params& params) { | 327 const BrowserPluginMsg_UpdateRect_Params& params) { |
357 return params.damage_buffer_sequence_id != 0 || params.needs_ack; | 328 return params.damage_buffer_sequence_id != 0 || params.needs_ack; |
358 } | 329 } |
359 | 330 |
360 bool BrowserPlugin::UsesPendingDamageBuffer( | 331 bool BrowserPluginImpl::UsesPendingDamageBuffer( |
361 const BrowserPluginMsg_UpdateRect_Params& params) { | 332 const BrowserPluginMsg_UpdateRect_Params& params) { |
362 if (!pending_damage_buffer_.get()) | 333 if (!pending_damage_buffer_.get()) |
363 return false; | 334 return false; |
364 return damage_buffer_sequence_id_ == params.damage_buffer_sequence_id; | 335 return damage_buffer_sequence_id_ == params.damage_buffer_sequence_id; |
365 } | 336 } |
366 | 337 |
367 void BrowserPlugin::SetInstanceID(int instance_id) { | 338 void BrowserPluginImpl::SetInstanceID(int instance_id) { |
368 CHECK(instance_id != browser_plugin::kInstanceIDNone); | 339 CHECK(instance_id != browser_plugin::kInstanceIDNone); |
369 instance_id_ = instance_id; | 340 instance_id_ = instance_id; |
370 browser_plugin_manager()->AddBrowserPlugin(instance_id, this); | 341 browser_plugin_manager()->AddBrowserPlugin(instance_id, this); |
371 | 342 |
372 BrowserPluginHostMsg_CreateGuest_Params create_guest_params; | 343 BrowserPluginHostMsg_CreateGuest_Params create_guest_params; |
373 create_guest_params.storage_partition_id = storage_partition_id_; | 344 create_guest_params.storage_partition_id = storage_partition_id_; |
374 create_guest_params.persist_storage = persist_storage_; | 345 create_guest_params.persist_storage = persist_storage_; |
375 create_guest_params.focused = ShouldGuestBeFocused(); | 346 create_guest_params.focused = ShouldGuestBeFocused(); |
376 create_guest_params.visible = visible_; | 347 create_guest_params.visible = visible_; |
377 create_guest_params.name = GetNameAttribute(); | 348 create_guest_params.name = GetNameAttribute(); |
378 create_guest_params.src = GetSrcAttribute(); | 349 create_guest_params.src = GetSrcAttribute(); |
379 GetDamageBufferWithSizeParams(&create_guest_params.auto_size_params, | 350 GetDamageBufferWithSizeParams(&create_guest_params.auto_size_params, |
380 &create_guest_params.resize_guest_params); | 351 &create_guest_params.resize_guest_params); |
381 browser_plugin_manager()->Send( | 352 browser_plugin_manager()->Send( |
382 new BrowserPluginHostMsg_CreateGuest(render_view_routing_id_, | 353 new BrowserPluginHostMsg_CreateGuest(render_view_routing_id_, |
383 instance_id_, | 354 instance_id_, |
384 create_guest_params)); | 355 create_guest_params)); |
385 | 356 |
386 // Record that we sent a navigation request to the browser process. | 357 // Record that we sent a navigation request to the browser process. |
387 // Once this instance has navigated, the storage partition cannot be changed, | 358 // Once this instance has navigated, the storage partition cannot be changed, |
388 // so this value is used for enforcing this. | 359 // so this value is used for enforcing this. |
389 navigate_src_sent_ = true; | 360 navigate_src_sent_ = true; |
390 } | 361 } |
391 | 362 |
392 void BrowserPlugin::OnAdvanceFocus(int instance_id, bool reverse) { | 363 void BrowserPluginImpl::OnAdvanceFocus(int instance_id, bool reverse) { |
393 DCHECK(render_view_); | 364 DCHECK(render_view_); |
394 render_view_->GetWebView()->advanceFocus(reverse); | 365 render_view_->GetWebView()->advanceFocus(reverse); |
395 } | 366 } |
396 | 367 |
397 void BrowserPlugin::OnBuffersSwapped(int instance_id, | 368 void BrowserPluginImpl::OnBuffersSwapped(int instance_id, |
398 const gfx::Size& size, | 369 const gfx::Size& size, |
399 std::string mailbox_name, | 370 std::string mailbox_name, |
400 int gpu_route_id, | 371 int gpu_route_id, |
401 int gpu_host_id) { | 372 int gpu_host_id) { |
402 DCHECK(instance_id == instance_id_); | 373 DCHECK(instance_id == instance_id_); |
403 EnableCompositing(true); | 374 EnableCompositing(true); |
404 | 375 |
405 compositing_helper_->OnBuffersSwapped(size, | 376 compositing_helper_->OnBuffersSwapped(size, |
406 mailbox_name, | 377 mailbox_name, |
407 gpu_route_id, | 378 gpu_route_id, |
408 gpu_host_id); | 379 gpu_host_id); |
409 } | 380 } |
410 | 381 |
411 void BrowserPlugin::OnGuestContentWindowReady(int instance_id, | 382 void BrowserPluginImpl::OnForwardMessage(int instance_id, |
412 int content_window_routing_id) { | 383 const IPC::Message& msg) { |
| 384 if (!observers_.might_have_observers()) |
| 385 return; |
| 386 ObserverListBase<BrowserPluginObserver>::Iterator it(observers_); |
| 387 BrowserPluginObserver* observer; |
| 388 while ((observer = it.GetNext()) != NULL) { |
| 389 if (observer->OnMessageReceived(msg)) |
| 390 return; |
| 391 } |
| 392 } |
| 393 |
| 394 void BrowserPluginImpl::OnGuestContentWindowReady( |
| 395 int instance_id, |
| 396 int content_window_routing_id) { |
413 DCHECK(content_window_routing_id != MSG_ROUTING_NONE); | 397 DCHECK(content_window_routing_id != MSG_ROUTING_NONE); |
414 content_window_routing_id_ = content_window_routing_id; | 398 content_window_routing_id_ = content_window_routing_id; |
415 } | 399 } |
416 | 400 |
417 void BrowserPlugin::OnGuestGone(int instance_id, int process_id, int status) { | 401 void BrowserPluginImpl::OnGuestGone(int instance_id, |
| 402 int process_id, |
| 403 int status) { |
418 // Set the BrowserPlugin in a crashed state before firing event listeners so | 404 // Set the BrowserPlugin in a crashed state before firing event listeners so |
419 // that operations on the BrowserPlugin within listeners are aware that | 405 // that operations on the BrowserPlugin within listeners are aware that |
420 // BrowserPlugin is in a crashed state. | 406 // BrowserPlugin is in a crashed state. |
421 guest_crashed_ = true; | 407 guest_crashed_ = true; |
422 | 408 |
423 // We fire the event listeners before painting the sad graphic to give the | 409 // We fire the event listeners before painting the sad graphic to give the |
424 // developer an opportunity to display an alternative overlay image on crash. | 410 // developer an opportunity to display an alternative overlay image on crash. |
425 std::string termination_status = TerminationStatusToString( | 411 std::string termination_status = TerminationStatusToString( |
426 static_cast<base::TerminationStatus>(status)); | 412 static_cast<base::TerminationStatus>(status)); |
427 std::map<std::string, base::Value*> props; | 413 std::map<std::string, base::Value*> props; |
428 props[browser_plugin::kProcessId] = new base::FundamentalValue(process_id); | 414 props[browser_plugin::kProcessId] = new base::FundamentalValue(process_id); |
429 props[browser_plugin::kReason] = new base::StringValue(termination_status); | 415 props[browser_plugin::kReason] = new base::StringValue(termination_status); |
430 | 416 |
431 // Event listeners may remove the BrowserPlugin from the document. If that | 417 // Event listeners may remove the BrowserPlugin from the document. If that |
432 // happens, the BrowserPlugin will be scheduled for later deletion (see | 418 // happens, the BrowserPlugin will be scheduled for later deletion (see |
433 // BrowserPlugin::destroy()). That will clear the container_ reference, | 419 // BrowserPluginImpl::destroy()). That will clear the container_ reference, |
434 // but leave other member variables valid below. | 420 // but leave other member variables valid below. |
435 TriggerEvent(browser_plugin::kEventExit, &props); | 421 TriggerEvent(browser_plugin::kEventExit, &props); |
436 | 422 |
437 // We won't paint the contents of the current backing store again so we might | 423 // We won't paint the contents of the current backing store again so we might |
438 // as well toss it out and save memory. | 424 // as well toss it out and save memory. |
439 backing_store_.reset(); | 425 backing_store_.reset(); |
440 // If the BrowserPlugin is scheduled to be deleted, then container_ will be | 426 // If the BrowserPlugin is scheduled to be deleted, then container_ will be |
441 // NULL so we shouldn't attempt to access it. | 427 // NULL so we shouldn't attempt to access it. |
442 if (container_) | 428 if (container_) |
443 container_->invalidate(); | 429 container_->invalidate(); |
444 // Turn off compositing so we can display the sad graphic. | 430 // Turn off compositing so we can display the sad graphic. |
445 EnableCompositing(false); | 431 EnableCompositing(false); |
446 } | 432 } |
447 | 433 |
448 void BrowserPlugin::OnGuestResponsive(int instance_id, int process_id) { | 434 void BrowserPluginImpl::OnGuestResponsive(int instance_id, int process_id) { |
449 std::map<std::string, base::Value*> props; | 435 std::map<std::string, base::Value*> props; |
450 props[browser_plugin::kProcessId] = new base::FundamentalValue(process_id); | 436 props[browser_plugin::kProcessId] = new base::FundamentalValue(process_id); |
451 TriggerEvent(browser_plugin::kEventResponsive, &props); | 437 TriggerEvent(browser_plugin::kEventResponsive, &props); |
452 } | 438 } |
453 | 439 |
454 void BrowserPlugin::OnGuestUnresponsive(int instance_id, int process_id) { | 440 void BrowserPluginImpl::OnGuestUnresponsive(int instance_id, int process_id) { |
455 std::map<std::string, base::Value*> props; | 441 std::map<std::string, base::Value*> props; |
456 props[browser_plugin::kProcessId] = new base::FundamentalValue(process_id); | 442 props[browser_plugin::kProcessId] = new base::FundamentalValue(process_id); |
457 TriggerEvent(browser_plugin::kEventUnresponsive, &props); | 443 TriggerEvent(browser_plugin::kEventUnresponsive, &props); |
458 } | 444 } |
459 | 445 |
460 void BrowserPlugin::OnLoadAbort(int instance_id, | 446 void BrowserPluginImpl::OnLoadAbort(int instance_id, |
461 const GURL& url, | 447 const GURL& url, |
462 bool is_top_level, | 448 bool is_top_level, |
463 const std::string& type) { | 449 const std::string& type) { |
464 std::map<std::string, base::Value*> props; | 450 std::map<std::string, base::Value*> props; |
465 props[browser_plugin::kURL] = new base::StringValue(url.spec()); | 451 props[browser_plugin::kURL] = new base::StringValue(url.spec()); |
466 props[browser_plugin::kIsTopLevel] = new base::FundamentalValue(is_top_level); | 452 props[browser_plugin::kIsTopLevel] = new base::FundamentalValue(is_top_level); |
467 props[browser_plugin::kReason] = new base::StringValue(type); | 453 props[browser_plugin::kReason] = new base::StringValue(type); |
468 TriggerEvent(browser_plugin::kEventLoadAbort, &props); | 454 TriggerEvent(browser_plugin::kEventLoadAbort, &props); |
469 } | 455 } |
470 | 456 |
471 void BrowserPlugin::OnLoadCommit( | 457 void BrowserPluginImpl::OnLoadCommit( |
472 int instance_id, | 458 int instance_id, |
473 const BrowserPluginMsg_LoadCommit_Params& params) { | 459 const BrowserPluginMsg_LoadCommit_Params& params) { |
474 // If the guest has just committed a new navigation then it is no longer | 460 // If the guest has just committed a new navigation then it is no longer |
475 // crashed. | 461 // crashed. |
476 guest_crashed_ = false; | 462 guest_crashed_ = false; |
477 if (params.is_top_level) | 463 if (params.is_top_level) |
478 UpdateDOMAttribute(browser_plugin::kAttributeSrc, params.url.spec()); | 464 UpdateDOMAttribute(browser_plugin::kAttributeSrc, params.url.spec()); |
479 | 465 |
480 guest_process_id_ = params.process_id; | 466 guest_process_id_ = params.process_id; |
481 guest_route_id_ = params.route_id; | 467 guest_route_id_ = params.route_id; |
482 current_nav_entry_index_ = params.current_entry_index; | 468 current_nav_entry_index_ = params.current_entry_index; |
483 nav_entry_count_ = params.entry_count; | 469 nav_entry_count_ = params.entry_count; |
484 | 470 |
485 std::map<std::string, base::Value*> props; | 471 std::map<std::string, base::Value*> props; |
486 props[browser_plugin::kURL] = new base::StringValue(params.url.spec()); | 472 props[browser_plugin::kURL] = new base::StringValue(params.url.spec()); |
487 props[browser_plugin::kIsTopLevel] = | 473 props[browser_plugin::kIsTopLevel] = |
488 new base::FundamentalValue(params.is_top_level); | 474 new base::FundamentalValue(params.is_top_level); |
489 TriggerEvent(browser_plugin::kEventLoadCommit, &props); | 475 TriggerEvent(browser_plugin::kEventLoadCommit, &props); |
490 } | 476 } |
491 | 477 |
492 void BrowserPlugin::OnLoadRedirect(int instance_id, | 478 void BrowserPluginImpl::OnLoadRedirect(int instance_id, |
493 const GURL& old_url, | 479 const GURL& old_url, |
494 const GURL& new_url, | 480 const GURL& new_url, |
495 bool is_top_level) { | 481 bool is_top_level) { |
496 std::map<std::string, base::Value*> props; | 482 std::map<std::string, base::Value*> props; |
497 props[browser_plugin::kOldURL] = new base::StringValue(old_url.spec()); | 483 props[browser_plugin::kOldURL] = new base::StringValue(old_url.spec()); |
498 props[browser_plugin::kNewURL] = new base::StringValue(new_url.spec()); | 484 props[browser_plugin::kNewURL] = new base::StringValue(new_url.spec()); |
499 props[browser_plugin::kIsTopLevel] = new base::FundamentalValue(is_top_level); | 485 props[browser_plugin::kIsTopLevel] = new base::FundamentalValue(is_top_level); |
500 TriggerEvent(browser_plugin::kEventLoadRedirect, &props); | 486 TriggerEvent(browser_plugin::kEventLoadRedirect, &props); |
501 } | 487 } |
502 | 488 |
503 void BrowserPlugin::OnLoadStart(int instance_id, | 489 void BrowserPluginImpl::OnLoadStart(int instance_id, |
504 const GURL& url, | 490 const GURL& url, |
505 bool is_top_level) { | 491 bool is_top_level) { |
506 std::map<std::string, base::Value*> props; | 492 std::map<std::string, base::Value*> props; |
507 props[browser_plugin::kURL] = new base::StringValue(url.spec()); | 493 props[browser_plugin::kURL] = new base::StringValue(url.spec()); |
508 props[browser_plugin::kIsTopLevel] = new base::FundamentalValue(is_top_level); | 494 props[browser_plugin::kIsTopLevel] = new base::FundamentalValue(is_top_level); |
509 | 495 |
510 TriggerEvent(browser_plugin::kEventLoadStart, &props); | 496 TriggerEvent(browser_plugin::kEventLoadStart, &props); |
511 } | 497 } |
512 | 498 |
513 void BrowserPlugin::OnLoadStop(int instance_id) { | 499 void BrowserPluginImpl::OnLoadStop(int instance_id) { |
514 TriggerEvent(browser_plugin::kEventLoadStop, NULL); | 500 TriggerEvent(browser_plugin::kEventLoadStop, NULL); |
515 } | 501 } |
516 | 502 |
517 void BrowserPlugin::OnRequestPermission( | 503 void BrowserPluginImpl::OnRequestPermission( |
518 int instance_id, | 504 int instance_id, |
519 BrowserPluginPermissionType permission_type, | 505 BrowserPluginPermissionType permission_type, |
520 int request_id, | 506 int request_id, |
521 const base::DictionaryValue& request_info) { | 507 const base::DictionaryValue& request_info) { |
522 if (permission_type == BrowserPluginPermissionTypeMedia) | 508 if (permission_type == BrowserPluginPermissionTypeMedia) |
523 RequestMediaPermission(request_id, request_info); | 509 RequestMediaPermission(request_id, request_info); |
524 } | 510 } |
525 | 511 |
526 void BrowserPlugin::OnSetCursor(int instance_id, const WebCursor& cursor) { | 512 void BrowserPluginImpl::OnSetCursor(int instance_id, const WebCursor& cursor) { |
527 cursor_ = cursor; | 513 cursor_ = cursor; |
528 } | 514 } |
529 | 515 |
530 void BrowserPlugin::OnShouldAcceptTouchEvents(int instance_id, bool accept) { | 516 void BrowserPluginImpl::OnShouldAcceptTouchEvents(int instance_id, |
| 517 bool accept) { |
531 if (container()) { | 518 if (container()) { |
532 container()->requestTouchEventType(accept ? | 519 container()->requestTouchEventType(accept ? |
533 WebKit::WebPluginContainer::TouchEventRequestTypeRaw : | 520 WebKit::WebPluginContainer::TouchEventRequestTypeRaw : |
534 WebKit::WebPluginContainer::TouchEventRequestTypeNone); | 521 WebKit::WebPluginContainer::TouchEventRequestTypeNone); |
535 } | 522 } |
536 } | 523 } |
537 | 524 |
538 void BrowserPlugin::OnUpdatedName(int instance_id, const std::string& name) { | 525 void BrowserPluginImpl::OnUpdatedName(int instance_id, |
| 526 const std::string& name) { |
539 UpdateDOMAttribute(browser_plugin::kAttributeName, name); | 527 UpdateDOMAttribute(browser_plugin::kAttributeName, name); |
540 } | 528 } |
541 | 529 |
542 void BrowserPlugin::RequestMediaPermission( | 530 void BrowserPluginImpl::RequestMediaPermission( |
543 int request_id, const base::DictionaryValue& request_info) { | 531 int request_id, const base::DictionaryValue& request_info) { |
544 if (!HasEventListeners(browser_plugin::kEventRequestPermission)) { | 532 if (!HasEventListeners(browser_plugin::kEventRequestPermission)) { |
545 // Automatically deny the request if there are no event listeners for | 533 // Automatically deny the request if there are no event listeners for |
546 // permissionrequest. | 534 // permissionrequest. |
547 RespondPermission( | 535 RespondPermission( |
548 BrowserPluginPermissionTypeMedia, request_id, false /* allow */); | 536 BrowserPluginPermissionTypeMedia, request_id, false /* allow */); |
549 return; | 537 return; |
550 } | 538 } |
551 DCHECK(!pending_permission_requests_.count(request_id)); | 539 DCHECK(!pending_permission_requests_.count(request_id)); |
552 pending_permission_requests_.insert( | 540 pending_permission_requests_.insert( |
553 std::make_pair(request_id, | 541 std::make_pair(request_id, |
554 std::make_pair(request_id, | 542 std::make_pair(request_id, |
555 BrowserPluginPermissionTypeMedia))); | 543 BrowserPluginPermissionTypeMedia))); |
556 | 544 |
557 std::map<std::string, base::Value*> props; | 545 std::map<std::string, base::Value*> props; |
558 props[browser_plugin::kPermission] = | 546 props[browser_plugin::kPermission] = |
559 base::Value::CreateStringValue(browser_plugin::kPermissionTypeMedia); | 547 base::Value::CreateStringValue(browser_plugin::kPermissionTypeMedia); |
560 props[browser_plugin::kRequestId] = | 548 props[browser_plugin::kRequestId] = |
561 base::Value::CreateIntegerValue(request_id); | 549 base::Value::CreateIntegerValue(request_id); |
562 | 550 |
563 // Fill in the info provided by the browser. | 551 // Fill in the info provided by the browser. |
564 for (DictionaryValue::Iterator iter(request_info); !iter.IsAtEnd(); | 552 for (DictionaryValue::Iterator iter(request_info); !iter.IsAtEnd(); |
565 iter.Advance()) { | 553 iter.Advance()) { |
566 props[iter.key()] = iter.value().DeepCopy(); | 554 props[iter.key()] = iter.value().DeepCopy(); |
567 } | 555 } |
568 TriggerEvent(browser_plugin::kEventRequestPermission, &props); | 556 TriggerEvent(browser_plugin::kEventRequestPermission, &props); |
569 } | 557 } |
570 | 558 |
571 bool BrowserPlugin::HasEventListeners(const std::string& event_name) { | 559 bool BrowserPluginImpl::HasEventListeners(const std::string& event_name) { |
572 if (!container()) | 560 if (!container()) |
573 return false; | 561 return false; |
574 | 562 |
575 WebKit::WebNode node = container()->element(); | 563 WebKit::WebNode node = container()->element(); |
576 // Escape the <webview> shim if this BrowserPlugin has one. | 564 // Escape the <webview> shim if this BrowserPlugin has one. |
577 WebKit::WebElement shim = node.shadowHost(); | 565 WebKit::WebElement shim = node.shadowHost(); |
578 if (!shim.isNull()) | 566 if (!shim.isNull()) |
579 node = shim; | 567 node = shim; |
580 | 568 |
581 const WebKit::WebString& web_event_name = | 569 const WebKit::WebString& web_event_name = |
582 WebKit::WebString::fromUTF8(event_name); | 570 WebKit::WebString::fromUTF8(event_name); |
583 while (!node.isNull()) { | 571 while (!node.isNull()) { |
584 if (node.hasEventListeners(web_event_name)) | 572 if (node.hasEventListeners(web_event_name)) |
585 return true; | 573 return true; |
586 node = node.parentNode(); | 574 node = node.parentNode(); |
587 } | 575 } |
588 return false; | 576 return false; |
589 } | 577 } |
590 | 578 |
591 void BrowserPlugin::OnUpdateRect( | 579 void BrowserPluginImpl::OnUpdateRect( |
592 int instance_id, | 580 int instance_id, |
593 const BrowserPluginMsg_UpdateRect_Params& params) { | 581 const BrowserPluginMsg_UpdateRect_Params& params) { |
594 bool use_new_damage_buffer = !backing_store_; | 582 bool use_new_damage_buffer = !backing_store_; |
595 BrowserPluginHostMsg_AutoSize_Params auto_size_params; | 583 BrowserPluginHostMsg_AutoSize_Params auto_size_params; |
596 BrowserPluginHostMsg_ResizeGuest_Params resize_guest_params; | 584 BrowserPluginHostMsg_ResizeGuest_Params resize_guest_params; |
597 // If we have a pending damage buffer, and the guest has begun to use the | 585 // If we have a pending damage buffer, and the guest has begun to use the |
598 // damage buffer then we know the guest will no longer use the current | 586 // damage buffer then we know the guest will no longer use the current |
599 // damage buffer. At this point, we drop the current damage buffer, and | 587 // damage buffer. At this point, we drop the current damage buffer, and |
600 // mark the pending damage buffer as the current damage buffer. | 588 // mark the pending damage buffer as the current damage buffer. |
601 if (UsesPendingDamageBuffer(params)) { | 589 if (UsesPendingDamageBuffer(params)) { |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
658 // resize to avoid flicker. |size_changed_in_flight_| acts as a form of | 646 // resize to avoid flicker. |size_changed_in_flight_| acts as a form of |
659 // flow control for SizeChanged events. If the guest's view size is changing | 647 // flow control for SizeChanged events. If the guest's view size is changing |
660 // rapidly before a SizeChanged event fires, then we avoid scheduling | 648 // rapidly before a SizeChanged event fires, then we avoid scheduling |
661 // another SizeChanged event. SizeChanged reads the new size from | 649 // another SizeChanged event. SizeChanged reads the new size from |
662 // |last_view_size_| so we can be sure that it always fires an event | 650 // |last_view_size_| so we can be sure that it always fires an event |
663 // with the last seen view size. | 651 // with the last seen view size. |
664 if (container_ && !size_changed_in_flight_) { | 652 if (container_ && !size_changed_in_flight_) { |
665 size_changed_in_flight_ = true; | 653 size_changed_in_flight_ = true; |
666 MessageLoop::current()->PostTask( | 654 MessageLoop::current()->PostTask( |
667 FROM_HERE, | 655 FROM_HERE, |
668 base::Bind(&BrowserPlugin::SizeChangedDueToAutoSize, | 656 base::Bind(&BrowserPluginImpl::SizeChangedDueToAutoSize, |
669 base::Unretained(this), | 657 base::Unretained(this), |
670 old_view_size)); | 658 old_view_size)); |
671 } | 659 } |
672 } | 660 } |
673 | 661 |
674 // No more work to do since the guest is no longer using a damage buffer. | 662 // No more work to do since the guest is no longer using a damage buffer. |
675 if (!UsesDamageBuffer(params)) | 663 if (!UsesDamageBuffer(params)) |
676 return; | 664 return; |
677 | 665 |
678 // If we are seeing damage buffers, HW compositing should be turned off. | 666 // If we are seeing damage buffers, HW compositing should be turned off. |
(...skipping 30 matching lines...) Expand all Loading... |
709 container_->invalidate(); | 697 container_->invalidate(); |
710 if (auto_size) | 698 if (auto_size) |
711 PopulateAutoSizeParameters(&auto_size_params, auto_size); | 699 PopulateAutoSizeParameters(&auto_size_params, auto_size); |
712 browser_plugin_manager()->Send(new BrowserPluginHostMsg_UpdateRect_ACK( | 700 browser_plugin_manager()->Send(new BrowserPluginHostMsg_UpdateRect_ACK( |
713 render_view_routing_id_, | 701 render_view_routing_id_, |
714 instance_id_, | 702 instance_id_, |
715 auto_size_params, | 703 auto_size_params, |
716 resize_guest_params)); | 704 resize_guest_params)); |
717 } | 705 } |
718 | 706 |
719 void BrowserPlugin::ParseSizeContraintsChanged() { | 707 void BrowserPluginImpl::ParseSizeContraintsChanged() { |
720 bool auto_size = GetAutoSizeAttribute(); | 708 bool auto_size = GetAutoSizeAttribute(); |
721 if (auto_size) | 709 if (auto_size) |
722 UpdateGuestAutoSizeState(true); | 710 UpdateGuestAutoSizeState(true); |
723 } | 711 } |
724 | 712 |
725 bool BrowserPlugin::InAutoSizeBounds(const gfx::Size& size) const { | 713 bool BrowserPluginImpl::InAutoSizeBounds(const gfx::Size& size) const { |
726 return size.width() <= GetAdjustedMaxWidth() && | 714 return size.width() <= GetAdjustedMaxWidth() && |
727 size.height() <= GetAdjustedMaxHeight(); | 715 size.height() <= GetAdjustedMaxHeight(); |
728 } | 716 } |
729 | 717 |
730 NPObject* BrowserPlugin::GetContentWindow() const { | 718 NPObject* BrowserPluginImpl::GetContentWindow() const { |
731 if (content_window_routing_id_ == MSG_ROUTING_NONE) | 719 if (content_window_routing_id_ == MSG_ROUTING_NONE) |
732 return NULL; | 720 return NULL; |
733 RenderViewImpl* guest_render_view = static_cast<RenderViewImpl*>( | 721 RenderViewImpl* guest_render_view = static_cast<RenderViewImpl*>( |
734 ChildThread::current()->ResolveRoute(content_window_routing_id_)); | 722 ChildThread::current()->ResolveRoute(content_window_routing_id_)); |
735 if (!guest_render_view) | 723 if (!guest_render_view) |
736 return NULL; | 724 return NULL; |
737 WebKit::WebFrame* guest_frame = guest_render_view->GetWebView()->mainFrame(); | 725 WebKit::WebFrame* guest_frame = guest_render_view->GetWebView()->mainFrame(); |
738 return guest_frame->windowObject(); | 726 return guest_frame->windowObject(); |
739 } | 727 } |
740 | 728 |
741 bool BrowserPlugin::CanGoBack() const { | 729 bool BrowserPluginImpl::CanGoBack() const { |
742 return nav_entry_count_ > 1 && current_nav_entry_index_ > 0; | 730 return nav_entry_count_ > 1 && current_nav_entry_index_ > 0; |
743 } | 731 } |
744 | 732 |
745 bool BrowserPlugin::CanGoForward() const { | 733 bool BrowserPluginImpl::CanGoForward() const { |
746 return current_nav_entry_index_ >= 0 && | 734 return current_nav_entry_index_ >= 0 && |
747 current_nav_entry_index_ < (nav_entry_count_ - 1); | 735 current_nav_entry_index_ < (nav_entry_count_ - 1); |
748 } | 736 } |
749 | 737 |
750 bool BrowserPlugin::ParsePartitionAttribute(std::string* error_message) { | 738 bool BrowserPluginImpl::ParsePartitionAttribute(std::string* error_message) { |
751 if (allocate_instance_id_sent_) { | 739 if (allocate_instance_id_sent_) { |
752 *error_message = browser_plugin::kErrorAlreadyNavigated; | 740 *error_message = browser_plugin::kErrorAlreadyNavigated; |
753 return false; | 741 return false; |
754 } | 742 } |
755 | 743 |
756 std::string input = GetPartitionAttribute(); | 744 std::string input = GetPartitionAttribute(); |
757 | 745 |
758 // Since the "persist:" prefix is in ASCII, StartsWith will work fine on | 746 // Since the "persist:" prefix is in ASCII, StartsWith will work fine on |
759 // UTF-8 encoded |partition_id|. If the prefix is a match, we can safely | 747 // UTF-8 encoded |partition_id|. If the prefix is a match, we can safely |
760 // remove the prefix without splicing in the middle of a multi-byte codepoint. | 748 // remove the prefix without splicing in the middle of a multi-byte codepoint. |
(...skipping 11 matching lines...) Expand all Loading... |
772 persist_storage_ = true; | 760 persist_storage_ = true; |
773 } else { | 761 } else { |
774 persist_storage_ = false; | 762 persist_storage_ = false; |
775 } | 763 } |
776 | 764 |
777 valid_partition_id_ = true; | 765 valid_partition_id_ = true; |
778 storage_partition_id_ = input; | 766 storage_partition_id_ = input; |
779 return true; | 767 return true; |
780 } | 768 } |
781 | 769 |
782 bool BrowserPlugin::CanRemovePartitionAttribute(std::string* error_message) { | 770 bool BrowserPluginImpl::CanRemovePartitionAttribute( |
| 771 std::string* error_message) { |
783 if (navigate_src_sent_) | 772 if (navigate_src_sent_) |
784 *error_message = browser_plugin::kErrorCannotRemovePartition; | 773 *error_message = browser_plugin::kErrorCannotRemovePartition; |
785 return !navigate_src_sent_; | 774 return !navigate_src_sent_; |
786 } | 775 } |
787 | 776 |
788 void BrowserPlugin::ParseAttributes() { | 777 void BrowserPluginImpl::ParseAttributes() { |
789 // TODO(mthiesse): Handle errors here? | 778 // TODO(mthiesse): Handle errors here? |
790 std::string error; | 779 std::string error; |
791 ParsePartitionAttribute(&error); | 780 ParsePartitionAttribute(&error); |
792 | 781 |
793 // Parse the 'src' attribute last, as it will set the has_navigated_ flag to | 782 // Parse the 'src' attribute last, as it will set the has_navigated_ flag to |
794 // true, which prevents changing the 'partition' attribute. | 783 // true, which prevents changing the 'partition' attribute. |
795 ParseSrcAttribute(&error); | 784 ParseSrcAttribute(&error); |
796 } | 785 } |
797 | 786 |
798 float BrowserPlugin::GetDeviceScaleFactor() const { | 787 float BrowserPluginImpl::GetDeviceScaleFactor() const { |
799 if (!render_view_) | 788 if (!render_view_) |
800 return 1.0f; | 789 return 1.0f; |
801 return render_view_->GetWebView()->deviceScaleFactor(); | 790 return render_view_->GetWebView()->deviceScaleFactor(); |
802 } | 791 } |
803 | 792 |
804 void BrowserPlugin::TriggerEvent(const std::string& event_name, | 793 void BrowserPluginImpl::OnRequestObjectGarbageCollected(int request_id) { |
805 std::map<std::string, base::Value*>* props) { | |
806 if (!container() || !container()->element().document().frame()) | |
807 return; | |
808 v8::HandleScope handle_scope; | |
809 std::string json_string; | |
810 if (props) { | |
811 base::DictionaryValue dict; | |
812 for (std::map<std::string, base::Value*>::iterator iter = props->begin(), | |
813 end = props->end(); iter != end; ++iter) { | |
814 dict.Set(iter->first, iter->second); | |
815 } | |
816 | |
817 JSONStringValueSerializer serializer(&json_string); | |
818 if (!serializer.Serialize(dict)) | |
819 return; | |
820 } | |
821 | |
822 WebKit::WebFrame* frame = container()->element().document().frame(); | |
823 WebKit::WebDOMEvent dom_event = frame->document().createEvent("CustomEvent"); | |
824 WebKit::WebDOMCustomEvent event = dom_event.to<WebKit::WebDOMCustomEvent>(); | |
825 | |
826 // The events triggered directly from the plugin <object> are internal events | |
827 // whose implementation details can (and likely will) change over time. The | |
828 // wrapper/shim (e.g. <webview> tag) should receive these events, and expose a | |
829 // more appropriate (and stable) event to the consumers as part of the API. | |
830 event.initCustomEvent( | |
831 WebKit::WebString::fromUTF8(GetInternalEventName(event_name.c_str())), | |
832 false, false, | |
833 WebKit::WebSerializedScriptValue::serialize( | |
834 v8::String::New(json_string.c_str(), json_string.size()))); | |
835 container()->element().dispatchEvent(event); | |
836 } | |
837 | |
838 void BrowserPlugin::OnRequestObjectGarbageCollected(int request_id) { | |
839 // Remove from alive objects. | 794 // Remove from alive objects. |
840 std::map<int, AliveV8PermissionRequestItem*>::iterator iter = | 795 std::map<int, AliveV8PermissionRequestItem*>::iterator iter = |
841 alive_v8_permission_request_objects_.find(request_id); | 796 alive_v8_permission_request_objects_.find(request_id); |
842 if (iter != alive_v8_permission_request_objects_.end()) | 797 if (iter != alive_v8_permission_request_objects_.end()) |
843 alive_v8_permission_request_objects_.erase(iter); | 798 alive_v8_permission_request_objects_.erase(iter); |
844 | 799 |
845 // If a decision has not been made for this request yet, deny it. | 800 // If a decision has not been made for this request yet, deny it. |
846 RespondPermissionIfRequestIsPending(request_id, false /*allow*/); | 801 RespondPermissionIfRequestIsPending(request_id, false /*allow*/); |
847 } | 802 } |
848 | 803 |
849 void BrowserPlugin::PersistRequestObject( | 804 void BrowserPluginImpl::PersistRequestObject( |
850 const NPVariant* request, const std::string& type, int id) { | 805 const NPVariant* request, const std::string& type, int id) { |
851 CHECK(alive_v8_permission_request_objects_.find(id) == | 806 CHECK(alive_v8_permission_request_objects_.find(id) == |
852 alive_v8_permission_request_objects_.end()); | 807 alive_v8_permission_request_objects_.end()); |
853 if (pending_permission_requests_.find(id) == | 808 if (pending_permission_requests_.find(id) == |
854 pending_permission_requests_.end()) { | 809 pending_permission_requests_.end()) { |
855 return; | 810 return; |
856 } | 811 } |
857 | 812 |
858 v8::Persistent<v8::Value> weak_request = | 813 v8::Persistent<v8::Value> weak_request = |
859 v8::Persistent<v8::Value>::New(WebKit::WebBindings::toV8Value(request)); | 814 v8::Persistent<v8::Value>::New(WebKit::WebBindings::toV8Value(request)); |
860 | 815 |
861 AliveV8PermissionRequestItem* new_item = | 816 AliveV8PermissionRequestItem* new_item = |
862 new std::pair<int, base::WeakPtr<BrowserPlugin> >( | 817 new std::pair<int, base::WeakPtr<BrowserPluginImpl> >( |
863 id, weak_ptr_factory_.GetWeakPtr()); | 818 id, weak_ptr_factory_.GetWeakPtr()); |
864 | 819 |
865 std::pair<std::map<int, AliveV8PermissionRequestItem*>::iterator, bool> | 820 std::pair<std::map<int, AliveV8PermissionRequestItem*>::iterator, bool> |
866 result = alive_v8_permission_request_objects_.insert( | 821 result = alive_v8_permission_request_objects_.insert( |
867 std::make_pair(id, new_item)); | 822 std::make_pair(id, new_item)); |
868 CHECK(result.second); // Inserted in the map. | 823 CHECK(result.second); // Inserted in the map. |
869 AliveV8PermissionRequestItem* request_item = result.first->second; | 824 AliveV8PermissionRequestItem* request_item = result.first->second; |
870 weak_request.MakeWeak(request_item, WeakCallbackForPersistObject); | 825 weak_request.MakeWeak(request_item, WeakCallbackForPersistObject); |
871 } | 826 } |
872 | 827 |
873 // static | 828 // static |
874 void BrowserPlugin::WeakCallbackForPersistObject( | 829 void BrowserPluginImpl::WeakCallbackForPersistObject( |
875 v8::Persistent<v8::Value> object, void* param) { | 830 v8::Persistent<v8::Value> object, void* param) { |
876 v8::Persistent<v8::Object> persistent_object = | 831 v8::Persistent<v8::Object> persistent_object = |
877 v8::Persistent<v8::Object>::Cast(object); | 832 v8::Persistent<v8::Object>::Cast(object); |
878 | 833 |
879 AliveV8PermissionRequestItem* item_ptr = | 834 AliveV8PermissionRequestItem* item_ptr = |
880 static_cast<AliveV8PermissionRequestItem*>(param); | 835 static_cast<AliveV8PermissionRequestItem*>(param); |
881 int request_id = item_ptr->first; | 836 int request_id = item_ptr->first; |
882 base::WeakPtr<BrowserPlugin> plugin = item_ptr->second; | 837 base::WeakPtr<BrowserPluginImpl> plugin = item_ptr->second; |
883 delete item_ptr; | 838 delete item_ptr; |
884 | 839 |
885 persistent_object.Dispose(); | 840 persistent_object.Dispose(); |
886 persistent_object.Clear(); | 841 persistent_object.Clear(); |
887 | 842 |
888 if (plugin) { | 843 if (plugin) { |
889 // Asynchronously remove item from |alive_v8_permission_request_objects_|. | 844 // Asynchronously remove item from |alive_v8_permission_request_objects_|. |
890 // Note that we are using weak pointer for the following PostTask, so we | 845 // Note that we are using weak pointer for the following PostTask, so we |
891 // don't need to worry about BrowserPlugin going away. | 846 // don't need to worry about BrowserPlugin going away. |
892 MessageLoop::current()->PostTask( | 847 MessageLoop::current()->PostTask( |
893 FROM_HERE, | 848 FROM_HERE, |
894 base::Bind(&BrowserPlugin::OnRequestObjectGarbageCollected, | 849 base::Bind(&BrowserPluginImpl::OnRequestObjectGarbageCollected, |
895 plugin, request_id)); | 850 plugin, request_id)); |
896 } | 851 } |
897 } | 852 } |
898 | 853 |
899 void BrowserPlugin::Back() { | 854 void BrowserPluginImpl::Back() { |
900 if (!navigate_src_sent_) | 855 if (!navigate_src_sent_) |
901 return; | 856 return; |
902 browser_plugin_manager()->Send( | 857 browser_plugin_manager()->Send( |
903 new BrowserPluginHostMsg_Go(render_view_routing_id_, | 858 new BrowserPluginHostMsg_Go(render_view_routing_id_, |
904 instance_id_, -1)); | 859 instance_id_, -1)); |
905 } | 860 } |
906 | 861 |
907 void BrowserPlugin::Forward() { | 862 void BrowserPluginImpl::Forward() { |
908 if (!navigate_src_sent_) | 863 if (!navigate_src_sent_) |
909 return; | 864 return; |
910 browser_plugin_manager()->Send( | 865 browser_plugin_manager()->Send( |
911 new BrowserPluginHostMsg_Go(render_view_routing_id_, | 866 new BrowserPluginHostMsg_Go(render_view_routing_id_, |
912 instance_id_, 1)); | 867 instance_id_, 1)); |
913 } | 868 } |
914 | 869 |
915 void BrowserPlugin::Go(int relative_index) { | 870 void BrowserPluginImpl::Go(int relative_index) { |
916 if (!navigate_src_sent_) | 871 if (!navigate_src_sent_) |
917 return; | 872 return; |
918 browser_plugin_manager()->Send( | 873 browser_plugin_manager()->Send( |
919 new BrowserPluginHostMsg_Go(render_view_routing_id_, | 874 new BrowserPluginHostMsg_Go(render_view_routing_id_, |
920 instance_id_, | 875 instance_id_, |
921 relative_index)); | 876 relative_index)); |
922 } | 877 } |
923 | 878 |
924 void BrowserPlugin::TerminateGuest() { | 879 void BrowserPluginImpl::TerminateGuest() { |
925 if (!navigate_src_sent_ || guest_crashed_) | 880 if (!navigate_src_sent_ || guest_crashed_) |
926 return; | 881 return; |
927 browser_plugin_manager()->Send( | 882 browser_plugin_manager()->Send( |
928 new BrowserPluginHostMsg_TerminateGuest(render_view_routing_id_, | 883 new BrowserPluginHostMsg_TerminateGuest(render_view_routing_id_, |
929 instance_id_)); | 884 instance_id_)); |
930 } | 885 } |
931 | 886 |
932 void BrowserPlugin::Stop() { | 887 void BrowserPluginImpl::Stop() { |
933 if (!navigate_src_sent_) | 888 if (!navigate_src_sent_) |
934 return; | 889 return; |
935 browser_plugin_manager()->Send( | 890 browser_plugin_manager()->Send( |
936 new BrowserPluginHostMsg_Stop(render_view_routing_id_, | 891 new BrowserPluginHostMsg_Stop(render_view_routing_id_, |
937 instance_id_)); | 892 instance_id_)); |
938 } | 893 } |
939 | 894 |
940 void BrowserPlugin::Reload() { | 895 void BrowserPluginImpl::Reload() { |
941 if (!navigate_src_sent_) | 896 if (!navigate_src_sent_) |
942 return; | 897 return; |
943 browser_plugin_manager()->Send( | 898 browser_plugin_manager()->Send( |
944 new BrowserPluginHostMsg_Reload(render_view_routing_id_, | 899 new BrowserPluginHostMsg_Reload(render_view_routing_id_, |
945 instance_id_)); | 900 instance_id_)); |
946 } | 901 } |
947 | 902 |
948 void BrowserPlugin::UpdateGuestFocusState() { | 903 void BrowserPluginImpl::UpdateGuestFocusState() { |
949 if (!navigate_src_sent_) | 904 if (!navigate_src_sent_) |
950 return; | 905 return; |
951 bool should_be_focused = ShouldGuestBeFocused(); | 906 bool should_be_focused = ShouldGuestBeFocused(); |
952 browser_plugin_manager()->Send(new BrowserPluginHostMsg_SetFocus( | 907 browser_plugin_manager()->Send(new BrowserPluginHostMsg_SetFocus( |
953 render_view_routing_id_, | 908 render_view_routing_id_, |
954 instance_id_, | 909 instance_id_, |
955 should_be_focused)); | 910 should_be_focused)); |
956 } | 911 } |
957 | 912 |
958 bool BrowserPlugin::ShouldGuestBeFocused() const { | 913 bool BrowserPluginImpl::ShouldGuestBeFocused() const { |
959 bool embedder_focused = false; | 914 bool embedder_focused = false; |
960 if (render_view_) | 915 if (render_view_) |
961 embedder_focused = render_view_->has_focus(); | 916 embedder_focused = render_view_->has_focus(); |
962 return plugin_focused_ && embedder_focused; | 917 return plugin_focused_ && embedder_focused; |
963 } | 918 } |
964 | 919 |
965 WebKit::WebPluginContainer* BrowserPlugin::container() const { | 920 WebKit::WebPluginContainer* BrowserPluginImpl::container() const { |
966 return container_; | 921 return container_; |
967 } | 922 } |
968 | 923 |
969 void BrowserPlugin::RespondPermission( | 924 void BrowserPluginImpl::RespondPermission( |
970 BrowserPluginPermissionType permission_type, int request_id, bool allow) { | 925 BrowserPluginPermissionType permission_type, int request_id, bool allow) { |
971 switch (permission_type) { | 926 switch (permission_type) { |
972 case BrowserPluginPermissionTypeMedia: | 927 case BrowserPluginPermissionTypeMedia: |
973 browser_plugin_manager()->Send( | 928 browser_plugin_manager()->Send( |
974 new BrowserPluginHostMsg_RespondPermission( | 929 new BrowserPluginHostMsg_RespondPermission( |
975 render_view_->GetRoutingID(), instance_id_, | 930 render_view_->GetRoutingID(), instance_id_, |
976 BrowserPluginPermissionTypeMedia, request_id, allow)); | 931 BrowserPluginPermissionTypeMedia, request_id, allow)); |
977 break; | 932 break; |
978 case BrowserPluginPermissionTypeUnknown: | 933 case BrowserPluginPermissionTypeUnknown: |
979 default: | 934 default: |
980 // Not a valid permission type. | 935 // Not a valid permission type. |
981 NOTREACHED(); | 936 NOTREACHED(); |
982 break; | 937 break; |
983 } | 938 } |
984 } | 939 } |
985 | 940 |
986 void BrowserPlugin::RespondPermissionIfRequestIsPending( | 941 void BrowserPluginImpl::RespondPermissionIfRequestIsPending( |
987 int request_id, bool allow) { | 942 int request_id, bool allow) { |
988 PendingPermissionRequests::iterator iter = | 943 PendingPermissionRequests::iterator iter = |
989 pending_permission_requests_.find(request_id); | 944 pending_permission_requests_.find(request_id); |
990 if (iter == pending_permission_requests_.end()) | 945 if (iter == pending_permission_requests_.end()) |
991 return; | 946 return; |
992 | 947 |
993 BrowserPluginPermissionType permission_type = iter->second.second; | 948 BrowserPluginPermissionType permission_type = iter->second.second; |
994 pending_permission_requests_.erase(iter); | 949 pending_permission_requests_.erase(iter); |
995 RespondPermission(permission_type, request_id, allow); | 950 RespondPermission(permission_type, request_id, allow); |
996 } | 951 } |
997 | 952 |
998 void BrowserPlugin::OnEmbedderDecidedPermission(int request_id, bool allow) { | 953 void BrowserPluginImpl::OnEmbedderDecidedPermission(int request_id, |
| 954 bool allow) { |
999 RespondPermissionIfRequestIsPending(request_id, allow); | 955 RespondPermissionIfRequestIsPending(request_id, allow); |
1000 } | 956 } |
1001 | 957 |
1002 bool BrowserPlugin::initialize(WebPluginContainer* container) { | 958 bool BrowserPluginImpl::initialize(WebPluginContainer* container) { |
1003 if (!container) | 959 if (!container) |
1004 return false; | 960 return false; |
1005 | 961 |
1006 if (!GetContentClient()->renderer()->AllowBrowserPlugin(container)) | 962 if (!GetContentClient()->renderer()->AllowBrowserPlugin(container)) |
1007 return false; | 963 return false; |
1008 | 964 |
1009 bindings_.reset(new BrowserPluginBindings(this)); | 965 bindings_.reset(new BrowserPluginBindings(this)); |
1010 container_ = container; | 966 container_ = container; |
1011 container_->setWantsWheelEvents(true); | 967 container_->setWantsWheelEvents(true); |
1012 ParseAttributes(); | 968 ParseAttributes(); |
1013 return true; | 969 return true; |
1014 } | 970 } |
1015 | 971 |
1016 void BrowserPlugin::EnableCompositing(bool enable) { | 972 void BrowserPluginImpl::EnableCompositing(bool enable) { |
1017 if (compositing_enabled_ == enable) | 973 if (compositing_enabled_ == enable) |
1018 return; | 974 return; |
1019 | 975 |
1020 compositing_enabled_ = enable; | 976 compositing_enabled_ = enable; |
1021 if (enable) { | 977 if (enable) { |
1022 // No need to keep the backing store and damage buffer around if we're now | 978 // No need to keep the backing store and damage buffer around if we're now |
1023 // compositing. | 979 // compositing. |
1024 backing_store_.reset(); | 980 backing_store_.reset(); |
1025 current_damage_buffer_.reset(); | 981 current_damage_buffer_.reset(); |
1026 if (!compositing_helper_) { | 982 if (!compositing_helper_) { |
(...skipping 13 matching lines...) Expand all Loading... |
1040 params.repaint = true; | 996 params.repaint = true; |
1041 resize_ack_received_ = false; | 997 resize_ack_received_ = false; |
1042 browser_plugin_manager()->Send(new BrowserPluginHostMsg_ResizeGuest( | 998 browser_plugin_manager()->Send(new BrowserPluginHostMsg_ResizeGuest( |
1043 render_view_routing_id_, | 999 render_view_routing_id_, |
1044 instance_id_, | 1000 instance_id_, |
1045 params)); | 1001 params)); |
1046 } | 1002 } |
1047 compositing_helper_->EnableCompositing(enable); | 1003 compositing_helper_->EnableCompositing(enable); |
1048 } | 1004 } |
1049 | 1005 |
1050 void BrowserPlugin::destroy() { | 1006 void BrowserPluginImpl::destroy() { |
1051 // The BrowserPlugin's WebPluginContainer is deleted immediately after this | 1007 // The BrowserPlugin's WebPluginContainer is deleted immediately after this |
1052 // call returns, so let's not keep a reference to it around. | 1008 // call returns, so let's not keep a reference to it around. |
1053 container_ = NULL; | 1009 container_ = NULL; |
| 1010 // BrowserPluginObservers might create additional bindings. These bindings |
| 1011 // might refer back to the observers that created them. In order to ensure |
| 1012 // that bindings can always refer to valid observers, we get rid of bindings |
| 1013 // prior to cleaning up observers. |
| 1014 bindings_.reset(); |
| 1015 FOR_EACH_OBSERVER(BrowserPluginObserver, observers_, BrowserPluginGone()); |
| 1016 FOR_EACH_OBSERVER(BrowserPluginObserver, observers_, OnDestruct()); |
1054 if (compositing_helper_) | 1017 if (compositing_helper_) |
1055 compositing_helper_->OnContainerDestroy(); | 1018 compositing_helper_->OnContainerDestroy(); |
1056 MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 1019 MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
1057 } | 1020 } |
1058 | 1021 |
1059 NPObject* BrowserPlugin::scriptableObject() { | 1022 NPObject* BrowserPluginImpl::scriptableObject() { |
1060 if (!bindings_.get()) | 1023 if (!bindings_.get()) |
1061 return NULL; | 1024 return NULL; |
1062 | 1025 |
1063 NPObject* browser_plugin_np_object(bindings_->np_object()); | 1026 NPObject* browser_plugin_np_object(bindings_->np_object()); |
1064 // The object is expected to be retained before it is returned. | 1027 // The object is expected to be retained before it is returned. |
1065 WebKit::WebBindings::retainObject(browser_plugin_np_object); | 1028 WebKit::WebBindings::retainObject(browser_plugin_np_object); |
1066 return browser_plugin_np_object; | 1029 return browser_plugin_np_object; |
1067 } | 1030 } |
1068 | 1031 |
1069 bool BrowserPlugin::supportsKeyboardFocus() const { | 1032 bool BrowserPluginImpl::supportsKeyboardFocus() const { |
1070 return true; | 1033 return true; |
1071 } | 1034 } |
1072 | 1035 |
1073 bool BrowserPlugin::canProcessDrag() const { | 1036 bool BrowserPluginImpl::canProcessDrag() const { |
1074 return true; | 1037 return true; |
1075 } | 1038 } |
1076 | 1039 |
1077 void BrowserPlugin::paint(WebCanvas* canvas, const WebRect& rect) { | 1040 void BrowserPluginImpl::paint(WebCanvas* canvas, const WebRect& rect) { |
1078 if (guest_crashed_) { | 1041 if (guest_crashed_) { |
1079 if (!sad_guest_) // Lazily initialize bitmap. | 1042 if (!sad_guest_) // Lazily initialize bitmap. |
1080 sad_guest_ = content::GetContentClient()->renderer()-> | 1043 sad_guest_ = GetContentClient()->renderer()->GetSadWebViewBitmap(); |
1081 GetSadWebViewBitmap(); | |
1082 // content_shell does not have the sad plugin bitmap, so we'll paint black | 1044 // content_shell does not have the sad plugin bitmap, so we'll paint black |
1083 // instead to make it clear that something went wrong. | 1045 // instead to make it clear that something went wrong. |
1084 if (sad_guest_) { | 1046 if (sad_guest_) { |
1085 webkit::PaintSadPlugin(canvas, plugin_rect_, *sad_guest_); | 1047 webkit::PaintSadPlugin(canvas, plugin_rect_, *sad_guest_); |
1086 return; | 1048 return; |
1087 } | 1049 } |
1088 } | 1050 } |
1089 SkAutoCanvasRestore auto_restore(canvas, true); | 1051 SkAutoCanvasRestore auto_restore(canvas, true); |
1090 canvas->translate(plugin_rect_.x(), plugin_rect_.y()); | 1052 canvas->translate(plugin_rect_.x(), plugin_rect_.y()); |
1091 SkRect image_data_rect = SkRect::MakeXYWH( | 1053 SkRect image_data_rect = SkRect::MakeXYWH( |
(...skipping 10 matching lines...) Expand all Loading... |
1102 canvas->drawRect(image_data_rect, paint); | 1064 canvas->drawRect(image_data_rect, paint); |
1103 // Stay a solid color if we have never set a non-empty src, or we don't have a | 1065 // Stay a solid color if we have never set a non-empty src, or we don't have a |
1104 // backing store. | 1066 // backing store. |
1105 if (!backing_store_.get() || !navigate_src_sent_) | 1067 if (!backing_store_.get() || !navigate_src_sent_) |
1106 return; | 1068 return; |
1107 float inverse_scale_factor = 1.0f / backing_store_->GetScaleFactor(); | 1069 float inverse_scale_factor = 1.0f / backing_store_->GetScaleFactor(); |
1108 canvas->scale(inverse_scale_factor, inverse_scale_factor); | 1070 canvas->scale(inverse_scale_factor, inverse_scale_factor); |
1109 canvas->drawBitmap(backing_store_->GetBitmap(), 0, 0); | 1071 canvas->drawBitmap(backing_store_->GetBitmap(), 0, 0); |
1110 } | 1072 } |
1111 | 1073 |
1112 bool BrowserPlugin::InBounds(const gfx::Point& position) const { | 1074 bool BrowserPluginImpl::InBounds(const gfx::Point& position) const { |
1113 // Note that even for plugins that are rotated using rotate transformations, | 1075 // Note that even for plugins that are rotated using rotate transformations, |
1114 // we use the the |plugin_rect_| provided by updateGeometry, which means we | 1076 // we use the the |plugin_rect_| provided by updateGeometry, which means we |
1115 // will be off if |position| is within the plugin rect but does not fall | 1077 // will be off if |position| is within the plugin rect but does not fall |
1116 // within the actual plugin boundary. Not supporting such edge case is OK | 1078 // within the actual plugin boundary. Not supporting such edge case is OK |
1117 // since this function should not be used for making security-sensitive | 1079 // since this function should not be used for making security-sensitive |
1118 // decisions. | 1080 // decisions. |
1119 // This also does not take overlapping plugins into account. | 1081 // This also does not take overlapping plugins into account. |
1120 bool result = position.x() >= plugin_rect_.x() && | 1082 bool result = position.x() >= plugin_rect_.x() && |
1121 position.x() < plugin_rect_.x() + plugin_rect_.width() && | 1083 position.x() < plugin_rect_.x() + plugin_rect_.width() && |
1122 position.y() >= plugin_rect_.y() && | 1084 position.y() >= plugin_rect_.y() && |
1123 position.y() < plugin_rect_.y() + plugin_rect_.height(); | 1085 position.y() < plugin_rect_.y() + plugin_rect_.height(); |
1124 return result; | 1086 return result; |
1125 } | 1087 } |
1126 | 1088 |
1127 gfx::Point BrowserPlugin::ToLocalCoordinates(const gfx::Point& point) const { | 1089 RenderView* BrowserPluginImpl::GetRenderView() const { |
| 1090 return render_view_.get(); |
| 1091 } |
| 1092 |
| 1093 WebKit::WebPluginContainer* BrowserPluginImpl::GetContainer() const { |
| 1094 return container(); |
| 1095 } |
| 1096 |
| 1097 void BrowserPluginImpl::AddMethodBinding( |
| 1098 BrowserPluginMethodBinding* method_binding) { |
| 1099 bindings_->AddMethodBinding(method_binding); |
| 1100 } |
| 1101 |
| 1102 void BrowserPluginImpl::AddPropertyBinding( |
| 1103 BrowserPluginPropertyBinding* method_binding) { |
| 1104 bindings_->AddPropertyBinding(method_binding); |
| 1105 } |
| 1106 |
| 1107 void BrowserPluginImpl::TriggerEvent( |
| 1108 const std::string& event_name, |
| 1109 std::map<std::string, base::Value*>* props) { |
| 1110 if (!container() || !container()->element().document().frame()) |
| 1111 return; |
| 1112 v8::HandleScope handle_scope; |
| 1113 std::string json_string; |
| 1114 if (props) { |
| 1115 base::DictionaryValue dict; |
| 1116 for (std::map<std::string, base::Value*>::iterator iter = props->begin(), |
| 1117 end = props->end(); iter != end; ++iter) { |
| 1118 dict.Set(iter->first, iter->second); |
| 1119 } |
| 1120 |
| 1121 JSONStringValueSerializer serializer(&json_string); |
| 1122 if (!serializer.Serialize(dict)) |
| 1123 return; |
| 1124 } |
| 1125 |
| 1126 WebKit::WebFrame* frame = container()->element().document().frame(); |
| 1127 WebKit::WebDOMEvent dom_event = frame->document().createEvent("CustomEvent"); |
| 1128 WebKit::WebDOMCustomEvent event = dom_event.to<WebKit::WebDOMCustomEvent>(); |
| 1129 |
| 1130 // The events triggered directly from the plugin <object> are internal events |
| 1131 // whose implementation details can (and likely will) change over time. The |
| 1132 // wrapper/shim (e.g. <webview> tag) should receive these events, and expose a |
| 1133 // more appropriate (and stable) event to the consumers as part of the API. |
| 1134 event.initCustomEvent( |
| 1135 WebKit::WebString::fromUTF8(GetInternalEventName(event_name.c_str())), |
| 1136 false, false, |
| 1137 WebKit::WebSerializedScriptValue::serialize( |
| 1138 v8::String::New(json_string.c_str(), json_string.size()))); |
| 1139 container()->element().dispatchEvent(event); |
| 1140 } |
| 1141 |
| 1142 void BrowserPluginImpl::UpdateDOMAttribute(const std::string& attribute_name, |
| 1143 const std::string& attribute_value) { |
| 1144 if (!container()) |
| 1145 return; |
| 1146 |
| 1147 WebKit::WebElement element = container()->element(); |
| 1148 WebKit::WebString web_attribute_name = |
| 1149 WebKit::WebString::fromUTF8(attribute_name); |
| 1150 if (!HasDOMAttribute(attribute_name) || |
| 1151 (std::string(element.getAttribute(web_attribute_name).utf8()) != |
| 1152 attribute_value)) { |
| 1153 element.setAttribute(web_attribute_name, |
| 1154 WebKit::WebString::fromUTF8(attribute_value)); |
| 1155 } |
| 1156 } |
| 1157 void BrowserPluginImpl::RemoveDOMAttribute(const std::string& attribute_name) { |
| 1158 if (!container()) |
| 1159 return; |
| 1160 |
| 1161 container()->element().removeAttribute( |
| 1162 WebKit::WebString::fromUTF8(attribute_name)); |
| 1163 } |
| 1164 |
| 1165 std::string BrowserPluginImpl::GetDOMAttributeValue( |
| 1166 const std::string& attribute_name) const { |
| 1167 if (!container()) |
| 1168 return ""; |
| 1169 |
| 1170 return container()->element().getAttribute( |
| 1171 WebKit::WebString::fromUTF8(attribute_name)).utf8(); |
| 1172 } |
| 1173 |
| 1174 bool BrowserPluginImpl::HasDOMAttribute( |
| 1175 const std::string& attribute_name) const { |
| 1176 if (!container()) |
| 1177 return false; |
| 1178 |
| 1179 return container()->element().hasAttribute( |
| 1180 WebKit::WebString::fromUTF8(attribute_name)); |
| 1181 } |
| 1182 |
| 1183 bool BrowserPluginImpl::HasNavigated() const { |
| 1184 return navigate_src_sent_; |
| 1185 } |
| 1186 |
| 1187 bool BrowserPluginImpl::Send(IPC::Message* message) { |
| 1188 IPC::Message* wrapper_msg = |
| 1189 new BrowserPluginHostMsg_ForwardMessage( |
| 1190 render_view_routing_id_, instance_id_, *message); |
| 1191 delete message; |
| 1192 return browser_plugin_manager()->Send(wrapper_msg); |
| 1193 } |
| 1194 |
| 1195 gfx::Point BrowserPluginImpl::ToLocalCoordinates( |
| 1196 const gfx::Point& point) const { |
1128 if (container_) | 1197 if (container_) |
1129 return container_->windowToLocalPoint(WebKit::WebPoint(point)); | 1198 return container_->windowToLocalPoint(WebKit::WebPoint(point)); |
1130 return gfx::Point(point.x() - plugin_rect_.x(), point.y() - plugin_rect_.y()); | 1199 return gfx::Point(point.x() - plugin_rect_.x(), point.y() - plugin_rect_.y()); |
1131 } | 1200 } |
1132 | 1201 |
1133 void BrowserPlugin::updateGeometry( | 1202 void BrowserPluginImpl::updateGeometry( |
1134 const WebRect& window_rect, | 1203 const WebRect& window_rect, |
1135 const WebRect& clip_rect, | 1204 const WebRect& clip_rect, |
1136 const WebVector<WebRect>& cut_outs_rects, | 1205 const WebVector<WebRect>& cut_outs_rects, |
1137 bool is_visible) { | 1206 bool is_visible) { |
1138 int old_width = width(); | 1207 int old_width = width(); |
1139 int old_height = height(); | 1208 int old_height = height(); |
1140 plugin_rect_ = window_rect; | 1209 plugin_rect_ = window_rect; |
1141 // In AutoSize mode, guests don't care when the BrowserPlugin container is | 1210 // In AutoSize mode, guests don't care when the BrowserPlugin container is |
1142 // resized. If |!resize_ack_received_|, then we are still waiting on a | 1211 // resized. If |!resize_ack_received_|, then we are still waiting on a |
1143 // previous resize to be ACK'ed and so we don't issue additional resizes | 1212 // previous resize to be ACK'ed and so we don't issue additional resizes |
1144 // until the previous one is ACK'ed. | 1213 // until the previous one is ACK'ed. |
1145 // TODO(mthiesse): Assess the performance of calling GetAutoSizeAttribute() on | 1214 // TODO(mthiesse): Assess the performance of calling GetAutoSizeAttribute() on |
1146 // resize. | 1215 // resize. |
1147 if (!navigate_src_sent_ || | 1216 if (!navigate_src_sent_ || |
1148 !resize_ack_received_ || | 1217 !resize_ack_received_ || |
1149 (old_width == window_rect.width && old_height == window_rect.height) || | 1218 (old_width == window_rect.width && old_height == window_rect.height) || |
1150 GetAutoSizeAttribute()) { | 1219 GetAutoSizeAttribute()) { |
1151 return; | 1220 return; |
1152 } | 1221 } |
1153 | 1222 |
1154 BrowserPluginHostMsg_ResizeGuest_Params params; | 1223 BrowserPluginHostMsg_ResizeGuest_Params params; |
1155 PopulateResizeGuestParameters(¶ms, gfx::Size(width(), height())); | 1224 PopulateResizeGuestParameters(¶ms, gfx::Size(width(), height())); |
1156 resize_ack_received_ = false; | 1225 resize_ack_received_ = false; |
1157 browser_plugin_manager()->Send(new BrowserPluginHostMsg_ResizeGuest( | 1226 browser_plugin_manager()->Send(new BrowserPluginHostMsg_ResizeGuest( |
1158 render_view_routing_id_, | 1227 render_view_routing_id_, |
1159 instance_id_, | 1228 instance_id_, |
1160 params)); | 1229 params)); |
1161 } | 1230 } |
1162 | 1231 |
1163 void BrowserPlugin::SwapDamageBuffers() { | 1232 void BrowserPluginImpl::SwapDamageBuffers() { |
1164 current_damage_buffer_.reset(pending_damage_buffer_.release()); | 1233 current_damage_buffer_.reset(pending_damage_buffer_.release()); |
1165 resize_ack_received_ = true; | 1234 resize_ack_received_ = true; |
1166 } | 1235 } |
1167 | 1236 |
1168 void BrowserPlugin::PopulateResizeGuestParameters( | 1237 void BrowserPluginImpl::PopulateResizeGuestParameters( |
1169 BrowserPluginHostMsg_ResizeGuest_Params* params, | 1238 BrowserPluginHostMsg_ResizeGuest_Params* params, |
1170 const gfx::Size& view_size) { | 1239 const gfx::Size& view_size) { |
1171 params->view_size = view_size; | 1240 params->view_size = view_size; |
1172 params->scale_factor = GetDeviceScaleFactor(); | 1241 params->scale_factor = GetDeviceScaleFactor(); |
1173 | 1242 |
1174 // In HW compositing mode, we do not need a damage buffer. | 1243 // In HW compositing mode, we do not need a damage buffer. |
1175 if (compositing_enabled_) | 1244 if (compositing_enabled_) |
1176 return; | 1245 return; |
1177 | 1246 |
1178 const size_t stride = skia::PlatformCanvasStrideForWidth(view_size.width()); | 1247 const size_t stride = skia::PlatformCanvasStrideForWidth(view_size.width()); |
1179 // Make sure the size of the damage buffer is at least four bytes so that we | 1248 // Make sure the size of the damage buffer is at least four bytes so that we |
1180 // can fit in a magic word to verify that the memory is shared correctly. | 1249 // can fit in a magic word to verify that the memory is shared correctly. |
1181 size_t size = | 1250 size_t size = |
1182 std::max(sizeof(unsigned int), | 1251 std::max(sizeof(unsigned int), |
1183 static_cast<size_t>(view_size.height() * | 1252 static_cast<size_t>(view_size.height() * |
1184 stride * | 1253 stride * |
1185 GetDeviceScaleFactor() * | 1254 GetDeviceScaleFactor() * |
1186 GetDeviceScaleFactor())); | 1255 GetDeviceScaleFactor())); |
1187 | 1256 |
1188 params->damage_buffer_size = size; | 1257 params->damage_buffer_size = size; |
1189 pending_damage_buffer_.reset( | 1258 pending_damage_buffer_.reset( |
1190 CreateDamageBuffer(size, ¶ms->damage_buffer_handle)); | 1259 CreateDamageBuffer(size, ¶ms->damage_buffer_handle)); |
1191 if (!pending_damage_buffer_.get()) | 1260 if (!pending_damage_buffer_.get()) |
1192 NOTREACHED(); | 1261 NOTREACHED(); |
1193 params->damage_buffer_sequence_id = ++damage_buffer_sequence_id_; | 1262 params->damage_buffer_sequence_id = ++damage_buffer_sequence_id_; |
1194 } | 1263 } |
1195 | 1264 |
1196 void BrowserPlugin::GetDamageBufferWithSizeParams( | 1265 void BrowserPluginImpl::GetDamageBufferWithSizeParams( |
1197 BrowserPluginHostMsg_AutoSize_Params* auto_size_params, | 1266 BrowserPluginHostMsg_AutoSize_Params* auto_size_params, |
1198 BrowserPluginHostMsg_ResizeGuest_Params* resize_guest_params) { | 1267 BrowserPluginHostMsg_ResizeGuest_Params* resize_guest_params) { |
1199 if (auto_size_params) | 1268 if (auto_size_params) |
1200 PopulateAutoSizeParameters(auto_size_params, GetAutoSizeAttribute()); | 1269 PopulateAutoSizeParameters(auto_size_params, GetAutoSizeAttribute()); |
1201 gfx::Size view_size = (auto_size_params && auto_size_params->enable) ? | 1270 gfx::Size view_size = (auto_size_params && auto_size_params->enable) ? |
1202 auto_size_params->max_size : gfx::Size(width(), height()); | 1271 auto_size_params->max_size : gfx::Size(width(), height()); |
1203 if (view_size.IsEmpty()) | 1272 if (view_size.IsEmpty()) |
1204 return; | 1273 return; |
1205 resize_ack_received_ = false; | 1274 resize_ack_received_ = false; |
1206 PopulateResizeGuestParameters(resize_guest_params, view_size); | 1275 PopulateResizeGuestParameters(resize_guest_params, view_size); |
1207 } | 1276 } |
1208 | 1277 |
1209 #if defined(OS_POSIX) | 1278 #if defined(OS_POSIX) |
1210 base::SharedMemory* BrowserPlugin::CreateDamageBuffer( | 1279 base::SharedMemory* BrowserPluginImpl::CreateDamageBuffer( |
1211 const size_t size, | 1280 const size_t size, |
1212 base::SharedMemoryHandle* damage_buffer_handle) { | 1281 base::SharedMemoryHandle* damage_buffer_handle) { |
1213 scoped_ptr<base::SharedMemory> shared_buf( | 1282 scoped_ptr<base::SharedMemory> shared_buf( |
1214 content::RenderThread::Get()->HostAllocateSharedMemoryBuffer( | 1283 content::RenderThread::Get()->HostAllocateSharedMemoryBuffer( |
1215 size).release()); | 1284 size).release()); |
1216 | 1285 |
1217 if (shared_buf.get()) { | 1286 if (shared_buf.get()) { |
1218 if (shared_buf->Map(size)) { | 1287 if (shared_buf->Map(size)) { |
1219 // Insert the magic word. | 1288 // Insert the magic word. |
1220 *static_cast<unsigned int*>(shared_buf->memory()) = 0xdeadbeef; | 1289 *static_cast<unsigned int*>(shared_buf->memory()) = 0xdeadbeef; |
1221 shared_buf->ShareToProcess(base::GetCurrentProcessHandle(), | 1290 shared_buf->ShareToProcess(base::GetCurrentProcessHandle(), |
1222 damage_buffer_handle); | 1291 damage_buffer_handle); |
1223 return shared_buf.release(); | 1292 return shared_buf.release(); |
1224 } | 1293 } |
1225 } | 1294 } |
1226 NOTREACHED(); | 1295 NOTREACHED(); |
1227 return NULL; | 1296 return NULL; |
1228 } | 1297 } |
1229 #elif defined(OS_WIN) | 1298 #elif defined(OS_WIN) |
1230 base::SharedMemory* BrowserPlugin::CreateDamageBuffer( | 1299 base::SharedMemory* BrowserPluginImpl::CreateDamageBuffer( |
1231 const size_t size, | 1300 const size_t size, |
1232 base::SharedMemoryHandle* damage_buffer_handle) { | 1301 base::SharedMemoryHandle* damage_buffer_handle) { |
1233 scoped_ptr<base::SharedMemory> shared_buf(new base::SharedMemory()); | 1302 scoped_ptr<base::SharedMemory> shared_buf(new base::SharedMemory()); |
1234 | 1303 |
1235 if (!shared_buf->CreateAndMapAnonymous(size)) { | 1304 if (!shared_buf->CreateAndMapAnonymous(size)) { |
1236 NOTREACHED() << "Buffer allocation failed"; | 1305 NOTREACHED() << "Buffer allocation failed"; |
1237 return NULL; | 1306 return NULL; |
1238 } | 1307 } |
1239 | |
1240 // Insert the magic word. | 1308 // Insert the magic word. |
1241 *static_cast<unsigned int*>(shared_buf->memory()) = 0xdeadbeef; | 1309 *static_cast<unsigned int*>(shared_buf->memory()) = 0xdeadbeef; |
1242 if (shared_buf->ShareToProcess(base::GetCurrentProcessHandle(), | 1310 if (shared_buf->ShareToProcess(base::GetCurrentProcessHandle(), |
1243 damage_buffer_handle)) | 1311 damage_buffer_handle)) |
1244 return shared_buf.release(); | 1312 return shared_buf.release(); |
1245 NOTREACHED(); | 1313 NOTREACHED(); |
1246 return NULL; | 1314 return NULL; |
1247 } | 1315 } |
1248 #endif | 1316 #endif |
1249 | 1317 |
1250 void BrowserPlugin::updateFocus(bool focused) { | 1318 void BrowserPluginImpl::updateFocus(bool focused) { |
1251 if (plugin_focused_ == focused) | 1319 if (plugin_focused_ == focused) |
1252 return; | 1320 return; |
1253 | 1321 |
1254 bool old_guest_focus_state = ShouldGuestBeFocused(); | 1322 bool old_guest_focus_state = ShouldGuestBeFocused(); |
1255 plugin_focused_ = focused; | 1323 plugin_focused_ = focused; |
1256 | 1324 |
1257 if (ShouldGuestBeFocused() != old_guest_focus_state) | 1325 if (ShouldGuestBeFocused() != old_guest_focus_state) |
1258 UpdateGuestFocusState(); | 1326 UpdateGuestFocusState(); |
1259 } | 1327 } |
1260 | 1328 |
1261 void BrowserPlugin::updateVisibility(bool visible) { | 1329 void BrowserPluginImpl::updateVisibility(bool visible) { |
1262 if (visible_ == visible) | 1330 if (visible_ == visible) |
1263 return; | 1331 return; |
1264 | 1332 |
1265 visible_ = visible; | 1333 visible_ = visible; |
1266 if (!navigate_src_sent_) | 1334 if (!navigate_src_sent_) |
1267 return; | 1335 return; |
1268 | 1336 |
1269 if (compositing_helper_) | 1337 if (compositing_helper_) |
1270 compositing_helper_->UpdateVisibility(visible); | 1338 compositing_helper_->UpdateVisibility(visible); |
1271 | 1339 |
1272 browser_plugin_manager()->Send(new BrowserPluginHostMsg_SetVisibility( | 1340 browser_plugin_manager()->Send(new BrowserPluginHostMsg_SetVisibility( |
1273 render_view_routing_id_, | 1341 render_view_routing_id_, |
1274 instance_id_, | 1342 instance_id_, |
1275 visible)); | 1343 visible)); |
1276 } | 1344 } |
1277 | 1345 |
1278 bool BrowserPlugin::acceptsInputEvents() { | 1346 bool BrowserPluginImpl::acceptsInputEvents() { |
1279 return true; | 1347 return true; |
1280 } | 1348 } |
1281 | 1349 |
1282 bool BrowserPlugin::handleInputEvent(const WebKit::WebInputEvent& event, | 1350 bool BrowserPluginImpl::handleInputEvent(const WebKit::WebInputEvent& event, |
1283 WebKit::WebCursorInfo& cursor_info) { | 1351 WebKit::WebCursorInfo& cursor_info) { |
1284 if (guest_crashed_ || !navigate_src_sent_ || | 1352 if (guest_crashed_ || !navigate_src_sent_ || |
1285 event.type == WebKit::WebInputEvent::ContextMenu) | 1353 event.type == WebKit::WebInputEvent::ContextMenu) |
1286 return false; | 1354 return false; |
1287 browser_plugin_manager()->Send( | 1355 browser_plugin_manager()->Send( |
1288 new BrowserPluginHostMsg_HandleInputEvent(render_view_routing_id_, | 1356 new BrowserPluginHostMsg_HandleInputEvent(render_view_routing_id_, |
1289 instance_id_, | 1357 instance_id_, |
1290 plugin_rect_, | 1358 plugin_rect_, |
1291 &event)); | 1359 &event)); |
1292 cursor_.GetCursorInfo(&cursor_info); | 1360 cursor_.GetCursorInfo(&cursor_info); |
1293 return true; | 1361 return true; |
1294 } | 1362 } |
1295 | 1363 |
1296 bool BrowserPlugin::handleDragStatusUpdate(WebKit::WebDragStatus drag_status, | 1364 bool BrowserPluginImpl::handleDragStatusUpdate( |
1297 const WebKit::WebDragData& drag_data, | 1365 WebKit::WebDragStatus drag_status, |
1298 WebKit::WebDragOperationsMask mask, | 1366 const WebKit::WebDragData& drag_data, |
1299 const WebKit::WebPoint& position, | 1367 WebKit::WebDragOperationsMask mask, |
1300 const WebKit::WebPoint& screen) { | 1368 const WebKit::WebPoint& position, |
| 1369 const WebKit::WebPoint& screen) { |
1301 if (guest_crashed_ || !navigate_src_sent_) | 1370 if (guest_crashed_ || !navigate_src_sent_) |
1302 return false; | 1371 return false; |
1303 browser_plugin_manager()->Send( | 1372 browser_plugin_manager()->Send(new BrowserPluginHostMsg_DragStatusUpdate( |
1304 new BrowserPluginHostMsg_DragStatusUpdate( | 1373 render_view_routing_id_, |
1305 render_view_routing_id_, | 1374 instance_id_, |
1306 instance_id_, | 1375 drag_status, |
1307 drag_status, | 1376 WebDropData(drag_data), |
1308 WebDropData(drag_data), | 1377 mask, |
1309 mask, | 1378 position)); |
1310 position)); | |
1311 return false; | 1379 return false; |
1312 } | 1380 } |
1313 | 1381 |
1314 void BrowserPlugin::didReceiveResponse( | 1382 void BrowserPluginImpl::didReceiveResponse( |
1315 const WebKit::WebURLResponse& response) { | 1383 const WebKit::WebURLResponse& response) { |
1316 } | 1384 } |
1317 | 1385 |
1318 void BrowserPlugin::didReceiveData(const char* data, int data_length) { | 1386 void BrowserPluginImpl::didReceiveData(const char* data, int data_length) { |
1319 } | 1387 } |
1320 | 1388 |
1321 void BrowserPlugin::didFinishLoading() { | 1389 void BrowserPluginImpl::didFinishLoading() { |
1322 } | 1390 } |
1323 | 1391 |
1324 void BrowserPlugin::didFailLoading(const WebKit::WebURLError& error) { | 1392 void BrowserPluginImpl::didFailLoading(const WebKit::WebURLError& error) { |
1325 } | 1393 } |
1326 | 1394 |
1327 void BrowserPlugin::didFinishLoadingFrameRequest(const WebKit::WebURL& url, | 1395 void BrowserPluginImpl::didFinishLoadingFrameRequest(const WebKit::WebURL& url, |
1328 void* notify_data) { | 1396 void* notify_data) { |
1329 } | 1397 } |
1330 | 1398 |
1331 void BrowserPlugin::didFailLoadingFrameRequest( | 1399 void BrowserPluginImpl::didFailLoadingFrameRequest( |
1332 const WebKit::WebURL& url, | 1400 const WebKit::WebURL& url, |
1333 void* notify_data, | 1401 void* notify_data, |
1334 const WebKit::WebURLError& error) { | 1402 const WebKit::WebURLError& error) { |
1335 } | 1403 } |
1336 | 1404 |
1337 } // namespace content | 1405 } // namespace content |
OLD | NEW |