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

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 Test and Nits 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 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 // called. See http://crbug.com/155044. 338 // called. See http://crbug.com/155044.
338 EventListeners listeners(event_listener_map_[kCrashEventName]); 339 EventListeners listeners(event_listener_map_[kCrashEventName]);
339 EventListeners::iterator it = listeners.begin(); 340 EventListeners::iterator it = listeners.begin();
340 for (; it != listeners.end(); ++it) { 341 for (; it != listeners.end(); ++it) {
341 WebKit::WebFrame* frame = plugin.document().frame(); 342 WebKit::WebFrame* frame = plugin.document().frame();
342 if (frame) 343 if (frame)
343 frame->callFunctionEvenIfScriptDisabled(*it, v8::Object::New(), 0, NULL); 344 frame->callFunctionEvenIfScriptDisabled(*it, v8::Object::New(), 0, NULL);
344 } 345 }
345 } 346 }
346 347
347 void BrowserPlugin::DidNavigate(const GURL& url, int process_id) { 348 void BrowserPlugin::LoadStart(const GURL& url, bool is_top_level) {
348 src_ = url.spec(); 349 if (!HasListeners(kLoadStartEventName))
349 process_id_ = process_id;
350 if (!HasListeners(kNavigationEventName))
351 return; 350 return;
352 351
353 WebKit::WebElement plugin = container()->element(); 352 WebKit::WebElement plugin = container()->element();
354 v8::HandleScope handle_scope; 353 v8::HandleScope handle_scope;
355 v8::Context::Scope context_scope( 354 v8::Context::Scope context_scope(
356 plugin.document().frame()->mainWorldScriptContext()); 355 plugin.document().frame()->mainWorldScriptContext());
357 356
358 v8::Local<v8::Value> param = v8::String::New(src_.data(), src_.size()); 357 // Construct the loadStart event object.
358 v8::Local<v8::Object> event = v8::Object::New();
359 event->Set(v8::String::New(kURL, sizeof(kURL) - 1),
360 v8::String::New(url.spec().data(), url.spec().size()));
361 event->Set(v8::String::New(kIsTopLevel, sizeof(kIsTopLevel) - 1),
362 v8::Boolean::New(is_top_level));
363 v8::Local<v8::Value> val = event;
359 364
360 // TODO(fsamuel): Copying the event listeners is insufficent because 365 // TODO(fsamuel): Copying the event listeners is insufficent because
361 // new persistent handles are not created when the copy constructor is 366 // new persistent handles are not created when the copy constructor is
362 // called. See http://crbug.com/155044. 367 // called. See http://crbug.com/155044.
363 EventListeners listeners(event_listener_map_[kNavigationEventName]); 368 EventListeners listeners(event_listener_map_[kLoadStartEventName]);
364 EventListeners::iterator it = listeners.begin(); 369 EventListeners::iterator it = listeners.begin();
365 for (; it != listeners.end(); ++it) { 370 for (; it != listeners.end(); ++it) {
366 WebKit::WebFrame* frame = plugin.document().frame(); 371 WebKit::WebFrame* frame = plugin.document().frame();
367 if (frame) { 372 if (frame)
368 frame->callFunctionEvenIfScriptDisabled( 373 frame->callFunctionEvenIfScriptDisabled(*it, v8::Object::New(), 1, &val);
369 *it, v8::Object::New(), 1, &param);
370 }
371 } 374 }
372 } 375 }
373 376
374 void BrowserPlugin::LoadStart(const GURL& url, bool is_top_level) { 377 void BrowserPlugin::LoadCommit(
375 if (!HasListeners(kLoadStartEventName)) 378 const GURL& url,
379 int process_id,
380 bool is_top_level) {
381 process_id_ = process_id;
382 if (!HasListeners(kLoadCommitEventName))
376 return; 383 return;
377 384
378 WebKit::WebElement plugin = container()->element(); 385 WebKit::WebElement plugin = container()->element();
379 v8::HandleScope handle_scope; 386 v8::HandleScope handle_scope;
380 v8::Context::Scope context_scope( 387 v8::Context::Scope context_scope(
381 plugin.document().frame()->mainWorldScriptContext()); 388 plugin.document().frame()->mainWorldScriptContext());
382 389
383 // Construct the loadStart event object. 390 // Construct the loadCommit event object.
384 v8::Local<v8::Object> event = v8::Object::New(); 391 v8::Local<v8::Object> event = v8::Object::New();
385 event->Set(v8::String::New(kURL, sizeof(kURL) - 1), 392 event->Set(v8::String::New(kURL, sizeof(kURL) - 1),
386 v8::String::New(url.spec().data(), url.spec().size())); 393 v8::String::New(url.spec().data(), url.spec().size()));
387 event->Set(v8::String::New(kIsTopLevel, sizeof(kIsTopLevel) - 1), 394 event->Set(v8::String::New(kIsTopLevel, sizeof(kIsTopLevel) - 1),
388 v8::Boolean::New(is_top_level)); 395 v8::Boolean::New(is_top_level));
389 v8::Local<v8::Value> val = event; 396 v8::Local<v8::Value> val = event;
390 397
391 // TODO(fsamuel): Copying the event listeners is insufficent because 398 // TODO(fsamuel): Copying the event listeners is insufficent because
392 // new persistent handles are not created when the copy constructor is 399 // new persistent handles are not created when the copy constructor is
393 // called. See http://crbug.com/155044. 400 // called. See http://crbug.com/155044.
394 EventListeners listeners(event_listener_map_[kLoadStartEventName]); 401 EventListeners listeners(event_listener_map_[kLoadCommitEventName]);
395 EventListeners::iterator it = listeners.begin(); 402 EventListeners::iterator it = listeners.begin();
396 for (; it != listeners.end(); ++it) { 403 for (; it != listeners.end(); ++it) {
397 WebKit::WebFrame* frame = plugin.document().frame(); 404 WebKit::WebFrame* frame = plugin.document().frame();
398 if (frame) 405 if (frame)
399 frame->callFunctionEvenIfScriptDisabled(*it, v8::Object::New(), 1, &val); 406 frame->callFunctionEvenIfScriptDisabled(*it, v8::Object::New(), 1, &val);
400 } 407 }
401 } 408 }
402 409
410 void BrowserPlugin::LoadStop() {
411 if (!HasListeners(kLoadStopEventName))
412 return;
413
414 WebKit::WebElement plugin = container()->element();
415 v8::HandleScope handle_scope;
416 v8::Context::Scope context_scope(
417 plugin.document().frame()->mainWorldScriptContext());
418
419 // Construct the loadStop event object.
420 v8::Local<v8::Object> event = v8::Object::New();
421 v8::Local<v8::Value> val = event;
422
423 // TODO(fsamuel): Copying the event listeners is insufficent because
424 // new persistent handles are not created when the copy constructor is
425 // called. See http://crbug.com/155044.
426 EventListeners listeners(event_listener_map_[kLoadStopEventName]);
427 EventListeners::iterator it = listeners.begin();
428 for (; it != listeners.end(); ++it) {
429 WebKit::WebFrame* frame = plugin.document().frame();
430 if (frame) {
431 frame->callFunctionEvenIfScriptDisabled(*it, v8::Object::New(), 1, &val);
432 }
433 }
434 }
435
403 void BrowserPlugin::LoadAbort(const GURL& url, 436 void BrowserPlugin::LoadAbort(const GURL& url,
404 bool is_top_level, 437 bool is_top_level,
405 const std::string& type) { 438 const std::string& type) {
406 if (!HasListeners(kLoadAbortEventName)) 439 if (!HasListeners(kLoadAbortEventName))
407 return; 440 return;
408 441
409 WebKit::WebElement plugin = container()->element(); 442 WebKit::WebElement plugin = container()->element();
410 v8::HandleScope handle_scope; 443 v8::HandleScope handle_scope;
411 v8::Context::Scope context_scope( 444 v8::Context::Scope context_scope(
412 plugin.document().frame()->mainWorldScriptContext()); 445 plugin.document().frame()->mainWorldScriptContext());
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
757 void* notify_data) { 790 void* notify_data) {
758 } 791 }
759 792
760 void BrowserPlugin::didFailLoadingFrameRequest( 793 void BrowserPlugin::didFailLoadingFrameRequest(
761 const WebKit::WebURL& url, 794 const WebKit::WebURL& url,
762 void* notify_data, 795 void* notify_data,
763 const WebKit::WebURLError& error) { 796 const WebKit::WebURLError& error) {
764 } 797 }
765 798
766 } // namespace content 799 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698