summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/extensions/extension_webnavigation_api.cc29
-rw-r--r--chrome/browser/extensions/extension_webnavigation_api.h6
-rw-r--r--chrome/browser/extensions/extension_webnavigation_apitest.cc34
3 files changed, 68 insertions, 1 deletions
diff --git a/chrome/browser/extensions/extension_webnavigation_api.cc b/chrome/browser/extensions/extension_webnavigation_api.cc
index 66643ee..b675871 100644
--- a/chrome/browser/extensions/extension_webnavigation_api.cc
+++ b/chrome/browser/extensions/extension_webnavigation_api.cc
@@ -576,6 +576,35 @@ void ExtensionWebNavigationTabObserver::DidFinishLoad(
frame_id);
}
+void ExtensionWebNavigationTabObserver::DidOpenRequestedURL(
+ TabContents* new_contents,
+ const GURL& url,
+ const GURL& referrer,
+ WindowOpenDisposition disposition,
+ PageTransition::Type transition,
+ int64 source_frame_id) {
+ if (!navigation_state_.CanSendEvents(source_frame_id))
+ return;
+
+ // We only send the onCreatedNavigationTarget if we end up creating a new
+ // window.
+ if (disposition != SINGLETON_TAB &&
+ disposition != NEW_FOREGROUND_TAB &&
+ disposition != NEW_BACKGROUND_TAB &&
+ disposition != NEW_POPUP &&
+ disposition != NEW_WINDOW &&
+ disposition != OFF_THE_RECORD)
+ return;
+
+ DispatchOnCreatedNavigationTarget(
+ tab_contents(),
+ new_contents->browser_context(),
+ source_frame_id,
+ navigation_state_.IsMainFrame(source_frame_id),
+ new_contents,
+ url);
+}
+
void ExtensionWebNavigationTabObserver::TabContentsDestroyed(
TabContents* tab) {
g_tab_observer.Get().erase(tab);
diff --git a/chrome/browser/extensions/extension_webnavigation_api.h b/chrome/browser/extensions/extension_webnavigation_api.h
index 92d0985..932734f 100644
--- a/chrome/browser/extensions/extension_webnavigation_api.h
+++ b/chrome/browser/extensions/extension_webnavigation_api.h
@@ -148,6 +148,12 @@ class ExtensionWebNavigationTabObserver : public TabContentsObserver {
int error_code) OVERRIDE;
virtual void DocumentLoadedInFrame(int64 frame_id) OVERRIDE;
virtual void DidFinishLoad(int64 frame_id) OVERRIDE;
+ virtual void DidOpenRequestedURL(TabContents* new_contents,
+ const GURL& url,
+ const GURL& referrer,
+ WindowOpenDisposition disposition,
+ PageTransition::Type transition,
+ int64 source_frame_id) OVERRIDE;
virtual void TabContentsDestroyed(TabContents* tab) OVERRIDE;
private:
diff --git a/chrome/browser/extensions/extension_webnavigation_apitest.cc b/chrome/browser/extensions/extension_webnavigation_apitest.cc
index 1996e28..22fb035 100644
--- a/chrome/browser/extensions/extension_webnavigation_apitest.cc
+++ b/chrome/browser/extensions/extension_webnavigation_apitest.cc
@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "base/command_line.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/extensions/extension_apitest.h"
#include "chrome/browser/extensions/extension_service.h"
@@ -12,9 +11,11 @@
#include "chrome/browser/ui/browser.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/test/base/ui_test_utils.h"
+#include "content/browser/renderer_host/render_view_host.h"
#include "content/browser/tab_contents/tab_contents.h"
#include "net/base/mock_host_resolver.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebContextMenuData.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
#include "webkit/glue/context_menu.h"
namespace {
@@ -147,3 +148,34 @@ IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WebNavigationUserAction) {
ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
}
+
+IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WebNavigationRequestOpenTab) {
+ FrameNavigationState::set_allow_extension_scheme(true);
+
+ // Wait for the extension to set itself up and return control to us.
+ ASSERT_TRUE(RunExtensionSubtest("webnavigation", "test_requestOpenTab.html"))
+ << message_;
+
+ ResultCatcher catcher;
+
+ ExtensionService* service = browser()->profile()->GetExtensionService();
+ const Extension* extension =
+ service->GetExtensionById(last_loaded_extension_id_, false);
+ GURL url = extension->GetResourceURL("requestOpenTab/a.html");
+
+ ui_test_utils::NavigateToURL(browser(), url);
+
+ // There's a link on a.html. Middle-click on it to open it in a new tab.
+ WebKit::WebMouseEvent mouse_event;
+ mouse_event.type = WebKit::WebInputEvent::MouseDown;
+ mouse_event.button = WebKit::WebMouseEvent::ButtonMiddle;
+ mouse_event.x = 7;
+ mouse_event.y = 7;
+ mouse_event.clickCount = 1;
+ TabContents* tab = browser()->GetSelectedTabContents();
+ tab->render_view_host()->ForwardMouseEvent(mouse_event);
+ mouse_event.type = WebKit::WebInputEvent::MouseUp;
+ tab->render_view_host()->ForwardMouseEvent(mouse_event);
+
+ ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
+}