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