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 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
338 // called. See http://crbug.com/155044. | 339 // called. See http://crbug.com/155044. |
339 EventListeners listeners(event_listener_map_[kCrashEventName]); | 340 EventListeners listeners(event_listener_map_[kCrashEventName]); |
340 EventListeners::iterator it = listeners.begin(); | 341 EventListeners::iterator it = listeners.begin(); |
341 for (; it != listeners.end(); ++it) { | 342 for (; it != listeners.end(); ++it) { |
342 WebKit::WebFrame* frame = plugin.document().frame(); | 343 WebKit::WebFrame* frame = plugin.document().frame(); |
343 if (frame) | 344 if (frame) |
344 frame->callFunctionEvenIfScriptDisabled(*it, v8::Object::New(), 0, NULL); | 345 frame->callFunctionEvenIfScriptDisabled(*it, v8::Object::New(), 0, NULL); |
345 } | 346 } |
346 } | 347 } |
347 | 348 |
348 void BrowserPlugin::DidNavigate( | 349 void BrowserPlugin::LoadStart(const GURL& url, bool is_top_level) { |
349 const BrowserPluginMsg_DidNavigate_Params& params) { | 350 if (!HasListeners(kLoadStartEventName)) |
350 // If the guest has just committed a new navigation then it is no longer | 351 return; |
351 // crashed. | 352 |
352 guest_crashed_ = false; | 353 WebKit::WebElement plugin = container()->element(); |
Charlie Reis
2012/10/16 21:17:55
Please keep these three lines at the start of Load
irobert
2012/10/17 20:12:37
Done.
| |
354 v8::HandleScope handle_scope; | |
355 v8::Context::Scope context_scope( | |
356 plugin.document().frame()->mainWorldScriptContext()); | |
357 | |
358 // Construct the loadStart event object. | |
359 v8::Local<v8::Object> event = v8::Object::New(); | |
360 event->Set(v8::String::New(kURL, sizeof(kURL) - 1), | |
361 v8::String::New(url.spec().data(), url.spec().size())); | |
362 event->Set(v8::String::New(kIsTopLevel, sizeof(kIsTopLevel) - 1), | |
363 v8::Boolean::New(is_top_level)); | |
364 v8::Local<v8::Value> val = event; | |
365 | |
366 // TODO(fsamuel): Copying the event listeners is insufficent because | |
367 // new persistent handles are not created when the copy constructor is | |
368 // called. See http://crbug.com/155044. | |
369 EventListeners listeners(event_listener_map_[kLoadStartEventName]); | |
370 EventListeners::iterator it = listeners.begin(); | |
371 for (; it != listeners.end(); ++it) { | |
372 WebKit::WebFrame* frame = plugin.document().frame(); | |
373 if (frame) | |
374 frame->callFunctionEvenIfScriptDisabled(*it, v8::Object::New(), 1, &val); | |
375 } | |
376 } | |
377 | |
378 void BrowserPlugin::LoadCommit( | |
379 const BrowserPluginMsg_LoadCommit_Params& params) { | |
353 src_ = params.url.spec(); | 380 src_ = params.url.spec(); |
354 process_id_ = params.process_id; | 381 process_id_ = params.process_id; |
355 current_nav_entry_index_ = params.current_entry_index; | 382 current_nav_entry_index_ = params.current_entry_index; |
356 nav_entry_count_ = params.entry_count; | 383 nav_entry_count_ = params.entry_count; |
357 | 384 |
358 if (!HasListeners(kNavigationEventName)) | 385 if (!HasListeners(kLoadCommitEventName)) |
359 return; | 386 return; |
360 | 387 |
361 WebKit::WebElement plugin = container()->element(); | 388 WebKit::WebElement plugin = container()->element(); |
362 v8::HandleScope handle_scope; | 389 v8::HandleScope handle_scope; |
363 v8::Context::Scope context_scope( | 390 v8::Context::Scope context_scope( |
364 plugin.document().frame()->mainWorldScriptContext()); | 391 plugin.document().frame()->mainWorldScriptContext()); |
365 | 392 |
366 // Construct the navigation event object. | 393 // Construct the loadCommit event object. |
367 v8::Local<v8::Object> event = v8::Object::New(); | 394 v8::Local<v8::Object> event = v8::Object::New(); |
368 event->Set(v8::String::New(kURL, sizeof(kURL) - 1), | 395 event->Set(v8::String::New(kURL, sizeof(kURL) - 1), |
369 v8::String::New(src_.data(), src_.size())); | 396 v8::String::New(src_.data(), src_.size())); |
370 event->Set(v8::String::New(kIsTopLevel, sizeof(kIsTopLevel) - 1), | 397 event->Set(v8::String::New(kIsTopLevel, sizeof(kIsTopLevel) - 1), |
371 v8::Boolean::New(params.is_top_level)); | 398 v8::Boolean::New(params.is_top_level)); |
372 v8::Local<v8::Value> val = event; | 399 v8::Local<v8::Value> val = event; |
373 | 400 |
374 // TODO(fsamuel): Copying the event listeners is insufficent because | 401 // TODO(fsamuel): Copying the event listeners is insufficent because |
375 // new persistent handles are not created when the copy constructor is | 402 // new persistent handles are not created when the copy constructor is |
376 // called. See http://crbug.com/155044. | 403 // called. See http://crbug.com/155044. |
377 EventListeners listeners(event_listener_map_[kNavigationEventName]); | 404 EventListeners listeners(event_listener_map_[kLoadCommitEventName]); |
378 EventListeners::iterator it = listeners.begin(); | 405 EventListeners::iterator it = listeners.begin(); |
379 for (; it != listeners.end(); ++it) { | 406 for (; it != listeners.end(); ++it) { |
380 WebKit::WebFrame* frame = plugin.document().frame(); | 407 WebKit::WebFrame* frame = plugin.document().frame(); |
381 if (frame) { | 408 if (frame) |
382 frame->callFunctionEvenIfScriptDisabled( | 409 frame->callFunctionEvenIfScriptDisabled(*it, v8::Object::New(), 1, &val); |
383 *it, v8::Object::New(), 1, &val); | |
384 } | |
385 } | 410 } |
386 } | 411 } |
387 | 412 |
388 void BrowserPlugin::LoadStart(const GURL& url, bool is_top_level) { | 413 void BrowserPlugin::LoadStop() { |
389 if (!HasListeners(kLoadStartEventName)) | 414 if (!HasListeners(kLoadStopEventName)) |
390 return; | 415 return; |
391 | 416 |
392 WebKit::WebElement plugin = container()->element(); | 417 WebKit::WebElement plugin = container()->element(); |
393 v8::HandleScope handle_scope; | 418 v8::HandleScope handle_scope; |
394 v8::Context::Scope context_scope( | 419 v8::Context::Scope context_scope( |
395 plugin.document().frame()->mainWorldScriptContext()); | 420 plugin.document().frame()->mainWorldScriptContext()); |
396 | 421 |
397 // Construct the loadStart event object. | 422 // Construct the loadStop event object. |
398 v8::Local<v8::Object> event = v8::Object::New(); | 423 v8::Local<v8::Object> event = v8::Object::New(); |
399 event->Set(v8::String::New(kURL, sizeof(kURL) - 1), | |
400 v8::String::New(url.spec().data(), url.spec().size())); | |
401 event->Set(v8::String::New(kIsTopLevel, sizeof(kIsTopLevel) - 1), | |
402 v8::Boolean::New(is_top_level)); | |
403 v8::Local<v8::Value> val = event; | 424 v8::Local<v8::Value> val = event; |
404 | 425 |
405 // TODO(fsamuel): Copying the event listeners is insufficent because | 426 // TODO(fsamuel): Copying the event listeners is insufficent because |
406 // new persistent handles are not created when the copy constructor is | 427 // new persistent handles are not created when the copy constructor is |
407 // called. See http://crbug.com/155044. | 428 // called. See http://crbug.com/155044. |
408 EventListeners listeners(event_listener_map_[kLoadStartEventName]); | 429 EventListeners listeners(event_listener_map_[kLoadStopEventName]); |
409 EventListeners::iterator it = listeners.begin(); | 430 EventListeners::iterator it = listeners.begin(); |
410 for (; it != listeners.end(); ++it) { | 431 for (; it != listeners.end(); ++it) { |
411 WebKit::WebFrame* frame = plugin.document().frame(); | 432 WebKit::WebFrame* frame = plugin.document().frame(); |
412 if (frame) | 433 if (frame) { |
Charlie Reis
2012/10/16 21:17:55
nit: No braces needed, since both the conditional
irobert
2012/10/17 20:12:37
Done.
| |
413 frame->callFunctionEvenIfScriptDisabled(*it, v8::Object::New(), 1, &val); | 434 frame->callFunctionEvenIfScriptDisabled(*it, v8::Object::New(), 1, &val); |
435 } | |
414 } | 436 } |
415 } | 437 } |
416 | 438 |
417 void BrowserPlugin::LoadAbort(const GURL& url, | 439 void BrowserPlugin::LoadAbort(const GURL& url, |
418 bool is_top_level, | 440 bool is_top_level, |
419 const std::string& type) { | 441 const std::string& type) { |
420 if (!HasListeners(kLoadAbortEventName)) | 442 if (!HasListeners(kLoadAbortEventName)) |
421 return; | 443 return; |
422 | 444 |
423 WebKit::WebElement plugin = container()->element(); | 445 WebKit::WebElement plugin = container()->element(); |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
789 void* notify_data) { | 811 void* notify_data) { |
790 } | 812 } |
791 | 813 |
792 void BrowserPlugin::didFailLoadingFrameRequest( | 814 void BrowserPlugin::didFailLoadingFrameRequest( |
793 const WebKit::WebURL& url, | 815 const WebKit::WebURL& url, |
794 void* notify_data, | 816 void* notify_data, |
795 const WebKit::WebURLError& error) { | 817 const WebKit::WebURLError& error) { |
796 } | 818 } |
797 | 819 |
798 } // namespace content | 820 } // namespace content |
OLD | NEW |