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

Unified 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 Comments 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 side-by-side diff with in-line comments
Download patch
Index: content/renderer/browser_plugin/browser_plugin.cc
diff --git a/content/renderer/browser_plugin/browser_plugin.cc b/content/renderer/browser_plugin/browser_plugin.cc
index 6139b839c0b5fb59bee0e1fcb2196686c49dbba4..2886115e0174428ab22de302345da98295910ac4 100644
--- a/content/renderer/browser_plugin/browser_plugin.cc
+++ b/content/renderer/browser_plugin/browser_plugin.cc
@@ -45,9 +45,10 @@ namespace {
const char kCrashEventName[] = "crash";
const char kIsTopLevel[] = "isTopLevel";
const char kLoadAbortEventName[] = "loadAbort";
+const char kLoadCommitEventName[] = "loadCommit";
const char kLoadRedirectEventName[] = "loadRedirect";
const char kLoadStartEventName[] = "loadStart";
-const char kNavigationEventName[] = "navigation";
+const char kLoadStopEventName[] = "loadStop";
const char kNewURL[] = "newUrl";
const char kOldURL[] = "oldUrl";
const char kPartitionAttribute[] = "partition";
@@ -345,17 +346,43 @@ void BrowserPlugin::GuestCrashed() {
}
}
-void BrowserPlugin::DidNavigate(
- const BrowserPluginMsg_DidNavigate_Params& params) {
- // If the guest has just committed a new navigation then it is no longer
- // crashed.
- guest_crashed_ = false;
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.
+void BrowserPlugin::LoadStart(const GURL& url, bool is_top_level) {
+ if (!HasListeners(kLoadStartEventName))
+ return;
+
+ WebKit::WebElement plugin = container()->element();
+ v8::HandleScope handle_scope;
+ v8::Context::Scope context_scope(
+ plugin.document().frame()->mainWorldScriptContext());
+
+ // Construct the loadStart event object.
+ v8::Local<v8::Object> event = v8::Object::New();
+ event->Set(v8::String::New(kURL, sizeof(kURL) - 1),
+ v8::String::New(url.spec().data(), url.spec().size()));
+ event->Set(v8::String::New(kIsTopLevel, sizeof(kIsTopLevel) - 1),
+ v8::Boolean::New(is_top_level));
+ v8::Local<v8::Value> val = event;
+
+ // TODO(fsamuel): Copying the event listeners is insufficent because
+ // new persistent handles are not created when the copy constructor is
+ // called. See http://crbug.com/155044.
+ EventListeners listeners(event_listener_map_[kLoadStartEventName]);
+ EventListeners::iterator it = listeners.begin();
+ for (; it != listeners.end(); ++it) {
+ WebKit::WebFrame* frame = plugin.document().frame();
+ if (frame)
+ frame->callFunctionEvenIfScriptDisabled(*it, v8::Object::New(), 1, &val);
+ }
+}
+
+void BrowserPlugin::LoadCommit(
+ const BrowserPluginMsg_LoadCommit_Params& params) {
src_ = params.url.spec();
process_id_ = params.process_id;
current_nav_entry_index_ = params.current_entry_index;
nav_entry_count_ = params.entry_count;
- if (!HasListeners(kNavigationEventName))
+ if (!HasListeners(kLoadCommitEventName))
return;
WebKit::WebElement plugin = container()->element();
@@ -363,30 +390,28 @@ void BrowserPlugin::DidNavigate(
v8::Context::Scope context_scope(
plugin.document().frame()->mainWorldScriptContext());
- // Construct the navigation event object.
+ // Construct the loadCommit event object.
v8::Local<v8::Object> event = v8::Object::New();
event->Set(v8::String::New(kURL, sizeof(kURL) - 1),
- v8::String::New(src_.data(), src_.size()));
+ v8::String::New(src_.data(), src_.size()));
event->Set(v8::String::New(kIsTopLevel, sizeof(kIsTopLevel) - 1),
- v8::Boolean::New(params.is_top_level));
+ v8::Boolean::New(params.is_top_level));
v8::Local<v8::Value> val = event;
// TODO(fsamuel): Copying the event listeners is insufficent because
// new persistent handles are not created when the copy constructor is
// called. See http://crbug.com/155044.
- EventListeners listeners(event_listener_map_[kNavigationEventName]);
+ EventListeners listeners(event_listener_map_[kLoadCommitEventName]);
EventListeners::iterator it = listeners.begin();
for (; it != listeners.end(); ++it) {
WebKit::WebFrame* frame = plugin.document().frame();
- if (frame) {
- frame->callFunctionEvenIfScriptDisabled(
- *it, v8::Object::New(), 1, &val);
- }
+ if (frame)
+ frame->callFunctionEvenIfScriptDisabled(*it, v8::Object::New(), 1, &val);
}
}
-void BrowserPlugin::LoadStart(const GURL& url, bool is_top_level) {
- if (!HasListeners(kLoadStartEventName))
+void BrowserPlugin::LoadStop() {
+ if (!HasListeners(kLoadStopEventName))
return;
WebKit::WebElement plugin = container()->element();
@@ -394,23 +419,20 @@ void BrowserPlugin::LoadStart(const GURL& url, bool is_top_level) {
v8::Context::Scope context_scope(
plugin.document().frame()->mainWorldScriptContext());
- // Construct the loadStart event object.
+ // Construct the loadStop event object.
v8::Local<v8::Object> event = v8::Object::New();
- event->Set(v8::String::New(kURL, sizeof(kURL) - 1),
- v8::String::New(url.spec().data(), url.spec().size()));
- event->Set(v8::String::New(kIsTopLevel, sizeof(kIsTopLevel) - 1),
- v8::Boolean::New(is_top_level));
v8::Local<v8::Value> val = event;
// TODO(fsamuel): Copying the event listeners is insufficent because
// new persistent handles are not created when the copy constructor is
// called. See http://crbug.com/155044.
- EventListeners listeners(event_listener_map_[kLoadStartEventName]);
+ EventListeners listeners(event_listener_map_[kLoadStopEventName]);
EventListeners::iterator it = listeners.begin();
for (; it != listeners.end(); ++it) {
WebKit::WebFrame* frame = plugin.document().frame();
- if (frame)
+ 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.
frame->callFunctionEvenIfScriptDisabled(*it, v8::Object::New(), 1, &val);
+ }
}
}

Powered by Google App Engine
This is Rietveld 408576698