diff options
author | mdm@chromium.org <mdm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-04 23:39:58 +0000 |
---|---|---|
committer | mdm@chromium.org <mdm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-04 23:39:58 +0000 |
commit | 264f74d108c0ebe22e633735606a4b8515a34400 (patch) | |
tree | 7bbe511e816955a1bac5cac1cf043d521b69ba4b /chrome | |
parent | 8ecce8712d3f7ff8051340dfbebf20872b86e372 (diff) | |
download | chromium_src-264f74d108c0ebe22e633735606a4b8515a34400.zip chromium_src-264f74d108c0ebe22e633735606a4b8515a34400.tar.gz chromium_src-264f74d108c0ebe22e633735606a4b8515a34400.tar.bz2 |
Allow the default browser check to return "unknown" and reflect that in the UI.
On Linux this can happen for unsupported desktop environments. On Windows and Mac OS X this probably should not occur and likely indicates some sort of serious configuration error. This change avoids repeatedly bothering the user to set the default browser in cases where we're likely to fail at that, without incorrectly displaying that we are the default browser.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/200025
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25553 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/app/generated_resources.grd | 3 | ||||
-rw-r--r-- | chrome/browser/cocoa/preferences_window_controller.mm | 20 | ||||
-rw-r--r-- | chrome/browser/gtk/options/general_page_gtk.cc | 6 | ||||
-rw-r--r-- | chrome/browser/shell_integration.cc | 27 | ||||
-rw-r--r-- | chrome/browser/shell_integration.h | 29 | ||||
-rw-r--r-- | chrome/browser/shell_integration_linux.cc | 11 | ||||
-rw-r--r-- | chrome/browser/shell_integration_mac.mm | 17 | ||||
-rw-r--r-- | chrome/browser/shell_integration_win.cc | 20 | ||||
-rw-r--r-- | chrome/browser/views/options/general_page_view.cc | 8 |
9 files changed, 93 insertions, 48 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd index c510d0e..d044e29 100644 --- a/chrome/app/generated_resources.grd +++ b/chrome/app/generated_resources.grd @@ -3470,6 +3470,9 @@ Keep your key file in a safe place. You will need it to create new versions of y <message name="IDS_OPTIONS_DEFAULTBROWSER_NOTDEFAULT" desc="The text displayed when Chrome is not the default browser"> <ph name="PRODUCT_NAME">$1<ex>Google Chrome</ex></ph> is not currently your default browser. </message> + <message name="IDS_OPTIONS_DEFAULTBROWSER_UNKNOWN" desc="The text displayed when Chrome cannot determine or set the default browser"> + <ph name="PRODUCT_NAME">$1<ex>Google Chrome</ex></ph> cannot determine or set the default browser. + </message> <message name="IDS_OPTIONS_DEFAULTBROWSER_USEASDEFAULT" desc="The label of the 'Use Chrome as default' browser button"> Make <ph name="PRODUCT_NAME">$1<ex>Google Chrome</ex></ph> my default browser </message> diff --git a/chrome/browser/cocoa/preferences_window_controller.mm b/chrome/browser/cocoa/preferences_window_controller.mm index 400c6cd..7a7179d 100644 --- a/chrome/browser/cocoa/preferences_window_controller.mm +++ b/chrome/browser/cocoa/preferences_window_controller.mm @@ -554,15 +554,16 @@ enum { kHomepageNewTabPage, kHomepageURL }; [self didChangeValueForKey:@"defaultBrowser"]; } -// Returns if Chromium is the default browser. -- (BOOL)isDefaultBrowser { - return ShellIntegration::IsDefaultBrowser() ? YES : NO; +// Returns the Chromium default browser state. +- (ShellIntegration::DefaultBrowserState)isDefaultBrowser { + return ShellIntegration::IsDefaultBrowser(); } // Returns the text color of the "chromium is your default browser" text (green // for yes, red for no). - (NSColor*)defaultBrowserTextColor { - return [self isDefaultBrowser] ? + ShellIntegration::DefaultBrowserState state = [self isDefaultBrowser]; + return (state == ShellIntegration::IS_DEFAULT_BROWSER) ? [NSColor colorWithCalibratedRed:0.0 green:135.0/255.0 blue:0 alpha:1.0] : [NSColor colorWithCalibratedRed:135.0/255.0 green:0 blue:0 alpha:1.0]; } @@ -570,9 +571,14 @@ enum { kHomepageNewTabPage, kHomepageURL }; // Returns the text for the "chromium is your default browser" string dependent // on if Chromium actually is or not. - (NSString*)defaultBrowserText { - BOOL isDefault = [self isDefaultBrowser]; - int stringId = isDefault ? IDS_OPTIONS_DEFAULTBROWSER_DEFAULT : - IDS_OPTIONS_DEFAULTBROWSER_NOTDEFAULT; + ShellIntegration::DefaultBrowserState state = [self isDefaultBrowser]; + int stringId; + if (state == ShellIntegration::IS_DEFAULT_BROWSER) + stringId = IDS_OPTIONS_DEFAULTBROWSER_DEFAULT; + else if (state == ShellIntegration::NOT_DEFAULT_BROWSER) + stringId = IDS_OPTIONS_DEFAULTBROWSER_NOTDEFAULT; + else + stringId = IDS_OPTIONS_DEFAULTBROWSER_UNKNOWN; std::wstring text = l10n_util::GetStringF(stringId, l10n_util::GetString(IDS_PRODUCT_NAME)); return base::SysWideToNSString(text); diff --git a/chrome/browser/gtk/options/general_page_gtk.cc b/chrome/browser/gtk/options/general_page_gtk.cc index ae97778..76915d2 100644 --- a/chrome/browser/gtk/options/general_page_gtk.cc +++ b/chrome/browser/gtk/options/general_page_gtk.cc @@ -693,7 +693,7 @@ void GeneralPageGtk::SetDefaultBrowserUIState( ShellIntegration::DefaultBrowserUIState state) { const char* color = NULL; std::string text; - if (state == ShellIntegration::STATE_DEFAULT) { + if (state == ShellIntegration::STATE_IS_DEFAULT) { color = kDefaultBrowserLabelColor; text = l10n_util::GetStringFUTF8(IDS_OPTIONS_DEFAULTBROWSER_DEFAULT, l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); @@ -701,6 +701,10 @@ void GeneralPageGtk::SetDefaultBrowserUIState( color = kNotDefaultBrowserLabelColor; text = l10n_util::GetStringFUTF8(IDS_OPTIONS_DEFAULTBROWSER_NOTDEFAULT, l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); + } else if (state == ShellIntegration::STATE_UNKNOWN) { + color = kNotDefaultBrowserLabelColor; + text = l10n_util::GetStringFUTF8(IDS_OPTIONS_DEFAULTBROWSER_UNKNOWN, + l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); } if (color) { char* markup = g_markup_printf_escaped(kDefaultBrowserLabelMarkup, diff --git a/chrome/browser/shell_integration.cc b/chrome/browser/shell_integration.cc index 219ce77..66833854 100644 --- a/chrome/browser/shell_integration.cc +++ b/chrome/browser/shell_integration.cc @@ -44,15 +44,15 @@ void ShellIntegration::DefaultBrowserWorker::ObserverDestroyed() { void ShellIntegration::DefaultBrowserWorker::ExecuteCheckDefaultBrowser() { DCHECK(MessageLoop::current() == file_loop_); - bool is_default = ShellIntegration::IsDefaultBrowser(); + DefaultBrowserState state = ShellIntegration::IsDefaultBrowser(); ui_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, - &DefaultBrowserWorker::CompleteCheckDefaultBrowser, is_default)); + &DefaultBrowserWorker::CompleteCheckDefaultBrowser, state)); } void ShellIntegration::DefaultBrowserWorker::CompleteCheckDefaultBrowser( - bool is_default) { + DefaultBrowserState state) { DCHECK(MessageLoop::current() == ui_loop_); - UpdateUI(is_default); + UpdateUI(state); } void ShellIntegration::DefaultBrowserWorker::ExecuteSetAsDefaultBrowser() { @@ -70,10 +70,21 @@ void ShellIntegration::DefaultBrowserWorker::CompleteSetAsDefaultBrowser() { } } -void ShellIntegration::DefaultBrowserWorker::UpdateUI(bool is_default) { +void ShellIntegration::DefaultBrowserWorker::UpdateUI( + DefaultBrowserState state) { if (observer_) { - DefaultBrowserUIState state = - is_default ? STATE_DEFAULT : STATE_NOT_DEFAULT; - observer_->SetDefaultBrowserUIState(state); + switch (state) { + case NOT_DEFAULT_BROWSER: + observer_->SetDefaultBrowserUIState(STATE_NOT_DEFAULT); + break; + case IS_DEFAULT_BROWSER: + observer_->SetDefaultBrowserUIState(STATE_IS_DEFAULT); + break; + case UNKNOWN_DEFAULT_BROWSER: + observer_->SetDefaultBrowserUIState(STATE_UNKNOWN); + break; + default: + break; + } } } diff --git a/chrome/browser/shell_integration.h b/chrome/browser/shell_integration.h index 2bc955c..daecacf 100644 --- a/chrome/browser/shell_integration.h +++ b/chrome/browser/shell_integration.h @@ -21,11 +21,21 @@ class ShellIntegration { // this operation fails. static bool SetAsDefaultBrowser(); - // Returns true if this instance of Chrome is the default browser. (Defined - // as being the handler for the http/https protocols... we don't want to - // report false here if the user has simply chosen to open HTML files in a - // text editor and ftp links with a FTP client). - static bool IsDefaultBrowser(); + // On Linux, it may not be possible to determine or set the default browser + // on some desktop environments or configurations. So, we use this enum and + // not a plain bool. (Note however that if used like a bool, this enum will + // have reasonable behavior.) + enum DefaultBrowserState { + NOT_DEFAULT_BROWSER = 0, + IS_DEFAULT_BROWSER, + UNKNOWN_DEFAULT_BROWSER + }; + + // Attempt to determine if this instance of Chrome is the default browser and + // return the appropriate state. (Defined as being the handler for HTTP/HTTPS + // protocols; we don't want to report "no" here if the user has simply chosen + // to open HTML files in a text editor and FTP links with an FTP client.) + static DefaultBrowserState IsDefaultBrowser(); // Returns true if Firefox is likely to be the default browser for the current // user. This method is very fast so it can be invoked in the UI thread. @@ -59,8 +69,9 @@ class ShellIntegration { // The current default browser UI state enum DefaultBrowserUIState { STATE_PROCESSING, - STATE_DEFAULT, - STATE_NOT_DEFAULT + STATE_NOT_DEFAULT, + STATE_IS_DEFAULT, + STATE_UNKNOWN }; class DefaultBrowserObserver { @@ -95,7 +106,7 @@ class ShellIntegration { // thread. |CompleteCheckDefaultBrowser| notifies the view to update on the // UI thread. void ExecuteCheckDefaultBrowser(); - void CompleteCheckDefaultBrowser(bool is_default); + void CompleteCheckDefaultBrowser(DefaultBrowserState state); // Functions that track the process of setting Chrome as the default // browser. |ExecuteSetAsDefaultBrowser| updates the registry on the file @@ -106,7 +117,7 @@ class ShellIntegration { // Updates the UI in our associated view with the current default browser // state. - void UpdateUI(bool is_default); + void UpdateUI(DefaultBrowserState state); DefaultBrowserObserver* observer_; diff --git a/chrome/browser/shell_integration_linux.cc b/chrome/browser/shell_integration_linux.cc index c7077d1..fb3fef8 100644 --- a/chrome/browser/shell_integration_linux.cc +++ b/chrome/browser/shell_integration_linux.cc @@ -180,7 +180,7 @@ bool ShellIntegration::SetAsDefaultBrowser() { return LaunchXdgUtility(argv); } -bool ShellIntegration::IsDefaultBrowser() { +ShellIntegration::DefaultBrowserState ShellIntegration::IsDefaultBrowser() { std::vector<std::string> argv; argv.push_back("xdg-settings"); argv.push_back("check"); @@ -189,15 +189,12 @@ bool ShellIntegration::IsDefaultBrowser() { std::string reply; if (!base::GetAppOutput(CommandLine(argv), &reply)) { - // If xdg-settings fails, we assume that we should pretend we're the default - // browser to avoid giving repeated prompts to set ourselves as the default. - // TODO(mdm): Really, being the default browser should be a ternary query: - // yes, no, and "don't know" so the UI can reflect this more accurately. - return true; + // xdg-settings failed: we can't determine or set the default browser. + return UNKNOWN_DEFAULT_BROWSER; } // Allow any reply that starts with "yes". - return reply.find("yes") == 0; + return (reply.find("yes") == 0) ? IS_DEFAULT_BROWSER : NOT_DEFAULT_BROWSER; } bool ShellIntegration::IsFirefoxDefaultBrowser() { diff --git a/chrome/browser/shell_integration_mac.mm b/chrome/browser/shell_integration_mac.mm index 28fdd8c..fbf88bb 100644 --- a/chrome/browser/shell_integration_mac.mm +++ b/chrome/browser/shell_integration_mac.mm @@ -22,7 +22,7 @@ namespace { bool IsIdentifierDefaultBrowser(NSString* identifier) { NSString* defaultBrowser = [[NSWorkspace sharedWorkspace] defaultBrowserIdentifier]; - if (!identifier || !defaultBrowser) + if (!defaultBrowser) return false; // We need to ensure we do the comparison case-insensitive as LS doesn't // persist the case of our bundle id. @@ -33,14 +33,17 @@ bool IsIdentifierDefaultBrowser(NSString* identifier) { } // namespace -// Returns true if this instance of Chromium is the default browser. (Defined -// as being the handler for the http/https protocols... we don't want to -// report false here if the user has simply chosen to open HTML files in a -// text editor and ftp links with a FTP client). -bool ShellIntegration::IsDefaultBrowser() { +// Attempt to determine if this instance of Chrome is the default browser and +// return the appropriate state. (Defined as being the handler for HTTP/HTTPS +// protocols; we don't want to report "no" here if the user has simply chosen +// to open HTML files in a text editor and FTP links with an FTP client.) +ShellIntegration::DefaultBrowserState ShellIntegration::IsDefaultBrowser() { NSBundle* mainBundle = mac_util::MainAppBundle(); NSString* myIdentifier = [mainBundle bundleIdentifier]; - return IsIdentifierDefaultBrowser(myIdentifier); + if (!myIdentifier) + return UNKNOWN_DEFAULT_BROWSER; + return IsIdentifierDefaultBrowser(myIdentifier) ? IS_DEFAULT_BROWSER + : NOT_DEFAULT_BROWSER; } // Returns true if Firefox is the default browser for the current user. diff --git a/chrome/browser/shell_integration_win.cc b/chrome/browser/shell_integration_win.cc index 040b03c..cebc421 100644 --- a/chrome/browser/shell_integration_win.cc +++ b/chrome/browser/shell_integration_win.cc @@ -44,13 +44,13 @@ bool ShellIntegration::SetAsDefaultBrowser() { return true; } -bool ShellIntegration::IsDefaultBrowser() { +ShellIntegration::DefaultBrowserState ShellIntegration::IsDefaultBrowser() { // First determine the app path. If we can't determine what that is, we have // bigger fish to fry... std::wstring app_path; if (!PathService::Get(base::FILE_EXE, &app_path)) { LOG(ERROR) << "Error getting app exe path"; - return false; + return UNKNOWN_DEFAULT_BROWSER; } // When we check for default browser we don't necessarily want to count file // type handlers and icons as having changed the default browser status, @@ -69,7 +69,7 @@ bool ShellIntegration::IsDefaultBrowser() { NULL, CLSCTX_INPROC, __uuidof(IApplicationAssociationRegistration), (void**)&pAAR); if (!SUCCEEDED(hr)) - return false; + return UNKNOWN_DEFAULT_BROWSER; BrowserDistribution* dist = BrowserDistribution::GetDistribution(); std::wstring app_name = dist->GetApplicationName(); @@ -84,9 +84,13 @@ bool ShellIntegration::IsDefaultBrowser() { BOOL result = TRUE; hr = pAAR->QueryAppIsDefault(kChromeProtocols[i].c_str(), AT_URLPROTOCOL, AL_EFFECTIVE, app_name.c_str(), &result); - if (!SUCCEEDED(hr) || (result == FALSE)) { + if (!SUCCEEDED(hr)) { + pAAR->Release(); + return UNKNOWN_DEFAULT_BROWSER; + } + if (result == FALSE) { pAAR->Release(); - return false; + return NOT_DEFAULT_BROWSER; } } pAAR->Release(); @@ -105,7 +109,7 @@ bool ShellIntegration::IsDefaultBrowser() { RegKey key(root_key, key_path.c_str(), KEY_READ); std::wstring value; if (!key.Valid() || !key.ReadValue(L"", &value)) - return false; + return UNKNOWN_DEFAULT_BROWSER; // Need to normalize path in case it's been munged. CommandLine command_line(L""); command_line.ParseFromString(value); @@ -117,10 +121,10 @@ bool ShellIntegration::IsDefaultBrowser() { short_path.end(), short_app_path.begin(), CaseInsensitiveCompare<wchar_t>()))) - return false; + return NOT_DEFAULT_BROWSER; } } - return true; + return IS_DEFAULT_BROWSER; } // There is no reliable way to say which browser is default on a machine (each diff --git a/chrome/browser/views/options/general_page_view.cc b/chrome/browser/views/options/general_page_view.cc index cb87b72..94fb959 100644 --- a/chrome/browser/views/options/general_page_view.cc +++ b/chrome/browser/views/options/general_page_view.cc @@ -646,7 +646,7 @@ void GeneralPageView::SetDefaultBrowserUIState( ShellIntegration::DefaultBrowserUIState state) { bool button_enabled = state == ShellIntegration::STATE_NOT_DEFAULT; default_browser_use_as_default_button_->SetEnabled(button_enabled); - if (state == ShellIntegration::STATE_DEFAULT) { + if (state == ShellIntegration::STATE_IS_DEFAULT) { default_browser_status_label_->SetText( l10n_util::GetStringF(IDS_OPTIONS_DEFAULTBROWSER_DEFAULT, l10n_util::GetString(IDS_PRODUCT_NAME))); @@ -658,6 +658,12 @@ void GeneralPageView::SetDefaultBrowserUIState( l10n_util::GetString(IDS_PRODUCT_NAME))); default_browser_status_label_->SetColor(kNotDefaultBrowserLabelColor); Layout(); + } else if (state == ShellIntegration::STATE_UNKNOWN) { + default_browser_status_label_->SetText( + l10n_util::GetStringF(IDS_OPTIONS_DEFAULTBROWSER_UNKNOWN, + l10n_util::GetString(IDS_PRODUCT_NAME))); + default_browser_status_label_->SetColor(kNotDefaultBrowserLabelColor); + Layout(); } } |