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" |
| (...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(); |
|
Charlie Reis
2012/10/10 00:05:09
nit: It looks like you never use plugin directly,
| |
| 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 WebKit::WebFrame* frame = plugin.document().frame(); |
| 331 v8::HandleScope handle_scope; | 336 if (frame) |
|
Charlie Reis
2012/10/10 00:05:09
If this null check is to guard against frame being
Charlie Reis
2012/10/10 02:46:13
Ok, I missed the fact that document()'s reference
| |
| 332 container()->element().document().frame()-> | 337 frame->callFunctionEvenIfScriptDisabled(*it, v8::Object::New(), 0, NULL); |
| 333 callFunctionEvenIfScriptDisabled(*it, | |
| 334 v8::Object::New(), | |
| 335 0, | |
| 336 NULL); | |
| 337 } | 338 } |
| 338 } | 339 } |
| 339 | 340 |
| 340 void BrowserPlugin::DidNavigate(const GURL& url, int process_id) { | 341 void BrowserPlugin::DidNavigate(const GURL& url, int process_id) { |
| 341 src_ = url.spec(); | 342 src_ = url.spec(); |
| 342 process_id_ = process_id; | 343 process_id_ = process_id; |
| 343 if (!HasListeners(kNavigationEventName)) | 344 if (!HasListeners(kNavigationEventName)) |
| 344 return; | 345 return; |
| 345 | 346 |
| 346 EventListeners& listeners = event_listener_map_[kNavigationEventName]; | 347 WebKit::WebElement plugin = container()->element(); |
| 348 v8::HandleScope handle_scope; | |
| 349 v8::Context::Scope context_scope( | |
| 350 plugin.document().frame()->mainWorldScriptContext()); | |
| 351 | |
| 352 v8::Local<v8::Value> param = v8::String::New(src_.data(), src_.size()); | |
| 353 | |
| 354 EventListeners listeners(event_listener_map_[kNavigationEventName]); | |
| 347 EventListeners::iterator it = listeners.begin(); | 355 EventListeners::iterator it = listeners.begin(); |
| 348 for (; it != listeners.end(); ++it) { | 356 for (; it != listeners.end(); ++it) { |
| 349 v8::Context::Scope context_scope(v8::Context::New()); | 357 WebKit::WebFrame* frame = plugin.document().frame(); |
| 350 v8::HandleScope handle_scope; | 358 if (frame) { |
| 351 v8::Local<v8::Value> param = | 359 frame->callFunctionEvenIfScriptDisabled( |
| 352 v8::Local<v8::Value>::New(v8::String::New(src_.c_str())); | 360 *it, v8::Object::New(), 1, ¶m); |
| 353 container()->element().document().frame()-> | 361 } |
| 354 callFunctionEvenIfScriptDisabled(*it, | |
| 355 v8::Object::New(), | |
| 356 1, | |
| 357 ¶m); | |
| 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 WebKit::WebFrame* frame = plugin.document().frame(); |
| 381 container()->element().document().frame()-> | 386 if (frame) |
| 382 callFunctionEvenIfScriptDisabled(*it, | 387 frame->callFunctionEvenIfScriptDisabled(*it, v8::Object::New(), 1, &val); |
| 383 v8::Object::New(), | |
| 384 1, | |
| 385 &event); | |
| 386 } | 388 } |
| 387 } | 389 } |
| 388 | 390 |
| 389 void BrowserPlugin::LoadAbort(const GURL& url, | 391 void BrowserPlugin::LoadAbort(const GURL& url, |
| 390 bool is_top_level, | 392 bool is_top_level, |
| 391 const std::string& type) { | 393 const std::string& type) { |
| 392 if (!HasListeners(kLoadAbortEventName)) | 394 if (!HasListeners(kLoadAbortEventName)) |
| 393 return; | 395 return; |
| 394 | 396 |
| 395 EventListeners& listeners = event_listener_map_[kLoadAbortEventName]; | 397 WebKit::WebElement plugin = container()->element(); |
| 398 v8::HandleScope handle_scope; | |
| 399 v8::Context::Scope context_scope( | |
| 400 plugin.document().frame()->mainWorldScriptContext()); | |
| 401 | |
| 402 // Construct the loadAbort event object. | |
| 403 v8::Local<v8::Object> event = v8::Object::New(); | |
| 404 event->Set(v8::String::New(kURL, sizeof(kURL) - 1), | |
| 405 v8::String::New(url.spec().data(), url.spec().size())); | |
| 406 event->Set(v8::String::New(kIsTopLevel, sizeof(kIsTopLevel) - 1), | |
| 407 v8::Boolean::New(is_top_level)); | |
| 408 event->Set(v8::String::New(kType, sizeof(kType) - 1), | |
| 409 v8::String::New(type.data(), type.size())); | |
| 410 v8::Local<v8::Value> val = event; | |
| 411 | |
| 412 EventListeners listeners(event_listener_map_[kLoadAbortEventName]); | |
| 396 EventListeners::iterator it = listeners.begin(); | 413 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) { | 414 for (; it != listeners.end(); ++it) { |
| 413 // Fire the event listener. | 415 WebKit::WebFrame* frame = plugin.document().frame(); |
| 414 container()->element().document().frame()-> | 416 if (frame) |
| 415 callFunctionEvenIfScriptDisabled(*it, | 417 frame->callFunctionEvenIfScriptDisabled(*it, v8::Object::New(), 1, &val); |
| 416 v8::Object::New(), | |
| 417 1, | |
| 418 &event); | |
| 419 } | 418 } |
| 420 } | 419 } |
| 421 | 420 |
| 422 void BrowserPlugin::LoadRedirect(const GURL& old_url, | 421 void BrowserPlugin::LoadRedirect(const GURL& old_url, |
| 423 const GURL& new_url, | 422 const GURL& new_url, |
| 424 bool is_top_level) { | 423 bool is_top_level) { |
| 425 if (!HasListeners(kLoadRedirectEventName)) | 424 if (!HasListeners(kLoadRedirectEventName)) |
| 426 return; | 425 return; |
| 427 | 426 |
| 428 EventListeners& listeners = event_listener_map_[kLoadRedirectEventName]; | 427 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; | 428 v8::HandleScope handle_scope; |
| 429 v8::Context::Scope context_scope( | |
| 430 plugin.document().frame()->mainWorldScriptContext()); | |
| 433 | 431 |
| 434 // Construct the loadRedirect event object. | 432 // Construct the loadRedirect event object. |
| 435 v8::Local<v8::Value> event = | 433 v8::Local<v8::Object> event = v8::Object::New(); |
| 436 v8::Local<v8::Object>::New(v8::Object::New()); | 434 event->Set(v8::String::New(kOldURL, sizeof(kOldURL) - 1), |
| 437 v8::Local<v8::Object>::Cast(event)->Set( | 435 v8::String::New(old_url.spec().data(), old_url.spec().size())); |
| 438 v8::String::New(kOldURL, sizeof(kOldURL) - 1), | 436 event->Set(v8::String::New(kNewURL, sizeof(kNewURL) - 1), |
| 439 v8::String::New(old_url.spec().c_str(), old_url.spec().size())); | 437 v8::String::New(new_url.spec().data(), new_url.spec().size())); |
| 440 v8::Local<v8::Object>::Cast(event)->Set( | 438 event->Set(v8::String::New(kIsTopLevel, sizeof(kIsTopLevel) - 1), |
| 441 v8::String::New(kNewURL, sizeof(kNewURL) - 1), | 439 v8::Boolean::New(is_top_level)); |
| 442 v8::String::New(new_url.spec().c_str(), new_url.spec().size())); | 440 v8::Local<v8::Value> val = event; |
| 443 v8::Local<v8::Object>::Cast(event)->Set( | 441 |
| 444 v8::String::New(kIsTopLevel, sizeof(kIsTopLevel) - 1), | 442 EventListeners listeners(event_listener_map_[kLoadRedirectEventName]); |
| 445 v8::Boolean::New(is_top_level)); | 443 EventListeners::iterator it = listeners.begin(); |
| 446 for (; it != listeners.end(); ++it) { | 444 for (; it != listeners.end(); ++it) { |
| 447 // Fire the event listener. | 445 WebKit::WebFrame* frame = plugin.document().frame(); |
| 448 container()->element().document().frame()-> | 446 if (frame) |
| 449 callFunctionEvenIfScriptDisabled(*it, | 447 frame->callFunctionEvenIfScriptDisabled(*it, v8::Object::New(), 1, &val); |
| 450 v8::Object::New(), | |
| 451 1, | |
| 452 &event); | |
| 453 } | 448 } |
| 454 } | 449 } |
| 455 | 450 |
| 456 void BrowserPlugin::AdvanceFocus(bool reverse) { | 451 void BrowserPlugin::AdvanceFocus(bool reverse) { |
| 457 // We do not have a RenderView when we are testing. | 452 // We do not have a RenderView when we are testing. |
| 458 if (render_view_) | 453 if (render_view_) |
| 459 render_view_->GetWebView()->advanceFocus(reverse); | 454 render_view_->GetWebView()->advanceFocus(reverse); |
| 460 } | 455 } |
| 461 | 456 |
| 462 void BrowserPlugin::SetAcceptTouchEvents(bool accept) { | 457 void BrowserPlugin::SetAcceptTouchEvents(bool accept) { |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 740 void* notify_data) { | 735 void* notify_data) { |
| 741 } | 736 } |
| 742 | 737 |
| 743 void BrowserPlugin::didFailLoadingFrameRequest( | 738 void BrowserPlugin::didFailLoadingFrameRequest( |
| 744 const WebKit::WebURL& url, | 739 const WebKit::WebURL& url, |
| 745 void* notify_data, | 740 void* notify_data, |
| 746 const WebKit::WebURLError& error) { | 741 const WebKit::WebURLError& error) { |
| 747 } | 742 } |
| 748 | 743 |
| 749 } // namespace content | 744 } // namespace content |
| OLD | NEW |