diff options
author | jochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-21 18:52:00 +0000 |
---|---|---|
committer | jochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-21 18:52:00 +0000 |
commit | 420e5740babf87df0630964c42ca3c0d34a318c0 (patch) | |
tree | a1f744c51c545dcc1c2e15f610775c1b17e97bb1 /chrome/browser/extensions | |
parent | ad74a59d383e658187ae48d084c7a65145d84449 (diff) | |
download | chromium_src-420e5740babf87df0630964c42ca3c0d34a318c0.zip chromium_src-420e5740babf87df0630964c42ca3c0d34a318c0.tar.gz chromium_src-420e5740babf87df0630964c42ca3c0d34a318c0.tar.bz2 |
Implement the onBeforeRetarget event of the webNavigation API
TEST=none
BUG=50943
Review URL: http://codereview.chromium.org/6363002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@72163 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions')
-rw-r--r-- | chrome/browser/extensions/extension_webnavigation_api.cc | 29 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_webnavigation_api.h | 7 |
2 files changed, 35 insertions, 1 deletions
diff --git a/chrome/browser/extensions/extension_webnavigation_api.cc b/chrome/browser/extensions/extension_webnavigation_api.cc index 2e3a1ca..dd755e3 100644 --- a/chrome/browser/extensions/extension_webnavigation_api.cc +++ b/chrome/browser/extensions/extension_webnavigation_api.cc @@ -15,8 +15,9 @@ #include "chrome/browser/profiles/profile.h" #include "chrome/browser/tab_contents/navigation_controller.h" #include "chrome/browser/tab_contents/provisional_load_details.h" -#include "chrome/common/notification_type.h" +#include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/common/notification_service.h" +#include "chrome/common/render_messages_params.h" #include "net/base/net_errors.h" namespace keys = extension_webnavigation_api_constants; @@ -126,6 +127,9 @@ void ExtensionWebNavigationEventRouter::Init() { NotificationType::FAIL_PROVISIONAL_LOAD_WITH_ERROR, NotificationService::AllSources()); registrar_.Add(this, + NotificationType::CREATING_NEW_WINDOW, + NotificationService::AllSources()); + registrar_.Add(this, NotificationType::TAB_CONTENTS_DESTROYED, NotificationService::AllSources()); } @@ -161,6 +165,11 @@ void ExtensionWebNavigationEventRouter::Observe( Source<NavigationController>(source).ptr(), Details<ProvisionalLoadDetails>(details).ptr()); break; + case NotificationType::CREATING_NEW_WINDOW: + CreatingNewWindow( + Source<TabContents>(source).ptr(), + Details<const ViewHostMsg_CreateWindow_Params>(details).ptr()); + break; case NotificationType::TAB_CONTENTS_DESTROYED: navigation_state_.RemoveTabContentsState( Source<TabContents>(source).ptr()); @@ -282,6 +291,24 @@ void ExtensionWebNavigationEventRouter::FailProvisionalLoadWithError( DispatchEvent(controller->profile(), keys::kOnErrorOccurred, json_args); } +void ExtensionWebNavigationEventRouter::CreatingNewWindow( + TabContents* tab_contents, + const ViewHostMsg_CreateWindow_Params* details) { + ListValue args; + DictionaryValue* dict = new DictionaryValue(); + dict->SetInteger(keys::kSourceTabIdKey, + ExtensionTabUtil::GetTabId(tab_contents)); + dict->SetString(keys::kSourceUrlKey, details->opener_url.spec()); + dict->SetString(keys::kTargetUrlKey, + details->target_url.possibly_invalid_spec()); + dict->SetReal(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now())); + args.Append(dict); + + std::string json_args; + base::JSONWriter::Write(&args, false, &json_args); + DispatchEvent(tab_contents->profile(), keys::kOnBeforeRetarget, 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 0f5948e..0ecac0d 100644 --- a/chrome/browser/extensions/extension_webnavigation_api.h +++ b/chrome/browser/extensions/extension_webnavigation_api.h @@ -21,6 +21,7 @@ class NavigationController; class ProvisionalLoadDetails; class TabContents; +struct ViewHostMsg_CreateWindow_Params; // Tracks the navigation state of all frames currently known to the // webNavigation API. It is mainly used to track in which frames an error @@ -121,6 +122,12 @@ class ExtensionWebNavigationEventRouter : public NotificationObserver { void FailProvisionalLoadWithError(NavigationController* controller, ProvisionalLoadDetails* details); + // Handler for the CREATING_NEW_WINDOW event. The method takes the details of + // such an event and constructs a suitable JSON formatted extension event from + // it. + void CreatingNewWindow(TabContents* tab_content, + const ViewHostMsg_CreateWindow_Params* details); + // Dispatches events to the extension message service. void DispatchEvent(Profile* context, const char* event_name, |