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

Side by Side Diff: chrome/browser/dom_ui/options/browser_options_handler.cc

Issue 6332006: DOMUI Prefs: Improve saving of homepage pref. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 11 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/dom_ui/options/browser_options_handler.h" 5 #include "chrome/browser/dom_ui/options/browser_options_handler.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/scoped_ptr.h" 9 #include "base/scoped_ptr.h"
10 #include "base/singleton.h" 10 #include "base/singleton.h"
11 #include "base/string_number_conversions.h" 11 #include "base/string_number_conversions.h"
12 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "chrome/browser/browser_thread.h" 14 #include "chrome/browser/browser_thread.h"
15 #include "chrome/browser/custom_home_pages_table_model.h" 15 #include "chrome/browser/custom_home_pages_table_model.h"
16 #include "chrome/browser/dom_ui/dom_ui_favicon_source.h" 16 #include "chrome/browser/dom_ui/dom_ui_favicon_source.h"
17 #include "chrome/browser/dom_ui/options/dom_options_util.h" 17 #include "chrome/browser/dom_ui/options/dom_options_util.h"
18 #include "chrome/browser/dom_ui/options/options_managed_banner_handler.h" 18 #include "chrome/browser/dom_ui/options/options_managed_banner_handler.h"
19 #include "chrome/browser/instant/instant_confirm_dialog.h" 19 #include "chrome/browser/instant/instant_confirm_dialog.h"
20 #include "chrome/browser/metrics/user_metrics.h" 20 #include "chrome/browser/metrics/user_metrics.h"
21 #include "chrome/browser/net/url_fixer_upper.h" 21 #include "chrome/browser/net/url_fixer_upper.h"
22 #include "chrome/browser/prefs/session_startup_pref.h" 22 #include "chrome/browser/prefs/session_startup_pref.h"
23 #include "chrome/browser/profiles/profile.h" 23 #include "chrome/browser/profiles/profile.h"
24 #include "chrome/browser/search_engines/template_url.h" 24 #include "chrome/browser/search_engines/template_url.h"
25 #include "chrome/browser/search_engines/template_url_model.h" 25 #include "chrome/browser/search_engines/template_url_model.h"
26 #include "chrome/browser/ui/options/options_window.h" 26 #include "chrome/browser/ui/options/options_window.h"
27 #include "chrome/common/pref_names.h"
27 #include "chrome/installer/util/browser_distribution.h" 28 #include "chrome/installer/util/browser_distribution.h"
28 #include "grit/chromium_strings.h" 29 #include "grit/chromium_strings.h"
29 #include "grit/generated_resources.h" 30 #include "grit/generated_resources.h"
30 31
31 BrowserOptionsHandler::BrowserOptionsHandler() 32 BrowserOptionsHandler::BrowserOptionsHandler()
32 : template_url_model_(NULL), startup_custom_pages_table_model_(NULL) { 33 : template_url_model_(NULL), startup_custom_pages_table_model_(NULL) {
33 #if !defined(OS_MACOSX) 34 #if !defined(OS_MACOSX)
34 default_browser_worker_ = new ShellIntegration::DefaultBrowserWorker(this); 35 default_browser_worker_ = new ShellIntegration::DefaultBrowserWorker(this);
35 #endif 36 #endif
36 } 37 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 localized_strings->SetString("defaultBrowserUnknown", 92 localized_strings->SetString("defaultBrowserUnknown",
92 l10n_util::GetStringFUTF16(IDS_OPTIONS_DEFAULTBROWSER_UNKNOWN, 93 l10n_util::GetStringFUTF16(IDS_OPTIONS_DEFAULTBROWSER_UNKNOWN,
93 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); 94 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)));
94 localized_strings->SetString("defaultBrowserUseAsDefault", 95 localized_strings->SetString("defaultBrowserUseAsDefault",
95 l10n_util::GetStringFUTF16(IDS_OPTIONS_DEFAULTBROWSER_USEASDEFAULT, 96 l10n_util::GetStringFUTF16(IDS_OPTIONS_DEFAULTBROWSER_USEASDEFAULT,
96 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); 97 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)));
97 } 98 }
98 99
99 void BrowserOptionsHandler::RegisterMessages() { 100 void BrowserOptionsHandler::RegisterMessages() {
100 dom_ui_->RegisterMessageCallback( 101 dom_ui_->RegisterMessageCallback(
102 "setHomePage",
103 NewCallback(this, &BrowserOptionsHandler::SetHomePage));
104 dom_ui_->RegisterMessageCallback(
101 "becomeDefaultBrowser", 105 "becomeDefaultBrowser",
102 NewCallback(this, &BrowserOptionsHandler::BecomeDefaultBrowser)); 106 NewCallback(this, &BrowserOptionsHandler::BecomeDefaultBrowser));
103 dom_ui_->RegisterMessageCallback( 107 dom_ui_->RegisterMessageCallback(
104 "setDefaultSearchEngine", 108 "setDefaultSearchEngine",
105 NewCallback(this, &BrowserOptionsHandler::SetDefaultSearchEngine)); 109 NewCallback(this, &BrowserOptionsHandler::SetDefaultSearchEngine));
106 dom_ui_->RegisterMessageCallback( 110 dom_ui_->RegisterMessageCallback(
107 "removeStartupPages", 111 "removeStartupPages",
108 NewCallback(this, &BrowserOptionsHandler::RemoveStartupPages)); 112 NewCallback(this, &BrowserOptionsHandler::RemoveStartupPages));
109 dom_ui_->RegisterMessageCallback( 113 dom_ui_->RegisterMessageCallback(
110 "addStartupPage", 114 "addStartupPage",
111 NewCallback(this, &BrowserOptionsHandler::AddStartupPage)); 115 NewCallback(this, &BrowserOptionsHandler::AddStartupPage));
112 dom_ui_->RegisterMessageCallback( 116 dom_ui_->RegisterMessageCallback(
113 "editStartupPage", 117 "editStartupPage",
114 NewCallback(this, &BrowserOptionsHandler::EditStartupPage)); 118 NewCallback(this, &BrowserOptionsHandler::EditStartupPage));
115 dom_ui_->RegisterMessageCallback( 119 dom_ui_->RegisterMessageCallback(
116 "setStartupPagesToCurrentPages", 120 "setStartupPagesToCurrentPages",
117 NewCallback(this, &BrowserOptionsHandler::SetStartupPagesToCurrentPages)); 121 NewCallback(this, &BrowserOptionsHandler::SetStartupPagesToCurrentPages));
118 } 122 }
119 123
120 void BrowserOptionsHandler::Initialize() { 124 void BrowserOptionsHandler::Initialize() {
125 Profile* profile = dom_ui_->GetProfile();
126
121 // Create our favicon data source. 127 // Create our favicon data source.
122 BrowserThread::PostTask( 128 BrowserThread::PostTask(
123 BrowserThread::IO, FROM_HERE, 129 BrowserThread::IO, FROM_HERE,
124 NewRunnableMethod( 130 NewRunnableMethod(
125 ChromeURLDataManager::GetInstance(), 131 ChromeURLDataManager::GetInstance(),
126 &ChromeURLDataManager::AddDataSource, 132 &ChromeURLDataManager::AddDataSource,
127 make_scoped_refptr(new DOMUIFavIconSource(dom_ui_->GetProfile())))); 133 make_scoped_refptr(new DOMUIFavIconSource(profile))));
128 134
135 homepage_.Init(prefs::kHomePage, profile->GetPrefs(), NULL);
129 UpdateDefaultBrowserState(); 136 UpdateDefaultBrowserState();
130 UpdateStartupPages(); 137 UpdateStartupPages();
131 UpdateSearchEngines(); 138 UpdateSearchEngines();
132 banner_handler_.reset( 139 banner_handler_.reset(
133 new OptionsManagedBannerHandler(dom_ui_, 140 new OptionsManagedBannerHandler(dom_ui_,
134 ASCIIToUTF16("BrowserOptions"), 141 ASCIIToUTF16("BrowserOptions"),
135 OPTIONS_PAGE_GENERAL)); 142 OPTIONS_PAGE_GENERAL));
136 } 143 }
137 144
145 void BrowserOptionsHandler::SetHomePage(const ListValue* args) {
146 std::string url_string;
147 std::string do_fixup_string;
148 int do_fixup;
149 if (args->GetSize() != 2 ||
150 !args->GetString(0, &url_string) ||
151 !args->GetString(1, &do_fixup_string) ||
152 !base::StringToInt(do_fixup_string, &do_fixup)) {
153 CHECK(false);
154 };
155
156 if (do_fixup) {
157 GURL fixed_url = URLFixerUpper::FixupURL(url_string, std::string());
158 url_string = fixed_url.spec();
159 }
160 homepage_.SetValueIfNotManaged(url_string);
161 }
162
138 void BrowserOptionsHandler::UpdateDefaultBrowserState() { 163 void BrowserOptionsHandler::UpdateDefaultBrowserState() {
139 #if defined(OS_WIN) 164 #if defined(OS_WIN)
140 // Check for side-by-side first. 165 // Check for side-by-side first.
141 if (!BrowserDistribution::GetDistribution()->CanSetAsDefault()) { 166 if (!BrowserDistribution::GetDistribution()->CanSetAsDefault()) {
142 SetDefaultBrowserUIString(IDS_OPTIONS_DEFAULTBROWSER_SXS); 167 SetDefaultBrowserUIString(IDS_OPTIONS_DEFAULTBROWSER_SXS);
143 return; 168 return;
144 } 169 }
145 #endif 170 #endif
146 171
147 #if defined(OS_MACOSX) 172 #if defined(OS_MACOSX)
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 } 402 }
378 403
379 void BrowserOptionsHandler::SaveStartupPagesPref() { 404 void BrowserOptionsHandler::SaveStartupPagesPref() {
380 PrefService* prefs = dom_ui_->GetProfile()->GetPrefs(); 405 PrefService* prefs = dom_ui_->GetProfile()->GetPrefs();
381 406
382 SessionStartupPref pref = SessionStartupPref::GetStartupPref(prefs); 407 SessionStartupPref pref = SessionStartupPref::GetStartupPref(prefs);
383 pref.urls = startup_custom_pages_table_model_->GetURLs(); 408 pref.urls = startup_custom_pages_table_model_->GetURLs();
384 409
385 SessionStartupPref::SetStartupPref(prefs, pref); 410 SessionStartupPref::SetStartupPref(prefs, pref);
386 } 411 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698