summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorstevenjb@chromium.org <stevenjb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-21 17:13:52 +0000
committerstevenjb@chromium.org <stevenjb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-21 17:13:52 +0000
commit8a585cbb238840eadf792f120d1b80a321b37220 (patch)
tree3452a7cf6d16f488de4fa897f766a363ec894b53 /chrome
parentc1b3468d91c5ec0bda9192c4781cefb43cc90379 (diff)
downloadchromium_src-8a585cbb238840eadf792f120d1b80a321b37220.zip
chromium_src-8a585cbb238840eadf792f120d1b80a321b37220.tar.gz
chromium_src-8a585cbb238840eadf792f120d1b80a321b37220.tar.bz2
Implement settings om a window
Adds SettingsWindowManager which manages settings popup windows, one per Profile. Implemented behind the flag -enable-settings-window Includes some cleanup in chrome_pages for settings url generation and showing settings by profile in general. Also moves logic for whether to display the Location Bar in a Browser to ShowLocationBar() (affects code for streamlined hosted apps, shouldn't change the logic any). BUG=342983 R=ben@chromium.org, calamity@chromium.org Review URL: https://codereview.chromium.org/178863002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@258615 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/app/generated_resources.grd8
-rw-r--r--chrome/browser/about_flags.cc7
-rw-r--r--chrome/browser/first_run/first_run.cc5
-rw-r--r--chrome/browser/renderer_context_menu/render_view_context_menu.cc11
-rw-r--r--chrome/browser/ui/ash/system_tray_delegate_chromeos.cc54
-rw-r--r--chrome/browser/ui/autofill/new_credit_card_bubble_controller.cc6
-rw-r--r--chrome/browser/ui/browser.cc43
-rw-r--r--chrome/browser/ui/browser.h3
-rw-r--r--chrome/browser/ui/chrome_pages.cc95
-rw-r--r--chrome/browser/ui/chrome_pages.h12
-rw-r--r--chrome/browser/ui/settings_window_manager.cc64
-rw-r--r--chrome/browser/ui/settings_window_manager.h43
-rw-r--r--chrome/browser/ui/sync/one_click_signin_sync_starter.cc4
-rw-r--r--chrome/browser/ui/views/translate/translate_bubble_view.cc6
-rw-r--r--chrome/chrome_browser_ui.gypi2
-rw-r--r--chrome/common/chrome_switches.cc3
-rw-r--r--chrome/common/chrome_switches.h1
17 files changed, 281 insertions, 86 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd
index 84f842e..4dd4622 100644
--- a/chrome/app/generated_resources.grd
+++ b/chrome/app/generated_resources.grd
@@ -14771,6 +14771,14 @@ Do you accept?
<message name="IDS_FLAGS_PREFETCH_SEARCH_RESULTS_DESCRIPTION" desc="Describes an about:flags experiment for prefetching search results">
If enabled, prefetch search results for the typed omnibox query and reuse prerendered search base page to commit any search query (not just prefetch query).
</message>
+
+ <!-- Settings window flags -->
+ <message name="IDS_FLAGS_ENABLE_SETTINGS_WINDOW_NAME" desc="An about::flags experiment title to show settings in a separate window">
+ Show settings in a window
+ </message>
+ <message name="IDS_FLAGS_ENABLE_SETTINGS_WINDOW_DESCRIPTION" desc="Describes an about:flags experiment to show settings in a separate window">
+ If enabled, Settings will be shown in a dedicated window instead of as a browser tab.
+ </message>
</messages>
</release>
</grit>
diff --git a/chrome/browser/about_flags.cc b/chrome/browser/about_flags.cc
index 3838cfa..5a77fbb 100644
--- a/chrome/browser/about_flags.cc
+++ b/chrome/browser/about_flags.cc
@@ -1813,6 +1813,13 @@ const Experiment kExperiments[] = {
kOsAll,
SINGLE_VALUE_TYPE(switches::kEnableBleedingEdgeRenderingFastPaths)
},
+ {
+ "enable-settings-window",
+ IDS_FLAGS_ENABLE_SETTINGS_WINDOW_NAME,
+ IDS_FLAGS_ENABLE_SETTINGS_WINDOW_DESCRIPTION,
+ kOsDesktop,
+ SINGLE_VALUE_TYPE(switches::kEnableSettingsWindow)
+ },
};
const Experiment* experiments = kExperiments;
diff --git a/chrome/browser/first_run/first_run.cc b/chrome/browser/first_run/first_run.cc
index d89e76b..ee7d583 100644
--- a/chrome/browser/first_run/first_run.cc
+++ b/chrome/browser/first_run/first_run.cc
@@ -41,6 +41,7 @@
#include "chrome/browser/signin/signin_tracker.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
+#include "chrome/browser/ui/chrome_pages.h"
#include "chrome/browser/ui/global_error/global_error_service.h"
#include "chrome/browser/ui/global_error/global_error_service_factory.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
@@ -361,8 +362,8 @@ void FirstRunBubbleLauncher::Observe(
chrome::kChromeUIChromeSigninURL ||
gaia::IsGaiaSignonRealm(contents->GetURL().GetOrigin()) ||
signin::IsContinueUrlForWebBasedSigninFlow(contents->GetURL()) ||
- contents->GetURL() == GURL(std::string(chrome::kChromeUISettingsURL) +
- chrome::kSyncSetupSubPage))) {
+ (contents->GetURL() ==
+ chrome::GetSettingsUrl(chrome::kSyncSetupSubPage)))) {
return;
}
diff --git a/chrome/browser/renderer_context_menu/render_view_context_menu.cc b/chrome/browser/renderer_context_menu/render_view_context_menu.cc
index 8062f4f..a2f2f60 100644
--- a/chrome/browser/renderer_context_menu/render_view_context_menu.cc
+++ b/chrome/browser/renderer_context_menu/render_view_context_menu.cc
@@ -56,6 +56,7 @@
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_finder.h"
+#include "chrome/browser/ui/chrome_pages.h"
#include "chrome/browser/ui/search_engines/search_engine_tab_helper.h"
#include "chrome/browser/ui/tab_contents/core_tab_helper.h"
#include "chrome/common/chrome_constants.h"
@@ -1850,9 +1851,8 @@ void RenderViewContextMenu::ExecuteCommand(int id, int event_flags) {
case IDC_CONTENT_CONTEXT_LANGUAGE_SETTINGS: {
WindowOpenDisposition disposition =
ForceNewTabDispositionFromEventFlags(event_flags);
- std::string url = std::string(chrome::kChromeUISettingsURL) +
- chrome::kLanguageOptionsSubPage;
- OpenURL(GURL(url), GURL(), 0, disposition, content::PAGE_TRANSITION_LINK);
+ GURL url = chrome::GetSettingsUrl(chrome::kLanguageOptionsSubPage);
+ OpenURL(url, GURL(), 0, disposition, content::PAGE_TRANSITION_LINK);
break;
}
@@ -1861,9 +1861,8 @@ void RenderViewContextMenu::ExecuteCommand(int id, int event_flags) {
UserMetricsAction("RegisterProtocolHandler.ContextMenu_Settings"));
WindowOpenDisposition disposition =
ForceNewTabDispositionFromEventFlags(event_flags);
- std::string url = std::string(chrome::kChromeUISettingsURL) +
- chrome::kHandlerSettingsSubPage;
- OpenURL(GURL(url), GURL(), 0, disposition, content::PAGE_TRANSITION_LINK);
+ GURL url = chrome::GetSettingsUrl(chrome::kHandlerSettingsSubPage);
+ OpenURL(url, GURL(), 0, disposition, content::PAGE_TRANSITION_LINK);
break;
}
diff --git a/chrome/browser/ui/ash/system_tray_delegate_chromeos.cc b/chrome/browser/ui/ash/system_tray_delegate_chromeos.cc
index 2c4c359..d3fc1aa 100644
--- a/chrome/browser/ui/ash/system_tray_delegate_chromeos.cc
+++ b/chrome/browser/ui/ash/system_tray_delegate_chromeos.cc
@@ -89,6 +89,7 @@
#include "chrome/browser/ui/webui/chromeos/charger_replacement_handler.h"
#include "chrome/browser/ui/webui/chromeos/mobile_setup_dialog.h"
#include "chrome/browser/upgrade_detector.h"
+#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
#include "chromeos/dbus/dbus_thread_manager.h"
@@ -218,21 +219,21 @@ void BluetoothDeviceConnectError(
// TODO(sad): Do something?
}
-// Shows the settings sub page in the last active browser. If there is no such
-// browser, creates a new browser with the settings sub page.
-void ShowSettingsSubPageForAppropriateBrowser(const std::string& sub_page,
- Profile* profile) {
- chrome::ScopedTabbedBrowserDisplayer displayer(profile,
- chrome::HOST_DESKTOP_TYPE_ASH);
- chrome::ShowSettingsSubPage(displayer.browser(), sub_page);
+void ShowSettingsSubPageForActiveUser(const std::string& sub_page) {
+ chrome::ShowSettingsSubPageForProfile(
+ ProfileManager::GetActiveUserProfile(), sub_page);
+}
+
+void ShowSettingsSubPageForPrimaryUser(const std::string& sub_page) {
+ chrome::ShowSettingsSubPageForProfile(
+ ProfileManager::GetPrimaryUserProfile(), sub_page);
}
void ShowNetworkSettingsPage(const std::string& service_path) {
std::string page = chrome::kInternetOptionsSubPage;
page += "?servicePath=" + net::EscapeUrlEncodedData(service_path, true);
content::RecordAction(base::UserMetricsAction("OpenInternetOptionsDialog"));
- ShowSettingsSubPageForAppropriateBrowser(
- page, ProfileManager::GetPrimaryUserProfile());
+ ShowSettingsSubPageForPrimaryUser(page);
}
void OnAcceptMultiprofilesIntro(bool no_show_again) {
@@ -428,9 +429,7 @@ bool SystemTrayDelegateChromeOS::IsOobeCompleted() const {
void SystemTrayDelegateChromeOS::ChangeProfilePicture() {
content::RecordAction(
base::UserMetricsAction("OpenChangeProfilePictureDialog"));
- ShowSettingsSubPageForAppropriateBrowser(
- chrome::kChangeProfilePictureSubPage,
- ProfileManager::GetActiveUserProfile());
+ ShowSettingsSubPageForActiveUser(chrome::kChangeProfilePictureSubPage);
}
const std::string SystemTrayDelegateChromeOS::GetEnterpriseDomain() const {
@@ -478,9 +477,7 @@ base::HourClockType SystemTrayDelegateChromeOS::GetHourClockType() const {
}
void SystemTrayDelegateChromeOS::ShowSettings() {
- chrome::ScopedTabbedBrowserDisplayer displayer(
- ProfileManager::GetActiveUserProfile(), chrome::HOST_DESKTOP_TYPE_ASH);
- chrome::ShowSettings(displayer.browser());
+ ShowSettingsSubPageForActiveUser("");
}
bool SystemTrayDelegateChromeOS::ShouldShowSettings() {
@@ -493,8 +490,7 @@ void SystemTrayDelegateChromeOS::ShowDateSettings() {
std::string(chrome::kSearchSubPage) + "#" +
l10n_util::GetStringUTF8(IDS_OPTIONS_SETTINGS_SECTION_TITLE_DATETIME);
// Everybody can change the time zone (even though it is a device setting).
- ShowSettingsSubPageForAppropriateBrowser(
- sub_page, ProfileManager::GetActiveUserProfile());
+ ShowSettingsSubPageForActiveUser(sub_page);
}
void SystemTrayDelegateChromeOS::ShowNetworkSettings(
@@ -510,8 +506,7 @@ void SystemTrayDelegateChromeOS::ShowBluetoothSettings() {
void SystemTrayDelegateChromeOS::ShowDisplaySettings() {
content::RecordAction(base::UserMetricsAction("ShowDisplayOptions"));
- ShowSettingsSubPageForAppropriateBrowser(
- kDisplaySettingsSubPageName, ProfileManager::GetActiveUserProfile());
+ ShowSettingsSubPageForActiveUser(kDisplaySettingsSubPageName);
}
void SystemTrayDelegateChromeOS::ShowChromeSlow() {
@@ -535,12 +530,12 @@ bool SystemTrayDelegateChromeOS::ShouldShowDisplayNotification() {
return true;
GURL visible_url = active_contents->GetLastCommittedURL();
- std::string display_settings_url =
- std::string(chrome::kChromeUISettingsURL) + kDisplaySettingsSubPageName;
- std::string display_overscan_url = std::string(chrome::kChromeUISettingsURL) +
- kDisplayOverscanSettingsSubPageName;
- return (visible_url.spec() != display_settings_url) &&
- (visible_url.spec() != display_overscan_url);
+ GURL display_settings_url =
+ chrome::GetSettingsUrl(kDisplaySettingsSubPageName);
+ GURL display_overscan_url =
+ chrome::GetSettingsUrl(kDisplayOverscanSettingsSubPageName);
+ return (visible_url != display_settings_url &&
+ visible_url != display_overscan_url);
}
void SystemTrayDelegateChromeOS::ShowDriveSettings() {
@@ -556,8 +551,7 @@ void SystemTrayDelegateChromeOS::ShowDriveSettings() {
void SystemTrayDelegateChromeOS::ShowIMESettings() {
content::RecordAction(base::UserMetricsAction("OpenLanguageOptionsDialog"));
- ShowSettingsSubPageForAppropriateBrowser(
- chrome::kLanguageOptionsSubPage, ProfileManager::GetActiveUserProfile());
+ ShowSettingsSubPageForActiveUser(chrome::kLanguageOptionsSubPage);
}
void SystemTrayDelegateChromeOS::ShowHelp() {
@@ -577,8 +571,7 @@ void SystemTrayDelegateChromeOS::ShowAccessibilitySettings() {
std::string sub_page = std::string(chrome::kSearchSubPage) + "#" +
l10n_util::GetStringUTF8(
IDS_OPTIONS_SETTINGS_SECTION_TITLE_ACCESSIBILITY);
- ShowSettingsSubPageForAppropriateBrowser(
- sub_page, ProfileManager::GetActiveUserProfile());
+ ShowSettingsSubPageForActiveUser(sub_page);
}
void SystemTrayDelegateChromeOS::ShowPublicAccountInfo() {
@@ -840,8 +833,7 @@ void SystemTrayDelegateChromeOS::ManageBluetoothDevices() {
std::string sub_page =
std::string(chrome::kSearchSubPage) + "#" +
l10n_util::GetStringUTF8(IDS_OPTIONS_SETTINGS_SECTION_TITLE_BLUETOOTH);
- ShowSettingsSubPageForAppropriateBrowser(
- sub_page, ProfileManager::GetPrimaryUserProfile());
+ ShowSettingsSubPageForPrimaryUser(sub_page);
}
void SystemTrayDelegateChromeOS::ToggleBluetooth() {
diff --git a/chrome/browser/ui/autofill/new_credit_card_bubble_controller.cc b/chrome/browser/ui/autofill/new_credit_card_bubble_controller.cc
index e408068..8933a21 100644
--- a/chrome/browser/ui/autofill/new_credit_card_bubble_controller.cc
+++ b/chrome/browser/ui/autofill/new_credit_card_bubble_controller.cc
@@ -62,11 +62,7 @@ void NewCreditCardBubbleController::OnBubbleDestroyed() {
}
void NewCreditCardBubbleController::OnLinkClicked() {
- Browser* browser = chrome::FindTabbedBrowser(profile_, false,
- chrome::GetActiveDesktop());
- if (browser)
- chrome::ShowSettingsSubPage(browser, chrome::kAutofillSubPage);
-
+ chrome::ShowSettingsSubPageForProfile(profile_, chrome::kAutofillSubPage);
Hide();
}
diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc
index b04508d..de100f8 100644
--- a/chrome/browser/ui/browser.cc
+++ b/chrome/browser/ui/browser.cc
@@ -2179,6 +2179,35 @@ void Browser::TabDetachedAtImpl(content::WebContents* contents,
}
}
+bool Browser::ShouldShowLocationBar() const {
+ if (!is_app()) {
+ // Hide the URL for singleton settings windows.
+ // TODO(stevenjb): We could avoid this check by setting a Browser
+ // property for "system" windows, possibly shared with hosted app windows.
+ // crbug.com/350128.
+ if (chrome::IsSettingsWindow(this))
+ return false;
+ return true;
+ }
+
+ // Normally apps do not show a location bar.
+ if (app_type() != APP_TYPE_HOST ||
+ app_name() == DevToolsWindow::kDevToolsApp ||
+ !CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kEnableStreamlinedHostedApps))
+ return false;
+
+ // If kEnableStreamlinedHostedApps is true, show the locaiton bar for non
+ // legacy packaged apps.
+ ExtensionService* service =
+ extensions::ExtensionSystem::Get(profile_)->extension_service();
+ const extensions::Extension* extension =
+ service ? service->GetInstalledExtension(
+ web_app::GetExtensionIdFromApplicationName(app_name()))
+ : NULL;
+ return (!extension || !extension->is_legacy_packaged_app());
+}
+
bool Browser::SupportsWindowFeatureImpl(WindowFeature feature,
bool check_fullscreen) const {
bool hide_ui_for_fullscreen = check_fullscreen && ShouldHideUIForFullscreen();
@@ -2198,20 +2227,8 @@ bool Browser::SupportsWindowFeatureImpl(WindowFeature feature,
if (is_type_tabbed())
features |= FEATURE_TOOLBAR;
- ExtensionService* service =
- extensions::ExtensionSystem::Get(profile_)->extension_service();
- const extensions::Extension* extension =
- service ? service->GetInstalledExtension(
- web_app::GetExtensionIdFromApplicationName(app_name()))
- : NULL;
-
- if (!is_app() || (app_type() == APP_TYPE_HOST &&
- app_name() != DevToolsWindow::kDevToolsApp &&
- (!extension || !extension->is_legacy_packaged_app()) &&
- CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kEnableStreamlinedHostedApps))) {
+ if (ShouldShowLocationBar())
features |= FEATURE_LOCATIONBAR;
- }
}
return !!(features & feature);
}
diff --git a/chrome/browser/ui/browser.h b/chrome/browser/ui/browser.h
index 72bdcb8..0e81603 100644
--- a/chrome/browser/ui/browser.h
+++ b/chrome/browser/ui/browser.h
@@ -769,6 +769,9 @@ class Browser : public TabStripModelObserver,
// Shared code between Reload() and ReloadIgnoringCache().
void ReloadInternal(WindowOpenDisposition disposition, bool ignore_cache);
+ // Returns true if the Browser window should show the location bar.
+ bool ShouldShowLocationBar() const;
+
// Implementation of SupportsWindowFeature and CanSupportWindowFeature. If
// |check_fullscreen| is true, the set of features reflect the actual state of
// the browser, otherwise the set of features reflect the possible state of
diff --git a/chrome/browser/ui/chrome_pages.cc b/chrome/browser/ui/chrome_pages.cc
index acdb1f1..9b481ea 100644
--- a/chrome/browser/ui/chrome_pages.cc
+++ b/chrome/browser/ui/chrome_pages.cc
@@ -15,18 +15,22 @@
#include "chrome/browser/signin/signin_manager.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_navigator.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/extensions/application_launch.h"
#include "chrome/browser/ui/scoped_tabbed_browser_displayer.h"
+#include "chrome/browser/ui/settings_window_manager.h"
#include "chrome/browser/ui/singleton_tabs.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/webui/options/content_settings_handler.h"
+#include "chrome/common/chrome_switches.h"
#include "chrome/common/url_constants.h"
#include "content/public/browser/user_metrics.h"
+#include "content/public/browser/web_contents.h"
+#include "content/public/common/url_constants.h"
#include "google_apis/gaia/gaia_urls.h"
#include "net/base/url_util.h"
-#include "url/gurl.h"
#if defined(OS_WIN)
#include "chrome/browser/enumerate_modules_model_win.h"
@@ -51,9 +55,8 @@ void OpenBookmarkManagerWithHash(Browser* browser,
content::RecordAction(UserMetricsAction("ShowBookmarks"));
NavigateParams params(GetSingletonTabNavigateParams(
browser,
- GURL(kChromeUIBookmarksURL).Resolve(
- base::StringPrintf("/#%s%s", action.c_str(),
- base::Int64ToString(node_id).c_str()))));
+ GURL(kChromeUIBookmarksURL).Resolve(base::StringPrintf(
+ "/#%s%s", action.c_str(), base::Int64ToString(node_id).c_str()))));
params.path_behavior = NavigateParams::IGNORE_AND_NAVIGATE;
ShowSingletonTabOverwritingNTP(browser, params);
}
@@ -76,10 +79,10 @@ void ShowHelpImpl(Browser* browser,
#if defined(OS_CHROMEOS) && defined(OFFICIAL_BUILD)
const CommandLine* command_line = CommandLine::ForCurrentProcess();
if (!command_line->HasSwitch(chromeos::switches::kDisableGeniusApp)) {
- const extensions::Extension* extension = profile->GetExtensionService()->
- GetInstalledExtension(genius_app::kGeniusAppId);
- OpenApplication(
- AppLaunchParams(profile, extension, 0, host_desktop_type));
+ const extensions::Extension* extension =
+ profile->GetExtensionService()->GetInstalledExtension(
+ genius_app::kGeniusAppId);
+ OpenApplication(AppLaunchParams(profile, extension, 0, host_desktop_type));
return;
}
#endif
@@ -176,8 +179,8 @@ void ShowConflicts(Browser* browser) {
}
void ShowHelp(Browser* browser, HelpSource source) {
- ShowHelpImpl(browser, browser->profile(), browser->host_desktop_type(),
- source);
+ ShowHelpImpl(
+ browser, browser->profile(), browser->host_desktop_type(), source);
}
void ShowHelpForProfile(Profile* profile,
@@ -196,22 +199,69 @@ void ShowSlow(Browser* browser) {
#endif
}
-void ShowSettings(Browser* browser) {
- content::RecordAction(UserMetricsAction("ShowOptions"));
- ShowSettingsSubPage(browser, std::string());
-}
-
-void ShowSettingsSubPage(Browser* browser, const std::string& sub_page) {
+GURL GetSettingsUrl(const std::string& sub_page) {
std::string url = std::string(kChromeUISettingsURL) + sub_page;
#if defined(OS_CHROMEOS)
if (sub_page.find(kInternetOptionsSubPage, 0) != std::string::npos) {
std::string::size_type loc = sub_page.find("?", 0);
- std::string network_page = loc != std::string::npos ?
- sub_page.substr(loc) : std::string();
+ std::string network_page =
+ loc != std::string::npos ? sub_page.substr(loc) : std::string();
url = std::string(kChromeUISettingsURL) + network_page;
}
#endif
- NavigateParams params(GetSingletonTabNavigateParams(browser, GURL(url)));
+ return GURL(url);
+}
+
+bool IsSettingsWindow(const Browser* browser) {
+ if (!CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kEnableSettingsWindow))
+ return false;
+ if (browser->is_type_tabbed())
+ return false;
+ const content::WebContents* web_contents =
+ browser->tab_strip_model()->GetWebContentsAt(0);
+ if (!web_contents)
+ return false;
+ GURL url(web_contents->GetURL());
+ return (url.SchemeIs(content::kChromeUIScheme) &&
+ url.spec().find(chrome::kChromeUISettingsURL) == 0);
+}
+
+void ShowSettings(Browser* browser) {
+ ShowSettingsSubPage(browser, std::string());
+}
+
+void ShowSettingsSubPage(Browser* browser, const std::string& sub_page) {
+ if (CommandLine::ForCurrentProcess()->HasSwitch(
+ ::switches::kEnableSettingsWindow)) {
+ SettingsWindowManager::GetInstance()->ShowForProfile(browser->profile(),
+ sub_page);
+ return;
+ }
+ ShowSettingsSubPageInTabbedBrowser(browser, sub_page);
+}
+
+void ShowSettingsSubPageForProfile(Profile* profile,
+ const std::string& sub_page) {
+ if (CommandLine::ForCurrentProcess()->HasSwitch(
+ ::switches::kEnableSettingsWindow)) {
+ SettingsWindowManager::GetInstance()->ShowForProfile(profile, sub_page);
+ return;
+ }
+ Browser* browser =
+ chrome::FindTabbedBrowser(profile, false, HOST_DESKTOP_TYPE_NATIVE);
+ if (!browser) {
+ browser = new Browser(
+ Browser::CreateParams(profile, chrome::HOST_DESKTOP_TYPE_NATIVE));
+ }
+ ShowSettingsSubPageInTabbedBrowser(browser, sub_page);
+}
+
+void ShowSettingsSubPageInTabbedBrowser(Browser* browser,
+ const std::string& sub_page) {
+ content::RecordAction(UserMetricsAction("ShowOptions"));
+ GURL gurl = GetSettingsUrl(sub_page);
+ NavigateParams params(GetSingletonTabNavigateParams(browser, gurl));
params.path_behavior = NavigateParams::IGNORE_AND_NAVIGATE;
ShowSingletonTabOverwritingNTP(browser, params);
}
@@ -221,8 +271,8 @@ void ShowContentSettings(Browser* browser,
ShowSettingsSubPage(
browser,
kContentSettingsExceptionsSubPage + std::string(kHashMark) +
- options::ContentSettingsHandler::ContentSettingsTypeToGroupName(
- content_settings_type));
+ options::ContentSettingsHandler::ContentSettingsTypeToGroupName(
+ content_settings_type));
}
void ShowClearBrowsingDataDialog(Browser* browser) {
@@ -272,8 +322,7 @@ void ShowBrowserSignin(Browser* browser, signin::Source source) {
browser = displayer->browser();
}
- NavigateToSingletonTab(browser,
- GURL(signin::GetPromoURL(source, false)));
+ NavigateToSingletonTab(browser, GURL(signin::GetPromoURL(source, false)));
DCHECK_GT(browser->tab_strip_model()->count(), 0);
}
}
diff --git a/chrome/browser/ui/chrome_pages.h b/chrome/browser/ui/chrome_pages.h
index 29bee22..d780520 100644
--- a/chrome/browser/ui/chrome_pages.h
+++ b/chrome/browser/ui/chrome_pages.h
@@ -10,9 +10,9 @@
#include "chrome/browser/signin/signin_promo.h"
#include "chrome/browser/ui/host_desktop.h"
#include "chrome/common/content_settings_types.h"
+#include "url/gurl.h"
class Browser;
-class GURL;
namespace content {
class WebContents;
@@ -54,11 +54,21 @@ void ShowHelpForProfile(Profile* profile,
void ShowPolicy(Browser* browser);
void ShowSlow(Browser* browser);
+// Constructs a settings GURL for the specified |sub_page|.
+GURL GetSettingsUrl(const std::string& sub_page);
+
+// Returns true if |browser| is a popup window containing a settings page.
+bool IsSettingsWindow(const Browser* browser);
+
// Various things that open in a settings UI.
void ShowSettings(Browser* browser);
void ShowSettingsSubPage(Browser* browser, const std::string& sub_page);
+void ShowSettingsSubPageForProfile(Profile* profile,
+ const std::string& sub_page);
void ShowContentSettings(Browser* browser,
ContentSettingsType content_settings_type);
+void ShowSettingsSubPageInTabbedBrowser(Browser* browser,
+ const std::string& sub_page);
void ShowClearBrowsingDataDialog(Browser* browser);
void ShowPasswordManager(Browser* browser);
void ShowImportDialog(Browser* browser);
diff --git a/chrome/browser/ui/settings_window_manager.cc b/chrome/browser/ui/settings_window_manager.cc
new file mode 100644
index 0000000..f2a93ad
--- /dev/null
+++ b/chrome/browser/ui/settings_window_manager.cc
@@ -0,0 +1,64 @@
+// Copyright (c) 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/settings_window_manager.h"
+
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/ui/browser_finder.h"
+#include "chrome/browser/ui/browser_finder.h"
+#include "chrome/browser/ui/browser_navigator.h"
+#include "chrome/browser/ui/browser_window.h"
+#include "chrome/browser/ui/chrome_pages.h"
+#include "chrome/browser/ui/tabs/tab_strip_model.h"
+#include "content/public/browser/user_metrics.h"
+#include "content/public/browser/web_contents.h"
+
+namespace chrome {
+
+// static
+SettingsWindowManager* SettingsWindowManager::GetInstance() {
+ return Singleton<SettingsWindowManager>::get();
+}
+
+void SettingsWindowManager::ShowForProfile(Profile* profile,
+ const std::string& sub_page) {
+ content::RecordAction(base::UserMetricsAction("ShowOptions"));
+ GURL gurl = chrome::GetSettingsUrl(sub_page);
+ // Look for an existing browser window.
+ ProfileSessionMap::iterator iter = settings_session_map_.find(profile);
+ if (iter != settings_session_map_.end()) {
+ Browser* browser = chrome::FindBrowserWithID(iter->second);
+ if (browser) {
+ DCHECK(browser->profile() == profile);
+ const content::WebContents* web_contents =
+ browser->tab_strip_model()->GetWebContentsAt(0);
+ if (web_contents && web_contents->GetURL() == gurl) {
+ browser->window()->Show();
+ return;
+ }
+ NavigateParams params(browser, gurl,
+ content::PAGE_TRANSITION_AUTO_BOOKMARK);
+ params.window_action = NavigateParams::SHOW_WINDOW;
+ params.user_gesture = true;
+ chrome::Navigate(&params);
+ return;
+ }
+ }
+ // No existing browser window, create one.
+ NavigateParams params(profile, gurl, content::PAGE_TRANSITION_AUTO_BOOKMARK);
+ params.disposition = NEW_POPUP;
+ params.window_action = NavigateParams::SHOW_WINDOW;
+ params.user_gesture = true;
+ params.path_behavior = NavigateParams::IGNORE_AND_NAVIGATE;
+ chrome::Navigate(&params);
+ settings_session_map_[profile] = params.browser->session_id().id();
+}
+
+SettingsWindowManager::SettingsWindowManager() {
+}
+
+SettingsWindowManager::~SettingsWindowManager() {
+}
+
+} // namespace chrome
diff --git a/chrome/browser/ui/settings_window_manager.h b/chrome/browser/ui/settings_window_manager.h
new file mode 100644
index 0000000..fc96bcd
--- /dev/null
+++ b/chrome/browser/ui/settings_window_manager.h
@@ -0,0 +1,43 @@
+// Copyright (c) 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_UI_SETTINGS_WINDOW_MANAGER_H_
+#define CHROME_BROWSER_UI_SETTINGS_WINDOW_MANAGER_H_
+
+#include <map>
+#include <string>
+
+#include "base/memory/singleton.h"
+#include "chrome/browser/sessions/session_id.h"
+
+class Profile;
+
+namespace chrome {
+
+// Class for managing settings windows when --enable-settings-window is enabled.
+// TODO(stevenjb): Remove flag comment if enabled by default.
+
+class SettingsWindowManager {
+ public:
+ static SettingsWindowManager* GetInstance();
+
+ // Show an existing settings window for |profile| or create a new one, and
+ // navigate to |sub_page|.
+ void ShowForProfile(Profile* profile, const std::string& sub_page);
+
+ private:
+ friend struct DefaultSingletonTraits<SettingsWindowManager>;
+ typedef std::map<Profile*, SessionID::id_type> ProfileSessionMap;
+
+ SettingsWindowManager();
+ ~SettingsWindowManager();
+
+ ProfileSessionMap settings_session_map_;
+
+ DISALLOW_COPY_AND_ASSIGN(SettingsWindowManager);
+};
+
+} // namespace chrome
+
+#endif // CHROME_BROWSER_UI_SETTINGS_WINDOW_MANAGER_H_
diff --git a/chrome/browser/ui/sync/one_click_signin_sync_starter.cc b/chrome/browser/ui/sync/one_click_signin_sync_starter.cc
index 395b966..84a4420 100644
--- a/chrome/browser/ui/sync/one_click_signin_sync_starter.cc
+++ b/chrome/browser/ui/sync/one_click_signin_sync_starter.cc
@@ -508,8 +508,8 @@ void OneClickSigninSyncStarter::FinishProfileSyncServiceSetup() {
void OneClickSigninSyncStarter::ShowSettingsPageInWebContents(
content::WebContents* contents,
const std::string& sub_page) {
- std::string url = std::string(chrome::kChromeUISettingsURL) + sub_page;
- content::OpenURLParams params(GURL(url),
+ GURL url = chrome::GetSettingsUrl(sub_page);
+ content::OpenURLParams params(url,
content::Referrer(),
CURRENT_TAB,
content::PAGE_TRANSITION_AUTO_TOPLEVEL,
diff --git a/chrome/browser/ui/views/translate/translate_bubble_view.cc b/chrome/browser/ui/views/translate/translate_bubble_view.cc
index 19eb05c..4f5ad81 100644
--- a/chrome/browser/ui/views/translate/translate_bubble_view.cc
+++ b/chrome/browser/ui/views/translate/translate_bubble_view.cc
@@ -19,6 +19,7 @@
#include "chrome/browser/translate/translate_service.h"
#include "chrome/browser/translate/translate_tab_helper.h"
#include "chrome/browser/translate/translate_ui_delegate.h"
+#include "chrome/browser/ui/chrome_pages.h"
#include "chrome/browser/ui/translate/translate_bubble_model_impl.h"
#include "chrome/common/url_constants.h"
#include "components/translate/core/browser/translate_download_manager.h"
@@ -398,10 +399,9 @@ void TranslateBubbleView::HandleLinkClicked(
break;
}
case LINK_ID_LANGUAGE_SETTINGS: {
- std::string url = std::string(chrome::kChromeUISettingsURL) +
- chrome::kLanguageOptionsSubPage;
+ GURL url = chrome::GetSettingsUrl(chrome::kLanguageOptionsSubPage);
web_contents()->OpenURL(content::OpenURLParams(
- GURL(url),
+ url,
content::Referrer(),
NEW_FOREGROUND_TAB,
content::PAGE_TRANSITION_LINK,
diff --git a/chrome/chrome_browser_ui.gypi b/chrome/chrome_browser_ui.gypi
index 2cd7b4bd..4369805 100644
--- a/chrome/chrome_browser_ui.gypi
+++ b/chrome/chrome_browser_ui.gypi
@@ -1569,6 +1569,8 @@
'browser/ui/search_engines/template_url_fetcher_ui_callbacks.h',
'browser/ui/search_engines/template_url_table_model.cc',
'browser/ui/search_engines/template_url_table_model.h',
+ 'browser/ui/settings_window_manager.cc',
+ 'browser/ui/settings_window_manager.h',
'browser/ui/profile_reset_bubble.h',
'browser/ui/profile_reset_bubble_stub.cc',
'browser/ui/simple_message_box.h',
diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc
index 3e268e6..e277754 100644
--- a/chrome/common/chrome_switches.cc
+++ b/chrome/common/chrome_switches.cc
@@ -673,6 +673,9 @@ const char kEnableSearchButtonInOmniboxForStr[] =
const char kEnableSearchButtonInOmniboxForStrOrIip[] =
"enable-search-button-in-omnibox-for-str-or-iip";
+// Enable settings in a separate browser window per profile.
+const char kEnableSettingsWindow[] = "enable-settings-window";
+
// Enable SPDY/4 alpha 2. This is a temporary testing flag.
const char kEnableSpdy4a2[] = "enable-spdy4a2";
diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h
index 2be68f5..d0a932e 100644
--- a/chrome/common/chrome_switches.h
+++ b/chrome/common/chrome_switches.h
@@ -193,6 +193,7 @@ extern const char kEnableSdchOverHttps[];
extern const char kEnableSearchButtonInOmniboxAlways[];
extern const char kEnableSearchButtonInOmniboxForStr[];
extern const char kEnableSearchButtonInOmniboxForStrOrIip[];
+extern const char kEnableSettingsWindow[];
extern const char kEnableSpdy4a2[];
extern const char kEnableSpellingAutoCorrect[];
extern const char kEnableSpellingFeedbackFieldTrial[];