summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/dom_ui/browser_options_handler.cc96
-rw-r--r--chrome/browser/dom_ui/browser_options_handler.h24
-rw-r--r--chrome/browser/resources/options.html2
-rw-r--r--chrome/browser/resources/options/browser_options.html26
-rw-r--r--chrome/browser/resources/options/browser_options.js35
-rw-r--r--chrome/browser/resources/options/browser_options_page.css7
-rw-r--r--chrome/browser/resources/options/options_page.css2
7 files changed, 164 insertions, 28 deletions
diff --git a/chrome/browser/dom_ui/browser_options_handler.cc b/chrome/browser/dom_ui/browser_options_handler.cc
index dfcd223..7ab1bc1 100644
--- a/chrome/browser/dom_ui/browser_options_handler.cc
+++ b/chrome/browser/dom_ui/browser_options_handler.cc
@@ -6,14 +6,21 @@
#include "app/l10n_util.h"
#include "base/basictypes.h"
+#include "base/scoped_ptr.h"
#include "base/values.h"
+#include "chrome/installer/util/browser_distribution.h"
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
BrowserOptionsHandler::BrowserOptionsHandler() {
+#if !defined(OS_MACOSX)
+ default_browser_worker_ = new ShellIntegration::DefaultBrowserWorker(this);
+#endif
}
BrowserOptionsHandler::~BrowserOptionsHandler() {
+ if (default_browser_worker_.get())
+ default_browser_worker_->ObserverDestroyed();
}
void BrowserOptionsHandler::GetLocalizedValues(
@@ -47,16 +54,93 @@ void BrowserOptionsHandler::GetLocalizedValues(
l10n_util::GetString(IDS_OPTIONS_DEFAULTSEARCH_MANAGE_ENGINES_LINK));
localized_strings->SetString(L"defaultBrowserGroupName",
l10n_util::GetString(IDS_OPTIONS_DEFAULTBROWSER_GROUP_NAME));
- localized_strings->SetString(L"defaultBrowserNotDefault",
- l10n_util::GetStringF(IDS_OPTIONS_DEFAULTBROWSER_NOTDEFAULT,
- l10n_util::GetString(IDS_PRODUCT_NAME)));
localized_strings->SetString(L"defaultBrowserUnknown",
l10n_util::GetStringF(IDS_OPTIONS_DEFAULTBROWSER_UNKNOWN,
l10n_util::GetString(IDS_PRODUCT_NAME)));
- localized_strings->SetString(L"defaultBrowserSXS",
- l10n_util::GetStringF(IDS_OPTIONS_DEFAULTBROWSER_SXS,
- l10n_util::GetString(IDS_PRODUCT_NAME)));
localized_strings->SetString(L"defaultBrowserUseAsDefault",
l10n_util::GetStringF(IDS_OPTIONS_DEFAULTBROWSER_USEASDEFAULT,
l10n_util::GetString(IDS_PRODUCT_NAME)));
}
+
+void BrowserOptionsHandler::RegisterMessages() {
+ dom_ui_->RegisterMessageCallback(
+ "updateDefaultBrowserState",
+ NewCallback(this, &BrowserOptionsHandler::UpdateDefaultBrowserState));
+ dom_ui_->RegisterMessageCallback(
+ "becomeDefaultBrowser",
+ NewCallback(this, &BrowserOptionsHandler::BecomeDefaultBrowser));
+}
+
+void BrowserOptionsHandler::UpdateDefaultBrowserState(const Value* value) {
+#if defined(OS_WIN)
+ // Check for side-by-side first.
+ if (!BrowserDistribution::GetDistribution()->CanSetAsDefault()) {
+ SetDefaultBrowserUIString(IDS_OPTIONS_DEFAULTBROWSER_SXS);
+ return;
+ }
+#endif
+
+#if defined(OS_MACOSX)
+ ShellIntegration::DefaultBrowserState state =
+ ShellIntegration::IsDefaultBrowser();
+ int status_string_id;
+ if (state == ShellIntegration::IS_DEFAULT_BROWSER)
+ status_string_id = IDS_OPTIONS_DEFAULTBROWSER_DEFAULT;
+ else if (state == ShellIntegration::NOT_DEFAULT_BROWSER)
+ status_string_id = IDS_OPTIONS_DEFAULTBROWSER_NOTDEFAULT;
+ else
+ status_string_id = IDS_OPTIONS_DEFAULTBROWSER_UNKNOWN;
+
+ SetDefaultBrowserUIString(status_string_id);
+#else
+ default_browser_worker_->StartCheckDefaultBrowser();
+#endif
+}
+
+void BrowserOptionsHandler::BecomeDefaultBrowser(const Value* value) {
+#if defined(OS_MACOSX)
+ if (ShellIntegration::SetAsDefaultBrowser())
+ UpdateDefaultBrowserState(NULL);
+#else
+ default_browser_worker_->StartSetAsDefaultBrowser();
+ // Callback takes care of updating UI.
+#endif
+}
+
+int BrowserOptionsHandler::StatusStringIdForState(
+ ShellIntegration::DefaultBrowserState state) {
+ if (state == ShellIntegration::IS_DEFAULT_BROWSER)
+ return IDS_OPTIONS_DEFAULTBROWSER_DEFAULT;
+ if (state == ShellIntegration::NOT_DEFAULT_BROWSER)
+ return IDS_OPTIONS_DEFAULTBROWSER_NOTDEFAULT;
+ return IDS_OPTIONS_DEFAULTBROWSER_UNKNOWN;
+}
+
+void BrowserOptionsHandler::SetDefaultBrowserUIState(
+ ShellIntegration::DefaultBrowserUIState state) {
+ int status_string_id;
+ if (state == ShellIntegration::STATE_IS_DEFAULT)
+ status_string_id = IDS_OPTIONS_DEFAULTBROWSER_DEFAULT;
+ else if (state == ShellIntegration::STATE_NOT_DEFAULT)
+ status_string_id = IDS_OPTIONS_DEFAULTBROWSER_NOTDEFAULT;
+ else if (state == ShellIntegration::STATE_UNKNOWN)
+ status_string_id = IDS_OPTIONS_DEFAULTBROWSER_UNKNOWN;
+ else
+ return; // Still processing.
+
+ SetDefaultBrowserUIString(status_string_id);
+}
+
+void BrowserOptionsHandler::SetDefaultBrowserUIString(int status_string_id) {
+ scoped_ptr<Value> status_string(Value::CreateStringValue(
+ l10n_util::GetStringF(status_string_id,
+ l10n_util::GetString(IDS_PRODUCT_NAME))));
+
+ scoped_ptr<Value> is_default(Value::CreateBooleanValue(
+ status_string_id == IDS_OPTIONS_DEFAULTBROWSER_DEFAULT));
+
+ dom_ui_->CallJavascriptFunction(
+ L"BrowserOptions.updateDefaultBrowserStateCallback",
+ *(status_string.get()), *(is_default.get()));
+}
+
diff --git a/chrome/browser/dom_ui/browser_options_handler.h b/chrome/browser/dom_ui/browser_options_handler.h
index 4ba0897..2ba41da 100644
--- a/chrome/browser/dom_ui/browser_options_handler.h
+++ b/chrome/browser/dom_ui/browser_options_handler.h
@@ -6,17 +6,39 @@
#define CHROME_BROWSER_DOM_UI_BROWSER_OPTIONS_HANDLER_H_
#include "chrome/browser/dom_ui/options_ui.h"
+#include "chrome/browser/shell_integration.h"
// Chrome browser options page UI handler.
-class BrowserOptionsHandler : public OptionsPageUIHandler {
+class BrowserOptionsHandler : public OptionsPageUIHandler,
+ public ShellIntegration::DefaultBrowserObserver {
public:
BrowserOptionsHandler();
virtual ~BrowserOptionsHandler();
// OptionsUIHandler implementation.
virtual void GetLocalizedValues(DictionaryValue* localized_strings);
+ virtual void RegisterMessages();
+
+ // ShellIntegration::DefaultBrowserObserver implementation.
+ virtual void SetDefaultBrowserUIState(
+ ShellIntegration::DefaultBrowserUIState state);
private:
+ // Gets the current default browser state, and asynchronously reports it back
+ // to the DOMUI page. Called from DOMUI.
+ void UpdateDefaultBrowserState(const Value* value);
+
+ // Makes this the default browser. Called from DOMUI.
+ void BecomeDefaultBrowser(const Value* value);
+
+ // Returns the string ID for the given default browser state.
+ int StatusStringIdForState(ShellIntegration::DefaultBrowserState state);
+
+ // Updates the UI with the given state.
+ void SetDefaultBrowserUIString(int status_string_id);
+
+ scoped_refptr<ShellIntegration::DefaultBrowserWorker> default_browser_worker_;
+
DISALLOW_COPY_AND_ASSIGN(BrowserOptionsHandler);
};
diff --git a/chrome/browser/resources/options.html b/chrome/browser/resources/options.html
index bb67fb0..0fd0962 100644
--- a/chrome/browser/resources/options.html
+++ b/chrome/browser/resources/options.html
@@ -82,6 +82,7 @@ window.onpopstate = function(e) {
</script>
<link rel="stylesheet" href="dom_ui.css">
<link rel="stylesheet" href="options/options_page.css">
+<link rel="stylesheet" href="options/browser_options_page.css">
<link rel="stylesheet" href="options/content_settings_page.css">
</head>
<body i18n-values=".style.fontFamily:fontfamily;.style.fontSize:fontsize">
@@ -112,7 +113,6 @@ window.onpopstate = function(e) {
<include src="options/chromeos_labs.html">
<!-- TODO(mazda): include options/chromeos_language_hangul_options.html
once the language options dialog is ready. -->
- <include src="options/sync_options.html" >
</if>
<include src="options/browser_options.html">
<include src="options/personal_options.html">
diff --git a/chrome/browser/resources/options/browser_options.html b/chrome/browser/resources/options/browser_options.html
index eee5098..6fce008 100644
--- a/chrome/browser/resources/options/browser_options.html
+++ b/chrome/browser/resources/options/browser_options.html
@@ -3,23 +3,23 @@
<section>
<h3 i18n-content="startupGroupName"></h3>
<div>
- <label><input type="radio" name="startup"
+ <label><input type="radio" name="startup" disabled
value="ShowDefaultAndNewTab"><span
i18n-content="startupShowDefaultAndNewTab"></span></label><br>
- <label><input type="radio" name="startup"
+ <label><input type="radio" name="startup" disabled
value="ShowLastSession"><span
i18n-content="startupShowLastSession"></span></label><br>
- <label><input type="radio" name="startup"
+ <label><input type="radio" name="startup" disabled
value="ShowPages"><span
i18n-content="startupShowPages"></span></label>
<div class="suboption">
<select size="3" style="width:100%">
</select><br>
- <button id="startupAddButton"
+ <button id="startupAddButton" disabled
i18n-content="startupAddButton"></button>
- <button id="startupRemoveButton"
+ <button id="startupRemoveButton" disabled
i18n-content="startupRemoveButton"></button>
- <button id="startupUseCurrentButton"
+ <button id="startupUseCurrentButton" disabled
i18n-content="startupUseCurrent"></button>
</div>
</div>
@@ -27,14 +27,14 @@
<section>
<h3 i18n-content="homepageGroupName"></h3>
<div>
- <label><input type="radio" name="homepage"
+ <label><input type="radio" name="homepage" disabled
value="UseNewTab"><span
i18n-content="homepageUseNewTab"></span></label><br>
- <label><input type="radio" name="homepage"
- value="UseNewTab"><span
+ <label><input type="radio" name="homepage" disabled
+ value="UseURL"><span
i18n-content="homepageUseURL"></span></label><br>
<div class="suboption">
- <input type="url">
+ <input type="url" style="width:100%" disabled>
</div>
<div class="option">
<label><input id="homepageShowButton"
@@ -46,17 +46,17 @@
<section>
<h3 i18n-content="defaultSearchGroupName"></h3>
<div>
- <select>
+ <select disabled>
<option value="TODO" i18n-content="TODO"></option>
</select>
- <button id="defaultSearchManageEnginesButton"
+ <button id="defaultSearchManageEnginesButton" disabled
i18n-content="defaultSearchManageEnginesLink"></button>
</div>
</section>
<section>
<h3 i18n-content="defaultBrowserGroupName"></h3>
<div>
- <p><span i18n-content="TODO"></span></p>
+ <p id="defaultBrowserState" i18n-content="defaultBrowserUnknown"></p>
<button id="defaultBrowserUseAsDefaultButton"
i18n-content="defaultBrowserUseAsDefault"></button>
</div>
diff --git a/chrome/browser/resources/options/browser_options.js b/chrome/browser/resources/options/browser_options.js
index fc84913..42e3265 100644
--- a/chrome/browser/resources/options/browser_options.js
+++ b/chrome/browser/resources/options/browser_options.js
@@ -26,12 +26,10 @@ BrowserOptions.prototype = {
// Call base class implementation to start preference initialization.
OptionsPage.prototype.initializePage.call(this);
- $('defaultSearchManageEnginesButton').onclick = function(event) {
- // TODO(stuartmorgan): Spawn search engine management sub-dialog.
- };
- $('defaultBrowserUseAsDefaultButton').onclick = function(event) {
- // TODO(stuartmorgan): Handle making browser default.
- };
+ // Fetch initial state of the default browser pref section.
+ chrome.send('updateDefaultBrowserState');
+
+ // Wire up buttons.
$('startupAddButton').onclick = function(event) {
// TODO(stuartmorgan): Spawn add sub-dialog.
};
@@ -41,6 +39,31 @@ BrowserOptions.prototype = {
$('startupUseCurrentButton').onclick = function(event) {
// TODO(stuartmorgan): Add all open tabs (except this one).
};
+ $('defaultSearchManageEnginesButton').onclick = function(event) {
+ // TODO(stuartmorgan): Spawn search engine management sub-dialog.
+ };
+ $('defaultBrowserUseAsDefaultButton').onclick = function(event) {
+ chrome.send('becomeDefaultBrowser');
+ };
+ },
+
+ // Update the Default Browsers section based on the current state.
+ updateDefaultBrowserState_: function(statusString, isDefault) {
+ var label = $('defaultBrowserState');
+ label.textContent = statusString;
+ if (isDefault) {
+ label.classList.add('current');
+ } else {
+ label.classList.remove('current');
+ }
+
+ $('defaultBrowserUseAsDefaultButton').disabled = isDefault;
},
};
+BrowserOptions.updateDefaultBrowserStateCallback = function(statusString,
+ isDefault) {
+ BrowserOptions.getInstance().updateDefaultBrowserState_(statusString,
+ isDefault);
+}
+
diff --git a/chrome/browser/resources/options/browser_options_page.css b/chrome/browser/resources/options/browser_options_page.css
new file mode 100644
index 0000000..17dfc63
--- /dev/null
+++ b/chrome/browser/resources/options/browser_options_page.css
@@ -0,0 +1,7 @@
+#defaultBrowserState {
+ color: #880000;
+}
+
+#defaultBrowserState.current {
+ color: #008800;
+}
diff --git a/chrome/browser/resources/options/options_page.css b/chrome/browser/resources/options/options_page.css
index d2cf9c1..b515d01 100644
--- a/chrome/browser/resources/options/options_page.css
+++ b/chrome/browser/resources/options/options_page.css
@@ -120,7 +120,7 @@ section > div:only-of-type {
}
.suboption {
- margin-left: 18px;
+ -webkit-margin-start: 18px;
}
.hidden {