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

Side by Side Diff: chrome/browser/ui/webui/options/browser_options_handler.cc

Issue 7554008: Removal of Profile from content part 6. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Profile helper function, rebase Created 9 years, 4 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/ui/webui/options/browser_options_handler.h" 5 #include "chrome/browser/ui/webui/options/browser_options_handler.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/memory/singleton.h" 9 #include "base/memory/singleton.h"
10 #include "base/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 NewCallback(this, &BrowserOptionsHandler::EnableInstant)); 132 NewCallback(this, &BrowserOptionsHandler::EnableInstant));
133 web_ui_->RegisterMessageCallback( 133 web_ui_->RegisterMessageCallback(
134 "disableInstant", 134 "disableInstant",
135 NewCallback(this, &BrowserOptionsHandler::DisableInstant)); 135 NewCallback(this, &BrowserOptionsHandler::DisableInstant));
136 web_ui_->RegisterMessageCallback( 136 web_ui_->RegisterMessageCallback(
137 "getInstantFieldTrialStatus", 137 "getInstantFieldTrialStatus",
138 NewCallback(this, &BrowserOptionsHandler::GetInstantFieldTrialStatus)); 138 NewCallback(this, &BrowserOptionsHandler::GetInstantFieldTrialStatus));
139 } 139 }
140 140
141 void BrowserOptionsHandler::Initialize() { 141 void BrowserOptionsHandler::Initialize() {
142 Profile* profile = web_ui_->GetProfile(); 142 Profile* profile = Profile::FromWebUI(web_ui_);
143 143
144 // Create our favicon data source. 144 // Create our favicon data source.
145 profile->GetChromeURLDataManager()->AddDataSource( 145 profile->GetChromeURLDataManager()->AddDataSource(
146 new FaviconSource(profile, FaviconSource::FAVICON)); 146 new FaviconSource(profile, FaviconSource::FAVICON));
147 147
148 homepage_.Init(prefs::kHomePage, profile->GetPrefs(), NULL); 148 homepage_.Init(prefs::kHomePage, profile->GetPrefs(), NULL);
149 default_browser_policy_.Init(prefs::kDefaultBrowserSettingEnabled, 149 default_browser_policy_.Init(prefs::kDefaultBrowserSettingEnabled,
150 g_browser_process->local_state(), 150 g_browser_process->local_state(),
151 this); 151 this);
152 UpdateDefaultBrowserState(); 152 UpdateDefaultBrowserState();
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 #if defined(OS_MACOSX) 215 #if defined(OS_MACOSX)
216 if (ShellIntegration::SetAsDefaultBrowser()) 216 if (ShellIntegration::SetAsDefaultBrowser())
217 UpdateDefaultBrowserState(); 217 UpdateDefaultBrowserState();
218 #else 218 #else
219 default_browser_worker_->StartSetAsDefault(); 219 default_browser_worker_->StartSetAsDefault();
220 // Callback takes care of updating UI. 220 // Callback takes care of updating UI.
221 #endif 221 #endif
222 222
223 // If the user attempted to make Chrome the default browser, then he/she 223 // If the user attempted to make Chrome the default browser, then he/she
224 // arguably wants to be notified when that changes. 224 // arguably wants to be notified when that changes.
225 PrefService* prefs = web_ui_->GetProfile()->GetPrefs(); 225 PrefService* prefs = Profile::FromWebUI(web_ui_)->GetPrefs();
226 prefs->SetBoolean(prefs::kCheckDefaultBrowser, true); 226 prefs->SetBoolean(prefs::kCheckDefaultBrowser, true);
227 } 227 }
228 228
229 int BrowserOptionsHandler::StatusStringIdForState( 229 int BrowserOptionsHandler::StatusStringIdForState(
230 ShellIntegration::DefaultWebClientState state) { 230 ShellIntegration::DefaultWebClientState state) {
231 if (state == ShellIntegration::IS_DEFAULT_WEB_CLIENT) 231 if (state == ShellIntegration::IS_DEFAULT_WEB_CLIENT)
232 return IDS_OPTIONS_DEFAULTBROWSER_DEFAULT; 232 return IDS_OPTIONS_DEFAULTBROWSER_DEFAULT;
233 if (state == ShellIntegration::NOT_DEFAULT_WEB_CLIENT) 233 if (state == ShellIntegration::NOT_DEFAULT_WEB_CLIENT)
234 return IDS_OPTIONS_DEFAULTBROWSER_NOTDEFAULT; 234 return IDS_OPTIONS_DEFAULTBROWSER_NOTDEFAULT;
235 return IDS_OPTIONS_DEFAULTBROWSER_UNKNOWN; 235 return IDS_OPTIONS_DEFAULTBROWSER_UNKNOWN;
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 std::vector<const TemplateURL*> model_urls = 309 std::vector<const TemplateURL*> model_urls =
310 template_url_service_->GetTemplateURLs(); 310 template_url_service_->GetTemplateURLs();
311 if (selected_index >= 0 && 311 if (selected_index >= 0 &&
312 selected_index < static_cast<int>(model_urls.size())) 312 selected_index < static_cast<int>(model_urls.size()))
313 template_url_service_->SetDefaultSearchProvider(model_urls[selected_index]); 313 template_url_service_->SetDefaultSearchProvider(model_urls[selected_index]);
314 314
315 UserMetrics::RecordAction(UserMetricsAction("Options_SearchEngineChanged")); 315 UserMetrics::RecordAction(UserMetricsAction("Options_SearchEngineChanged"));
316 } 316 }
317 317
318 void BrowserOptionsHandler::UpdateSearchEngines() { 318 void BrowserOptionsHandler::UpdateSearchEngines() {
319 template_url_service_ = TemplateURLServiceFactory::GetForProfile( 319 template_url_service_ =
320 web_ui_->GetProfile()); 320 TemplateURLServiceFactory::GetForProfile(Profile::FromWebUI(web_ui_));
321 if (template_url_service_) { 321 if (template_url_service_) {
322 template_url_service_->Load(); 322 template_url_service_->Load();
323 template_url_service_->AddObserver(this); 323 template_url_service_->AddObserver(this);
324 OnTemplateURLServiceChanged(); 324 OnTemplateURLServiceChanged();
325 } 325 }
326 } 326 }
327 327
328 void BrowserOptionsHandler::UpdateRestoreOnStartup() { 328 void BrowserOptionsHandler::UpdateRestoreOnStartup() {
329 Profile* profile = web_ui_->GetProfile(); 329 Profile* profile = Profile::FromWebUI(web_ui_);
330 const SessionStartupPref startup_pref = 330 const SessionStartupPref startup_pref =
331 SessionStartupPref::GetStartupPref(profile->GetPrefs()); 331 SessionStartupPref::GetStartupPref(profile->GetPrefs());
332 FundamentalValue restore_on_startup(startup_pref.type); 332 FundamentalValue restore_on_startup(startup_pref.type);
333 web_ui_->CallJavascriptFunction("BrowserOptions.updateRestoreOnStartup", 333 web_ui_->CallJavascriptFunction("BrowserOptions.updateRestoreOnStartup",
334 restore_on_startup); 334 restore_on_startup);
335 } 335 }
336 336
337 void BrowserOptionsHandler::UpdateStartupPages() { 337 void BrowserOptionsHandler::UpdateStartupPages() {
338 Profile* profile = web_ui_->GetProfile(); 338 Profile* profile = Profile::FromWebUI(web_ui_);
339 const SessionStartupPref startup_pref = 339 const SessionStartupPref startup_pref =
340 SessionStartupPref::GetStartupPref(profile->GetPrefs()); 340 SessionStartupPref::GetStartupPref(profile->GetPrefs());
341 startup_custom_pages_table_model_->SetURLs(startup_pref.urls); 341 startup_custom_pages_table_model_->SetURLs(startup_pref.urls);
342 } 342 }
343 343
344 void BrowserOptionsHandler::OnModelChanged() { 344 void BrowserOptionsHandler::OnModelChanged() {
345 ListValue startup_pages; 345 ListValue startup_pages;
346 int page_count = startup_custom_pages_table_model_->RowCount(); 346 int page_count = startup_custom_pages_table_model_->RowCount();
347 std::vector<GURL> urls = startup_custom_pages_table_model_->GetURLs(); 347 std::vector<GURL> urls = startup_custom_pages_table_model_->GetURLs();
348 for (int i = 0; i < page_count; ++i) { 348 for (int i = 0; i < page_count; ++i) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 const ListValue* args) { 394 const ListValue* args) {
395 startup_custom_pages_table_model_->SetToCurrentlyOpenPages(); 395 startup_custom_pages_table_model_->SetToCurrentlyOpenPages();
396 SaveStartupPagesPref(); 396 SaveStartupPagesPref();
397 } 397 }
398 398
399 void BrowserOptionsHandler::SetRestoreOnStartup(const ListValue* args) { 399 void BrowserOptionsHandler::SetRestoreOnStartup(const ListValue* args) {
400 std::string pref_string; 400 std::string pref_string;
401 CHECK_EQ(args->GetSize(), 1UL); 401 CHECK_EQ(args->GetSize(), 1UL);
402 CHECK(args->GetString(0, &pref_string)); 402 CHECK(args->GetString(0, &pref_string));
403 403
404 PrefService* prefs = web_ui_->GetProfile()->GetPrefs(); 404 PrefService* prefs = Profile::FromWebUI(web_ui_)->GetPrefs();
405 405
406 SessionStartupPref pref = SessionStartupPref::GetStartupPref(prefs); 406 SessionStartupPref pref = SessionStartupPref::GetStartupPref(prefs);
407 if (pref_string == "0") { 407 if (pref_string == "0") {
408 pref.type = SessionStartupPref::DEFAULT; 408 pref.type = SessionStartupPref::DEFAULT;
409 } else if (pref_string == "1") { 409 } else if (pref_string == "1") {
410 pref.type = SessionStartupPref::LAST; 410 pref.type = SessionStartupPref::LAST;
411 } else if (pref_string == "2") { 411 } else if (pref_string == "2") {
412 pref.type = SessionStartupPref::URLS; 412 pref.type = SessionStartupPref::URLS;
413 } else { 413 } else {
414 NOTREACHED(); 414 NOTREACHED();
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 CHECK(selected->GetString(i, &value)); 484 CHECK(selected->GetString(i, &value));
485 base::StringToInt(value, &index); 485 base::StringToInt(value, &index);
486 index_list.push_back(index); 486 index_list.push_back(index);
487 } 487 }
488 488
489 startup_custom_pages_table_model_->MoveURLs(to_index, index_list); 489 startup_custom_pages_table_model_->MoveURLs(to_index, index_list);
490 SaveStartupPagesPref(); 490 SaveStartupPagesPref();
491 } 491 }
492 492
493 void BrowserOptionsHandler::SaveStartupPagesPref() { 493 void BrowserOptionsHandler::SaveStartupPagesPref() {
494 PrefService* prefs = web_ui_->GetProfile()->GetPrefs(); 494 PrefService* prefs = Profile::FromWebUI(web_ui_)->GetPrefs();
495 495
496 SessionStartupPref pref = SessionStartupPref::GetStartupPref(prefs); 496 SessionStartupPref pref = SessionStartupPref::GetStartupPref(prefs);
497 pref.urls = startup_custom_pages_table_model_->GetURLs(); 497 pref.urls = startup_custom_pages_table_model_->GetURLs();
498 498
499 SessionStartupPref::SetStartupPref(prefs, pref); 499 SessionStartupPref::SetStartupPref(prefs, pref);
500 } 500 }
501 501
502 void BrowserOptionsHandler::RequestAutocompleteSuggestions( 502 void BrowserOptionsHandler::RequestAutocompleteSuggestions(
503 const ListValue* args) { 503 const ListValue* args) {
504 string16 input; 504 string16 input;
505 CHECK_EQ(args->GetSize(), 1U); 505 CHECK_EQ(args->GetSize(), 1U);
506 CHECK(args->GetString(0, &input)); 506 CHECK(args->GetString(0, &input));
507 507
508 autocomplete_controller_->Start(input, string16(), true, false, false, 508 autocomplete_controller_->Start(input, string16(), true, false, false,
509 AutocompleteInput::ALL_MATCHES); 509 AutocompleteInput::ALL_MATCHES);
510 } 510 }
511 511
512 void BrowserOptionsHandler::ToggleShowBookmarksBar(const ListValue* args) { 512 void BrowserOptionsHandler::ToggleShowBookmarksBar(const ListValue* args) {
513 Source<Profile> source(web_ui_->GetProfile()); 513 Source<Profile> source(Profile::FromWebUI(web_ui_));
514 NotificationService::current()->Notify( 514 NotificationService::current()->Notify(
515 chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED, 515 chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED,
516 source, 516 source,
517 NotificationService::NoDetails()); 517 NotificationService::NoDetails());
518 } 518 }
519 519
520 void BrowserOptionsHandler::EnableInstant(const ListValue* args) { 520 void BrowserOptionsHandler::EnableInstant(const ListValue* args) {
521 InstantController::Enable(web_ui_->GetProfile()); 521 InstantController::Enable(Profile::FromWebUI(web_ui_));
522 } 522 }
523 523
524 void BrowserOptionsHandler::DisableInstant(const ListValue* args) { 524 void BrowserOptionsHandler::DisableInstant(const ListValue* args) {
525 InstantController::Disable(web_ui_->GetProfile()); 525 InstantController::Disable(Profile::FromWebUI(web_ui_));
526 } 526 }
527 527
528 void BrowserOptionsHandler::GetInstantFieldTrialStatus(const ListValue* args) { 528 void BrowserOptionsHandler::GetInstantFieldTrialStatus(const ListValue* args) {
529 FundamentalValue enabled( 529 FundamentalValue enabled(
530 InstantFieldTrial::IsExperimentGroup(web_ui_->GetProfile())); 530 InstantFieldTrial::IsExperimentGroup(Profile::FromWebUI(web_ui_)));
531 web_ui_->CallJavascriptFunction("BrowserOptions.setInstantFieldTrialStatus", 531 web_ui_->CallJavascriptFunction("BrowserOptions.setInstantFieldTrialStatus",
532 enabled); 532 enabled);
533 } 533 }
534 534
535 void BrowserOptionsHandler::OnResultChanged(bool default_match_changed) { 535 void BrowserOptionsHandler::OnResultChanged(bool default_match_changed) {
536 const AutocompleteResult& result = autocomplete_controller_->result(); 536 const AutocompleteResult& result = autocomplete_controller_->result();
537 ListValue suggestions; 537 ListValue suggestions;
538 for (size_t i = 0; i < result.size(); ++i) { 538 for (size_t i = 0; i < result.size(); ++i) {
539 const AutocompleteMatch& match = result.match_at(i); 539 const AutocompleteMatch& match = result.match_at(i);
540 AutocompleteMatch::Type type = match.type; 540 AutocompleteMatch::Type type = match.type;
541 if (type != AutocompleteMatch::HISTORY_URL && 541 if (type != AutocompleteMatch::HISTORY_URL &&
542 type != AutocompleteMatch::HISTORY_TITLE && 542 type != AutocompleteMatch::HISTORY_TITLE &&
543 type != AutocompleteMatch::HISTORY_BODY && 543 type != AutocompleteMatch::HISTORY_BODY &&
544 type != AutocompleteMatch::HISTORY_KEYWORD && 544 type != AutocompleteMatch::HISTORY_KEYWORD &&
545 type != AutocompleteMatch::NAVSUGGEST) 545 type != AutocompleteMatch::NAVSUGGEST)
546 continue; 546 continue;
547 DictionaryValue* entry = new DictionaryValue(); 547 DictionaryValue* entry = new DictionaryValue();
548 entry->SetString("title", match.description); 548 entry->SetString("title", match.description);
549 entry->SetString("displayURL", match.contents); 549 entry->SetString("displayURL", match.contents);
550 entry->SetString("url", match.destination_url.spec()); 550 entry->SetString("url", match.destination_url.spec());
551 suggestions.Append(entry); 551 suggestions.Append(entry);
552 } 552 }
553 553
554 web_ui_->CallJavascriptFunction( 554 web_ui_->CallJavascriptFunction(
555 "BrowserOptions.updateAutocompleteSuggestions", suggestions); 555 "BrowserOptions.updateAutocompleteSuggestions", suggestions);
556 } 556 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698