| 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"; |
| 51 const char kLoadStopEventName[] = "loadStop"; |
| 50 const char kNavigationEventName[] = "navigation"; | 52 const char kNavigationEventName[] = "navigation"; |
| 51 const char kNewURL[] = "newUrl"; | 53 const char kNewURL[] = "newUrl"; |
| 52 const char kOldURL[] = "oldUrl"; | 54 const char kOldURL[] = "oldUrl"; |
| 53 const char kPartitionAttribute[] = "partition"; | 55 const char kPartitionAttribute[] = "partition"; |
| 54 const char kPersistPrefix[] = "persist:"; | 56 const char kPersistPrefix[] = "persist:"; |
| 55 const char kSrcAttribute[] = "src"; | 57 const char kSrcAttribute[] = "src"; |
| 56 const char kType[] = "type"; | 58 const char kType[] = "type"; |
| 57 const char kURL[] = "url"; | 59 const char kURL[] = "url"; |
| 58 } | 60 } |
| 59 | 61 |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 // called. See http://crbug.com/155044. | 350 // called. See http://crbug.com/155044. |
| 349 EventListeners listeners(event_listener_map_[kCrashEventName]); | 351 EventListeners listeners(event_listener_map_[kCrashEventName]); |
| 350 EventListeners::iterator it = listeners.begin(); | 352 EventListeners::iterator it = listeners.begin(); |
| 351 for (; it != listeners.end(); ++it) { | 353 for (; it != listeners.end(); ++it) { |
| 352 WebKit::WebFrame* frame = plugin.document().frame(); | 354 WebKit::WebFrame* frame = plugin.document().frame(); |
| 353 if (frame) | 355 if (frame) |
| 354 frame->callFunctionEvenIfScriptDisabled(*it, v8::Object::New(), 0, NULL); | 356 frame->callFunctionEvenIfScriptDisabled(*it, v8::Object::New(), 0, NULL); |
| 355 } | 357 } |
| 356 } | 358 } |
| 357 | 359 |
| 358 void BrowserPlugin::DidNavigate( | 360 void BrowserPlugin::LoadStart(const GURL& url, bool is_top_level) { |
| 359 const BrowserPluginMsg_DidNavigate_Params& params) { | 361 if (!HasListeners(kLoadStartEventName)) |
| 362 return; |
| 363 |
| 364 WebKit::WebElement plugin = container()->element(); |
| 365 v8::HandleScope handle_scope; |
| 366 v8::Context::Scope context_scope( |
| 367 plugin.document().frame()->mainWorldScriptContext()); |
| 368 |
| 369 // Construct the loadStart event object. |
| 370 v8::Local<v8::Object> event = v8::Object::New(); |
| 371 event->Set(v8::String::New(kURL, sizeof(kURL) - 1), |
| 372 v8::String::New(url.spec().data(), url.spec().size())); |
| 373 event->Set(v8::String::New(kIsTopLevel, sizeof(kIsTopLevel) - 1), |
| 374 v8::Boolean::New(is_top_level)); |
| 375 v8::Local<v8::Value> val = event; |
| 376 |
| 377 // TODO(fsamuel): Copying the event listeners is insufficent because |
| 378 // new persistent handles are not created when the copy constructor is |
| 379 // called. See http://crbug.com/155044. |
| 380 EventListeners listeners(event_listener_map_[kLoadStartEventName]); |
| 381 EventListeners::iterator it = listeners.begin(); |
| 382 for (; it != listeners.end(); ++it) { |
| 383 WebKit::WebFrame* frame = plugin.document().frame(); |
| 384 if (frame) |
| 385 frame->callFunctionEvenIfScriptDisabled(*it, v8::Object::New(), 1, &val); |
| 386 } |
| 387 } |
| 388 |
| 389 void BrowserPlugin::LoadCommit( |
| 390 const BrowserPluginMsg_LoadCommit_Params& params) { |
| 360 src_ = params.url.spec(); | 391 src_ = params.url.spec(); |
| 361 process_id_ = params.process_id; | 392 process_id_ = params.process_id; |
| 362 current_nav_entry_index_ = params.current_entry_index; | 393 current_nav_entry_index_ = params.current_entry_index; |
| 363 nav_entry_count_ = params.entry_count; | 394 nav_entry_count_ = params.entry_count; |
| 364 | 395 |
| 365 if (!HasListeners(kNavigationEventName)) | 396 if (!HasListeners(kLoadCommitEventName)) |
| 366 return; | 397 return; |
| 367 | 398 |
| 368 WebKit::WebElement plugin = container()->element(); | 399 WebKit::WebElement plugin = container()->element(); |
| 369 v8::HandleScope handle_scope; | 400 v8::HandleScope handle_scope; |
| 370 v8::Context::Scope context_scope( | 401 v8::Context::Scope context_scope( |
| 371 plugin.document().frame()->mainWorldScriptContext()); | 402 plugin.document().frame()->mainWorldScriptContext()); |
| 372 | 403 |
| 373 // Construct the navigation event object. | 404 // Construct the loadCommit event object. |
| 374 v8::Local<v8::Object> event = v8::Object::New(); | 405 v8::Local<v8::Object> event = v8::Object::New(); |
| 375 event->Set(v8::String::New(kURL, sizeof(kURL) - 1), | 406 event->Set(v8::String::New(kURL, sizeof(kURL) - 1), |
| 376 v8::String::New(src_.data(), src_.size())); | 407 v8::String::New(src_.data(), src_.size())); |
| 377 event->Set(v8::String::New(kIsTopLevel, sizeof(kIsTopLevel) - 1), | 408 event->Set(v8::String::New(kIsTopLevel, sizeof(kIsTopLevel) - 1), |
| 378 v8::Boolean::New(params.is_top_level)); | 409 v8::Boolean::New(params.is_top_level)); |
| 379 v8::Local<v8::Value> val = event; | 410 v8::Local<v8::Value> val = event; |
| 380 | 411 |
| 381 // TODO(fsamuel): Copying the event listeners is insufficent because | 412 // TODO(fsamuel): Copying the event listeners is insufficent because |
| 382 // new persistent handles are not created when the copy constructor is | 413 // new persistent handles are not created when the copy constructor is |
| 383 // called. See http://crbug.com/155044. | 414 // called. See http://crbug.com/155044. |
| 384 EventListeners listeners(event_listener_map_[kNavigationEventName]); | 415 EventListeners listeners(event_listener_map_[kLoadCommitEventName]); |
| 385 EventListeners::iterator it = listeners.begin(); | 416 EventListeners::iterator it = listeners.begin(); |
| 386 for (; it != listeners.end(); ++it) { | 417 for (; it != listeners.end(); ++it) { |
| 387 WebKit::WebFrame* frame = plugin.document().frame(); | 418 WebKit::WebFrame* frame = plugin.document().frame(); |
| 388 if (frame) { | 419 if (frame) |
| 389 frame->callFunctionEvenIfScriptDisabled( | 420 frame->callFunctionEvenIfScriptDisabled(*it, v8::Object::New(), 1, &val); |
| 390 *it, v8::Object::New(), 1, &val); | |
| 391 } | |
| 392 } | 421 } |
| 393 } | 422 } |
| 394 | 423 |
| 395 void BrowserPlugin::LoadStart(const GURL& url, bool is_top_level) { | 424 void BrowserPlugin::LoadStop() { |
| 396 if (!HasListeners(kLoadStartEventName)) | 425 if (!HasListeners(kLoadStopEventName)) |
| 397 return; | 426 return; |
| 398 | 427 |
| 399 WebKit::WebElement plugin = container()->element(); | 428 WebKit::WebElement plugin = container()->element(); |
| 400 v8::HandleScope handle_scope; | 429 v8::HandleScope handle_scope; |
| 401 v8::Context::Scope context_scope( | 430 v8::Context::Scope context_scope( |
| 402 plugin.document().frame()->mainWorldScriptContext()); | 431 plugin.document().frame()->mainWorldScriptContext()); |
| 403 | 432 |
| 404 // Construct the loadStart event object. | 433 // Construct the loadStop event object. |
| 405 v8::Local<v8::Object> event = v8::Object::New(); | 434 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 v8::Local<v8::Value> val = event; | 435 v8::Local<v8::Value> val = event; |
| 411 | 436 |
| 412 // TODO(fsamuel): Copying the event listeners is insufficent because | 437 // TODO(fsamuel): Copying the event listeners is insufficent because |
| 413 // new persistent handles are not created when the copy constructor is | 438 // new persistent handles are not created when the copy constructor is |
| 414 // called. See http://crbug.com/155044. | 439 // called. See http://crbug.com/155044. |
| 415 EventListeners listeners(event_listener_map_[kLoadStartEventName]); | 440 EventListeners listeners(event_listener_map_[kLoadStopEventName]); |
| 416 EventListeners::iterator it = listeners.begin(); | 441 EventListeners::iterator it = listeners.begin(); |
| 417 for (; it != listeners.end(); ++it) { | 442 for (; it != listeners.end(); ++it) { |
| 418 WebKit::WebFrame* frame = plugin.document().frame(); | 443 WebKit::WebFrame* frame = plugin.document().frame(); |
| 419 if (frame) | 444 if (frame) { |
| 420 frame->callFunctionEvenIfScriptDisabled(*it, v8::Object::New(), 1, &val); | 445 frame->callFunctionEvenIfScriptDisabled(*it, v8::Object::New(), 1, &val); |
| 446 } |
| 421 } | 447 } |
| 422 } | 448 } |
| 423 | 449 |
| 424 void BrowserPlugin::LoadAbort(const GURL& url, | 450 void BrowserPlugin::LoadAbort(const GURL& url, |
| 425 bool is_top_level, | 451 bool is_top_level, |
| 426 const std::string& type) { | 452 const std::string& type) { |
| 427 if (!HasListeners(kLoadAbortEventName)) | 453 if (!HasListeners(kLoadAbortEventName)) |
| 428 return; | 454 return; |
| 429 | 455 |
| 430 WebKit::WebElement plugin = container()->element(); | 456 WebKit::WebElement plugin = container()->element(); |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 796 void* notify_data) { | 822 void* notify_data) { |
| 797 } | 823 } |
| 798 | 824 |
| 799 void BrowserPlugin::didFailLoadingFrameRequest( | 825 void BrowserPlugin::didFailLoadingFrameRequest( |
| 800 const WebKit::WebURL& url, | 826 const WebKit::WebURL& url, |
| 801 void* notify_data, | 827 void* notify_data, |
| 802 const WebKit::WebURLError& error) { | 828 const WebKit::WebURLError& error) { |
| 803 } | 829 } |
| 804 | 830 |
| 805 } // namespace content | 831 } // namespace content |
| OLD | NEW |