Commit 3b21259d authored by ericzeng's avatar ericzeng Committed by Commit bot

Embedded Extension Options: Open all external links in a new tab

Implement WebContentsDelegate::OpenURLFromTab in ExtensionOptionsGuest
to handle links that do not have the target=_blank attribute. Force all
links to URLs outside of the extension to be opened in a new tab.

This also handles <meta> redirects and setting window.location from the
options page by opening them in a new tab.

BUG=409344

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

Cr-Commit-Position: refs/heads/master@{#293612}
parent 478927e2
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "extensions/browser/extension_function_dispatcher.h" #include "extensions/browser/extension_function_dispatcher.h"
#include "extensions/browser/extension_registry.h" #include "extensions/browser/extension_registry.h"
#include "extensions/browser/guest_view/guest_view_manager.h" #include "extensions/browser/guest_view/guest_view_manager.h"
#include "extensions/common/constants.h"
#include "extensions/common/extension.h" #include "extensions/common/extension.h"
#include "extensions/common/extension_messages.h" #include "extensions/common/extension_messages.h"
#include "extensions/common/feature_switch.h" #include "extensions/common/feature_switch.h"
...@@ -155,6 +156,28 @@ content::WebContents* ExtensionOptionsGuest::GetAssociatedWebContents() const { ...@@ -155,6 +156,28 @@ content::WebContents* ExtensionOptionsGuest::GetAssociatedWebContents() const {
return web_contents(); return web_contents();
} }
content::WebContents* ExtensionOptionsGuest::OpenURLFromTab(
content::WebContents* source,
const content::OpenURLParams& params) {
Browser* browser =
chrome::FindBrowserWithWebContents(embedder_web_contents());
// Don't allow external URLs with the CURRENT_TAB disposition be opened in
// this guest view, change the disposition to NEW_FOREGROUND_TAB.
if ((!params.url.SchemeIs(extensions::kExtensionScheme) ||
params.url.host() != options_page_.host()) &&
params.disposition == CURRENT_TAB) {
return browser->OpenURL(
content::OpenURLParams(params.url,
params.referrer,
params.frame_tree_node_id,
NEW_FOREGROUND_TAB,
params.transition,
params.is_renderer_initiated));
}
return browser->OpenURL(params);
}
void ExtensionOptionsGuest::CloseContents(content::WebContents* source) { void ExtensionOptionsGuest::CloseContents(content::WebContents* source) {
DispatchEventToEmbedder(new extensions::GuestViewBase::Event( DispatchEventToEmbedder(new extensions::GuestViewBase::Event(
extension_options_internal::OnClose::kEventName, extension_options_internal::OnClose::kEventName,
......
...@@ -42,6 +42,9 @@ class ExtensionOptionsGuest ...@@ -42,6 +42,9 @@ class ExtensionOptionsGuest
virtual content::WebContents* GetAssociatedWebContents() const OVERRIDE; virtual content::WebContents* GetAssociatedWebContents() const OVERRIDE;
// content::WebContentsDelegate implementation. // content::WebContentsDelegate implementation.
virtual content::WebContents* OpenURLFromTab(
content::WebContents* source,
const content::OpenURLParams& params) OVERRIDE;
virtual void CloseContents(content::WebContents* source) OVERRIDE; virtual void CloseContents(content::WebContents* source) OVERRIDE;
virtual bool HandleContextMenu( virtual bool HandleContextMenu(
const content::ContextMenuParams& params) OVERRIDE; const content::ContextMenuParams& params) OVERRIDE;
......
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