Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(378)

Side by Side Diff: content/renderer/browser_plugin/browser_plugin.cc

Issue 11035067: Add loadCommit and loadStop Event (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix Merge Conflict Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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))
351 return;
352
353 WebKit::WebElement plugin = container()->element();
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) {
350 // If the guest has just committed a new navigation then it is no longer 380 // If the guest has just committed a new navigation then it is no longer
351 // crashed. 381 // crashed.
352 guest_crashed_ = false; 382 guest_crashed_ = false;
353 src_ = params.url.spec(); 383 src_ = params.url.spec();
354 process_id_ = params.process_id; 384 process_id_ = params.process_id;
355 current_nav_entry_index_ = params.current_entry_index; 385 current_nav_entry_index_ = params.current_entry_index;
356 nav_entry_count_ = params.entry_count; 386 nav_entry_count_ = params.entry_count;
357 387
358 if (!HasListeners(kNavigationEventName)) 388 if (!HasListeners(kLoadCommitEventName))
359 return; 389 return;
360 390
361 WebKit::WebElement plugin = container()->element(); 391 WebKit::WebElement plugin = container()->element();
362 v8::HandleScope handle_scope; 392 v8::HandleScope handle_scope;
363 v8::Context::Scope context_scope( 393 v8::Context::Scope context_scope(
364 plugin.document().frame()->mainWorldScriptContext()); 394 plugin.document().frame()->mainWorldScriptContext());
365 395
366 // Construct the navigation event object. 396 // Construct the loadCommit event object.
367 v8::Local<v8::Object> event = v8::Object::New(); 397 v8::Local<v8::Object> event = v8::Object::New();
368 event->Set(v8::String::New(kURL, sizeof(kURL) - 1), 398 event->Set(v8::String::New(kURL, sizeof(kURL) - 1),
369 v8::String::New(src_.data(), src_.size())); 399 v8::String::New(src_.data(), src_.size()));
Charlie Reis 2012/10/17 21:27:08 nit: No need to change the indent on these two lin
irobert 2012/10/18 01:42:25 Done.
370 event->Set(v8::String::New(kIsTopLevel, sizeof(kIsTopLevel) - 1), 400 event->Set(v8::String::New(kIsTopLevel, sizeof(kIsTopLevel) - 1),
371 v8::Boolean::New(params.is_top_level)); 401 v8::Boolean::New(params.is_top_level));
372 v8::Local<v8::Value> val = event; 402 v8::Local<v8::Value> val = event;
373 403
374 // TODO(fsamuel): Copying the event listeners is insufficent because 404 // TODO(fsamuel): Copying the event listeners is insufficent because
375 // new persistent handles are not created when the copy constructor is 405 // new persistent handles are not created when the copy constructor is
376 // called. See http://crbug.com/155044. 406 // called. See http://crbug.com/155044.
377 EventListeners listeners(event_listener_map_[kNavigationEventName]); 407 EventListeners listeners(event_listener_map_[kLoadCommitEventName]);
378 EventListeners::iterator it = listeners.begin(); 408 EventListeners::iterator it = listeners.begin();
379 for (; it != listeners.end(); ++it) { 409 for (; it != listeners.end(); ++it) {
380 WebKit::WebFrame* frame = plugin.document().frame(); 410 WebKit::WebFrame* frame = plugin.document().frame();
381 if (frame) { 411 if (frame)
382 frame->callFunctionEvenIfScriptDisabled( 412 frame->callFunctionEvenIfScriptDisabled(*it, v8::Object::New(), 1, &val);
383 *it, v8::Object::New(), 1, &val);
384 }
385 } 413 }
386 } 414 }
387 415
388 void BrowserPlugin::LoadStart(const GURL& url, bool is_top_level) { 416 void BrowserPlugin::LoadStop() {
389 if (!HasListeners(kLoadStartEventName)) 417 if (!HasListeners(kLoadStopEventName))
390 return; 418 return;
391 419
392 WebKit::WebElement plugin = container()->element(); 420 WebKit::WebElement plugin = container()->element();
393 v8::HandleScope handle_scope; 421 v8::HandleScope handle_scope;
394 v8::Context::Scope context_scope( 422 v8::Context::Scope context_scope(
395 plugin.document().frame()->mainWorldScriptContext()); 423 plugin.document().frame()->mainWorldScriptContext());
396 424
397 // Construct the loadStart event object. 425 // Construct the loadStop event object.
398 v8::Local<v8::Object> event = v8::Object::New(); 426 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; 427 v8::Local<v8::Value> val = event;
404 428
405 // TODO(fsamuel): Copying the event listeners is insufficent because 429 // TODO(fsamuel): Copying the event listeners is insufficent because
406 // new persistent handles are not created when the copy constructor is 430 // new persistent handles are not created when the copy constructor is
407 // called. See http://crbug.com/155044. 431 // called. See http://crbug.com/155044.
408 EventListeners listeners(event_listener_map_[kLoadStartEventName]); 432 EventListeners listeners(event_listener_map_[kLoadStopEventName]);
409 EventListeners::iterator it = listeners.begin(); 433 EventListeners::iterator it = listeners.begin();
410 for (; it != listeners.end(); ++it) { 434 for (; it != listeners.end(); ++it) {
411 WebKit::WebFrame* frame = plugin.document().frame(); 435 WebKit::WebFrame* frame = plugin.document().frame();
412 if (frame) 436 if (frame)
413 frame->callFunctionEvenIfScriptDisabled(*it, v8::Object::New(), 1, &val); 437 frame->callFunctionEvenIfScriptDisabled(*it, v8::Object::New(), 1, &val);
414 } 438 }
415 } 439 }
416 440
417 void BrowserPlugin::LoadAbort(const GURL& url, 441 void BrowserPlugin::LoadAbort(const GURL& url,
418 bool is_top_level, 442 bool is_top_level,
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
789 void* notify_data) { 813 void* notify_data) {
790 } 814 }
791 815
792 void BrowserPlugin::didFailLoadingFrameRequest( 816 void BrowserPlugin::didFailLoadingFrameRequest(
793 const WebKit::WebURL& url, 817 const WebKit::WebURL& url,
794 void* notify_data, 818 void* notify_data,
795 const WebKit::WebURLError& error) { 819 const WebKit::WebURLError& error) {
796 } 820 }
797 821
798 } // namespace content 822 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698