diff options
author | jochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-16 13:00:33 +0000 |
---|---|---|
committer | jochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-16 13:00:33 +0000 |
commit | b16b2a9d2f8107b6803c990cebf92f910ae238d5 (patch) | |
tree | 3140930ab7c5b5045aecfc06e25e21c8ea017215 /chrome/browser | |
parent | 4c028ff10f9a8a025d1490909ea257056bae0ad9 (diff) | |
download | chromium_src-b16b2a9d2f8107b6803c990cebf92f910ae238d5.zip chromium_src-b16b2a9d2f8107b6803c990cebf92f910ae238d5.tar.gz chromium_src-b16b2a9d2f8107b6803c990cebf92f910ae238d5.tar.bz2 |
Revert 59641 - Add the onBeforeNavigate and onErrorOccured events to the webNavigation API.
Also, rewrite the onCommitted event such that AUTO_SUBFRAME events are also registered.
The frameId and the requestId fields are still unimplemented.
Also, there occur navigation events after an error is reported.
BUG=50943
TEST=WebNavigationEvents
Review URL: http://codereview.chromium.org/3436002
TBR=jochen@chromium.org
Review URL: http://codereview.chromium.org/3389012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@59642 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
5 files changed, 19 insertions, 126 deletions
diff --git a/chrome/browser/extensions/extension_webnavigation_api.cc b/chrome/browser/extensions/extension_webnavigation_api.cc index de2442f..4a545fd 100644 --- a/chrome/browser/extensions/extension_webnavigation_api.cc +++ b/chrome/browser/extensions/extension_webnavigation_api.cc @@ -13,11 +13,9 @@ #include "chrome/browser/extensions/extension_tabs_module.h" #include "chrome/browser/extensions/extension_webnavigation_api_constants.h" #include "chrome/browser/profile.h" -#include "chrome/browser/tab_contents/navigation_controller.h" -#include "chrome/browser/tab_contents/provisional_load_details.h" +#include "chrome/browser/tab_contents/navigation_entry.h" #include "chrome/common/notification_type.h" #include "chrome/common/notification_service.h" -#include "net/base/net_errors.h" namespace keys = extension_webnavigation_api_constants; @@ -30,13 +28,7 @@ ExtensionWebNavigationEventRouter::GetInstance() { void ExtensionWebNavigationEventRouter::Init() { if (registrar_.IsEmpty()) { registrar_.Add(this, - NotificationType::FRAME_PROVISIONAL_LOAD_START, - NotificationService::AllSources()); - registrar_.Add(this, - NotificationType::FRAME_PROVISIONAL_LOAD_COMMITTED, - NotificationService::AllSources()); - registrar_.Add(this, - NotificationType::FAIL_PROVISIONAL_LOAD_WITH_ERROR, + NotificationType::NAV_ENTRY_COMMITTED, NotificationService::AllSources()); } } @@ -46,64 +38,35 @@ void ExtensionWebNavigationEventRouter::Observe( const NotificationSource& source, const NotificationDetails& details) { switch (type.value) { - case NotificationType::FRAME_PROVISIONAL_LOAD_START: - FrameProvisionalLoadStart( - Source<NavigationController>(source).ptr(), - Details<ProvisionalLoadDetails>(details).ptr()); - break; - case NotificationType::FRAME_PROVISIONAL_LOAD_COMMITTED: - FrameProvisionalLoadCommitted( - Source<NavigationController>(source).ptr(), - Details<ProvisionalLoadDetails>(details).ptr()); - break; - case NotificationType::FAIL_PROVISIONAL_LOAD_WITH_ERROR: - FailProvisionalLoadWithError( + case NotificationType::NAV_ENTRY_COMMITTED: + NavEntryCommitted( Source<NavigationController>(source).ptr(), - Details<ProvisionalLoadDetails>(details).ptr()); + Details<NavigationController::LoadCommittedDetails>(details).ptr()); break; default: NOTREACHED(); } } -void ExtensionWebNavigationEventRouter::FrameProvisionalLoadStart( - NavigationController* controller, - ProvisionalLoadDetails* details) { - ListValue args; - DictionaryValue* dict = new DictionaryValue(); - dict->SetInteger(keys::kTabIdKey, - ExtensionTabUtil::GetTabId(controller->tab_contents())); - dict->SetString(keys::kUrlKey, - details->url().spec()); - dict->SetInteger(keys::kFrameIdKey, 0); - dict->SetInteger(keys::kRequestIdKey, 0); - dict->SetReal(keys::kTimeStampKey, - (base::Time::Now() - base::Time::UnixEpoch()).InMilliseconds()); - args.Append(dict); - std::string json_args; - base::JSONWriter::Write(&args, false, &json_args); - DispatchEvent(controller->profile(), keys::kOnBeforeNavigate, json_args); -} - -void ExtensionWebNavigationEventRouter::FrameProvisionalLoadCommitted( +void ExtensionWebNavigationEventRouter::NavEntryCommitted( NavigationController* controller, - ProvisionalLoadDetails* details) { + NavigationController::LoadCommittedDetails* details) { ListValue args; DictionaryValue* dict = new DictionaryValue(); dict->SetInteger(keys::kTabIdKey, ExtensionTabUtil::GetTabId(controller->tab_contents())); dict->SetString(keys::kUrlKey, - details->url().spec()); - dict->SetInteger(keys::kFrameIdKey, 0); + details->entry->url().spec()); + dict->SetInteger(keys::kFrameIdKey, + details->is_main_frame ? 0 : details->entry->page_id()); dict->SetString(keys::kTransitionTypeKey, PageTransition::CoreTransitionString( - details->transition_type())); + details->entry->transition_type())); dict->SetString(keys::kTransitionQualifiersKey, PageTransition::QualifierString( - details->transition_type())); - dict->SetReal(keys::kTimeStampKey, - (base::Time::Now() - base::Time::UnixEpoch()).InMilliseconds()); + details->entry->transition_type())); + dict->SetReal(keys::kTimeStampKey, base::Time::Now().ToDoubleT()); args.Append(dict); std::string json_args; @@ -111,27 +74,6 @@ void ExtensionWebNavigationEventRouter::FrameProvisionalLoadCommitted( DispatchEvent(controller->profile(), keys::kOnCommitted, json_args); } -void ExtensionWebNavigationEventRouter::FailProvisionalLoadWithError( - NavigationController* controller, - ProvisionalLoadDetails* details) { - ListValue args; - DictionaryValue* dict = new DictionaryValue(); - dict->SetInteger(keys::kTabIdKey, - ExtensionTabUtil::GetTabId(controller->tab_contents())); - dict->SetString(keys::kUrlKey, - details->url().spec()); - dict->SetInteger(keys::kFrameIdKey, 0); - dict->SetString(keys::kErrorKey, - std::string(net::ErrorToString(details->error_code()))); - dict->SetReal(keys::kTimeStampKey, - (base::Time::Now() - base::Time::UnixEpoch()).InMilliseconds()); - args.Append(dict); - - std::string json_args; - base::JSONWriter::Write(&args, false, &json_args); - DispatchEvent(controller->profile(), keys::kOnErrorOccurred, json_args); -} - void ExtensionWebNavigationEventRouter::DispatchEvent( Profile* profile, const char* event_name, diff --git a/chrome/browser/extensions/extension_webnavigation_api.h b/chrome/browser/extensions/extension_webnavigation_api.h index 95ba032..77182e1 100644 --- a/chrome/browser/extensions/extension_webnavigation_api.h +++ b/chrome/browser/extensions/extension_webnavigation_api.h @@ -12,13 +12,10 @@ #include "base/singleton.h" #include "chrome/browser/extensions/extension_function.h" -#include "chrome/common/notification_observer.h" +#include "chrome/browser/tab_contents/navigation_controller.h" #include "chrome/common/notification_registrar.h" #include "googleurl/src/gurl.h" -class NavigationController; -class ProvisionalLoadDetails; - // Observes navigation notifications and routes them as events to the extension // system. class ExtensionWebNavigationEventRouter : public NotificationObserver { @@ -39,23 +36,11 @@ class ExtensionWebNavigationEventRouter : public NotificationObserver { const NotificationSource& source, const NotificationDetails& details); - // Handler for the FRAME_PROVISIONAL_LOAD_START event. The method takes the - // details of such an event and constructs a suitable JSON formatted extension - // event from it. - void FrameProvisionalLoadStart(NavigationController* controller, - ProvisionalLoadDetails* details); - - // Handler for the FRAME_PROVISIONAL_LOAD_COMMITTED event. The method takes - // the details of such an event and constructs a suitable JSON formatted - // extension event from it. - void FrameProvisionalLoadCommitted(NavigationController* controller, - ProvisionalLoadDetails* details); - - // Handler for the FAIL_PROVISIONAL_LOAD_WITH_ERROR event. The method takes - // the details of such an event and constructs a suitable JSON formatted - // extension event from it. - void FailProvisionalLoadWithError(NavigationController* controller, - ProvisionalLoadDetails* details); + // Handler for the NAV_ENTRY_COMMITTED event. The method takes the details of + // such an event and constructs a suitable JSON formatted extension event + // from it. + void NavEntryCommitted(NavigationController* controller, + NavigationController::LoadCommittedDetails* details); // This method dispatches events to the extension message service. void DispatchEvent(Profile* context, diff --git a/chrome/browser/tab_contents/provisional_load_details.cc b/chrome/browser/tab_contents/provisional_load_details.cc index e1e85d2..3bea977 100644 --- a/chrome/browser/tab_contents/provisional_load_details.cc +++ b/chrome/browser/tab_contents/provisional_load_details.cc @@ -13,7 +13,6 @@ ProvisionalLoadDetails::ProvisionalLoadDetails(bool is_main_frame, const std::string& security_info, bool is_content_filtered) : error_code_(net::OK), - transition_type_(PageTransition::LINK), url_(url), is_main_frame_(is_main_frame), is_in_page_navigation_(is_in_page_navigation), diff --git a/chrome/browser/tab_contents/provisional_load_details.h b/chrome/browser/tab_contents/provisional_load_details.h index 2073db0..92ac9b1 100644 --- a/chrome/browser/tab_contents/provisional_load_details.h +++ b/chrome/browser/tab_contents/provisional_load_details.h @@ -9,7 +9,6 @@ #include <string> #include "base/basictypes.h" -#include "chrome/common/page_transition_types.h" #include "googleurl/src/gurl.h" // This class captures some of the information associated to the provisional @@ -33,13 +32,6 @@ class ProvisionalLoadDetails { void set_error_code(int error_code) { error_code_ = error_code; } int error_code() const { return error_code_; } - void set_transition_type(PageTransition::Type transition_type) { - transition_type_ = transition_type; - } - PageTransition::Type transition_type() const { - return transition_type_; - } - const GURL& url() const { return url_; } bool main_frame() const { return is_main_frame_; } @@ -58,7 +50,6 @@ class ProvisionalLoadDetails { private: int error_code_; - PageTransition::Type transition_type_; GURL url_; bool is_main_frame_; bool is_in_page_navigation_; diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc index 1d702bd..67428ce 100644 --- a/chrome/browser/tab_contents/tab_contents.cc +++ b/chrome/browser/tab_contents/tab_contents.cc @@ -2452,30 +2452,6 @@ void TabContents::DidNavigate(RenderViewHost* rvh, bool did_navigate = controller_.RendererDidNavigate( params, extra_invalidate_flags, &details); - // Send notification about committed provisional loads. This notification is - // different from the NAV_ENTRY_COMMITTED notification which doesn't include - // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations. - if (details.type != NavigationType::NAV_IGNORE) { - ProvisionalLoadDetails load_details(details.is_main_frame, - details.is_in_page, - params.url, std::string(), false); - load_details.set_transition_type(params.transition); - // Whether or not a page transition was triggered by going backward or - // forward in the history is only stored in the navigation controller's - // entry list. - if (did_navigate && - (controller_.GetActiveEntry()->transition_type() & - PageTransition::FORWARD_BACK)) { - load_details.set_transition_type( - params.transition | PageTransition::FORWARD_BACK); - } - NotificationService::current()->Notify( - NotificationType::FRAME_PROVISIONAL_LOAD_COMMITTED, - Source<NavigationController>(&controller_), - Details<ProvisionalLoadDetails>(&load_details)); - - } - // Update history. Note that this needs to happen after the entry is complete, // which WillNavigate[Main,Sub]Frame will do before this function is called. if (params.should_update_history) { |