Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6358)

Unified Diff: chrome/browser/ui/extensions/shell_window.cc

Issue 15720009: Open new-window links externally from within packaged apps. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/extensions/shell_window.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/extensions/shell_window.cc
diff --git a/chrome/browser/ui/extensions/shell_window.cc b/chrome/browser/ui/extensions/shell_window.cc
index 0ac8a5f058f6644d8b150cbc5c03f2b5b7d4d38c..87b9690d07afb55bd91c55ee3a716c7f4dc1f6d3 100644
--- a/chrome/browser/ui/extensions/shell_window.cc
+++ b/chrome/browser/ui/extensions/shell_window.cc
@@ -17,6 +17,7 @@
#include "chrome/browser/file_select_helper.h"
#include "chrome/browser/lifetime/application_lifetime.h"
#include "chrome/browser/media/media_capture_devices_dispatcher.h"
+#include "chrome/browser/platform_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sessions/session_id.h"
#include "chrome/browser/ui/browser.h"
@@ -67,6 +68,23 @@ const int kPreferredIconSize = ash::kLauncherPreferredSize;
const int kPreferredIconSize = extension_misc::EXTENSION_ICON_SMALL;
#endif
+static bool disable_external_open_for_testing_ = false;
+
+class ShellWindowLinkDelegate : public content::WebContentsDelegate {
+ private:
+ virtual content::WebContents* OpenURLFromTab(
+ content::WebContents* source,
+ const content::OpenURLParams& params) OVERRIDE;
+};
+
+content::WebContents* ShellWindowLinkDelegate::OpenURLFromTab(
+ content::WebContents* source,
+ const content::OpenURLParams& params) {
+ platform_util::OpenExternal(params.url);
+ delete source;
+ return NULL;
miket_OOO 2013/06/03 21:12:38 Hmmm. Is this a common pattern? Fine if it is; it
Ken Rockot(use gerrit already) 2013/06/03 21:24:47 It's not terribly common, but it's not unheard of.
+}
+
} // namespace
ShellWindow::CreateParams::CreateParams()
@@ -284,6 +302,20 @@ void ShellWindow::AddNewContents(WebContents* source,
bool* was_blocked) {
DCHECK(Profile::FromBrowserContext(new_contents->GetBrowserContext()) ==
profile_);
+#if defined(OS_LINUX) || defined(OS_MACOSX) || defined(OS_WIN)
+ if (disable_external_open_for_testing_) {
+ Browser* browser =
+ chrome::FindOrCreateTabbedBrowser(profile_, chrome::GetActiveDesktop());
+ // Force all links to open in a new tab, even if they were trying to open a
+ // new window.
+ disposition =
+ disposition == NEW_BACKGROUND_TAB ? disposition : NEW_FOREGROUND_TAB;
+ chrome::AddWebContents(browser, NULL, new_contents, disposition,
+ initial_pos, user_gesture, was_blocked);
+ } else {
+ new_contents->SetDelegate(new ShellWindowLinkDelegate());
+ }
+#else
Browser* browser =
chrome::FindOrCreateTabbedBrowser(profile_, chrome::GetActiveDesktop());
// Force all links to open in a new tab, even if they were trying to open a
@@ -292,6 +324,7 @@ void ShellWindow::AddNewContents(WebContents* source,
disposition == NEW_BACKGROUND_TAB ? disposition : NEW_FOREGROUND_TAB;
chrome::AddWebContents(browser, NULL, new_contents, disposition, initial_pos,
user_gesture, was_blocked);
+#endif
}
void ShellWindow::HandleKeyboardEvent(
@@ -605,3 +638,8 @@ SkRegion* ShellWindow::RawDraggableRegionsToSkRegion(
}
return sk_region;
}
+
+void ShellWindow::DisableExternalOpenForTesting() {
+ disable_external_open_for_testing_ = true;
+}
+
« no previous file with comments | « chrome/browser/ui/extensions/shell_window.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698