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

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

Issue 9814030: get rid of old options pages (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more fixes Created 8 years, 9 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
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/webui/options/browser_options_handler.h"
6
7 #include "base/basictypes.h"
8 #include "base/bind.h"
9 #include "base/bind_helpers.h"
10 #include "base/command_line.h"
11 #include "base/memory/singleton.h"
12 #include "base/path_service.h"
13 #include "base/string_number_conversions.h"
14 #include "base/utf_string_conversions.h"
15 #include "base/values.h"
16 #include "chrome/browser/auto_launch_trial.h"
17 #include "chrome/browser/autocomplete/autocomplete.h"
18 #include "chrome/browser/autocomplete/autocomplete_match.h"
19 #include "chrome/browser/browser_process.h"
20 #include "chrome/browser/custom_home_pages_table_model.h"
21 #include "chrome/browser/instant/instant_confirm_dialog.h"
22 #include "chrome/browser/instant/instant_controller.h"
23 #include "chrome/browser/instant/instant_field_trial.h"
24 #include "chrome/browser/net/url_fixer_upper.h"
25 #include "chrome/browser/prefs/pref_service.h"
26 #include "chrome/browser/prefs/session_startup_pref.h"
27 #include "chrome/browser/profiles/profile.h"
28 #include "chrome/browser/search_engines/template_url.h"
29 #include "chrome/browser/search_engines/template_url_service.h"
30 #include "chrome/browser/search_engines/template_url_service_factory.h"
31 #include "chrome/browser/ui/webui/favicon_source.h"
32 #include "chrome/common/chrome_constants.h"
33 #include "chrome/common/chrome_notification_types.h"
34 #include "chrome/common/chrome_switches.h"
35 #include "chrome/common/pref_names.h"
36 #include "chrome/common/url_constants.h"
37 #include "content/public/browser/browser_thread.h"
38 #include "content/public/browser/notification_details.h"
39 #include "content/public/browser/notification_source.h"
40 #include "content/public/browser/user_metrics.h"
41 #include "content/public/browser/web_ui.h"
42 #include "grit/chromium_strings.h"
43 #include "grit/generated_resources.h"
44 #include "ui/base/l10n/l10n_util.h"
45
46 #if defined(OS_WIN)
47 #include "chrome/installer/util/auto_launch_util.h"
48 #endif
49
50 using content::BrowserThread;
51 using content::UserMetricsAction;
52
53 BrowserOptionsHandler::BrowserOptionsHandler()
54 : template_url_service_(NULL),
55 startup_custom_pages_table_model_(NULL),
56 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_for_file_(this)),
57 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_for_ui_(this)) {
58 #if !defined(OS_MACOSX)
59 default_browser_worker_ = new ShellIntegration::DefaultBrowserWorker(this);
60 #endif
61 }
62
63 BrowserOptionsHandler::~BrowserOptionsHandler() {
64 if (default_browser_worker_.get())
65 default_browser_worker_->ObserverDestroyed();
66 if (template_url_service_)
67 template_url_service_->RemoveObserver(this);
68 }
69
70 void BrowserOptionsHandler::GetLocalizedValues(
71 DictionaryValue* localized_strings) {
72 DCHECK(localized_strings);
73
74 static OptionsStringResource resources[] = {
75 { "startupGroupName", IDS_OPTIONS_STARTUP_GROUP_NAME },
76 { "startupShowDefaultAndNewTab",
77 IDS_OPTIONS_STARTUP_SHOW_DEFAULT_AND_NEWTAB},
78 { "startupShowLastSession", IDS_OPTIONS_STARTUP_SHOW_LAST_SESSION },
79 { "startupShowPages", IDS_OPTIONS_STARTUP_SHOW_PAGES },
80 { "startupAddLabel", IDS_OPTIONS_STARTUP_ADD_LABEL },
81 { "startupUseCurrent", IDS_OPTIONS_STARTUP_USE_CURRENT },
82 { "homepageGroupName", IDS_OPTIONS_HOMEPAGE_GROUP_NAME },
83 { "homepageUseNewTab", IDS_OPTIONS_HOMEPAGE_USE_NEWTAB },
84 { "homepageUseURL", IDS_OPTIONS_HOMEPAGE_USE_URL },
85 { "toolbarGroupName", IDS_OPTIONS_TOOLBAR_GROUP_NAME },
86 { "toolbarShowHomeButton", IDS_OPTIONS_TOOLBAR_SHOW_HOME_BUTTON },
87 { "toolbarShowBookmarksBar", IDS_OPTIONS_TOOLBAR_SHOW_BOOKMARKS_BAR },
88 { "defaultSearchGroupName", IDS_OPTIONS_DEFAULTSEARCH_GROUP_NAME },
89 { "defaultSearchManageEngines", IDS_OPTIONS_DEFAULTSEARCH_MANAGE_ENGINES },
90 { "instantName", IDS_INSTANT_PREF },
91 { "instantWarningText", IDS_INSTANT_PREF_WARNING },
92 { "instantConfirmTitle", IDS_INSTANT_OPT_IN_TITLE },
93 { "instantConfirmMessage", IDS_INSTANT_OPT_IN_MESSAGE },
94 { "defaultBrowserGroupName", IDS_OPTIONS_DEFAULTBROWSER_GROUP_NAME },
95 };
96
97 RegisterStrings(localized_strings, resources, arraysize(resources));
98 RegisterTitle(localized_strings, "browserPage",
99 IDS_OPTIONS_GENERAL_TAB_LABEL);
100
101 localized_strings->SetString("instantLearnMoreLink",
102 ASCIIToUTF16(chrome::kInstantLearnMoreURL));
103 localized_strings->SetString("defaultBrowserUnknown",
104 l10n_util::GetStringFUTF16(IDS_OPTIONS_DEFAULTBROWSER_UNKNOWN,
105 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)));
106 localized_strings->SetString("defaultBrowserUseAsDefault",
107 l10n_util::GetStringFUTF16(IDS_OPTIONS_DEFAULTBROWSER_USEASDEFAULT,
108 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)));
109 localized_strings->SetString("autoLaunchText",
110 l10n_util::GetStringFUTF16(IDS_AUTOLAUNCH_TEXT,
111 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)));
112 }
113
114 void BrowserOptionsHandler::RegisterMessages() {
115 web_ui()->RegisterMessageCallback("becomeDefaultBrowser",
116 base::Bind(&BrowserOptionsHandler::BecomeDefaultBrowser,
117 base::Unretained(this)));
118 web_ui()->RegisterMessageCallback("setDefaultSearchEngine",
119 base::Bind(&BrowserOptionsHandler::SetDefaultSearchEngine,
120 base::Unretained(this)));
121 web_ui()->RegisterMessageCallback("removeStartupPages",
122 base::Bind(&BrowserOptionsHandler::RemoveStartupPages,
123 base::Unretained(this)));
124 web_ui()->RegisterMessageCallback("addStartupPage",
125 base::Bind(&BrowserOptionsHandler::AddStartupPage,
126 base::Unretained(this)));
127 web_ui()->RegisterMessageCallback("editStartupPage",
128 base::Bind(&BrowserOptionsHandler::EditStartupPage,
129 base::Unretained(this)));
130 web_ui()->RegisterMessageCallback("setStartupPagesToCurrentPages",
131 base::Bind(&BrowserOptionsHandler::SetStartupPagesToCurrentPages,
132 base::Unretained(this)));
133 web_ui()->RegisterMessageCallback("dragDropStartupPage",
134 base::Bind(&BrowserOptionsHandler::DragDropStartupPage,
135 base::Unretained(this)));
136 web_ui()->RegisterMessageCallback("requestAutocompleteSuggestions",
137 base::Bind(&BrowserOptionsHandler::RequestAutocompleteSuggestions,
138 base::Unretained(this)));
139 web_ui()->RegisterMessageCallback("enableInstant",
140 base::Bind(&BrowserOptionsHandler::EnableInstant,
141 base::Unretained(this)));
142 web_ui()->RegisterMessageCallback("disableInstant",
143 base::Bind(&BrowserOptionsHandler::DisableInstant,
144 base::Unretained(this)));
145 web_ui()->RegisterMessageCallback("getInstantFieldTrialStatus",
146 base::Bind(&BrowserOptionsHandler::GetInstantFieldTrialStatus,
147 base::Unretained(this)));
148 }
149
150 void BrowserOptionsHandler::InitializeHandler() {
151 Profile* profile = Profile::FromWebUI(web_ui());
152
153 // Create our favicon data source.
154 profile->GetChromeURLDataManager()->AddDataSource(
155 new FaviconSource(profile, FaviconSource::FAVICON));
156
157 homepage_.Init(prefs::kHomePage, profile->GetPrefs(), NULL);
158 default_browser_policy_.Init(prefs::kDefaultBrowserSettingEnabled,
159 g_browser_process->local_state(),
160 this);
161 UpdateDefaultBrowserState();
162
163 startup_custom_pages_table_model_.reset(
164 new CustomHomePagesTableModel(profile));
165 startup_custom_pages_table_model_->SetObserver(this);
166 UpdateStartupPages();
167
168 pref_change_registrar_.Init(profile->GetPrefs());
169 pref_change_registrar_.Add(prefs::kURLsToRestoreOnStartup, this);
170
171 UpdateSearchEngines();
172
173 autocomplete_controller_.reset(new AutocompleteController(profile, this));
174
175 #if defined(OS_WIN)
176 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
177 if (!command_line.HasSwitch(switches::kChromeFrame) &&
178 !command_line.HasSwitch(switches::kUserDataDir)) {
179 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
180 base::Bind(&BrowserOptionsHandler::CheckAutoLaunch,
181 weak_ptr_factory_for_ui_.GetWeakPtr(),
182 weak_ptr_factory_for_file_.GetWeakPtr(),
183 profile->GetPath()));
184 weak_ptr_factory_for_ui_.DetachFromThread();
185 }
186 #endif
187 }
188
189 void BrowserOptionsHandler::CheckAutoLaunch(
190 base::WeakPtr<BrowserOptionsHandler> weak_this,
191 const FilePath& profile_path) {
192 #if defined(OS_WIN)
193 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
194
195 // Auto-launch is not supported for secondary profiles yet.
196 if (profile_path.BaseName().value() != ASCIIToUTF16(chrome::kInitialProfile))
197 return;
198
199 // Pass in weak pointer to this to avoid race if BrowserOptionsHandler is
200 // deleted.
201 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
202 base::Bind(&BrowserOptionsHandler::CheckAutoLaunchCallback,
203 weak_this,
204 auto_launch_trial::IsInAutoLaunchGroup(),
205 auto_launch_util::WillLaunchAtLogin(
206 FilePath(),
207 profile_path.BaseName().value())));
208 #endif
209 }
210
211 void BrowserOptionsHandler::CheckAutoLaunchCallback(
212 bool is_in_auto_launch_group,
213 bool will_launch_at_login) {
214 #if defined(OS_WIN)
215 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
216
217 if (is_in_auto_launch_group) {
218 web_ui()->RegisterMessageCallback("toggleAutoLaunch",
219 base::Bind(&BrowserOptionsHandler::ToggleAutoLaunch,
220 base::Unretained(this)));
221
222 base::FundamentalValue enabled(will_launch_at_login);
223 web_ui()->CallJavascriptFunction("BrowserOptions.updateAutoLaunchState",
224 enabled);
225 }
226 #endif
227 }
228
229 void BrowserOptionsHandler::UpdateDefaultBrowserState() {
230 // Check for side-by-side first.
231 if (!ShellIntegration::CanSetAsDefaultBrowser()) {
232 SetDefaultBrowserUIString(IDS_OPTIONS_DEFAULTBROWSER_SXS);
233 return;
234 }
235
236 #if defined(OS_MACOSX)
237 ShellIntegration::DefaultWebClientState state =
238 ShellIntegration::IsDefaultBrowser();
239 int status_string_id;
240 if (state == ShellIntegration::IS_DEFAULT_WEB_CLIENT)
241 status_string_id = IDS_OPTIONS_DEFAULTBROWSER_DEFAULT;
242 else if (state == ShellIntegration::NOT_DEFAULT_WEB_CLIENT)
243 status_string_id = IDS_OPTIONS_DEFAULTBROWSER_NOTDEFAULT;
244 else
245 status_string_id = IDS_OPTIONS_DEFAULTBROWSER_UNKNOWN;
246
247 SetDefaultBrowserUIString(status_string_id);
248 #else
249 default_browser_worker_->StartCheckIsDefault();
250 #endif
251 }
252
253 void BrowserOptionsHandler::BecomeDefaultBrowser(const ListValue* args) {
254 // If the default browser setting is managed then we should not be able to
255 // call this function.
256 if (default_browser_policy_.IsManaged())
257 return;
258
259 content::RecordAction(UserMetricsAction("Options_SetAsDefaultBrowser"));
260 #if defined(OS_MACOSX)
261 if (ShellIntegration::SetAsDefaultBrowser())
262 UpdateDefaultBrowserState();
263 #else
264 default_browser_worker_->StartSetAsDefault();
265 // Callback takes care of updating UI.
266 #endif
267
268 // If the user attempted to make Chrome the default browser, then he/she
269 // arguably wants to be notified when that changes.
270 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs();
271 prefs->SetBoolean(prefs::kCheckDefaultBrowser, true);
272 }
273
274 int BrowserOptionsHandler::StatusStringIdForState(
275 ShellIntegration::DefaultWebClientState state) {
276 if (state == ShellIntegration::IS_DEFAULT_WEB_CLIENT)
277 return IDS_OPTIONS_DEFAULTBROWSER_DEFAULT;
278 if (state == ShellIntegration::NOT_DEFAULT_WEB_CLIENT)
279 return IDS_OPTIONS_DEFAULTBROWSER_NOTDEFAULT;
280 return IDS_OPTIONS_DEFAULTBROWSER_UNKNOWN;
281 }
282
283 void BrowserOptionsHandler::SetDefaultWebClientUIState(
284 ShellIntegration::DefaultWebClientUIState state) {
285 int status_string_id;
286 if (state == ShellIntegration::STATE_IS_DEFAULT)
287 status_string_id = IDS_OPTIONS_DEFAULTBROWSER_DEFAULT;
288 else if (state == ShellIntegration::STATE_NOT_DEFAULT)
289 status_string_id = IDS_OPTIONS_DEFAULTBROWSER_NOTDEFAULT;
290 else if (state == ShellIntegration::STATE_UNKNOWN)
291 status_string_id = IDS_OPTIONS_DEFAULTBROWSER_UNKNOWN;
292 else
293 return; // Still processing.
294
295 SetDefaultBrowserUIString(status_string_id);
296 }
297
298 void BrowserOptionsHandler::SetDefaultBrowserUIString(int status_string_id) {
299 scoped_ptr<Value> status_string(Value::CreateStringValue(
300 l10n_util::GetStringFUTF16(status_string_id,
301 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))));
302
303 scoped_ptr<Value> is_default(Value::CreateBooleanValue(
304 status_string_id == IDS_OPTIONS_DEFAULTBROWSER_DEFAULT));
305
306 scoped_ptr<Value> can_be_default(Value::CreateBooleanValue(
307 !default_browser_policy_.IsManaged() &&
308 (status_string_id == IDS_OPTIONS_DEFAULTBROWSER_DEFAULT ||
309 status_string_id == IDS_OPTIONS_DEFAULTBROWSER_NOTDEFAULT)));
310
311 web_ui()->CallJavascriptFunction(
312 "BrowserOptions.updateDefaultBrowserState",
313 *status_string, *is_default, *can_be_default);
314 }
315
316 void BrowserOptionsHandler::OnTemplateURLServiceChanged() {
317 if (!template_url_service_ || !template_url_service_->loaded())
318 return;
319
320 const TemplateURL* default_url =
321 template_url_service_->GetDefaultSearchProvider();
322
323 int default_index = 0;
324 ListValue search_engines;
325 TemplateURLService::TemplateURLVector model_urls(
326 template_url_service_->GetTemplateURLs());
327 for (size_t i = 0; i < model_urls.size(); ++i) {
328 if (!model_urls[i]->ShowInDefaultList())
329 continue;
330
331 DictionaryValue* entry = new DictionaryValue();
332 entry->SetString("name", model_urls[i]->short_name());
333 entry->SetInteger("index", i);
334 search_engines.Append(entry);
335 if (model_urls[i] == default_url)
336 default_index = i;
337 }
338
339 scoped_ptr<Value> default_value(Value::CreateIntegerValue(default_index));
340 scoped_ptr<Value> default_managed(Value::CreateBooleanValue(
341 template_url_service_->is_default_search_managed()));
342
343 web_ui()->CallJavascriptFunction("BrowserOptions.updateSearchEngines",
344 search_engines, *default_value,
345 *default_managed);
346 }
347
348 void BrowserOptionsHandler::SetDefaultSearchEngine(const ListValue* args) {
349 int selected_index = -1;
350 if (!ExtractIntegerValue(args, &selected_index)) {
351 NOTREACHED();
352 return;
353 }
354
355 TemplateURLService::TemplateURLVector model_urls(
356 template_url_service_->GetTemplateURLs());
357 if (selected_index >= 0 &&
358 selected_index < static_cast<int>(model_urls.size()))
359 template_url_service_->SetDefaultSearchProvider(model_urls[selected_index]);
360
361 content::RecordAction(UserMetricsAction("Options_SearchEngineChanged"));
362 }
363
364 void BrowserOptionsHandler::UpdateSearchEngines() {
365 template_url_service_ =
366 TemplateURLServiceFactory::GetForProfile(Profile::FromWebUI(web_ui()));
367 if (template_url_service_) {
368 template_url_service_->Load();
369 template_url_service_->AddObserver(this);
370 OnTemplateURLServiceChanged();
371 }
372 }
373
374 void BrowserOptionsHandler::UpdateStartupPages() {
375 Profile* profile = Profile::FromWebUI(web_ui());
376 const SessionStartupPref startup_pref =
377 SessionStartupPref::GetStartupPref(profile->GetPrefs());
378 startup_custom_pages_table_model_->SetURLs(startup_pref.urls);
379 }
380
381 void BrowserOptionsHandler::OnModelChanged() {
382 ListValue startup_pages;
383 int page_count = startup_custom_pages_table_model_->RowCount();
384 std::vector<GURL> urls = startup_custom_pages_table_model_->GetURLs();
385 for (int i = 0; i < page_count; ++i) {
386 DictionaryValue* entry = new DictionaryValue();
387 entry->SetString("title", startup_custom_pages_table_model_->GetText(i, 0));
388 entry->SetString("url", urls[i].spec());
389 entry->SetString("tooltip",
390 startup_custom_pages_table_model_->GetTooltip(i));
391 entry->SetString("modelIndex", base::IntToString(i));
392 startup_pages.Append(entry);
393 }
394
395 web_ui()->CallJavascriptFunction("BrowserOptions.updateStartupPages",
396 startup_pages);
397 }
398
399 void BrowserOptionsHandler::OnItemsChanged(int start, int length) {
400 OnModelChanged();
401 }
402
403 void BrowserOptionsHandler::OnItemsAdded(int start, int length) {
404 OnModelChanged();
405 }
406
407 void BrowserOptionsHandler::OnItemsRemoved(int start, int length) {
408 OnModelChanged();
409 }
410
411 void BrowserOptionsHandler::Observe(
412 int type,
413 const content::NotificationSource& source,
414 const content::NotificationDetails& details) {
415 if (type == chrome::NOTIFICATION_PREF_CHANGED) {
416 std::string* pref = content::Details<std::string>(details).ptr();
417 if (*pref == prefs::kDefaultBrowserSettingEnabled) {
418 UpdateDefaultBrowserState();
419 } else if (*pref == prefs::kURLsToRestoreOnStartup) {
420 UpdateStartupPages();
421 } else {
422 NOTREACHED();
423 }
424 } else {
425 NOTREACHED();
426 }
427 }
428
429 void BrowserOptionsHandler::SetStartupPagesToCurrentPages(
430 const ListValue* args) {
431 startup_custom_pages_table_model_->SetToCurrentlyOpenPages();
432 SaveStartupPagesPref();
433 }
434
435 void BrowserOptionsHandler::RemoveStartupPages(const ListValue* args) {
436 for (int i = args->GetSize() - 1; i >= 0; --i) {
437 std::string string_value;
438 CHECK(args->GetString(i, &string_value));
439
440 int selected_index;
441 base::StringToInt(string_value, &selected_index);
442 if (selected_index < 0 ||
443 selected_index >= startup_custom_pages_table_model_->RowCount()) {
444 NOTREACHED();
445 return;
446 }
447 startup_custom_pages_table_model_->Remove(selected_index);
448 }
449
450 SaveStartupPagesPref();
451 }
452
453 void BrowserOptionsHandler::AddStartupPage(const ListValue* args) {
454 std::string url_string;
455 CHECK_EQ(args->GetSize(), 1U);
456 CHECK(args->GetString(0, &url_string));
457
458 GURL url = URLFixerUpper::FixupURL(url_string, std::string());
459 if (!url.is_valid())
460 return;
461 int index = startup_custom_pages_table_model_->RowCount();
462 startup_custom_pages_table_model_->Add(index, url);
463 SaveStartupPagesPref();
464 }
465
466 void BrowserOptionsHandler::EditStartupPage(const ListValue* args) {
467 std::string url_string;
468 std::string index_string;
469 int index;
470 CHECK_EQ(args->GetSize(), 2U);
471 CHECK(args->GetString(0, &index_string));
472 CHECK(base::StringToInt(index_string, &index));
473 CHECK(args->GetString(1, &url_string));
474
475 if (index < 0 || index > startup_custom_pages_table_model_->RowCount()) {
476 NOTREACHED();
477 return;
478 }
479
480 std::vector<GURL> urls = startup_custom_pages_table_model_->GetURLs();
481 urls[index] = URLFixerUpper::FixupURL(url_string, std::string());
482 startup_custom_pages_table_model_->SetURLs(urls);
483 SaveStartupPagesPref();
484 }
485
486 void BrowserOptionsHandler::DragDropStartupPage(const ListValue* args) {
487 CHECK_EQ(args->GetSize(), 2U);
488
489 std::string value;
490 int to_index;
491
492 CHECK(args->GetString(0, &value));
493 base::StringToInt(value, &to_index);
494
495 ListValue* selected;
496 CHECK(args->GetList(1, &selected));
497
498 std::vector<int> index_list;
499 for (size_t i = 0; i < selected->GetSize(); ++i) {
500 int index;
501 CHECK(selected->GetString(i, &value));
502 base::StringToInt(value, &index);
503 index_list.push_back(index);
504 }
505
506 startup_custom_pages_table_model_->MoveURLs(to_index, index_list);
507 SaveStartupPagesPref();
508 }
509
510 void BrowserOptionsHandler::SaveStartupPagesPref() {
511 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs();
512
513 SessionStartupPref pref = SessionStartupPref::GetStartupPref(prefs);
514 pref.urls = startup_custom_pages_table_model_->GetURLs();
515
516 SessionStartupPref::SetStartupPref(prefs, pref);
517 }
518
519 void BrowserOptionsHandler::RequestAutocompleteSuggestions(
520 const ListValue* args) {
521 string16 input;
522 CHECK_EQ(args->GetSize(), 1U);
523 CHECK(args->GetString(0, &input));
524
525 autocomplete_controller_->Start(input, string16(), true, false, false,
526 AutocompleteInput::ALL_MATCHES);
527 }
528
529 void BrowserOptionsHandler::EnableInstant(const ListValue* args) {
530 InstantController::Enable(Profile::FromWebUI(web_ui()));
531 }
532
533 void BrowserOptionsHandler::DisableInstant(const ListValue* args) {
534 InstantController::Disable(Profile::FromWebUI(web_ui()));
535 }
536
537 void BrowserOptionsHandler::ToggleAutoLaunch(const ListValue* args) {
538 #if defined(OS_WIN)
539 if (!auto_launch_trial::IsInAutoLaunchGroup())
540 return;
541
542 bool enable;
543 CHECK_EQ(args->GetSize(), 1U);
544 CHECK(args->GetBoolean(0, &enable));
545
546 // Make sure we keep track of how many disable and how many enable.
547 auto_launch_trial::UpdateToggleAutoLaunchMetric(enable);
548 Profile* profile = Profile::FromWebUI(web_ui());
549 content::BrowserThread::PostTask(
550 content::BrowserThread::FILE, FROM_HERE,
551 base::Bind(&auto_launch_util::SetWillLaunchAtLogin, enable,
552 FilePath(), profile->GetPath().BaseName().value()));
553 #endif // OS_WIN
554 }
555
556 void BrowserOptionsHandler::GetInstantFieldTrialStatus(const ListValue* args) {
557 Profile* profile = Profile::FromWebUI(web_ui());
558 base::FundamentalValue enabled(
559 InstantFieldTrial::IsInstantExperiment(profile) &&
560 !InstantFieldTrial::IsHiddenExperiment(profile));
561 web_ui()->CallJavascriptFunction("BrowserOptions.setInstantFieldTrialStatus",
562 enabled);
563 }
564
565 void BrowserOptionsHandler::OnResultChanged(bool default_match_changed) {
566 const AutocompleteResult& result = autocomplete_controller_->result();
567 ListValue suggestions;
568 for (size_t i = 0; i < result.size(); ++i) {
569 const AutocompleteMatch& match = result.match_at(i);
570 AutocompleteMatch::Type type = match.type;
571 if (type != AutocompleteMatch::HISTORY_URL &&
572 type != AutocompleteMatch::HISTORY_TITLE &&
573 type != AutocompleteMatch::HISTORY_BODY &&
574 type != AutocompleteMatch::HISTORY_KEYWORD &&
575 type != AutocompleteMatch::NAVSUGGEST)
576 continue;
577 DictionaryValue* entry = new DictionaryValue();
578 entry->SetString("title", match.description);
579 entry->SetString("displayURL", match.contents);
580 entry->SetString("url", match.destination_url.spec());
581 suggestions.Append(entry);
582 }
583
584 web_ui()->CallJavascriptFunction(
585 "BrowserOptions.updateAutocompleteSuggestions", suggestions);
586 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698