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/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #if defined (OS_WIN) | 9 #if defined (OS_WIN) |
10 #include "base/sys_info.h" | 10 #include "base/sys_info.h" |
11 #endif | 11 #endif |
12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
13 #include "content/common/browser_plugin_messages.h" | 13 #include "content/common/browser_plugin_messages.h" |
14 #include "content/common/view_messages.h" | 14 #include "content/common/view_messages.h" |
15 #include "content/public/common/content_client.h" | 15 #include "content/public/common/content_client.h" |
16 #include "content/public/renderer/content_renderer_client.h" | 16 #include "content/public/renderer/content_renderer_client.h" |
17 #include "content/renderer/browser_plugin/browser_plugin_bindings.h" | 17 #include "content/renderer/browser_plugin/browser_plugin_bindings.h" |
18 #include "content/renderer/browser_plugin/browser_plugin_manager.h" | 18 #include "content/renderer/browser_plugin/browser_plugin_manager.h" |
19 #include "content/renderer/render_process_impl.h" | 19 #include "content/renderer/render_process_impl.h" |
20 #include "content/renderer/render_thread_impl.h" | 20 #include "content/renderer/render_thread_impl.h" |
21 #include "content/renderer/v8_value_converter_impl.h" | |
21 #include "skia/ext/platform_canvas.h" | 22 #include "skia/ext/platform_canvas.h" |
22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" | 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" |
24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDOMCustomEvent.h" | |
23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" | 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" |
25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" | 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" |
28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginParams.h" | 30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginParams.h" |
29 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h" | 31 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h" |
32 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.h" | |
30 #include "webkit/plugins/sad_plugin.h" | 33 #include "webkit/plugins/sad_plugin.h" |
31 | 34 |
32 using WebKit::WebCanvas; | 35 using WebKit::WebCanvas; |
33 using WebKit::WebPlugin; | 36 using WebKit::WebPlugin; |
34 using WebKit::WebPluginContainer; | 37 using WebKit::WebPluginContainer; |
35 using WebKit::WebPluginParams; | 38 using WebKit::WebPluginParams; |
36 using WebKit::WebPoint; | 39 using WebKit::WebPoint; |
37 using WebKit::WebString; | 40 using WebKit::WebString; |
38 using WebKit::WebRect; | 41 using WebKit::WebRect; |
39 using WebKit::WebURL; | 42 using WebKit::WebURL; |
40 using WebKit::WebVector; | 43 using WebKit::WebVector; |
41 | 44 |
42 namespace content { | 45 namespace content { |
43 | 46 |
44 namespace { | 47 namespace { |
45 const char kExitEventName[] = "exit"; | 48 const char kExitEventName[] = "exit"; |
46 const char kIsTopLevel[] = "isTopLevel"; | 49 const char kIsTopLevel[] = "isTopLevel"; |
47 const char kLoadAbortEventName[] = "loadabort"; | 50 const char kLoadAbortEventName[] = "loadabort"; |
48 const char kLoadCommitEventName[] = "loadcommit"; | 51 const char kLoadCommitEventName[] = "loadcommit"; |
49 const char kLoadRedirectEventName[] = "loadredirect"; | 52 const char kLoadRedirectEventName[] = "loadredirect"; |
50 const char kLoadStartEventName[] = "loadstart"; | 53 const char kLoadStartEventName[] = "loadstart"; |
51 const char kLoadStopEventName[] = "loadstop"; | 54 const char kLoadStopEventName[] = "loadstop"; |
52 const char kNewURL[] = "newUrl"; | 55 const char kNewURL[] = "newUrl"; |
53 const char kOldURL[] = "oldUrl"; | 56 const char kOldURL[] = "oldUrl"; |
54 const char kPartitionAttribute[] = "partition"; | 57 const char kPartitionAttribute[] = "partition"; |
55 const char kPersistPrefix[] = "persist:"; | 58 const char kPersistPrefix[] = "persist:"; |
56 const char kProcessId[] = "processId"; | 59 const char kProcessId[] = "processId"; |
57 const char kSrcAttribute[] = "src"; | 60 const char kSrcAttribute[] = "src"; |
58 const char kType[] = "type"; | 61 const char kReason[] = "reason"; |
59 const char kURL[] = "url"; | 62 const char kURL[] = "url"; |
60 | 63 |
61 static std::string TerminationStatusToString(base::TerminationStatus status) { | 64 static std::string TerminationStatusToString(base::TerminationStatus status) { |
62 switch (status) { | 65 switch (status) { |
63 case base::TERMINATION_STATUS_NORMAL_TERMINATION: | 66 case base::TERMINATION_STATUS_NORMAL_TERMINATION: |
64 return "normal"; | 67 return "normal"; |
65 case base::TERMINATION_STATUS_ABNORMAL_TERMINATION: | 68 case base::TERMINATION_STATUS_ABNORMAL_TERMINATION: |
66 return "abnormal"; | 69 return "abnormal"; |
67 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED: | 70 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED: |
68 return "killed"; | 71 return "killed"; |
69 case base::TERMINATION_STATUS_PROCESS_CRASHED: | 72 case base::TERMINATION_STATUS_PROCESS_CRASHED: |
70 return "crashed"; | 73 return "crashed"; |
71 default: | 74 default: |
72 // This should never happen. | 75 // This should never happen. |
73 DCHECK(false); | 76 DCHECK(false); |
74 return "unknown"; | 77 return "unknown"; |
75 } | 78 } |
76 } | 79 } |
80 | |
81 v8::Handle<v8::Value> EventAttrGetter(v8::Local<v8::String> name, | |
82 const v8::AccessorInfo& info) { | |
83 return info.Data(); | |
77 } | 84 } |
78 | 85 |
86 } // namespace | |
87 | |
79 BrowserPlugin::BrowserPlugin( | 88 BrowserPlugin::BrowserPlugin( |
80 int instance_id, | 89 int instance_id, |
81 RenderViewImpl* render_view, | 90 RenderViewImpl* render_view, |
82 WebKit::WebFrame* frame, | 91 WebKit::WebFrame* frame, |
83 const WebPluginParams& params) | 92 const WebPluginParams& params) |
84 : instance_id_(instance_id), | 93 : instance_id_(instance_id), |
85 render_view_(render_view->AsWeakPtr()), | 94 render_view_(render_view->AsWeakPtr()), |
86 render_view_routing_id_(render_view->GetRoutingID()), | 95 render_view_routing_id_(render_view->GetRoutingID()), |
87 container_(NULL), | 96 container_(NULL), |
88 damage_buffer_(NULL), | 97 damage_buffer_(NULL), |
89 sad_guest_(NULL), | 98 sad_guest_(NULL), |
90 guest_crashed_(false), | 99 guest_crashed_(false), |
91 resize_pending_(false), | 100 resize_pending_(false), |
92 navigate_src_sent_(false), | 101 navigate_src_sent_(false), |
93 auto_size_(false), | 102 auto_size_(false), |
94 max_height_(0), | 103 max_height_(0), |
95 max_width_(0), | 104 max_width_(0), |
96 min_height_(0), | 105 min_height_(0), |
97 min_width_(0), | 106 min_width_(0), |
98 process_id_(-1), | 107 process_id_(-1), |
99 persist_storage_(false), | 108 persist_storage_(false), |
100 content_window_routing_id_(MSG_ROUTING_NONE), | 109 content_window_routing_id_(MSG_ROUTING_NONE), |
101 focused_(false), | 110 focused_(false), |
102 visible_(true), | 111 visible_(true), |
103 current_nav_entry_index_(0), | 112 current_nav_entry_index_(0), |
104 nav_entry_count_(0) { | 113 nav_entry_count_(0) { |
105 BrowserPluginManager::Get()->AddBrowserPlugin(instance_id, this); | 114 BrowserPluginManager::Get()->AddBrowserPlugin(instance_id, this); |
106 bindings_.reset(new BrowserPluginBindings(this)); | 115 bindings_.reset(new BrowserPluginBindings(this)); |
107 | 116 |
108 InitializeEvents(); | |
109 | |
110 ParseAttributes(params); | 117 ParseAttributes(params); |
111 } | 118 } |
112 | 119 |
113 BrowserPlugin::~BrowserPlugin() { | 120 BrowserPlugin::~BrowserPlugin() { |
114 if (damage_buffer_) | 121 if (damage_buffer_) |
115 FreeDamageBuffer(); | 122 FreeDamageBuffer(); |
116 RemoveEventListeners(); | |
117 BrowserPluginManager::Get()->RemoveBrowserPlugin(instance_id_); | 123 BrowserPluginManager::Get()->RemoveBrowserPlugin(instance_id_); |
118 BrowserPluginManager::Get()->Send( | 124 BrowserPluginManager::Get()->Send( |
119 new BrowserPluginHostMsg_PluginDestroyed( | 125 new BrowserPluginHostMsg_PluginDestroyed( |
120 render_view_routing_id_, | 126 render_view_routing_id_, |
121 instance_id_)); | 127 instance_id_)); |
122 } | 128 } |
123 | 129 |
124 void BrowserPlugin::Cleanup() { | 130 void BrowserPlugin::Cleanup() { |
125 if (damage_buffer_) | 131 if (damage_buffer_) |
126 FreeDamageBuffer(); | 132 FreeDamageBuffer(); |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
306 // true, which prevents changing the 'partition' attribute. | 312 // true, which prevents changing the 'partition' attribute. |
307 SetSrcAttribute(src); | 313 SetSrcAttribute(src); |
308 } | 314 } |
309 | 315 |
310 float BrowserPlugin::GetDeviceScaleFactor() const { | 316 float BrowserPlugin::GetDeviceScaleFactor() const { |
311 if (!render_view_) | 317 if (!render_view_) |
312 return 1.0f; | 318 return 1.0f; |
313 return render_view_->GetWebView()->deviceScaleFactor(); | 319 return render_view_->GetWebView()->deviceScaleFactor(); |
314 } | 320 } |
315 | 321 |
316 void BrowserPlugin::InitializeEvents() { | 322 void BrowserPlugin::TriggerEvent(const std::string& event_name, |
317 event_listener_map_[kExitEventName] = EventListeners(); | 323 std::map<std::string, base::Value*>* props) { |
318 event_listener_map_[kLoadAbortEventName] = EventListeners(); | 324 WebKit::WebFrame* frame = container()->element().document().frame(); |
319 event_listener_map_[kLoadCommitEventName] = EventListeners(); | 325 v8::HandleScope handle_scope; |
320 event_listener_map_[kLoadRedirectEventName] = EventListeners(); | 326 v8::Local<v8::Context> context = frame->mainWorldScriptContext(); |
321 event_listener_map_[kLoadStartEventName] = EventListeners(); | 327 v8::Context::Scope context_scope(context); |
322 event_listener_map_[kLoadStopEventName] = EventListeners(); | |
323 } | |
324 | 328 |
325 void BrowserPlugin::RemoveEventListeners() { | 329 WebKit::WebDOMEvent dom_event = frame->document().createEvent("Event"); |
326 EventListenerMap::iterator event_listener_map_iter = | 330 WebKit::WebDOMCustomEvent event = dom_event.to<WebKit::WebDOMCustomEvent>(); |
sadrul
2012/11/07 03:37:06
Ignore, for the moment, the fact that this is stil
| |
327 event_listener_map_.begin(); | 331 event.initCustomEvent( |
328 for (; event_listener_map_iter != event_listener_map_.end(); | 332 WebKit::WebString::fromUTF8(event_name.c_str()), |
329 ++event_listener_map_iter) { | 333 false, false); |
330 EventListeners& listeners = | 334 |
331 event_listener_map_[event_listener_map_iter->first]; | 335 v8::Handle<v8::Value> v8event = event.toV8Value(); |
332 EventListeners::iterator it = listeners.begin(); | 336 if (v8event->IsObject() && props) { |
333 for (; it != listeners.end(); ++it) { | 337 V8ValueConverterImpl converter; |
334 it->Dispose(); | 338 v8::Handle<v8::Object> object = v8event->ToObject(); |
339 for (std::map<std::string, base::Value*>::iterator iter = props->begin(), | |
340 end = props->end(); iter != end; ++iter) { | |
341 object->SetAccessor(v8::String::NewSymbol(iter->first.data()), | |
342 EventAttrGetter, 0, | |
343 converter.ToV8Value(iter->second, context), | |
344 v8::ALL_CAN_READ, | |
345 static_cast<v8::PropertyAttribute>(v8::DontDelete | v8::ReadOnly)); | |
335 } | 346 } |
336 } | 347 STLDeleteValues(props); |
337 event_listener_map_.clear(); | |
338 } | |
339 | |
340 bool BrowserPlugin::IsValidEvent(const std::string& event_name) { | |
341 return event_listener_map_.find(event_name) != event_listener_map_.end(); | |
342 } | |
343 | |
344 void BrowserPlugin::TriggerEvent(const std::string& event_name, | |
345 v8::Local<v8::Object>* event) { | |
346 WebKit::WebElement plugin = container()->element(); | |
347 | |
348 const EventListeners& listeners = event_listener_map_[event_name.c_str()]; | |
349 // A v8::Local copy of the listeners is created from the v8::Persistent | |
350 // listeners before firing them. This is to ensure that if one of these | |
351 // listeners mutate the list of listeners (by calling | |
352 // addEventListener/removeEventListener), this local copy is not affected. | |
353 // This means if you mutate the list of listeners for an event X while event X | |
354 // is firing, the mutation is deferred until all current listeners for X have | |
355 // fired. | |
356 EventListenersLocal listeners_local; | |
357 listeners_local.reserve(listeners.size()); | |
358 for (EventListeners::const_iterator it = listeners.begin(); | |
359 it != listeners.end(); | |
360 ++it) { | |
361 listeners_local.push_back(v8::Local<v8::Function>::New(*it)); | |
362 } | 348 } |
363 | 349 |
364 (*event)->Set(v8::String::New("name"), | 350 container()->element().dispatchEvent(dom_event); |
365 v8::String::New(event_name.c_str(), event_name.size()), | |
366 v8::ReadOnly); | |
367 v8::Local<v8::Value> argv[] = { *event }; | |
368 for (EventListenersLocal::const_iterator it = listeners_local.begin(); | |
369 it != listeners_local.end(); | |
370 ++it) { | |
371 WebKit::WebFrame* frame = plugin.document().frame(); | |
372 if (!frame) | |
373 break; | |
374 frame->callFunctionEvenIfScriptDisabled(*it, v8::Object::New(), 1, argv); | |
375 } | |
376 } | 351 } |
377 | 352 |
378 void BrowserPlugin::Back() { | 353 void BrowserPlugin::Back() { |
379 if (!navigate_src_sent_) | 354 if (!navigate_src_sent_) |
380 return; | 355 return; |
381 BrowserPluginManager::Get()->Send( | 356 BrowserPluginManager::Get()->Send( |
382 new BrowserPluginHostMsg_Go(render_view_routing_id_, | 357 new BrowserPluginHostMsg_Go(render_view_routing_id_, |
383 instance_id_, -1)); | 358 instance_id_, -1)); |
384 } | 359 } |
385 | 360 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
468 BrowserPluginManager::Get()->Send(new BrowserPluginHostMsg_UpdateRect_ACK( | 443 BrowserPluginManager::Get()->Send(new BrowserPluginHostMsg_UpdateRect_ACK( |
469 render_view_routing_id_, | 444 render_view_routing_id_, |
470 instance_id_, | 445 instance_id_, |
471 message_id, | 446 message_id, |
472 gfx::Size())); | 447 gfx::Size())); |
473 } | 448 } |
474 | 449 |
475 void BrowserPlugin::GuestGone(int process_id, base::TerminationStatus status) { | 450 void BrowserPlugin::GuestGone(int process_id, base::TerminationStatus status) { |
476 // We fire the event listeners before painting the sad graphic to give the | 451 // We fire the event listeners before painting the sad graphic to give the |
477 // developer an opportunity to display an alternative overlay image on crash. | 452 // developer an opportunity to display an alternative overlay image on crash. |
478 if (HasListeners(kExitEventName)) { | 453 std::string termination_status = TerminationStatusToString(status); |
479 WebKit::WebElement plugin = container()->element(); | 454 std::map<std::string, base::Value*> props; |
480 v8::HandleScope handle_scope; | 455 props[kProcessId] = base::Value::CreateIntegerValue(process_id); |
481 v8::Context::Scope context_scope( | 456 props[kReason] = base::Value::CreateStringValue(termination_status); |
482 plugin.document().frame()->mainWorldScriptContext()); | |
483 | 457 |
484 // Construct the exit event object. | 458 // Event listeners may remove the BrowserPlugin from the document. If that |
485 v8::Local<v8::Object> event = v8::Object::New(); | 459 // happens, the BrowserPlugin will be scheduled for later deletion (see |
486 event->Set(v8::String::New(kProcessId, sizeof(kProcessId) - 1), | 460 // BrowserPlugin::destroy()). That will clear the container_ reference, |
487 v8::Integer::New(process_id), | 461 // but leave other member variables valid below. |
488 v8::ReadOnly); | 462 TriggerEvent(kExitEventName, &props); |
489 std::string termination_status = TerminationStatusToString(status); | 463 |
490 event->Set(v8::String::New(kType, sizeof(kType) - 1), | |
491 v8::String::New(termination_status.data(), | |
492 termination_status.size()), | |
493 v8::ReadOnly); | |
494 // Event listeners may remove the BrowserPlugin from the document. If that | |
495 // happens, the BrowserPlugin will be scheduled for later deletion (see | |
496 // BrowserPlugin::destroy()). That will clear the container_ reference, | |
497 // but leave other member variables valid below. | |
498 TriggerEvent(kExitEventName, &event); | |
499 } | |
500 guest_crashed_ = true; | 464 guest_crashed_ = true; |
501 // We won't paint the contents of the current backing store again so we might | 465 // We won't paint the contents of the current backing store again so we might |
502 // as well toss it out and save memory. | 466 // as well toss it out and save memory. |
503 backing_store_.reset(); | 467 backing_store_.reset(); |
504 // If the BrowserPlugin is scheduled to be deleted, then container_ will be | 468 // If the BrowserPlugin is scheduled to be deleted, then container_ will be |
505 // NULL so we shouldn't attempt to access it. | 469 // NULL so we shouldn't attempt to access it. |
506 if (container_) | 470 if (container_) |
507 container_->invalidate(); | 471 container_->invalidate(); |
508 } | 472 } |
509 | 473 |
510 void BrowserPlugin::LoadStart(const GURL& url, bool is_top_level) { | 474 void BrowserPlugin::LoadStart(const GURL& url, bool is_top_level) { |
511 if (!HasListeners(kLoadStartEventName)) | 475 std::map<std::string, base::Value*> props; |
512 return; | 476 props[kURL] = base::Value::CreateStringValue(url.spec()); |
477 props[kIsTopLevel] = base::Value::CreateBooleanValue(is_top_level); | |
513 | 478 |
514 WebKit::WebElement plugin = container()->element(); | 479 TriggerEvent(kLoadStartEventName, &props); |
515 v8::HandleScope handle_scope; | |
516 v8::Context::Scope context_scope( | |
517 plugin.document().frame()->mainWorldScriptContext()); | |
518 | |
519 // Construct the loadStart event object. | |
520 v8::Local<v8::Object> event = v8::Object::New(); | |
521 event->Set(v8::String::New(kURL, sizeof(kURL) - 1), | |
522 v8::String::New(url.spec().data(), url.spec().size()), | |
523 v8::ReadOnly); | |
524 event->Set(v8::String::New(kIsTopLevel, sizeof(kIsTopLevel) - 1), | |
525 v8::Boolean::New(is_top_level), | |
526 v8::ReadOnly); | |
527 TriggerEvent(kLoadStartEventName, &event); | |
528 } | 480 } |
529 | 481 |
530 void BrowserPlugin::LoadCommit( | 482 void BrowserPlugin::LoadCommit( |
531 const BrowserPluginMsg_LoadCommit_Params& params) { | 483 const BrowserPluginMsg_LoadCommit_Params& params) { |
532 // If the guest has just committed a new navigation then it is no longer | 484 // If the guest has just committed a new navigation then it is no longer |
533 // crashed. | 485 // crashed. |
534 guest_crashed_ = false; | 486 guest_crashed_ = false; |
535 src_ = params.url.spec(); | 487 src_ = params.url.spec(); |
536 process_id_ = params.process_id; | 488 process_id_ = params.process_id; |
537 current_nav_entry_index_ = params.current_entry_index; | 489 current_nav_entry_index_ = params.current_entry_index; |
538 nav_entry_count_ = params.entry_count; | 490 nav_entry_count_ = params.entry_count; |
539 | 491 |
540 if (!HasListeners(kLoadCommitEventName)) | 492 std::map<std::string, base::Value*> props; |
541 return; | 493 props[kURL] = base::Value::CreateStringValue(src_); |
542 | 494 props[kIsTopLevel] = base::Value::CreateBooleanValue(params.is_top_level); |
543 WebKit::WebElement plugin = container()->element(); | 495 TriggerEvent(kLoadCommitEventName, &props); |
544 v8::HandleScope handle_scope; | |
545 v8::Context::Scope context_scope( | |
546 plugin.document().frame()->mainWorldScriptContext()); | |
547 | |
548 // Construct the loadCommit event object. | |
549 v8::Local<v8::Object> event = v8::Object::New(); | |
550 event->Set(v8::String::New(kURL, sizeof(kURL) - 1), | |
551 v8::String::New(src_.data(), src_.size()), | |
552 v8::ReadOnly); | |
553 event->Set(v8::String::New(kIsTopLevel, sizeof(kIsTopLevel) - 1), | |
554 v8::Boolean::New(params.is_top_level), | |
555 v8::ReadOnly); | |
556 | |
557 TriggerEvent(kLoadCommitEventName, &event); | |
558 } | 496 } |
559 | 497 |
560 void BrowserPlugin::LoadStop() { | 498 void BrowserPlugin::LoadStop() { |
561 if (!HasListeners(kLoadStopEventName)) | |
562 return; | |
563 | |
564 WebKit::WebElement plugin = container()->element(); | |
565 v8::HandleScope handle_scope; | |
566 v8::Context::Scope context_scope( | |
567 plugin.document().frame()->mainWorldScriptContext()); | |
568 | |
569 // Construct the loadStop event object. | 499 // Construct the loadStop event object. |
570 v8::Local<v8::Object> event = v8::Object::New(); | 500 TriggerEvent(kLoadStopEventName, NULL); |
571 TriggerEvent(kLoadStopEventName, &event); | |
572 } | 501 } |
573 | 502 |
574 void BrowserPlugin::LoadAbort(const GURL& url, | 503 void BrowserPlugin::LoadAbort(const GURL& url, |
575 bool is_top_level, | 504 bool is_top_level, |
576 const std::string& type) { | 505 const std::string& type) { |
577 if (!HasListeners(kLoadAbortEventName)) | 506 std::map<std::string, base::Value*> props; |
578 return; | 507 props[kURL] = base::Value::CreateStringValue(url.spec()); |
579 | 508 props[kIsTopLevel] = base::Value::CreateBooleanValue(is_top_level); |
580 WebKit::WebElement plugin = container()->element(); | 509 props[kReason] = base::Value::CreateStringValue(type); |
581 v8::HandleScope handle_scope; | 510 TriggerEvent(kLoadAbortEventName, &props); |
582 v8::Context::Scope context_scope( | |
583 plugin.document().frame()->mainWorldScriptContext()); | |
584 | |
585 // Construct the loadAbort event object. | |
586 v8::Local<v8::Object> event = v8::Object::New(); | |
587 event->Set(v8::String::New(kURL, sizeof(kURL) - 1), | |
588 v8::String::New(url.spec().data(), url.spec().size()), | |
589 v8::ReadOnly); | |
590 event->Set(v8::String::New(kIsTopLevel, sizeof(kIsTopLevel) - 1), | |
591 v8::Boolean::New(is_top_level), | |
592 v8::ReadOnly); | |
593 event->Set(v8::String::New(kType, sizeof(kType) - 1), | |
594 v8::String::New(type.data(), type.size()), | |
595 v8::ReadOnly); | |
596 | |
597 TriggerEvent(kLoadAbortEventName, &event); | |
598 } | 511 } |
599 | 512 |
600 void BrowserPlugin::LoadRedirect(const GURL& old_url, | 513 void BrowserPlugin::LoadRedirect(const GURL& old_url, |
601 const GURL& new_url, | 514 const GURL& new_url, |
602 bool is_top_level) { | 515 bool is_top_level) { |
603 if (!HasListeners(kLoadRedirectEventName)) | 516 std::map<std::string, base::Value*> props; |
604 return; | 517 props[kOldURL] = base::Value::CreateStringValue(old_url.spec()); |
605 | 518 props[kNewURL] = base::Value::CreateStringValue(new_url.spec()); |
606 WebKit::WebElement plugin = container()->element(); | 519 props[kIsTopLevel] = base::Value::CreateBooleanValue(is_top_level); |
607 v8::HandleScope handle_scope; | 520 TriggerEvent(kLoadRedirectEventName, &props); |
608 v8::Context::Scope context_scope( | |
609 plugin.document().frame()->mainWorldScriptContext()); | |
610 | |
611 // Construct the loadRedirect event object. | |
612 v8::Local<v8::Object> event = v8::Object::New(); | |
613 event->Set(v8::String::New(kOldURL, sizeof(kOldURL) - 1), | |
614 v8::String::New(old_url.spec().data(), old_url.spec().size()), | |
615 v8::ReadOnly); | |
616 event->Set(v8::String::New(kNewURL, sizeof(kNewURL) - 1), | |
617 v8::String::New(new_url.spec().data(), new_url.spec().size()), | |
618 v8::ReadOnly); | |
619 event->Set(v8::String::New(kIsTopLevel, sizeof(kIsTopLevel) - 1), | |
620 v8::Boolean::New(is_top_level), | |
621 v8::ReadOnly); | |
622 | |
623 TriggerEvent(kLoadRedirectEventName, &event); | |
624 } | 521 } |
625 | 522 |
626 void BrowserPlugin::AdvanceFocus(bool reverse) { | 523 void BrowserPlugin::AdvanceFocus(bool reverse) { |
627 // We do not have a RenderView when we are testing. | 524 // We do not have a RenderView when we are testing. |
628 if (render_view_) | 525 if (render_view_) |
629 render_view_->GetWebView()->advanceFocus(reverse); | 526 render_view_->GetWebView()->advanceFocus(reverse); |
630 } | 527 } |
631 | 528 |
632 void BrowserPlugin::GuestContentWindowReady(int content_window_routing_id) { | 529 void BrowserPlugin::GuestContentWindowReady(int content_window_routing_id) { |
633 DCHECK(content_window_routing_id != MSG_ROUTING_NONE); | 530 DCHECK(content_window_routing_id != MSG_ROUTING_NONE); |
634 content_window_routing_id_ = content_window_routing_id; | 531 content_window_routing_id_ = content_window_routing_id; |
635 } | 532 } |
636 | 533 |
637 void BrowserPlugin::SetAcceptTouchEvents(bool accept) { | 534 void BrowserPlugin::SetAcceptTouchEvents(bool accept) { |
638 if (container()) | 535 if (container()) |
639 container()->setIsAcceptingTouchEvents(accept); | 536 container()->setIsAcceptingTouchEvents(accept); |
640 } | 537 } |
641 | 538 |
642 bool BrowserPlugin::HasListeners(const std::string& event_name) { | |
643 return IsValidEvent(event_name) && | |
644 !event_listener_map_[event_name].empty(); | |
645 } | |
646 | |
647 bool BrowserPlugin::AddEventListener(const std::string& event_name, | |
648 v8::Local<v8::Function> function) { | |
649 if (!IsValidEvent(event_name)) | |
650 return false; | |
651 EventListeners& listeners = event_listener_map_[event_name]; | |
652 for (unsigned int i = 0; i < listeners.size(); ++i) { | |
653 if (listeners[i] == function) | |
654 return false; | |
655 } | |
656 v8::Persistent<v8::Function> persistent_function = | |
657 v8::Persistent<v8::Function>::New(function); | |
658 listeners.push_back(persistent_function); | |
659 return true; | |
660 } | |
661 | |
662 bool BrowserPlugin::RemoveEventListener(const std::string& event_name, | |
663 v8::Local<v8::Function> function) { | |
664 if (!HasListeners(event_name)) | |
665 return false; | |
666 | |
667 EventListeners& listeners = event_listener_map_[event_name]; | |
668 EventListeners::iterator it = listeners.begin(); | |
669 for (; it != listeners.end(); ++it) { | |
670 if (*it == function) { | |
671 it->Dispose(); | |
672 listeners.erase(it); | |
673 return true; | |
674 } | |
675 } | |
676 return false; | |
677 } | |
678 | |
679 WebKit::WebPluginContainer* BrowserPlugin::container() const { | 539 WebKit::WebPluginContainer* BrowserPlugin::container() const { |
680 return container_; | 540 return container_; |
681 } | 541 } |
682 | 542 |
683 bool BrowserPlugin::initialize(WebPluginContainer* container) { | 543 bool BrowserPlugin::initialize(WebPluginContainer* container) { |
684 container_ = container; | 544 container_ = container; |
685 return true; | 545 return true; |
686 } | 546 } |
687 | 547 |
688 void BrowserPlugin::destroy() { | 548 void BrowserPlugin::destroy() { |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
954 void* notify_data) { | 814 void* notify_data) { |
955 } | 815 } |
956 | 816 |
957 void BrowserPlugin::didFailLoadingFrameRequest( | 817 void BrowserPlugin::didFailLoadingFrameRequest( |
958 const WebKit::WebURL& url, | 818 const WebKit::WebURL& url, |
959 void* notify_data, | 819 void* notify_data, |
960 const WebKit::WebURLError& error) { | 820 const WebKit::WebURLError& error) { |
961 } | 821 } |
962 | 822 |
963 } // namespace content | 823 } // namespace content |
OLD | NEW |