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 27 matching lines...) Expand all Loading... |
38 using WebKit::WebRect; | 38 using WebKit::WebRect; |
39 using WebKit::WebURL; | 39 using WebKit::WebURL; |
40 using WebKit::WebVector; | 40 using WebKit::WebVector; |
41 | 41 |
42 namespace content { | 42 namespace content { |
43 | 43 |
44 namespace { | 44 namespace { |
45 const char kCrashEventName[] = "crash"; | 45 const char kCrashEventName[] = "crash"; |
46 const char kIsTopLevel[] = "isTopLevel"; | 46 const char kIsTopLevel[] = "isTopLevel"; |
47 const char kLoadAbortEventName[] = "loadAbort"; | 47 const char kLoadAbortEventName[] = "loadAbort"; |
| 48 const char kLoadCommitEventName[] = "loadCommit"; |
48 const char kLoadRedirectEventName[] = "loadRedirect"; | 49 const char kLoadRedirectEventName[] = "loadRedirect"; |
49 const char kLoadStartEventName[] = "loadStart"; | 50 const char kLoadStartEventName[] = "loadStart"; |
50 const char kNavigationEventName[] = "navigation"; | 51 const char kLoadStopEventName[] = "loadStop"; |
51 const char kNewURL[] = "newUrl"; | 52 const char kNewURL[] = "newUrl"; |
52 const char kOldURL[] = "oldUrl"; | 53 const char kOldURL[] = "oldUrl"; |
53 const char kPartitionAttribute[] = "partition"; | 54 const char kPartitionAttribute[] = "partition"; |
54 const char kPersistPrefix[] = "persist:"; | 55 const char kPersistPrefix[] = "persist:"; |
55 const char kSrcAttribute[] = "src"; | 56 const char kSrcAttribute[] = "src"; |
56 const char kType[] = "type"; | 57 const char kType[] = "type"; |
57 const char kURL[] = "url"; | 58 const char kURL[] = "url"; |
58 } | 59 } |
59 | 60 |
60 BrowserPlugin::BrowserPlugin( | 61 BrowserPlugin::BrowserPlugin( |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 // called. See http://crbug.com/155044. | 352 // called. See http://crbug.com/155044. |
352 EventListeners listeners(event_listener_map_[kCrashEventName]); | 353 EventListeners listeners(event_listener_map_[kCrashEventName]); |
353 EventListeners::iterator it = listeners.begin(); | 354 EventListeners::iterator it = listeners.begin(); |
354 for (; it != listeners.end(); ++it) { | 355 for (; it != listeners.end(); ++it) { |
355 WebKit::WebFrame* frame = plugin.document().frame(); | 356 WebKit::WebFrame* frame = plugin.document().frame(); |
356 if (frame) | 357 if (frame) |
357 frame->callFunctionEvenIfScriptDisabled(*it, v8::Object::New(), 0, NULL); | 358 frame->callFunctionEvenIfScriptDisabled(*it, v8::Object::New(), 0, NULL); |
358 } | 359 } |
359 } | 360 } |
360 | 361 |
361 void BrowserPlugin::DidNavigate( | 362 void BrowserPlugin::LoadStart(const GURL& url, bool is_top_level) { |
362 const BrowserPluginMsg_DidNavigate_Params& params) { | 363 if (!HasListeners(kLoadStartEventName)) |
| 364 return; |
| 365 |
| 366 WebKit::WebElement plugin = container()->element(); |
| 367 v8::HandleScope handle_scope; |
| 368 v8::Context::Scope context_scope( |
| 369 plugin.document().frame()->mainWorldScriptContext()); |
| 370 |
| 371 // Construct the loadStart event object. |
| 372 v8::Local<v8::Object> event = v8::Object::New(); |
| 373 event->Set(v8::String::New(kURL, sizeof(kURL) - 1), |
| 374 v8::String::New(url.spec().data(), url.spec().size())); |
| 375 event->Set(v8::String::New(kIsTopLevel, sizeof(kIsTopLevel) - 1), |
| 376 v8::Boolean::New(is_top_level)); |
| 377 v8::Local<v8::Value> val = event; |
| 378 |
| 379 // TODO(fsamuel): Copying the event listeners is insufficent because |
| 380 // new persistent handles are not created when the copy constructor is |
| 381 // called. See http://crbug.com/155044. |
| 382 EventListeners listeners(event_listener_map_[kLoadStartEventName]); |
| 383 EventListeners::iterator it = listeners.begin(); |
| 384 for (; it != listeners.end(); ++it) { |
| 385 WebKit::WebFrame* frame = plugin.document().frame(); |
| 386 if (frame) |
| 387 frame->callFunctionEvenIfScriptDisabled(*it, v8::Object::New(), 1, &val); |
| 388 } |
| 389 } |
| 390 |
| 391 void BrowserPlugin::LoadCommit( |
| 392 const BrowserPluginMsg_LoadCommit_Params& params) { |
363 // If the guest has just committed a new navigation then it is no longer | 393 // If the guest has just committed a new navigation then it is no longer |
364 // crashed. | 394 // crashed. |
365 guest_crashed_ = false; | 395 guest_crashed_ = false; |
366 src_ = params.url.spec(); | 396 src_ = params.url.spec(); |
367 process_id_ = params.process_id; | 397 process_id_ = params.process_id; |
368 current_nav_entry_index_ = params.current_entry_index; | 398 current_nav_entry_index_ = params.current_entry_index; |
369 nav_entry_count_ = params.entry_count; | 399 nav_entry_count_ = params.entry_count; |
370 | 400 |
371 if (!HasListeners(kNavigationEventName)) | 401 if (!HasListeners(kLoadCommitEventName)) |
372 return; | 402 return; |
373 | 403 |
374 WebKit::WebElement plugin = container()->element(); | 404 WebKit::WebElement plugin = container()->element(); |
375 v8::HandleScope handle_scope; | 405 v8::HandleScope handle_scope; |
376 v8::Context::Scope context_scope( | 406 v8::Context::Scope context_scope( |
377 plugin.document().frame()->mainWorldScriptContext()); | 407 plugin.document().frame()->mainWorldScriptContext()); |
378 | 408 |
379 // Construct the navigation event object. | 409 // Construct the loadCommit event object. |
380 v8::Local<v8::Object> event = v8::Object::New(); | 410 v8::Local<v8::Object> event = v8::Object::New(); |
381 event->Set(v8::String::New(kURL, sizeof(kURL) - 1), | 411 event->Set(v8::String::New(kURL, sizeof(kURL) - 1), |
382 v8::String::New(src_.data(), src_.size())); | 412 v8::String::New(src_.data(), src_.size())); |
383 event->Set(v8::String::New(kIsTopLevel, sizeof(kIsTopLevel) - 1), | 413 event->Set(v8::String::New(kIsTopLevel, sizeof(kIsTopLevel) - 1), |
384 v8::Boolean::New(params.is_top_level)); | 414 v8::Boolean::New(params.is_top_level)); |
385 v8::Local<v8::Value> val = event; | 415 v8::Local<v8::Value> val = event; |
386 | 416 |
387 // TODO(fsamuel): Copying the event listeners is insufficent because | 417 // TODO(fsamuel): Copying the event listeners is insufficent because |
388 // new persistent handles are not created when the copy constructor is | 418 // new persistent handles are not created when the copy constructor is |
389 // called. See http://crbug.com/155044. | 419 // called. See http://crbug.com/155044. |
390 EventListeners listeners(event_listener_map_[kNavigationEventName]); | 420 EventListeners listeners(event_listener_map_[kLoadCommitEventName]); |
391 EventListeners::iterator it = listeners.begin(); | 421 EventListeners::iterator it = listeners.begin(); |
392 for (; it != listeners.end(); ++it) { | 422 for (; it != listeners.end(); ++it) { |
393 WebKit::WebFrame* frame = plugin.document().frame(); | 423 WebKit::WebFrame* frame = plugin.document().frame(); |
394 if (frame) { | 424 if (frame) |
395 frame->callFunctionEvenIfScriptDisabled( | 425 frame->callFunctionEvenIfScriptDisabled(*it, v8::Object::New(), 1, &val); |
396 *it, v8::Object::New(), 1, &val); | |
397 } | |
398 } | 426 } |
399 } | 427 } |
400 | 428 |
401 void BrowserPlugin::LoadStart(const GURL& url, bool is_top_level) { | 429 void BrowserPlugin::LoadStop() { |
402 if (!HasListeners(kLoadStartEventName)) | 430 if (!HasListeners(kLoadStopEventName)) |
403 return; | 431 return; |
404 | 432 |
405 WebKit::WebElement plugin = container()->element(); | 433 WebKit::WebElement plugin = container()->element(); |
406 v8::HandleScope handle_scope; | 434 v8::HandleScope handle_scope; |
407 v8::Context::Scope context_scope( | 435 v8::Context::Scope context_scope( |
408 plugin.document().frame()->mainWorldScriptContext()); | 436 plugin.document().frame()->mainWorldScriptContext()); |
409 | 437 |
410 // Construct the loadStart event object. | 438 // Construct the loadStop event object. |
411 v8::Local<v8::Object> event = v8::Object::New(); | 439 v8::Local<v8::Object> event = v8::Object::New(); |
412 event->Set(v8::String::New(kURL, sizeof(kURL) - 1), | |
413 v8::String::New(url.spec().data(), url.spec().size())); | |
414 event->Set(v8::String::New(kIsTopLevel, sizeof(kIsTopLevel) - 1), | |
415 v8::Boolean::New(is_top_level)); | |
416 v8::Local<v8::Value> val = event; | 440 v8::Local<v8::Value> val = event; |
417 | 441 |
418 // TODO(fsamuel): Copying the event listeners is insufficent because | 442 // TODO(fsamuel): Copying the event listeners is insufficent because |
419 // new persistent handles are not created when the copy constructor is | 443 // new persistent handles are not created when the copy constructor is |
420 // called. See http://crbug.com/155044. | 444 // called. See http://crbug.com/155044. |
421 EventListeners listeners(event_listener_map_[kLoadStartEventName]); | 445 EventListeners listeners(event_listener_map_[kLoadStopEventName]); |
422 EventListeners::iterator it = listeners.begin(); | 446 EventListeners::iterator it = listeners.begin(); |
423 for (; it != listeners.end(); ++it) { | 447 for (; it != listeners.end(); ++it) { |
424 WebKit::WebFrame* frame = plugin.document().frame(); | 448 WebKit::WebFrame* frame = plugin.document().frame(); |
425 if (frame) | 449 if (frame) |
426 frame->callFunctionEvenIfScriptDisabled(*it, v8::Object::New(), 1, &val); | 450 frame->callFunctionEvenIfScriptDisabled(*it, v8::Object::New(), 1, &val); |
427 } | 451 } |
428 } | 452 } |
429 | 453 |
430 void BrowserPlugin::LoadAbort(const GURL& url, | 454 void BrowserPlugin::LoadAbort(const GURL& url, |
431 bool is_top_level, | 455 bool is_top_level, |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
811 void* notify_data) { | 835 void* notify_data) { |
812 } | 836 } |
813 | 837 |
814 void BrowserPlugin::didFailLoadingFrameRequest( | 838 void BrowserPlugin::didFailLoadingFrameRequest( |
815 const WebKit::WebURL& url, | 839 const WebKit::WebURL& url, |
816 void* notify_data, | 840 void* notify_data, |
817 const WebKit::WebURLError& error) { | 841 const WebKit::WebURLError& error) { |
818 } | 842 } |
819 | 843 |
820 } // namespace content | 844 } // namespace content |
OLD | NEW |