Chromium Code Reviews| 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" |
| 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
| 24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" | 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" |
| 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
| 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" | 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" |
| 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginParams.h" | 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginParams.h" |
| 29 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h" | 30 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h" |
| 31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.h" | |
| 30 #include "webkit/plugins/sad_plugin.h" | 32 #include "webkit/plugins/sad_plugin.h" |
| 31 | 33 |
| 32 using WebKit::WebCanvas; | 34 using WebKit::WebCanvas; |
| 33 using WebKit::WebPlugin; | 35 using WebKit::WebPlugin; |
| 34 using WebKit::WebPluginContainer; | 36 using WebKit::WebPluginContainer; |
| 35 using WebKit::WebPluginParams; | 37 using WebKit::WebPluginParams; |
| 36 using WebKit::WebPoint; | 38 using WebKit::WebPoint; |
| 37 using WebKit::WebString; | 39 using WebKit::WebString; |
| 38 using WebKit::WebRect; | 40 using WebKit::WebRect; |
| 39 using WebKit::WebURL; | 41 using WebKit::WebURL; |
| 40 using WebKit::WebVector; | 42 using WebKit::WebVector; |
| 41 | 43 |
| 42 namespace content { | 44 namespace content { |
| 43 | 45 |
| 44 namespace { | 46 namespace { |
| 45 const char kExitEventName[] = "exit"; | 47 const char kExitEventName[] = "exit"; |
| 46 const char kIsTopLevel[] = "isTopLevel"; | 48 const char kIsTopLevel[] = "isTopLevel"; |
| 47 const char kLoadAbortEventName[] = "loadabort"; | 49 const char kLoadAbortEventName[] = "loadabort"; |
| 48 const char kLoadCommitEventName[] = "loadcommit"; | 50 const char kLoadCommitEventName[] = "loadcommit"; |
| 49 const char kLoadRedirectEventName[] = "loadredirect"; | 51 const char kLoadRedirectEventName[] = "loadredirect"; |
| 50 const char kLoadStartEventName[] = "loadstart"; | 52 const char kLoadStartEventName[] = "loadstart"; |
| 51 const char kLoadStopEventName[] = "loadstop"; | 53 const char kLoadStopEventName[] = "loadstop"; |
| 52 const char kNewURL[] = "newUrl"; | 54 const char kNewURL[] = "newUrl"; |
| 53 const char kOldURL[] = "oldUrl"; | 55 const char kOldURL[] = "oldUrl"; |
| 54 const char kPartitionAttribute[] = "partition"; | 56 const char kPartitionAttribute[] = "partition"; |
| 55 const char kPersistPrefix[] = "persist:"; | 57 const char kPersistPrefix[] = "persist:"; |
| 56 const char kProcessId[] = "processId"; | 58 const char kProcessId[] = "processId"; |
| 57 const char kSrcAttribute[] = "src"; | 59 const char kSrcAttribute[] = "src"; |
| 58 const char kType[] = "type"; | 60 const char kReason[] = "reason"; |
| 59 const char kURL[] = "url"; | 61 const char kURL[] = "url"; |
| 60 | 62 |
| 61 static std::string TerminationStatusToString(base::TerminationStatus status) { | 63 static std::string TerminationStatusToString(base::TerminationStatus status) { |
| 62 switch (status) { | 64 switch (status) { |
| 63 case base::TERMINATION_STATUS_NORMAL_TERMINATION: | 65 case base::TERMINATION_STATUS_NORMAL_TERMINATION: |
| 64 return "normal"; | 66 return "normal"; |
| 65 case base::TERMINATION_STATUS_ABNORMAL_TERMINATION: | 67 case base::TERMINATION_STATUS_ABNORMAL_TERMINATION: |
| 66 return "abnormal"; | 68 return "abnormal"; |
| 67 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED: | 69 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED: |
| 68 return "killed"; | 70 return "killed"; |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 98 process_id_(-1), | 100 process_id_(-1), |
| 99 persist_storage_(false), | 101 persist_storage_(false), |
| 100 content_window_routing_id_(MSG_ROUTING_NONE), | 102 content_window_routing_id_(MSG_ROUTING_NONE), |
| 101 focused_(false), | 103 focused_(false), |
| 102 visible_(true), | 104 visible_(true), |
| 103 current_nav_entry_index_(0), | 105 current_nav_entry_index_(0), |
| 104 nav_entry_count_(0) { | 106 nav_entry_count_(0) { |
| 105 BrowserPluginManager::Get()->AddBrowserPlugin(instance_id, this); | 107 BrowserPluginManager::Get()->AddBrowserPlugin(instance_id, this); |
| 106 bindings_.reset(new BrowserPluginBindings(this)); | 108 bindings_.reset(new BrowserPluginBindings(this)); |
| 107 | 109 |
| 108 InitializeEvents(); | |
| 109 | |
| 110 ParseAttributes(params); | 110 ParseAttributes(params); |
| 111 } | 111 } |
| 112 | 112 |
| 113 BrowserPlugin::~BrowserPlugin() { | 113 BrowserPlugin::~BrowserPlugin() { |
| 114 if (damage_buffer_) | 114 if (damage_buffer_) |
| 115 FreeDamageBuffer(); | 115 FreeDamageBuffer(); |
| 116 RemoveEventListeners(); | |
| 117 BrowserPluginManager::Get()->RemoveBrowserPlugin(instance_id_); | 116 BrowserPluginManager::Get()->RemoveBrowserPlugin(instance_id_); |
| 118 BrowserPluginManager::Get()->Send( | 117 BrowserPluginManager::Get()->Send( |
| 119 new BrowserPluginHostMsg_PluginDestroyed( | 118 new BrowserPluginHostMsg_PluginDestroyed( |
| 120 render_view_routing_id_, | 119 render_view_routing_id_, |
| 121 instance_id_)); | 120 instance_id_)); |
| 122 } | 121 } |
| 123 | 122 |
| 124 void BrowserPlugin::Cleanup() { | 123 void BrowserPlugin::Cleanup() { |
| 125 if (damage_buffer_) | 124 if (damage_buffer_) |
| 126 FreeDamageBuffer(); | 125 FreeDamageBuffer(); |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 306 // true, which prevents changing the 'partition' attribute. | 305 // true, which prevents changing the 'partition' attribute. |
| 307 SetSrcAttribute(src); | 306 SetSrcAttribute(src); |
| 308 } | 307 } |
| 309 | 308 |
| 310 float BrowserPlugin::GetDeviceScaleFactor() const { | 309 float BrowserPlugin::GetDeviceScaleFactor() const { |
| 311 if (!render_view_) | 310 if (!render_view_) |
| 312 return 1.0f; | 311 return 1.0f; |
| 313 return render_view_->GetWebView()->deviceScaleFactor(); | 312 return render_view_->GetWebView()->deviceScaleFactor(); |
| 314 } | 313 } |
| 315 | 314 |
| 316 void BrowserPlugin::InitializeEvents() { | 315 void BrowserPlugin::TriggerEvent(const std::string& event_name, |
| 317 event_listener_map_[kExitEventName] = EventListeners(); | 316 std::map<std::string, base::Value*>* props) { |
| 318 event_listener_map_[kLoadAbortEventName] = EventListeners(); | 317 WebKit::WebElement plugin = container()->element(); |
| 319 event_listener_map_[kLoadCommitEventName] = EventListeners(); | 318 v8::HandleScope handle_scope; |
| 320 event_listener_map_[kLoadRedirectEventName] = EventListeners(); | 319 v8::Local<v8::Context> context = |
| 321 event_listener_map_[kLoadStartEventName] = EventListeners(); | 320 plugin.document().frame()->mainWorldScriptContext(); |
|
abarth-chromium
2012/11/05 19:07:15
Why is the main world the correct world?
sadrul
2012/11/06 03:23:34
The current code uses the main-world context, so I
| |
| 322 event_listener_map_[kLoadStopEventName] = EventListeners(); | 321 v8::Context::Scope context_scope(context); |
| 323 } | 322 std::string script = base::StringPrintf("new CustomEvent('%s', {" |
| 323 " 'bubbles': false, " | |
| 324 " 'cancelable': false" | |
| 325 "});", event_name.c_str()); | |
|
abarth-chromium
2012/11/05 19:07:15
Where does event_name come from? Could this lead
sadrul
2012/11/06 03:23:34
I have changed this code to use WebDOMCustomEvent
| |
| 326 v8::Local<v8::Value> value = v8::Local<v8::Value>::New( | |
| 327 plugin.document().frame()->executeScriptAndReturnValue( | |
| 328 WebKit::WebScriptSource(WebKit::WebString::fromUTF8(script.c_str())))); | |
| 329 v8::Local<v8::Object> event = value->ToObject(); | |
|
abarth-chromium
2012/11/05 19:07:15
Why not use the WebKit API to create a CustomEvent
sadrul
2012/11/06 03:23:34
Done: https://bugs.webkit.org/show_bug.cgi?id=1012
| |
| 324 | 330 |
| 325 void BrowserPlugin::RemoveEventListeners() { | 331 if (props) { |
| 326 EventListenerMap::iterator event_listener_map_iter = | 332 V8ValueConverterImpl converter; |
| 327 event_listener_map_.begin(); | 333 for (std::map<std::string, base::Value*>::iterator iter = props->begin(), |
| 328 for (; event_listener_map_iter != event_listener_map_.end(); | 334 end = props->end(); iter != end; ++iter) { |
| 329 ++event_listener_map_iter) { | 335 event->Set(v8::String::New(iter->first.data(), iter->first.size()), |
| 330 EventListeners& listeners = | 336 converter.ToV8Value(iter->second, context), |
| 331 event_listener_map_[event_listener_map_iter->first]; | 337 v8::ReadOnly); |
|
abarth-chromium
2012/11/05 19:07:15
This operation can trigger JavaScript setters, whi
| |
| 332 EventListeners::iterator it = listeners.begin(); | |
| 333 for (; it != listeners.end(); ++it) { | |
| 334 it->Dispose(); | |
| 335 } | 338 } |
| 336 } | 339 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 } | 340 } |
| 363 | 341 |
| 364 (*event)->Set(v8::String::New("name"), | 342 NPVariant npevent, npresult; |
| 365 v8::String::New(event_name.c_str(), event_name.size()), | 343 WebKit::WebBindings::toNPVariant(event, NULL, &npevent); |
| 366 v8::ReadOnly); | 344 |
| 367 v8::Local<v8::Value> argv[] = { *event }; | 345 NPIdentifier method = |
| 368 for (EventListenersLocal::const_iterator it = listeners_local.begin(); | 346 WebKit::WebBindings::getStringIdentifier("dispatchEvent"); |
| 369 it != listeners_local.end(); | 347 WebKit::WebBindings::invoke(NULL, container()->scriptableObjectForElement(), |
| 370 ++it) { | 348 method, &npevent, 1, &npresult); |
| 371 WebKit::WebFrame* frame = plugin.document().frame(); | 349 |
| 372 if (!frame) | 350 WebKit::WebBindings::releaseVariantValue(&npevent); |
| 373 break; | 351 WebKit::WebBindings::releaseVariantValue(&npresult); |
| 374 frame->callFunctionEvenIfScriptDisabled(*it, v8::Object::New(), 1, argv); | |
| 375 } | |
| 376 } | 352 } |
| 377 | 353 |
| 378 void BrowserPlugin::Back() { | 354 void BrowserPlugin::Back() { |
| 379 if (!navigate_src_sent_) | 355 if (!navigate_src_sent_) |
| 380 return; | 356 return; |
| 381 BrowserPluginManager::Get()->Send( | 357 BrowserPluginManager::Get()->Send( |
| 382 new BrowserPluginHostMsg_Go(render_view_routing_id_, | 358 new BrowserPluginHostMsg_Go(render_view_routing_id_, |
| 383 instance_id_, -1)); | 359 instance_id_, -1)); |
| 384 } | 360 } |
| 385 | 361 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 468 BrowserPluginManager::Get()->Send(new BrowserPluginHostMsg_UpdateRect_ACK( | 444 BrowserPluginManager::Get()->Send(new BrowserPluginHostMsg_UpdateRect_ACK( |
| 469 render_view_routing_id_, | 445 render_view_routing_id_, |
| 470 instance_id_, | 446 instance_id_, |
| 471 message_id, | 447 message_id, |
| 472 gfx::Size())); | 448 gfx::Size())); |
| 473 } | 449 } |
| 474 | 450 |
| 475 void BrowserPlugin::GuestGone(int process_id, base::TerminationStatus status) { | 451 void BrowserPlugin::GuestGone(int process_id, base::TerminationStatus status) { |
| 476 // We fire the event listeners before painting the sad graphic to give the | 452 // 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. | 453 // developer an opportunity to display an alternative overlay image on crash. |
| 478 if (HasListeners(kExitEventName)) { | 454 std::string termination_status = TerminationStatusToString(status); |
| 479 WebKit::WebElement plugin = container()->element(); | 455 std::map<std::string, base::Value*> props; |
| 480 v8::HandleScope handle_scope; | 456 props[kProcessId] = base::Value::CreateIntegerValue(process_id); |
| 481 v8::Context::Scope context_scope( | 457 props[kReason] = base::Value::CreateStringValue(termination_status); |
| 482 plugin.document().frame()->mainWorldScriptContext()); | |
| 483 | 458 |
| 484 // Construct the exit event object. | 459 // Event listeners may remove the BrowserPlugin from the document. If that |
| 485 v8::Local<v8::Object> event = v8::Object::New(); | 460 // happens, the BrowserPlugin will be scheduled for later deletion (see |
| 486 event->Set(v8::String::New(kProcessId, sizeof(kProcessId) - 1), | 461 // BrowserPlugin::destroy()). That will clear the container_ reference, |
| 487 v8::Integer::New(process_id), | 462 // but leave other member variables valid below. |
| 488 v8::ReadOnly); | 463 TriggerEvent(kExitEventName, &props); |
|
abarth-chromium
2012/11/05 19:07:15
It looks like you're using constants. Can we pass
| |
| 489 std::string termination_status = TerminationStatusToString(status); | 464 |
| 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; | 465 guest_crashed_ = true; |
| 501 // We won't paint the contents of the current backing store again so we might | 466 // We won't paint the contents of the current backing store again so we might |
| 502 // as well toss it out and save memory. | 467 // as well toss it out and save memory. |
| 503 backing_store_.reset(); | 468 backing_store_.reset(); |
| 504 // If the BrowserPlugin is scheduled to be deleted, then container_ will be | 469 // If the BrowserPlugin is scheduled to be deleted, then container_ will be |
| 505 // NULL so we shouldn't attempt to access it. | 470 // NULL so we shouldn't attempt to access it. |
| 506 if (container_) | 471 if (container_) |
| 507 container_->invalidate(); | 472 container_->invalidate(); |
| 508 } | 473 } |
| 509 | 474 |
| 510 void BrowserPlugin::LoadStart(const GURL& url, bool is_top_level) { | 475 void BrowserPlugin::LoadStart(const GURL& url, bool is_top_level) { |
| 511 if (!HasListeners(kLoadStartEventName)) | 476 std::map<std::string, base::Value*> props; |
| 512 return; | 477 props[kURL] = base::Value::CreateStringValue(url.spec()); |
| 478 props[kIsTopLevel] = base::Value::CreateBooleanValue(is_top_level); | |
| 513 | 479 |
| 514 WebKit::WebElement plugin = container()->element(); | 480 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 } | 481 } |
| 529 | 482 |
| 530 void BrowserPlugin::LoadCommit( | 483 void BrowserPlugin::LoadCommit( |
| 531 const BrowserPluginMsg_LoadCommit_Params& params) { | 484 const BrowserPluginMsg_LoadCommit_Params& params) { |
| 532 // If the guest has just committed a new navigation then it is no longer | 485 // If the guest has just committed a new navigation then it is no longer |
| 533 // crashed. | 486 // crashed. |
| 534 guest_crashed_ = false; | 487 guest_crashed_ = false; |
| 535 src_ = params.url.spec(); | 488 src_ = params.url.spec(); |
| 536 process_id_ = params.process_id; | 489 process_id_ = params.process_id; |
| 537 current_nav_entry_index_ = params.current_entry_index; | 490 current_nav_entry_index_ = params.current_entry_index; |
| 538 nav_entry_count_ = params.entry_count; | 491 nav_entry_count_ = params.entry_count; |
| 539 | 492 |
| 540 if (!HasListeners(kLoadCommitEventName)) | 493 std::map<std::string, base::Value*> props; |
| 541 return; | 494 props[kURL] = base::Value::CreateStringValue(src_); |
| 542 | 495 props[kIsTopLevel] = base::Value::CreateBooleanValue(params.is_top_level); |
| 543 WebKit::WebElement plugin = container()->element(); | 496 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 } | 497 } |
| 559 | 498 |
| 560 void BrowserPlugin::LoadStop() { | 499 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. | 500 // Construct the loadStop event object. |
| 570 v8::Local<v8::Object> event = v8::Object::New(); | 501 TriggerEvent(kLoadStopEventName, NULL); |
| 571 TriggerEvent(kLoadStopEventName, &event); | |
| 572 } | 502 } |
| 573 | 503 |
| 574 void BrowserPlugin::LoadAbort(const GURL& url, | 504 void BrowserPlugin::LoadAbort(const GURL& url, |
| 575 bool is_top_level, | 505 bool is_top_level, |
| 576 const std::string& type) { | 506 const std::string& type) { |
| 577 if (!HasListeners(kLoadAbortEventName)) | 507 std::map<std::string, base::Value*> props; |
| 578 return; | 508 props[kURL] = base::Value::CreateStringValue(url.spec()); |
| 579 | 509 props[kIsTopLevel] = base::Value::CreateBooleanValue(is_top_level); |
| 580 WebKit::WebElement plugin = container()->element(); | 510 props[kReason] = base::Value::CreateStringValue(type); |
| 581 v8::HandleScope handle_scope; | 511 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 } | 512 } |
| 599 | 513 |
| 600 void BrowserPlugin::LoadRedirect(const GURL& old_url, | 514 void BrowserPlugin::LoadRedirect(const GURL& old_url, |
| 601 const GURL& new_url, | 515 const GURL& new_url, |
| 602 bool is_top_level) { | 516 bool is_top_level) { |
| 603 if (!HasListeners(kLoadRedirectEventName)) | 517 std::map<std::string, base::Value*> props; |
| 604 return; | 518 props[kOldURL] = base::Value::CreateStringValue(old_url.spec()); |
| 605 | 519 props[kNewURL] = base::Value::CreateStringValue(new_url.spec()); |
| 606 WebKit::WebElement plugin = container()->element(); | 520 props[kIsTopLevel] = base::Value::CreateBooleanValue(is_top_level); |
| 607 v8::HandleScope handle_scope; | 521 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 } | 522 } |
| 625 | 523 |
| 626 void BrowserPlugin::AdvanceFocus(bool reverse) { | 524 void BrowserPlugin::AdvanceFocus(bool reverse) { |
| 627 // We do not have a RenderView when we are testing. | 525 // We do not have a RenderView when we are testing. |
| 628 if (render_view_) | 526 if (render_view_) |
| 629 render_view_->GetWebView()->advanceFocus(reverse); | 527 render_view_->GetWebView()->advanceFocus(reverse); |
| 630 } | 528 } |
| 631 | 529 |
| 632 void BrowserPlugin::GuestContentWindowReady(int content_window_routing_id) { | 530 void BrowserPlugin::GuestContentWindowReady(int content_window_routing_id) { |
| 633 DCHECK(content_window_routing_id != MSG_ROUTING_NONE); | 531 DCHECK(content_window_routing_id != MSG_ROUTING_NONE); |
| 634 content_window_routing_id_ = content_window_routing_id; | 532 content_window_routing_id_ = content_window_routing_id; |
| 635 } | 533 } |
| 636 | 534 |
| 637 void BrowserPlugin::SetAcceptTouchEvents(bool accept) { | 535 void BrowserPlugin::SetAcceptTouchEvents(bool accept) { |
| 638 if (container()) | 536 if (container()) |
| 639 container()->setIsAcceptingTouchEvents(accept); | 537 container()->setIsAcceptingTouchEvents(accept); |
| 640 } | 538 } |
| 641 | 539 |
| 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 { | 540 WebKit::WebPluginContainer* BrowserPlugin::container() const { |
| 680 return container_; | 541 return container_; |
| 681 } | 542 } |
| 682 | 543 |
| 683 bool BrowserPlugin::initialize(WebPluginContainer* container) { | 544 bool BrowserPlugin::initialize(WebPluginContainer* container) { |
| 684 container_ = container; | 545 container_ = container; |
| 685 return true; | 546 return true; |
| 686 } | 547 } |
| 687 | 548 |
| 688 void BrowserPlugin::destroy() { | 549 void BrowserPlugin::destroy() { |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 954 void* notify_data) { | 815 void* notify_data) { |
| 955 } | 816 } |
| 956 | 817 |
| 957 void BrowserPlugin::didFailLoadingFrameRequest( | 818 void BrowserPlugin::didFailLoadingFrameRequest( |
| 958 const WebKit::WebURL& url, | 819 const WebKit::WebURL& url, |
| 959 void* notify_data, | 820 void* notify_data, |
| 960 const WebKit::WebURLError& error) { | 821 const WebKit::WebURLError& error) { |
| 961 } | 822 } |
| 962 | 823 |
| 963 } // namespace content | 824 } // namespace content |
| OLD | NEW |