Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(150)

Side by Side Diff: content/renderer/browser_plugin/browser_plugin.cc

Issue 11368071: browser-plugin: Remove event handling code, and use CustomEvents in webkit instead. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: tot-merge Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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)
10 #include "base/sys_info.h"
11 #endif
12 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
13 #include "content/common/browser_plugin_messages.h" 10 #include "content/common/browser_plugin_messages.h"
14 #include "content/common/view_messages.h" 11 #include "content/common/view_messages.h"
15 #include "content/public/common/content_client.h" 12 #include "content/public/common/content_client.h"
16 #include "content/public/renderer/content_renderer_client.h" 13 #include "content/public/renderer/content_renderer_client.h"
17 #include "content/renderer/browser_plugin/browser_plugin_bindings.h" 14 #include "content/renderer/browser_plugin/browser_plugin_bindings.h"
18 #include "content/renderer/browser_plugin/browser_plugin_manager.h" 15 #include "content/renderer/browser_plugin/browser_plugin_manager.h"
19 #include "content/renderer/render_process_impl.h" 16 #include "content/renderer/render_process_impl.h"
20 #include "content/renderer/render_thread_impl.h" 17 #include "content/renderer/render_thread_impl.h"
18 #include "content/renderer/v8_value_converter_impl.h"
21 #include "skia/ext/platform_canvas.h" 19 #include "skia/ext/platform_canvas.h"
22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h"
21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDOMCustomEvent.h"
23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" 22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h"
28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginParams.h" 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginParams.h"
29 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h" 28 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h"
29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.h"
30 #include "webkit/plugins/sad_plugin.h" 30 #include "webkit/plugins/sad_plugin.h"
31 31
32 #if defined (OS_WIN)
33 #include "base/sys_info.h"
34 #endif
35
32 using WebKit::WebCanvas; 36 using WebKit::WebCanvas;
33 using WebKit::WebPlugin; 37 using WebKit::WebPlugin;
34 using WebKit::WebPluginContainer; 38 using WebKit::WebPluginContainer;
35 using WebKit::WebPluginParams; 39 using WebKit::WebPluginParams;
36 using WebKit::WebPoint; 40 using WebKit::WebPoint;
37 using WebKit::WebString; 41 using WebKit::WebString;
38 using WebKit::WebRect; 42 using WebKit::WebRect;
39 using WebKit::WebURL; 43 using WebKit::WebURL;
40 using WebKit::WebVector; 44 using WebKit::WebVector;
41 45
42 namespace content { 46 namespace content {
43 47
44 namespace { 48 namespace {
45 const char kExitEventName[] = "exit"; 49 const char kExitEventName[] = "exit";
46 const char kIsTopLevel[] = "isTopLevel"; 50 const char kIsTopLevel[] = "isTopLevel";
47 const char kLoadAbortEventName[] = "loadabort"; 51 const char kLoadAbortEventName[] = "loadabort";
48 const char kLoadCommitEventName[] = "loadcommit"; 52 const char kLoadCommitEventName[] = "loadcommit";
49 const char kLoadRedirectEventName[] = "loadredirect"; 53 const char kLoadRedirectEventName[] = "loadredirect";
50 const char kLoadStartEventName[] = "loadstart"; 54 const char kLoadStartEventName[] = "loadstart";
51 const char kLoadStopEventName[] = "loadstop"; 55 const char kLoadStopEventName[] = "loadstop";
52 const char kNewURL[] = "newUrl"; 56 const char kNewURL[] = "newUrl";
53 const char kOldURL[] = "oldUrl"; 57 const char kOldURL[] = "oldUrl";
54 const char kPartitionAttribute[] = "partition"; 58 const char kPartitionAttribute[] = "partition";
55 const char kPersistPrefix[] = "persist:"; 59 const char kPersistPrefix[] = "persist:";
56 const char kProcessId[] = "processId"; 60 const char kProcessId[] = "processId";
57 const char kSrcAttribute[] = "src"; 61 const char kSrcAttribute[] = "src";
58 const char kType[] = "type"; 62 const char kReason[] = "reason";
59 const char kURL[] = "url"; 63 const char kURL[] = "url";
60 64
61 static std::string TerminationStatusToString(base::TerminationStatus status) { 65 static std::string TerminationStatusToString(base::TerminationStatus status) {
62 switch (status) { 66 switch (status) {
63 case base::TERMINATION_STATUS_NORMAL_TERMINATION: 67 case base::TERMINATION_STATUS_NORMAL_TERMINATION:
64 return "normal"; 68 return "normal";
65 case base::TERMINATION_STATUS_ABNORMAL_TERMINATION: 69 case base::TERMINATION_STATUS_ABNORMAL_TERMINATION:
66 return "abnormal"; 70 return "abnormal";
67 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED: 71 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED:
68 return "killed"; 72 return "killed";
(...skipping 30 matching lines...) Expand all
99 persist_storage_(false), 103 persist_storage_(false),
100 content_window_routing_id_(MSG_ROUTING_NONE), 104 content_window_routing_id_(MSG_ROUTING_NONE),
101 plugin_focused_(false), 105 plugin_focused_(false),
102 embedder_focused_(false), 106 embedder_focused_(false),
103 visible_(true), 107 visible_(true),
104 current_nav_entry_index_(0), 108 current_nav_entry_index_(0),
105 nav_entry_count_(0) { 109 nav_entry_count_(0) {
106 BrowserPluginManager::Get()->AddBrowserPlugin(instance_id, this); 110 BrowserPluginManager::Get()->AddBrowserPlugin(instance_id, this);
107 bindings_.reset(new BrowserPluginBindings(this)); 111 bindings_.reset(new BrowserPluginBindings(this));
108 112
109 InitializeEvents();
110
111 ParseAttributes(params); 113 ParseAttributes(params);
112 } 114 }
113 115
114 BrowserPlugin::~BrowserPlugin() { 116 BrowserPlugin::~BrowserPlugin() {
115 if (damage_buffer_) 117 if (damage_buffer_)
116 FreeDamageBuffer(); 118 FreeDamageBuffer();
117 RemoveEventListeners();
118 BrowserPluginManager::Get()->RemoveBrowserPlugin(instance_id_); 119 BrowserPluginManager::Get()->RemoveBrowserPlugin(instance_id_);
119 BrowserPluginManager::Get()->Send( 120 BrowserPluginManager::Get()->Send(
120 new BrowserPluginHostMsg_PluginDestroyed( 121 new BrowserPluginHostMsg_PluginDestroyed(
121 render_view_routing_id_, 122 render_view_routing_id_,
122 instance_id_)); 123 instance_id_));
123 } 124 }
124 125
125 void BrowserPlugin::Cleanup() { 126 void BrowserPlugin::Cleanup() {
126 if (damage_buffer_) 127 if (damage_buffer_)
127 FreeDamageBuffer(); 128 FreeDamageBuffer();
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 // true, which prevents changing the 'partition' attribute. 308 // true, which prevents changing the 'partition' attribute.
308 SetSrcAttribute(src); 309 SetSrcAttribute(src);
309 } 310 }
310 311
311 float BrowserPlugin::GetDeviceScaleFactor() const { 312 float BrowserPlugin::GetDeviceScaleFactor() const {
312 if (!render_view_) 313 if (!render_view_)
313 return 1.0f; 314 return 1.0f;
314 return render_view_->GetWebView()->deviceScaleFactor(); 315 return render_view_->GetWebView()->deviceScaleFactor();
315 } 316 }
316 317
317 void BrowserPlugin::InitializeEvents() { 318 void BrowserPlugin::TriggerEvent(const std::string& event_name,
318 event_listener_map_[kExitEventName] = EventListeners(); 319 std::map<std::string, base::Value*>* props) {
319 event_listener_map_[kLoadAbortEventName] = EventListeners(); 320 if (!container())
320 event_listener_map_[kLoadCommitEventName] = EventListeners(); 321 return;
321 event_listener_map_[kLoadRedirectEventName] = EventListeners(); 322 WebKit::WebFrame* frame = container()->element().document().frame();
322 event_listener_map_[kLoadStartEventName] = EventListeners(); 323 v8::HandleScope handle_scope;
323 event_listener_map_[kLoadStopEventName] = EventListeners(); 324 v8::Local<v8::Context> context = frame->mainWorldScriptContext();
324 } 325 v8::Context::Scope context_scope(context);
326 v8::Local<v8::Object> detail = v8::Object::New();
325 327
326 void BrowserPlugin::RemoveEventListeners() { 328 if (props) {
327 EventListenerMap::iterator event_listener_map_iter = 329 V8ValueConverterImpl converter;
328 event_listener_map_.begin(); 330 for (std::map<std::string, base::Value*>::iterator iter = props->begin(),
329 for (; event_listener_map_iter != event_listener_map_.end(); 331 end = props->end(); iter != end; ++iter) {
330 ++event_listener_map_iter) { 332 detail->Set(v8::String::New(iter->first.data(), iter->first.size()),
abarth-chromium 2012/11/09 19:44:34 This line of code can execute arbitrary JavaScript
Fady Samuel 2012/11/09 19:49:11 We have a test for deleting BrowserPlugins inside
331 EventListeners& listeners = 333 converter.ToV8Value(iter->second, context),
332 event_listener_map_[event_listener_map_iter->first]; 334 v8::ReadOnly);
333 EventListeners::iterator it = listeners.begin();
334 for (; it != listeners.end(); ++it) {
335 it->Dispose();
336 } 335 }
337 } 336 STLDeleteValues(props);
338 event_listener_map_.clear();
339 }
340
341 bool BrowserPlugin::IsValidEvent(const std::string& event_name) {
342 return event_listener_map_.find(event_name) != event_listener_map_.end();
343 }
344
345 void BrowserPlugin::TriggerEvent(const std::string& event_name,
346 v8::Local<v8::Object>* event) {
347 WebKit::WebElement plugin = container()->element();
348
349 const EventListeners& listeners = event_listener_map_[event_name.c_str()];
350 // A v8::Local copy of the listeners is created from the v8::Persistent
351 // listeners before firing them. This is to ensure that if one of these
352 // listeners mutate the list of listeners (by calling
353 // addEventListener/removeEventListener), this local copy is not affected.
354 // This means if you mutate the list of listeners for an event X while event X
355 // is firing, the mutation is deferred until all current listeners for X have
356 // fired.
357 EventListenersLocal listeners_local;
358 listeners_local.reserve(listeners.size());
359 for (EventListeners::const_iterator it = listeners.begin();
360 it != listeners.end();
361 ++it) {
362 listeners_local.push_back(v8::Local<v8::Function>::New(*it));
363 } 337 }
364 338
365 (*event)->Set(v8::String::New("name"), 339 WebKit::WebDOMEvent dom_event = frame->document().createEvent("CustomEvent");
abarth-chromium 2012/11/09 19:52:13 Certainly |frame| can be destroyed, which means we
sadrul 2012/11/09 21:14:15 I have added a NULL check for container() and fram
366 v8::String::New(event_name.c_str(), event_name.size()), 340 WebKit::WebDOMCustomEvent event = dom_event.to<WebKit::WebDOMCustomEvent>();
367 v8::ReadOnly); 341 std::string obfuscated_name = base::StringPrintf("-internal-%s",
368 v8::Local<v8::Value> argv[] = { *event }; 342 event_name.c_str());
369 for (EventListenersLocal::const_iterator it = listeners_local.begin(); 343 event.initCustomEvent(
370 it != listeners_local.end(); 344 WebKit::WebString::fromUTF8(obfuscated_name.c_str()),
371 ++it) { 345 false, false,
372 WebKit::WebFrame* frame = plugin.document().frame(); 346 WebKit::WebSerializedScriptValue::serialize(detail));
373 if (!frame) 347 container()->element().dispatchEvent(event);
374 break;
375 frame->callFunctionEvenIfScriptDisabled(*it, v8::Object::New(), 1, argv);
376 }
377 } 348 }
378 349
379 void BrowserPlugin::Back() { 350 void BrowserPlugin::Back() {
380 if (!navigate_src_sent_) 351 if (!navigate_src_sent_)
381 return; 352 return;
382 BrowserPluginManager::Get()->Send( 353 BrowserPluginManager::Get()->Send(
383 new BrowserPluginHostMsg_Go(render_view_routing_id_, 354 new BrowserPluginHostMsg_Go(render_view_routing_id_,
384 instance_id_, -1)); 355 instance_id_, -1));
385 } 356 }
386 357
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 BrowserPluginManager::Get()->Send(new BrowserPluginHostMsg_UpdateRect_ACK( 440 BrowserPluginManager::Get()->Send(new BrowserPluginHostMsg_UpdateRect_ACK(
470 render_view_routing_id_, 441 render_view_routing_id_,
471 instance_id_, 442 instance_id_,
472 message_id, 443 message_id,
473 gfx::Size())); 444 gfx::Size()));
474 } 445 }
475 446
476 void BrowserPlugin::GuestGone(int process_id, base::TerminationStatus status) { 447 void BrowserPlugin::GuestGone(int process_id, base::TerminationStatus status) {
477 // We fire the event listeners before painting the sad graphic to give the 448 // We fire the event listeners before painting the sad graphic to give the
478 // developer an opportunity to display an alternative overlay image on crash. 449 // developer an opportunity to display an alternative overlay image on crash.
479 if (HasListeners(kExitEventName)) { 450 std::string termination_status = TerminationStatusToString(status);
480 WebKit::WebElement plugin = container()->element(); 451 std::map<std::string, base::Value*> props;
481 v8::HandleScope handle_scope; 452 props[kProcessId] = base::Value::CreateIntegerValue(process_id);
482 v8::Context::Scope context_scope( 453 props[kReason] = base::Value::CreateStringValue(termination_status);
483 plugin.document().frame()->mainWorldScriptContext());
484 454
485 // Construct the exit event object. 455 // Event listeners may remove the BrowserPlugin from the document. If that
486 v8::Local<v8::Object> event = v8::Object::New(); 456 // happens, the BrowserPlugin will be scheduled for later deletion (see
487 event->Set(v8::String::New(kProcessId, sizeof(kProcessId) - 1), 457 // BrowserPlugin::destroy()). That will clear the container_ reference,
488 v8::Integer::New(process_id), 458 // but leave other member variables valid below.
489 v8::ReadOnly); 459 TriggerEvent(kExitEventName, &props);
490 std::string termination_status = TerminationStatusToString(status); 460
491 event->Set(v8::String::New(kType, sizeof(kType) - 1),
492 v8::String::New(termination_status.data(),
493 termination_status.size()),
494 v8::ReadOnly);
495 // Event listeners may remove the BrowserPlugin from the document. If that
496 // happens, the BrowserPlugin will be scheduled for later deletion (see
497 // BrowserPlugin::destroy()). That will clear the container_ reference,
498 // but leave other member variables valid below.
499 TriggerEvent(kExitEventName, &event);
500 }
501 guest_crashed_ = true; 461 guest_crashed_ = true;
502 // We won't paint the contents of the current backing store again so we might 462 // We won't paint the contents of the current backing store again so we might
503 // as well toss it out and save memory. 463 // as well toss it out and save memory.
504 backing_store_.reset(); 464 backing_store_.reset();
505 // If the BrowserPlugin is scheduled to be deleted, then container_ will be 465 // If the BrowserPlugin is scheduled to be deleted, then container_ will be
506 // NULL so we shouldn't attempt to access it. 466 // NULL so we shouldn't attempt to access it.
507 if (container_) 467 if (container_)
508 container_->invalidate(); 468 container_->invalidate();
509 } 469 }
510 470
511 void BrowserPlugin::LoadStart(const GURL& url, bool is_top_level) { 471 void BrowserPlugin::LoadStart(const GURL& url, bool is_top_level) {
512 if (!HasListeners(kLoadStartEventName)) 472 std::map<std::string, base::Value*> props;
513 return; 473 props[kURL] = base::Value::CreateStringValue(url.spec());
474 props[kIsTopLevel] = base::Value::CreateBooleanValue(is_top_level);
514 475
515 WebKit::WebElement plugin = container()->element(); 476 TriggerEvent(kLoadStartEventName, &props);
516 v8::HandleScope handle_scope;
517 v8::Context::Scope context_scope(
518 plugin.document().frame()->mainWorldScriptContext());
519
520 // Construct the loadStart event object.
521 v8::Local<v8::Object> event = v8::Object::New();
522 event->Set(v8::String::New(kURL, sizeof(kURL) - 1),
523 v8::String::New(url.spec().data(), url.spec().size()),
524 v8::ReadOnly);
525 event->Set(v8::String::New(kIsTopLevel, sizeof(kIsTopLevel) - 1),
526 v8::Boolean::New(is_top_level),
527 v8::ReadOnly);
528 TriggerEvent(kLoadStartEventName, &event);
529 } 477 }
530 478
531 void BrowserPlugin::LoadCommit( 479 void BrowserPlugin::LoadCommit(
532 const BrowserPluginMsg_LoadCommit_Params& params) { 480 const BrowserPluginMsg_LoadCommit_Params& params) {
533 // If the guest has just committed a new navigation then it is no longer 481 // If the guest has just committed a new navigation then it is no longer
534 // crashed. 482 // crashed.
535 guest_crashed_ = false; 483 guest_crashed_ = false;
536 src_ = params.url.spec(); 484 src_ = params.url.spec();
537 process_id_ = params.process_id; 485 process_id_ = params.process_id;
538 current_nav_entry_index_ = params.current_entry_index; 486 current_nav_entry_index_ = params.current_entry_index;
539 nav_entry_count_ = params.entry_count; 487 nav_entry_count_ = params.entry_count;
540 488
541 if (!HasListeners(kLoadCommitEventName)) 489 std::map<std::string, base::Value*> props;
542 return; 490 props[kURL] = base::Value::CreateStringValue(src_);
543 491 props[kIsTopLevel] = base::Value::CreateBooleanValue(params.is_top_level);
544 WebKit::WebElement plugin = container()->element(); 492 TriggerEvent(kLoadCommitEventName, &props);
545 v8::HandleScope handle_scope;
546 v8::Context::Scope context_scope(
547 plugin.document().frame()->mainWorldScriptContext());
548
549 // Construct the loadCommit event object.
550 v8::Local<v8::Object> event = v8::Object::New();
551 event->Set(v8::String::New(kURL, sizeof(kURL) - 1),
552 v8::String::New(src_.data(), src_.size()),
553 v8::ReadOnly);
554 event->Set(v8::String::New(kIsTopLevel, sizeof(kIsTopLevel) - 1),
555 v8::Boolean::New(params.is_top_level),
556 v8::ReadOnly);
557
558 TriggerEvent(kLoadCommitEventName, &event);
559 } 493 }
560 494
561 void BrowserPlugin::LoadStop() { 495 void BrowserPlugin::LoadStop() {
562 if (!HasListeners(kLoadStopEventName))
563 return;
564
565 WebKit::WebElement plugin = container()->element();
566 v8::HandleScope handle_scope;
567 v8::Context::Scope context_scope(
568 plugin.document().frame()->mainWorldScriptContext());
569
570 // Construct the loadStop event object. 496 // Construct the loadStop event object.
571 v8::Local<v8::Object> event = v8::Object::New(); 497 TriggerEvent(kLoadStopEventName, NULL);
572 TriggerEvent(kLoadStopEventName, &event);
573 } 498 }
574 499
575 void BrowserPlugin::LoadAbort(const GURL& url, 500 void BrowserPlugin::LoadAbort(const GURL& url,
576 bool is_top_level, 501 bool is_top_level,
577 const std::string& type) { 502 const std::string& type) {
578 if (!HasListeners(kLoadAbortEventName)) 503 std::map<std::string, base::Value*> props;
579 return; 504 props[kURL] = base::Value::CreateStringValue(url.spec());
580 505 props[kIsTopLevel] = base::Value::CreateBooleanValue(is_top_level);
581 WebKit::WebElement plugin = container()->element(); 506 props[kReason] = base::Value::CreateStringValue(type);
582 v8::HandleScope handle_scope; 507 TriggerEvent(kLoadAbortEventName, &props);
583 v8::Context::Scope context_scope(
584 plugin.document().frame()->mainWorldScriptContext());
585
586 // Construct the loadAbort event object.
587 v8::Local<v8::Object> event = v8::Object::New();
588 event->Set(v8::String::New(kURL, sizeof(kURL) - 1),
589 v8::String::New(url.spec().data(), url.spec().size()),
590 v8::ReadOnly);
591 event->Set(v8::String::New(kIsTopLevel, sizeof(kIsTopLevel) - 1),
592 v8::Boolean::New(is_top_level),
593 v8::ReadOnly);
594 event->Set(v8::String::New(kType, sizeof(kType) - 1),
595 v8::String::New(type.data(), type.size()),
596 v8::ReadOnly);
597
598 TriggerEvent(kLoadAbortEventName, &event);
599 } 508 }
600 509
601 void BrowserPlugin::LoadRedirect(const GURL& old_url, 510 void BrowserPlugin::LoadRedirect(const GURL& old_url,
602 const GURL& new_url, 511 const GURL& new_url,
603 bool is_top_level) { 512 bool is_top_level) {
604 if (!HasListeners(kLoadRedirectEventName)) 513 std::map<std::string, base::Value*> props;
605 return; 514 props[kOldURL] = base::Value::CreateStringValue(old_url.spec());
606 515 props[kNewURL] = base::Value::CreateStringValue(new_url.spec());
607 WebKit::WebElement plugin = container()->element(); 516 props[kIsTopLevel] = base::Value::CreateBooleanValue(is_top_level);
608 v8::HandleScope handle_scope; 517 TriggerEvent(kLoadRedirectEventName, &props);
609 v8::Context::Scope context_scope(
610 plugin.document().frame()->mainWorldScriptContext());
611
612 // Construct the loadRedirect event object.
613 v8::Local<v8::Object> event = v8::Object::New();
614 event->Set(v8::String::New(kOldURL, sizeof(kOldURL) - 1),
615 v8::String::New(old_url.spec().data(), old_url.spec().size()),
616 v8::ReadOnly);
617 event->Set(v8::String::New(kNewURL, sizeof(kNewURL) - 1),
618 v8::String::New(new_url.spec().data(), new_url.spec().size()),
619 v8::ReadOnly);
620 event->Set(v8::String::New(kIsTopLevel, sizeof(kIsTopLevel) - 1),
621 v8::Boolean::New(is_top_level),
622 v8::ReadOnly);
623
624 TriggerEvent(kLoadRedirectEventName, &event);
625 } 518 }
626 519
627 void BrowserPlugin::AdvanceFocus(bool reverse) { 520 void BrowserPlugin::AdvanceFocus(bool reverse) {
628 DCHECK(render_view_); 521 DCHECK(render_view_);
629 render_view_->GetWebView()->advanceFocus(reverse); 522 render_view_->GetWebView()->advanceFocus(reverse);
630 } 523 }
631 524
632 void BrowserPlugin::SetEmbedderFocus(bool focused) { 525 void BrowserPlugin::SetEmbedderFocus(bool focused) {
633 if (embedder_focused_ == focused) 526 if (embedder_focused_ == focused)
634 return; 527 return;
(...skipping 22 matching lines...) Expand all
657 void BrowserPlugin::GuestContentWindowReady(int content_window_routing_id) { 550 void BrowserPlugin::GuestContentWindowReady(int content_window_routing_id) {
658 DCHECK(content_window_routing_id != MSG_ROUTING_NONE); 551 DCHECK(content_window_routing_id != MSG_ROUTING_NONE);
659 content_window_routing_id_ = content_window_routing_id; 552 content_window_routing_id_ = content_window_routing_id;
660 } 553 }
661 554
662 void BrowserPlugin::SetAcceptTouchEvents(bool accept) { 555 void BrowserPlugin::SetAcceptTouchEvents(bool accept) {
663 if (container()) 556 if (container())
664 container()->setIsAcceptingTouchEvents(accept); 557 container()->setIsAcceptingTouchEvents(accept);
665 } 558 }
666 559
667 bool BrowserPlugin::HasListeners(const std::string& event_name) {
668 return IsValidEvent(event_name) &&
669 !event_listener_map_[event_name].empty();
670 }
671
672 bool BrowserPlugin::AddEventListener(const std::string& event_name,
673 v8::Local<v8::Function> function) {
674 if (!IsValidEvent(event_name))
675 return false;
676 EventListeners& listeners = event_listener_map_[event_name];
677 for (unsigned int i = 0; i < listeners.size(); ++i) {
678 if (listeners[i] == function)
679 return false;
680 }
681 v8::Persistent<v8::Function> persistent_function =
682 v8::Persistent<v8::Function>::New(function);
683 listeners.push_back(persistent_function);
684 return true;
685 }
686
687 bool BrowserPlugin::RemoveEventListener(const std::string& event_name,
688 v8::Local<v8::Function> function) {
689 if (!HasListeners(event_name))
690 return false;
691
692 EventListeners& listeners = event_listener_map_[event_name];
693 EventListeners::iterator it = listeners.begin();
694 for (; it != listeners.end(); ++it) {
695 if (*it == function) {
696 it->Dispose();
697 listeners.erase(it);
698 return true;
699 }
700 }
701 return false;
702 }
703
704 WebKit::WebPluginContainer* BrowserPlugin::container() const { 560 WebKit::WebPluginContainer* BrowserPlugin::container() const {
705 return container_; 561 return container_;
706 } 562 }
707 563
708 bool BrowserPlugin::initialize(WebPluginContainer* container) { 564 bool BrowserPlugin::initialize(WebPluginContainer* container) {
709 container_ = container; 565 container_ = container;
710 return true; 566 return true;
711 } 567 }
712 568
713 void BrowserPlugin::destroy() { 569 void BrowserPlugin::destroy() {
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
976 void* notify_data) { 832 void* notify_data) {
977 } 833 }
978 834
979 void BrowserPlugin::didFailLoadingFrameRequest( 835 void BrowserPlugin::didFailLoadingFrameRequest(
980 const WebKit::WebURL& url, 836 const WebKit::WebURL& url,
981 void* notify_data, 837 void* notify_data,
982 const WebKit::WebURLError& error) { 838 const WebKit::WebURLError& error) {
983 } 839 }
984 840
985 } // namespace content 841 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/browser_plugin/browser_plugin.h ('k') | content/renderer/browser_plugin/browser_plugin_bindings.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698