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

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: With improved approach to creating the event listeners 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::LoadStop() {
348 src_ = url.spec(); 349 if (!HasListeners(kLoadStopEventName))
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();
353 v8::HandleScope handle_scope;
354 v8::Context::Scope context_scope(
355 plugin.document().frame()->mainWorldScriptContext());
356
357 // Construct the loadStop event object.
358 v8::Local<v8::Object> event = v8::Object::New();
359 v8::Local<v8::Value> val = event;
360
361 // TODO(fsamuel): Copying the event listeners is insufficent because
362 // new persistent handles are not created when the copy constructor is
363 // called. See http://crbug.com/155044.
364 EventListeners listeners(event_listener_map_[kLoadStopEventName]);
365 EventListeners::iterator it = listeners.begin();
366 for (; it != listeners.end(); ++it) {
367 WebKit::WebFrame* frame = plugin.document().frame();
368 if (frame) {
369 frame->callFunctionEvenIfScriptDisabled(*it, v8::Object::New(), 1, &val);
370 }
371 }
372 }
373
374 void BrowserPlugin::LoadCommit(
375 const GURL& url,
376 int process_id,
377 bool is_top_level) {
378 process_id_ = process_id;
379 if (!HasListeners(kLoadCommitEventName))
380 return;
381
382 WebKit::WebElement plugin = container()->element();
354 v8::HandleScope handle_scope; 383 v8::HandleScope handle_scope;
355 v8::Context::Scope context_scope( 384 v8::Context::Scope context_scope(
356 plugin.document().frame()->mainWorldScriptContext()); 385 plugin.document().frame()->mainWorldScriptContext());
357 386
358 v8::Local<v8::Value> param = v8::String::New(src_.data(), src_.size()); 387 // Construct the loadCommit event object.
388 v8::Local<v8::Object> event = v8::Object::New();
389 event->Set(v8::String::New(kURL, sizeof(kURL) - 1),
390 v8::String::New(url.spec().data(), url.spec().size()));
391 event->Set(v8::String::New(kIsTopLevel, sizeof(kIsTopLevel) - 1),
392 v8::Boolean::New(is_top_level));
393 v8::Local<v8::Value> val = event;
359 394
360 // TODO(fsamuel): Copying the event listeners is insufficent because 395 // TODO(fsamuel): Copying the event listeners is insufficent because
361 // new persistent handles are not created when the copy constructor is 396 // new persistent handles are not created when the copy constructor is
362 // called. See http://crbug.com/155044. 397 // called. See http://crbug.com/155044.
363 EventListeners listeners(event_listener_map_[kNavigationEventName]); 398 EventListeners listeners(event_listener_map_[kLoadCommitEventName]);
364 EventListeners::iterator it = listeners.begin(); 399 EventListeners::iterator it = listeners.begin();
365 for (; it != listeners.end(); ++it) { 400 for (; it != listeners.end(); ++it) {
366 WebKit::WebFrame* frame = plugin.document().frame(); 401 WebKit::WebFrame* frame = plugin.document().frame();
367 if (frame) { 402 if (frame) {
368 frame->callFunctionEvenIfScriptDisabled( 403 frame->callFunctionEvenIfScriptDisabled(*it, v8::Object::New(), 1, &val);
369 *it, v8::Object::New(), 1, &param);
370 } 404 }
371 } 405 }
372 } 406 }
373 407
374 void BrowserPlugin::LoadStart(const GURL& url, bool is_top_level) { 408 void BrowserPlugin::LoadStart(const GURL& url, bool is_top_level) {
375 if (!HasListeners(kLoadStartEventName)) 409 if (!HasListeners(kLoadStartEventName))
376 return; 410 return;
377 411
378 WebKit::WebElement plugin = container()->element(); 412 WebKit::WebElement plugin = container()->element();
379 v8::HandleScope handle_scope; 413 v8::HandleScope handle_scope;
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
757 void* notify_data) { 791 void* notify_data) {
758 } 792 }
759 793
760 void BrowserPlugin::didFailLoadingFrameRequest( 794 void BrowserPlugin::didFailLoadingFrameRequest(
761 const WebKit::WebURL& url, 795 const WebKit::WebURL& url,
762 void* notify_data, 796 void* notify_data,
763 const WebKit::WebURLError& error) { 797 const WebKit::WebURLError& error) {
764 } 798 }
765 799
766 } // namespace content 800 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698