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

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

Issue 11086025: Browser Plugin: Fix Events (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed abarth@'s comments Created 8 years, 2 months 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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) 9 #if defined (OS_WIN)
10 #include "base/sys_info.h" 10 #include "base/sys_info.h"
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 gfx::Size())); 317 gfx::Size()));
318 } 318 }
319 319
320 void BrowserPlugin::GuestCrashed() { 320 void BrowserPlugin::GuestCrashed() {
321 guest_crashed_ = true; 321 guest_crashed_ = true;
322 container_->invalidate(); 322 container_->invalidate();
323 323
324 if (!HasListeners(kCrashEventName)) 324 if (!HasListeners(kCrashEventName))
325 return; 325 return;
326 326
327 EventListeners& listeners = event_listener_map_[kCrashEventName]; 327 WebKit::WebElement plugin = container()->element();
328 v8::HandleScope handle_scope;
329 v8::Context::Scope context_scope(
330 plugin.document().frame()->mainWorldScriptContext());
331
332 EventListeners listeners(event_listener_map_[kCrashEventName]);
328 EventListeners::iterator it = listeners.begin(); 333 EventListeners::iterator it = listeners.begin();
329 for (; it != listeners.end(); ++it) { 334 for (; it != listeners.end(); ++it) {
330 v8::Context::Scope context_scope(v8::Context::New()); 335 if (plugin.document().frame()) {
abarth-chromium 2012/10/09 20:30:00 I would have put this in a local variable, but I'm
Fady Samuel 2012/10/09 21:35:21 Done.
331 v8::HandleScope handle_scope; 336 plugin.document().frame()->callFunctionEvenIfScriptDisabled(
332 container()->element().document().frame()-> 337 *it, v8::Object::New(), 0, NULL);
333 callFunctionEvenIfScriptDisabled(*it, 338 }
334 v8::Object::New(),
335 0,
336 NULL);
337 } 339 }
338 } 340 }
339 341
340 void BrowserPlugin::DidNavigate(const GURL& url, int process_id) { 342 void BrowserPlugin::DidNavigate(const GURL& url, int process_id) {
341 src_ = url.spec(); 343 src_ = url.spec();
342 process_id_ = process_id; 344 process_id_ = process_id;
343 if (!HasListeners(kNavigationEventName)) 345 if (!HasListeners(kNavigationEventName))
344 return; 346 return;
345 347
346 EventListeners& listeners = event_listener_map_[kNavigationEventName]; 348 WebKit::WebElement plugin = container()->element();
349 v8::HandleScope handle_scope;
350 v8::Context::Scope context_scope(
351 plugin.document().frame()->mainWorldScriptContext());
352
353 v8::Local<v8::Value> param = v8::String::New(src_.data(), src_.size());
354
355 EventListeners listeners(event_listener_map_[kNavigationEventName]);
347 EventListeners::iterator it = listeners.begin(); 356 EventListeners::iterator it = listeners.begin();
348 for (; it != listeners.end(); ++it) { 357 for (; it != listeners.end(); ++it) {
349 v8::Context::Scope context_scope(v8::Context::New()); 358 if (plugin.document().frame()) {
350 v8::HandleScope handle_scope; 359 plugin.document().frame()->callFunctionEvenIfScriptDisabled(
351 v8::Local<v8::Value> param = 360 *it, v8::Object::New(), 1, &param);
352 v8::Local<v8::Value>::New(v8::String::New(src_.c_str())); 361 }
353 container()->element().document().frame()->
354 callFunctionEvenIfScriptDisabled(*it,
355 v8::Object::New(),
356 1,
357 &param);
358 } 362 }
359 } 363 }
360 364
361 void BrowserPlugin::LoadStart(const GURL& url, bool is_top_level) { 365 void BrowserPlugin::LoadStart(const GURL& url, bool is_top_level) {
362 if (!HasListeners(kLoadStartEventName)) 366 if (!HasListeners(kLoadStartEventName))
363 return; 367 return;
364 368
365 EventListeners& listeners = event_listener_map_[kLoadStartEventName]; 369 WebKit::WebElement plugin = container()->element();
370 v8::HandleScope handle_scope;
371 v8::Context::Scope context_scope(
372 plugin.document().frame()->mainWorldScriptContext());
373
374 // Construct the loadStart event object.
375 v8::Local<v8::Object> event = v8::Object::New();
376 event->Set(v8::String::New(kURL, sizeof(kURL) - 1),
377 v8::String::New(url.spec().data(), url.spec().size()));
378 event->Set(v8::String::New(kIsTopLevel, sizeof(kIsTopLevel) - 1),
379 v8::Boolean::New(is_top_level));
380 v8::Local<v8::Value> val = event;
381
382 EventListeners listeners(event_listener_map_[kLoadStartEventName]);
366 EventListeners::iterator it = listeners.begin(); 383 EventListeners::iterator it = listeners.begin();
367
368 v8::Context::Scope context_scope(v8::Context::New());
369 v8::HandleScope handle_scope;
370 // Construct the loadStart event object.
371 v8::Local<v8::Value> event =
372 v8::Local<v8::Object>::New(v8::Object::New());
373 v8::Local<v8::Object>::Cast(event)->Set(
374 v8::String::New(kURL, sizeof(kURL) - 1),
375 v8::String::New(url.spec().c_str(), url.spec().size()));
376 v8::Local<v8::Object>::Cast(event)->Set(
377 v8::String::New(kIsTopLevel, sizeof(kIsTopLevel) - 1),
378 v8::Boolean::New(is_top_level));
379 for (; it != listeners.end(); ++it) { 384 for (; it != listeners.end(); ++it) {
380 // Fire the event listener. 385 if (plugin.document().frame()) {
381 container()->element().document().frame()-> 386 // Fire the event listener.
382 callFunctionEvenIfScriptDisabled(*it, 387 plugin.document().frame()->callFunctionEvenIfScriptDisabled(
383 v8::Object::New(), 388 *it, v8::Object::New(), 1, &val);
384 1, 389 }
385 &event);
386 } 390 }
387 } 391 }
388 392
389 void BrowserPlugin::LoadAbort(const GURL& url, 393 void BrowserPlugin::LoadAbort(const GURL& url,
390 bool is_top_level, 394 bool is_top_level,
391 const std::string& type) { 395 const std::string& type) {
392 if (!HasListeners(kLoadAbortEventName)) 396 if (!HasListeners(kLoadAbortEventName))
393 return; 397 return;
394 398
395 EventListeners& listeners = event_listener_map_[kLoadAbortEventName]; 399 WebKit::WebElement plugin = container()->element();
400 v8::HandleScope handle_scope;
401 v8::Context::Scope context_scope(
402 plugin.document().frame()->mainWorldScriptContext());
403
404 // Construct the loadAbort event object.
405 v8::Local<v8::Object> event = v8::Object::New();
406 event->Set(v8::String::New(kURL, sizeof(kURL) - 1),
407 v8::String::New(url.spec().data(), url.spec().size()));
408 event->Set(v8::String::New(kIsTopLevel, sizeof(kIsTopLevel) - 1),
409 v8::Boolean::New(is_top_level));
410 event->Set(v8::String::New(kType, sizeof(kType) - 1),
411 v8::String::New(type.data(), type.size()));
412 v8::Local<v8::Value> val = event;
413
414 EventListeners listeners(event_listener_map_[kLoadAbortEventName]);
396 EventListeners::iterator it = listeners.begin(); 415 EventListeners::iterator it = listeners.begin();
397
398 v8::Context::Scope context_scope(v8::Context::New());
399 v8::HandleScope handle_scope;
400 // Construct the loadAbort event object.
401 v8::Local<v8::Value> event =
402 v8::Local<v8::Object>::New(v8::Object::New());
403 v8::Local<v8::Object>::Cast(event)->Set(
404 v8::String::New(kURL, sizeof(kURL) - 1),
405 v8::String::New(url.spec().c_str(), url.spec().size()));
406 v8::Local<v8::Object>::Cast(event)->Set(
407 v8::String::New(kIsTopLevel, sizeof(kIsTopLevel) - 1),
408 v8::Boolean::New(is_top_level));
409 v8::Local<v8::Object>::Cast(event)->Set(
410 v8::String::New(kType, sizeof(kType) - 1),
411 v8::String::New(type.c_str(), type.size()));
412 for (; it != listeners.end(); ++it) { 416 for (; it != listeners.end(); ++it) {
413 // Fire the event listener. 417 if (plugin.document().frame()) {
414 container()->element().document().frame()-> 418 // Fire the event listener.
415 callFunctionEvenIfScriptDisabled(*it, 419 plugin.document().frame()->callFunctionEvenIfScriptDisabled(
416 v8::Object::New(), 420 *it, v8::Object::New(), 1, &val);
417 1, 421 }
418 &event);
419 } 422 }
420 } 423 }
421 424
422 void BrowserPlugin::LoadRedirect(const GURL& old_url, 425 void BrowserPlugin::LoadRedirect(const GURL& old_url,
423 const GURL& new_url, 426 const GURL& new_url,
424 bool is_top_level) { 427 bool is_top_level) {
425 if (!HasListeners(kLoadRedirectEventName)) 428 if (!HasListeners(kLoadRedirectEventName))
426 return; 429 return;
427 430
428 EventListeners& listeners = event_listener_map_[kLoadRedirectEventName]; 431 WebKit::WebElement plugin = container()->element();
429 EventListeners::iterator it = listeners.begin();
430
431 v8::Context::Scope context_scope(v8::Context::New());
432 v8::HandleScope handle_scope; 432 v8::HandleScope handle_scope;
433 v8::Context::Scope context_scope(
434 plugin.document().frame()->mainWorldScriptContext());
433 435
434 // Construct the loadRedirect event object. 436 // Construct the loadRedirect event object.
435 v8::Local<v8::Value> event = 437 v8::Local<v8::Object> event =
436 v8::Local<v8::Object>::New(v8::Object::New()); 438 v8::Local<v8::Object>::New(v8::Object::New());
abarth-chromium 2012/10/09 20:30:00 No need to create a new local handle here either.
Fady Samuel 2012/10/09 21:35:21 Done.
437 v8::Local<v8::Object>::Cast(event)->Set( 439 event->Set(v8::String::New(kOldURL, sizeof(kOldURL) - 1),
438 v8::String::New(kOldURL, sizeof(kOldURL) - 1), 440 v8::String::New(old_url.spec().c_str(), old_url.spec().size()));
abarth-chromium 2012/10/09 20:30:00 c_str -> data
Fady Samuel 2012/10/09 21:35:21 Done.
439 v8::String::New(old_url.spec().c_str(), old_url.spec().size())); 441 event->Set(v8::String::New(kNewURL, sizeof(kNewURL) - 1),
440 v8::Local<v8::Object>::Cast(event)->Set( 442 v8::String::New(new_url.spec().c_str(), new_url.spec().size()));
441 v8::String::New(kNewURL, sizeof(kNewURL) - 1), 443 event->Set(v8::String::New(kIsTopLevel, sizeof(kIsTopLevel) - 1),
442 v8::String::New(new_url.spec().c_str(), new_url.spec().size())); 444 v8::Boolean::New(is_top_level));
443 v8::Local<v8::Object>::Cast(event)->Set( 445 v8::Local<v8::Value> val = event;
444 v8::String::New(kIsTopLevel, sizeof(kIsTopLevel) - 1), 446
445 v8::Boolean::New(is_top_level)); 447 EventListeners listeners(event_listener_map_[kLoadRedirectEventName]);
448 EventListeners::iterator it = listeners.begin();
446 for (; it != listeners.end(); ++it) { 449 for (; it != listeners.end(); ++it) {
447 // Fire the event listener. 450 if (plugin.document().frame()) {
448 container()->element().document().frame()-> 451 // Fire the event listener.
abarth-chromium 2012/10/09 20:30:00 I would remove this comment since it doesn't reall
Fady Samuel 2012/10/09 21:35:21 Done.
449 callFunctionEvenIfScriptDisabled(*it, 452 plugin.document().frame()->callFunctionEvenIfScriptDisabled(
450 v8::Object::New(), 453 *it, v8::Object::New(), 1, &val);
451 1, 454 }
452 &event);
453 } 455 }
454 } 456 }
455 457
456 void BrowserPlugin::AdvanceFocus(bool reverse) { 458 void BrowserPlugin::AdvanceFocus(bool reverse) {
457 // We do not have a RenderView when we are testing. 459 // We do not have a RenderView when we are testing.
458 if (render_view_) 460 if (render_view_)
459 render_view_->GetWebView()->advanceFocus(reverse); 461 render_view_->GetWebView()->advanceFocus(reverse);
460 } 462 }
461 463
462 void BrowserPlugin::SetAcceptTouchEvents(bool accept) { 464 void BrowserPlugin::SetAcceptTouchEvents(bool accept) {
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
740 void* notify_data) { 742 void* notify_data) {
741 } 743 }
742 744
743 void BrowserPlugin::didFailLoadingFrameRequest( 745 void BrowserPlugin::didFailLoadingFrameRequest(
744 const WebKit::WebURL& url, 746 const WebKit::WebURL& url,
745 void* notify_data, 747 void* notify_data,
746 const WebKit::WebURLError& error) { 748 const WebKit::WebURLError& error) {
747 } 749 }
748 750
749 } // namespace content 751 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698