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.h" |
6 | 6 |
| 7 #include "base/json/json_string_value_serializer.h" |
7 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
8 #include "base/string_util.h" | 9 #include "base/string_util.h" |
9 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
10 #include "content/common/browser_plugin_messages.h" | 11 #include "content/common/browser_plugin_messages.h" |
11 #include "content/common/view_messages.h" | 12 #include "content/common/view_messages.h" |
12 #include "content/public/common/content_client.h" | 13 #include "content/public/common/content_client.h" |
13 #include "content/public/renderer/content_renderer_client.h" | 14 #include "content/public/renderer/content_renderer_client.h" |
14 #include "content/renderer/browser_plugin/browser_plugin_bindings.h" | 15 #include "content/renderer/browser_plugin/browser_plugin_bindings.h" |
15 #include "content/renderer/browser_plugin/browser_plugin_manager.h" | 16 #include "content/renderer/browser_plugin/browser_plugin_manager.h" |
16 #include "content/renderer/render_process_impl.h" | 17 #include "content/renderer/render_process_impl.h" |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 float BrowserPlugin::GetDeviceScaleFactor() const { | 313 float BrowserPlugin::GetDeviceScaleFactor() const { |
313 if (!render_view_) | 314 if (!render_view_) |
314 return 1.0f; | 315 return 1.0f; |
315 return render_view_->GetWebView()->deviceScaleFactor(); | 316 return render_view_->GetWebView()->deviceScaleFactor(); |
316 } | 317 } |
317 | 318 |
318 void BrowserPlugin::TriggerEvent(const std::string& event_name, | 319 void BrowserPlugin::TriggerEvent(const std::string& event_name, |
319 std::map<std::string, base::Value*>* props) { | 320 std::map<std::string, base::Value*>* props) { |
320 if (!container()) | 321 if (!container()) |
321 return; | 322 return; |
322 WebKit::WebFrame* frame = container()->element().document().frame(); | |
323 v8::HandleScope handle_scope; | 323 v8::HandleScope handle_scope; |
324 v8::Local<v8::Context> context = frame->mainWorldScriptContext(); | 324 std::string json_string; |
325 v8::Context::Scope context_scope(context); | |
326 v8::Local<v8::Object> detail = v8::Object::New(); | |
327 | |
328 if (props) { | 325 if (props) { |
329 V8ValueConverterImpl converter; | 326 base::DictionaryValue dict; |
330 for (std::map<std::string, base::Value*>::iterator iter = props->begin(), | 327 for (std::map<std::string, base::Value*>::iterator iter = props->begin(), |
331 end = props->end(); iter != end; ++iter) { | 328 end = props->end(); iter != end; ++iter) { |
332 detail->Set(v8::String::New(iter->first.data(), iter->first.size()), | 329 dict.Set(iter->first, iter->second); |
333 converter.ToV8Value(iter->second, context), | |
334 v8::ReadOnly); | |
335 } | 330 } |
336 STLDeleteValues(props); | 331 |
| 332 JSONStringValueSerializer serializer(&json_string); |
| 333 if (!serializer.Serialize(dict)) |
| 334 return; |
337 } | 335 } |
338 | 336 |
339 // Setting properties on the |detail| object may have triggered JS code that | 337 // Setting properties on the |detail| object may have triggered JS code that |
340 // destroyed the plugin, or done other things that caused the plugin or the | 338 // destroyed the plugin, or done other things that caused the plugin or the |
341 // frame to be destroyed. So do a check here for these. | 339 // frame to be destroyed. So do a check here for these. |
342 if (!container() || !container()->element().document().frame()) | 340 if (!container() || !container()->element().document().frame()) |
343 return; | 341 return; |
| 342 WebKit::WebFrame* frame = container()->element().document().frame(); |
344 WebKit::WebDOMEvent dom_event = frame->document().createEvent("CustomEvent"); | 343 WebKit::WebDOMEvent dom_event = frame->document().createEvent("CustomEvent"); |
345 WebKit::WebDOMCustomEvent event = dom_event.to<WebKit::WebDOMCustomEvent>(); | 344 WebKit::WebDOMCustomEvent event = dom_event.to<WebKit::WebDOMCustomEvent>(); |
346 std::string obfuscated_name = base::StringPrintf("-internal-%s", | 345 std::string obfuscated_name = base::StringPrintf("-internal-%s", |
347 event_name.c_str()); | 346 event_name.c_str()); |
348 event.initCustomEvent( | 347 event.initCustomEvent( |
349 WebKit::WebString::fromUTF8(obfuscated_name.c_str()), | 348 WebKit::WebString::fromUTF8(obfuscated_name.c_str()), |
350 false, false, | 349 false, false, |
351 WebKit::WebSerializedScriptValue::serialize(detail)); | 350 WebKit::WebSerializedScriptValue::serialize( |
| 351 v8::String::New(json_string.c_str()))); |
352 container()->element().dispatchEvent(event); | 352 container()->element().dispatchEvent(event); |
353 } | 353 } |
354 | 354 |
355 void BrowserPlugin::Back() { | 355 void BrowserPlugin::Back() { |
356 if (!navigate_src_sent_) | 356 if (!navigate_src_sent_) |
357 return; | 357 return; |
358 BrowserPluginManager::Get()->Send( | 358 BrowserPluginManager::Get()->Send( |
359 new BrowserPluginHostMsg_Go(render_view_routing_id_, | 359 new BrowserPluginHostMsg_Go(render_view_routing_id_, |
360 instance_id_, -1)); | 360 instance_id_, -1)); |
361 } | 361 } |
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
837 void* notify_data) { | 837 void* notify_data) { |
838 } | 838 } |
839 | 839 |
840 void BrowserPlugin::didFailLoadingFrameRequest( | 840 void BrowserPlugin::didFailLoadingFrameRequest( |
841 const WebKit::WebURL& url, | 841 const WebKit::WebURL& url, |
842 void* notify_data, | 842 void* notify_data, |
843 const WebKit::WebURLError& error) { | 843 const WebKit::WebURLError& error) { |
844 } | 844 } |
845 | 845 |
846 } // namespace content | 846 } // namespace content |
OLD | NEW |