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::WebFrame* frame = container()->element().document().frame(); |
328 v8::HandleScope handle_scope; | |
329 v8::Context::Scope context_scope(frame->mainWorldScriptContext()); | |
330 | |
331 EventListeners listeners(event_listener_map_[kCrashEventName]); | |
328 EventListeners::iterator it = listeners.begin(); | 332 EventListeners::iterator it = listeners.begin(); |
329 for (; it != listeners.end(); ++it) { | 333 for (; it != listeners.end(); ++it) { |
330 v8::Context::Scope context_scope(v8::Context::New()); | |
331 v8::HandleScope handle_scope; | 334 v8::HandleScope handle_scope; |
332 container()->element().document().frame()-> | 335 frame->callFunctionEvenIfScriptDisabled(*it, |
abarth-chromium
2012/10/09 18:38:18
How do you know that this call doesn't destroy |fr
Fady Samuel
2012/10/09 20:25:11
Done.
| |
333 callFunctionEvenIfScriptDisabled(*it, | 336 v8::Object::New(), |
334 v8::Object::New(), | 337 0, |
335 0, | 338 NULL); |
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::WebFrame* frame = container()->element().document().frame(); |
349 v8::HandleScope handle_scope; | |
350 v8::Context::Scope context_scope(frame->mainWorldScriptContext()); | |
351 | |
352 v8::Local<v8::Value> param = | |
353 v8::Local<v8::Value>::New(v8::String::New(src_.c_str())); | |
abarth-chromium
2012/10/09 18:38:18
It's more efficient to the two-argument form of v8
Fady Samuel
2012/10/09 20:25:11
Done.
| |
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 frame->callFunctionEvenIfScriptDisabled(*it, |
350 v8::HandleScope handle_scope; | 359 v8::Object::New(), |
351 v8::Local<v8::Value> param = | 360 1, |
352 v8::Local<v8::Value>::New(v8::String::New(src_.c_str())); | 361 ¶m); |
353 container()->element().document().frame()-> | |
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::WebFrame* frame = container()->element().document().frame(); |
370 v8::HandleScope handle_scope; | |
371 v8::Context::Scope context_scope(frame->mainWorldScriptContext()); | |
372 | |
373 // Construct the loadStart event object. | |
374 v8::Local<v8::Object> event = | |
375 v8::Local<v8::Object>::New(v8::Object::New()); | |
abarth-chromium
2012/10/09 18:38:18
v8::Object::New already returns a local handle. T
Fady Samuel
2012/10/09 20:25:11
Done.
| |
376 event->Set(v8::String::New(kURL, sizeof(kURL) - 1), | |
377 v8::String::New(url.spec().c_str(), url.spec().size())); | |
abarth-chromium
2012/10/09 18:38:18
There's no reason to call c_str here because you d
Fady Samuel
2012/10/09 20:25:11
Done.
| |
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 // Fire the event listener. |
381 container()->element().document().frame()-> | 386 frame->callFunctionEvenIfScriptDisabled(*it, |
382 callFunctionEvenIfScriptDisabled(*it, | 387 v8::Object::New(), |
383 v8::Object::New(), | 388 1, |
384 1, | 389 &val); |
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::WebFrame* frame = container()->element().document().frame(); |
400 v8::HandleScope handle_scope; | |
401 v8::Context::Scope context_scope(frame->mainWorldScriptContext()); | |
402 | |
403 // Construct the loadAbort event object. | |
404 v8::Local<v8::Object> event = | |
405 v8::Local<v8::Object>::New(v8::Object::New()); | |
406 event->Set(v8::String::New(kURL, sizeof(kURL) - 1), | |
407 v8::String::New(url.spec().c_str(), 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.c_str(), 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 // Fire the event listener. |
414 container()->element().document().frame()-> | 418 frame->callFunctionEvenIfScriptDisabled(*it, |
415 callFunctionEvenIfScriptDisabled(*it, | 419 v8::Object::New(), |
416 v8::Object::New(), | 420 1, |
417 1, | 421 &val); |
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::WebFrame* frame = container()->element().document().frame(); |
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(frame->mainWorldScriptContext()); | |
433 | 434 |
434 // Construct the loadRedirect event object. | 435 // Construct the loadRedirect event object. |
435 v8::Local<v8::Value> event = | 436 v8::Local<v8::Object> event = |
436 v8::Local<v8::Object>::New(v8::Object::New()); | 437 v8::Local<v8::Object>::New(v8::Object::New()); |
437 v8::Local<v8::Object>::Cast(event)->Set( | 438 event->Set(v8::String::New(kOldURL, sizeof(kOldURL) - 1), |
438 v8::String::New(kOldURL, sizeof(kOldURL) - 1), | 439 v8::String::New(old_url.spec().c_str(), old_url.spec().size())); |
439 v8::String::New(old_url.spec().c_str(), old_url.spec().size())); | 440 event->Set(v8::String::New(kNewURL, sizeof(kNewURL) - 1), |
440 v8::Local<v8::Object>::Cast(event)->Set( | 441 v8::String::New(new_url.spec().c_str(), new_url.spec().size())); |
441 v8::String::New(kNewURL, sizeof(kNewURL) - 1), | 442 event->Set(v8::String::New(kIsTopLevel, sizeof(kIsTopLevel) - 1), |
442 v8::String::New(new_url.spec().c_str(), new_url.spec().size())); | 443 v8::Boolean::New(is_top_level)); |
443 v8::Local<v8::Object>::Cast(event)->Set( | 444 v8::Local<v8::Value> val = event; |
444 v8::String::New(kIsTopLevel, sizeof(kIsTopLevel) - 1), | 445 |
445 v8::Boolean::New(is_top_level)); | 446 EventListeners listeners(event_listener_map_[kLoadRedirectEventName]); |
447 EventListeners::iterator it = listeners.begin(); | |
446 for (; it != listeners.end(); ++it) { | 448 for (; it != listeners.end(); ++it) { |
447 // Fire the event listener. | 449 // Fire the event listener. |
448 container()->element().document().frame()-> | 450 frame->callFunctionEvenIfScriptDisabled(*it, |
449 callFunctionEvenIfScriptDisabled(*it, | 451 v8::Object::New(), |
450 v8::Object::New(), | 452 1, |
451 1, | 453 &val); |
452 &event); | |
453 } | 454 } |
454 } | 455 } |
455 | 456 |
456 void BrowserPlugin::AdvanceFocus(bool reverse) { | 457 void BrowserPlugin::AdvanceFocus(bool reverse) { |
457 // We do not have a RenderView when we are testing. | 458 // We do not have a RenderView when we are testing. |
458 if (render_view_) | 459 if (render_view_) |
459 render_view_->GetWebView()->advanceFocus(reverse); | 460 render_view_->GetWebView()->advanceFocus(reverse); |
460 } | 461 } |
461 | 462 |
462 void BrowserPlugin::SetAcceptTouchEvents(bool accept) { | 463 void BrowserPlugin::SetAcceptTouchEvents(bool accept) { |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
740 void* notify_data) { | 741 void* notify_data) { |
741 } | 742 } |
742 | 743 |
743 void BrowserPlugin::didFailLoadingFrameRequest( | 744 void BrowserPlugin::didFailLoadingFrameRequest( |
744 const WebKit::WebURL& url, | 745 const WebKit::WebURL& url, |
745 void* notify_data, | 746 void* notify_data, |
746 const WebKit::WebURLError& error) { | 747 const WebKit::WebURLError& error) { |
747 } | 748 } |
748 | 749 |
749 } // namespace content | 750 } // namespace content |
OLD | NEW |