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" |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 // TODO(fsamuel): Copying the event listeners is insufficent because |
| 333 // new persistent handles are not created when the copy constructor is |
| 334 // called. See http://crbug.com/155044. |
| 335 EventListeners listeners(event_listener_map_[kCrashEventName]); |
328 EventListeners::iterator it = listeners.begin(); | 336 EventListeners::iterator it = listeners.begin(); |
329 for (; it != listeners.end(); ++it) { | 337 for (; it != listeners.end(); ++it) { |
330 v8::Context::Scope context_scope(v8::Context::New()); | 338 WebKit::WebFrame* frame = plugin.document().frame(); |
331 v8::HandleScope handle_scope; | 339 if (frame) |
332 container()->element().document().frame()-> | 340 frame->callFunctionEvenIfScriptDisabled(*it, v8::Object::New(), 0, NULL); |
333 callFunctionEvenIfScriptDisabled(*it, | |
334 v8::Object::New(), | |
335 0, | |
336 NULL); | |
337 } | 341 } |
338 } | 342 } |
339 | 343 |
340 void BrowserPlugin::DidNavigate(const GURL& url, int process_id) { | 344 void BrowserPlugin::DidNavigate(const GURL& url, int process_id) { |
341 src_ = url.spec(); | 345 src_ = url.spec(); |
342 process_id_ = process_id; | 346 process_id_ = process_id; |
343 if (!HasListeners(kNavigationEventName)) | 347 if (!HasListeners(kNavigationEventName)) |
344 return; | 348 return; |
345 | 349 |
346 EventListeners& listeners = event_listener_map_[kNavigationEventName]; | 350 WebKit::WebElement plugin = container()->element(); |
| 351 v8::HandleScope handle_scope; |
| 352 v8::Context::Scope context_scope( |
| 353 plugin.document().frame()->mainWorldScriptContext()); |
| 354 |
| 355 v8::Local<v8::Value> param = v8::String::New(src_.data(), src_.size()); |
| 356 |
| 357 // TODO(fsamuel): Copying the event listeners is insufficent because |
| 358 // new persistent handles are not created when the copy constructor is |
| 359 // called. See http://crbug.com/155044. |
| 360 EventListeners listeners(event_listener_map_[kNavigationEventName]); |
347 EventListeners::iterator it = listeners.begin(); | 361 EventListeners::iterator it = listeners.begin(); |
348 for (; it != listeners.end(); ++it) { | 362 for (; it != listeners.end(); ++it) { |
349 v8::Context::Scope context_scope(v8::Context::New()); | 363 WebKit::WebFrame* frame = plugin.document().frame(); |
350 v8::HandleScope handle_scope; | 364 if (frame) { |
351 v8::Local<v8::Value> param = | 365 frame->callFunctionEvenIfScriptDisabled( |
352 v8::Local<v8::Value>::New(v8::String::New(src_.c_str())); | 366 *it, v8::Object::New(), 1, ¶m); |
353 container()->element().document().frame()-> | 367 } |
354 callFunctionEvenIfScriptDisabled(*it, | |
355 v8::Object::New(), | |
356 1, | |
357 ¶m); | |
358 } | 368 } |
359 } | 369 } |
360 | 370 |
361 void BrowserPlugin::LoadStart(const GURL& url, bool is_top_level) { | 371 void BrowserPlugin::LoadStart(const GURL& url, bool is_top_level) { |
362 if (!HasListeners(kLoadStartEventName)) | 372 if (!HasListeners(kLoadStartEventName)) |
363 return; | 373 return; |
364 | 374 |
365 EventListeners& listeners = event_listener_map_[kLoadStartEventName]; | 375 WebKit::WebElement plugin = container()->element(); |
| 376 v8::HandleScope handle_scope; |
| 377 v8::Context::Scope context_scope( |
| 378 plugin.document().frame()->mainWorldScriptContext()); |
| 379 |
| 380 // Construct the loadStart event object. |
| 381 v8::Local<v8::Object> event = v8::Object::New(); |
| 382 event->Set(v8::String::New(kURL, sizeof(kURL) - 1), |
| 383 v8::String::New(url.spec().data(), url.spec().size())); |
| 384 event->Set(v8::String::New(kIsTopLevel, sizeof(kIsTopLevel) - 1), |
| 385 v8::Boolean::New(is_top_level)); |
| 386 v8::Local<v8::Value> val = event; |
| 387 |
| 388 // TODO(fsamuel): Copying the event listeners is insufficent because |
| 389 // new persistent handles are not created when the copy constructor is |
| 390 // called. See http://crbug.com/155044. |
| 391 EventListeners listeners(event_listener_map_[kLoadStartEventName]); |
366 EventListeners::iterator it = listeners.begin(); | 392 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) { | 393 for (; it != listeners.end(); ++it) { |
380 // Fire the event listener. | 394 WebKit::WebFrame* frame = plugin.document().frame(); |
381 container()->element().document().frame()-> | 395 if (frame) |
382 callFunctionEvenIfScriptDisabled(*it, | 396 frame->callFunctionEvenIfScriptDisabled(*it, v8::Object::New(), 1, &val); |
383 v8::Object::New(), | |
384 1, | |
385 &event); | |
386 } | 397 } |
387 } | 398 } |
388 | 399 |
389 void BrowserPlugin::LoadAbort(const GURL& url, | 400 void BrowserPlugin::LoadAbort(const GURL& url, |
390 bool is_top_level, | 401 bool is_top_level, |
391 const std::string& type) { | 402 const std::string& type) { |
392 if (!HasListeners(kLoadAbortEventName)) | 403 if (!HasListeners(kLoadAbortEventName)) |
393 return; | 404 return; |
394 | 405 |
395 EventListeners& listeners = event_listener_map_[kLoadAbortEventName]; | 406 WebKit::WebElement plugin = container()->element(); |
| 407 v8::HandleScope handle_scope; |
| 408 v8::Context::Scope context_scope( |
| 409 plugin.document().frame()->mainWorldScriptContext()); |
| 410 |
| 411 // Construct the loadAbort event object. |
| 412 v8::Local<v8::Object> event = v8::Object::New(); |
| 413 event->Set(v8::String::New(kURL, sizeof(kURL) - 1), |
| 414 v8::String::New(url.spec().data(), url.spec().size())); |
| 415 event->Set(v8::String::New(kIsTopLevel, sizeof(kIsTopLevel) - 1), |
| 416 v8::Boolean::New(is_top_level)); |
| 417 event->Set(v8::String::New(kType, sizeof(kType) - 1), |
| 418 v8::String::New(type.data(), type.size())); |
| 419 v8::Local<v8::Value> val = event; |
| 420 |
| 421 // TODO(fsamuel): Copying the event listeners is insufficent because |
| 422 // new persistent handles are not created when the copy constructor is |
| 423 // called. See http://crbug.com/155044. |
| 424 EventListeners listeners(event_listener_map_[kLoadAbortEventName]); |
396 EventListeners::iterator it = listeners.begin(); | 425 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) { | 426 for (; it != listeners.end(); ++it) { |
413 // Fire the event listener. | 427 WebKit::WebFrame* frame = plugin.document().frame(); |
414 container()->element().document().frame()-> | 428 if (frame) |
415 callFunctionEvenIfScriptDisabled(*it, | 429 frame->callFunctionEvenIfScriptDisabled(*it, v8::Object::New(), 1, &val); |
416 v8::Object::New(), | |
417 1, | |
418 &event); | |
419 } | 430 } |
420 } | 431 } |
421 | 432 |
422 void BrowserPlugin::LoadRedirect(const GURL& old_url, | 433 void BrowserPlugin::LoadRedirect(const GURL& old_url, |
423 const GURL& new_url, | 434 const GURL& new_url, |
424 bool is_top_level) { | 435 bool is_top_level) { |
425 if (!HasListeners(kLoadRedirectEventName)) | 436 if (!HasListeners(kLoadRedirectEventName)) |
426 return; | 437 return; |
427 | 438 |
428 EventListeners& listeners = event_listener_map_[kLoadRedirectEventName]; | 439 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; | 440 v8::HandleScope handle_scope; |
| 441 v8::Context::Scope context_scope( |
| 442 plugin.document().frame()->mainWorldScriptContext()); |
433 | 443 |
434 // Construct the loadRedirect event object. | 444 // Construct the loadRedirect event object. |
435 v8::Local<v8::Value> event = | 445 v8::Local<v8::Object> event = v8::Object::New(); |
436 v8::Local<v8::Object>::New(v8::Object::New()); | 446 event->Set(v8::String::New(kOldURL, sizeof(kOldURL) - 1), |
437 v8::Local<v8::Object>::Cast(event)->Set( | 447 v8::String::New(old_url.spec().data(), old_url.spec().size())); |
438 v8::String::New(kOldURL, sizeof(kOldURL) - 1), | 448 event->Set(v8::String::New(kNewURL, sizeof(kNewURL) - 1), |
439 v8::String::New(old_url.spec().c_str(), old_url.spec().size())); | 449 v8::String::New(new_url.spec().data(), new_url.spec().size())); |
440 v8::Local<v8::Object>::Cast(event)->Set( | 450 event->Set(v8::String::New(kIsTopLevel, sizeof(kIsTopLevel) - 1), |
441 v8::String::New(kNewURL, sizeof(kNewURL) - 1), | 451 v8::Boolean::New(is_top_level)); |
442 v8::String::New(new_url.spec().c_str(), new_url.spec().size())); | 452 v8::Local<v8::Value> val = event; |
443 v8::Local<v8::Object>::Cast(event)->Set( | 453 |
444 v8::String::New(kIsTopLevel, sizeof(kIsTopLevel) - 1), | 454 // TODO(fsamuel): Copying the event listeners is insufficent because |
445 v8::Boolean::New(is_top_level)); | 455 // new persistent handles are not created when the copy constructor is |
| 456 // called. See http://crbug.com/155044. |
| 457 EventListeners listeners(event_listener_map_[kLoadRedirectEventName]); |
| 458 EventListeners::iterator it = listeners.begin(); |
446 for (; it != listeners.end(); ++it) { | 459 for (; it != listeners.end(); ++it) { |
447 // Fire the event listener. | 460 WebKit::WebFrame* frame = plugin.document().frame(); |
448 container()->element().document().frame()-> | 461 if (frame) |
449 callFunctionEvenIfScriptDisabled(*it, | 462 frame->callFunctionEvenIfScriptDisabled(*it, v8::Object::New(), 1, &val); |
450 v8::Object::New(), | |
451 1, | |
452 &event); | |
453 } | 463 } |
454 } | 464 } |
455 | 465 |
456 void BrowserPlugin::AdvanceFocus(bool reverse) { | 466 void BrowserPlugin::AdvanceFocus(bool reverse) { |
457 // We do not have a RenderView when we are testing. | 467 // We do not have a RenderView when we are testing. |
458 if (render_view_) | 468 if (render_view_) |
459 render_view_->GetWebView()->advanceFocus(reverse); | 469 render_view_->GetWebView()->advanceFocus(reverse); |
460 } | 470 } |
461 | 471 |
462 void BrowserPlugin::SetAcceptTouchEvents(bool accept) { | 472 void BrowserPlugin::SetAcceptTouchEvents(bool accept) { |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
740 void* notify_data) { | 750 void* notify_data) { |
741 } | 751 } |
742 | 752 |
743 void BrowserPlugin::didFailLoadingFrameRequest( | 753 void BrowserPlugin::didFailLoadingFrameRequest( |
744 const WebKit::WebURL& url, | 754 const WebKit::WebURL& url, |
745 void* notify_data, | 755 void* notify_data, |
746 const WebKit::WebURLError& error) { | 756 const WebKit::WebURLError& error) { |
747 } | 757 } |
748 | 758 |
749 } // namespace content | 759 } // namespace content |
OLD | NEW |