Commit a73aae7d authored by ericzeng@chromium.org's avatar ericzeng@chromium.org

Allow links inside <extensionoptions> to be opened in new tabs

Extension options pages often have links to external pages as well as
internal extension pages. When embedded in an <extensionoptions> element
open external links in a new tab, and internal links in the embedded
view (unless specified otherwise).

BUG=386838

Review URL: https://codereview.chromium.org/471053003

Cr-Commit-Position: refs/heads/master@{#291241}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@291241 0039d316-1c4b-4281-b951-d872f2087c98
parent 02a8ac28
......@@ -210,9 +210,9 @@ IN_PROC_BROWSER_TEST_F(ExtensionWebUITest, CanEmbedExtensionOptions) {
scoped_ptr<ExtensionTestMessageListener> listener(
new ExtensionTestMessageListener("ready", true));
const Extension* extension = InstallExtension(
test_data_dir_.AppendASCII("extension_options").AppendASCII("embed_self"),
1);
const Extension* extension =
LoadExtension(test_data_dir_.AppendASCII("extension_options")
.AppendASCII("embed_self"));
ASSERT_TRUE(extension);
ASSERT_TRUE(RunTestOnExtensionsFrame("can_embed_extension_options.js"));
......
......@@ -32,7 +32,7 @@ class ExtensionOptionsApiTest : public ExtensionApiTest {
IN_PROC_BROWSER_TEST_F(ExtensionOptionsApiTest, ExtensionCanEmbedOwnOptions) {
base::FilePath extension_dir =
test_data_dir_.AppendASCII("extension_options").AppendASCII("embed_self");
ASSERT_TRUE(InstallExtension(extension_dir, 1));
ASSERT_TRUE(LoadExtension(extension_dir));
ASSERT_TRUE(RunExtensionSubtest("extension_options/embed_self", "test.html"));
}
......
......@@ -6,8 +6,13 @@
#include "base/values.h"
#include "chrome/browser/extensions/chrome_extension_web_contents_observer.h"
#include "chrome/browser/extensions/extension_tab_util.h"
#include "chrome/browser/guest_view/extension_options/extension_options_constants.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/extensions/api/extension_options_internal.h"
#include "chrome/common/extensions/manifest_url_handler.h"
#include "components/crx_file/id_util.h"
......@@ -16,6 +21,7 @@
#include "content/public/browser/web_contents.h"
#include "extensions/browser/extension_function_dispatcher.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/guest_view/guest_view_manager.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_messages.h"
#include "extensions/common/feature_switch.h"
......@@ -178,3 +184,29 @@ void ExtensionOptionsGuest::SetUpAutoSize() {
SetAutoSize(
true, gfx::Size(min_width, min_height), gfx::Size(max_width, max_height));
}
bool ExtensionOptionsGuest::ShouldCreateWebContents(
content::WebContents* web_contents,
int route_id,
WindowContainerType window_container_type,
const base::string16& frame_name,
const GURL& target_url,
const std::string& partition_id,
content::SessionStorageNamespace* session_storage_namespace) {
// This method handles opening links from within the guest. Since this guest
// view is used for displaying embedded extension options, we want any
// external links to be opened in a new tab, not in a new guest view.
// Therefore we just open the URL in a new tab, and since we aren't handling
// the new web contents, we return false.
Browser* browser =
chrome::FindBrowserWithWebContents(embedder_web_contents());
content::OpenURLParams params(target_url,
content::Referrer(),
NEW_FOREGROUND_TAB,
content::PAGE_TRANSITION_LINK,
false);
browser->OpenURL(params);
// TODO(ericzeng): Open the tab in the background if the click was a
// ctrl-click or middle mouse button click
return false;
}
......@@ -40,6 +40,16 @@ class ExtensionOptionsGuest
// ExtensionFunctionDispatcher::Delegate implementation.
virtual content::WebContents* GetAssociatedWebContents() const OVERRIDE;
// content::WebContentsDelegate implementation.
virtual bool ShouldCreateWebContents(
content::WebContents* web_contents,
int route_id,
WindowContainerType window_container_type,
const base::string16& frame_name,
const GURL& target_url,
const std::string& partition_id,
content::SessionStorageNamespace* session_storage_namespace) OVERRIDE;
// content::WebContentsObserver implementation.
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
......
......@@ -6,6 +6,7 @@
"description": "Tests if extensions can embed their own options pages using <extensionoptions>",
"permissions": [
"embeddedExtensionOptions",
"storage"
"storage",
"tabs"
]
}
......@@ -6,6 +6,7 @@
<html>
<body>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam neque lacus, ultricies in dui ac, consequat mattis justo. Curabitur in felis sed sapien vulputate vulputate. In mauris mi, rhoncus quis massa in, viverra molestie mauris. Vestibulum ac dui ante. Etiam rutrum tristique fermentum. Nulla ut pretium leo. Phasellus ac ligula tristique, lacinia nulla non, bibendum mauris. Vestibulum venenatis tortor leo, laoreet lobortis urna tempor eu. </p>
<a id='link' href="http://www.chromium.org/" target=_blank>Chromium</a>
<script src="options.js"></script>
</body>
</html>
......@@ -44,5 +44,14 @@ chrome.runtime.sendMessage('ready', function(command) {
});
});
});
break;
case 'externalLinksOpenInNewTab':
var link = document.getElementById('link');
chrome.test.runWithUserGesture(function() {
link.click();
chrome.runtime.sendMessage('done');
}.bind(link));
}
});
......@@ -135,6 +135,29 @@ chrome.test.runTests([
}
};
document.body.appendChild(extensionoptions);
},
function externalLinksOpenInNewTab() {
var done = chrome.test.listenForever(chrome.runtime.onMessage,
function(message, sender, sendResponse) {
if (message == 'ready') {
sendResponse('externalLinksOpenInNewTab');
} else if (message == 'done') {
try {
chrome.tabs.query({url: 'http://www.chromium.org/'}, function(tabs) {
chrome.test.assertEq(1, tabs.length);
chrome.test.assertEq('http://www.chromium.org/', tabs[0].url);
done();
});
} finally {
document.body.removeChild(extensionoptions);
}
}
});
var extensionoptions = document.createElement('extensionoptions');
extensionoptions.setAttribute('extension', chrome.runtime.id);
document.body.appendChild(extensionoptions);
}
]);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment