15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/webui/options/startup_pages_handler.h" 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/bind.h" 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/bind_helpers.h" 92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/prefs/pref_service.h" 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/autocomplete/autocomplete_classifier.h" 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/autocomplete/autocomplete_controller.h" 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/autocomplete/autocomplete_input.h" 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/autocomplete/autocomplete_result.h" 147dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "chrome/browser/chrome_notification_types.h" 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/custom_home_pages_table_model.h" 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/prefs/session_startup_pref.h" 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/profiles/profile.h" 18558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch#include "chrome/common/net/url_fixer_upper.h" 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/pref_names.h" 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/notification_details.h" 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/web_ui.h" 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "grit/generated_resources.h" 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace options { 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 267d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)StartupPagesHandler::StartupPagesHandler() {} 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)StartupPagesHandler::~StartupPagesHandler() { 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void StartupPagesHandler::GetLocalizedValues( 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DictionaryValue* localized_strings) { 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(localized_strings); 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static OptionsStringResource resources[] = { 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { "startupAddLabel", IDS_OPTIONS_STARTUP_ADD_LABEL }, 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { "startupUseCurrent", IDS_OPTIONS_STARTUP_USE_CURRENT }, 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { "startupPagesPlaceholder", IDS_OPTIONS_STARTUP_PAGES_PLACEHOLDER }, 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) RegisterStrings(localized_strings, resources, arraysize(resources)); 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) RegisterTitle(localized_strings, "startupPagesOverlay", 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) IDS_OPTIONS_STARTUP_PAGES_DIALOG_TITLE); 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void StartupPagesHandler::RegisterMessages() { 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) web_ui()->RegisterMessageCallback("removeStartupPages", 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::Bind(&StartupPagesHandler::RemoveStartupPages, 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::Unretained(this))); 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) web_ui()->RegisterMessageCallback("addStartupPage", 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::Bind(&StartupPagesHandler::AddStartupPage, 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::Unretained(this))); 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) web_ui()->RegisterMessageCallback("editStartupPage", 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::Bind(&StartupPagesHandler::EditStartupPage, 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::Unretained(this))); 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) web_ui()->RegisterMessageCallback("setStartupPagesToCurrentPages", 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::Bind(&StartupPagesHandler::SetStartupPagesToCurrentPages, 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::Unretained(this))); 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) web_ui()->RegisterMessageCallback("dragDropStartupPage", 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::Bind(&StartupPagesHandler::DragDropStartupPage, 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::Unretained(this))); 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) web_ui()->RegisterMessageCallback( 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) "requestAutocompleteSuggestionsForStartupPages", 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::Bind(&StartupPagesHandler::RequestAutocompleteSuggestions, 665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::Unretained(this))); 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) web_ui()->RegisterMessageCallback("commitStartupPrefChanges", 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::Bind(&StartupPagesHandler::CommitChanges, 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::Unretained(this))); 705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) web_ui()->RegisterMessageCallback("cancelStartupPrefChanges", 715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::Bind(&StartupPagesHandler::CancelChanges, 725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::Unretained(this))); 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void StartupPagesHandler::UpdateStartupPages() { 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Profile* profile = Profile::FromWebUI(web_ui()); 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const SessionStartupPref startup_pref = 785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SessionStartupPref::GetStartupPref(profile->GetPrefs()); 795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) startup_custom_pages_table_model_->SetURLs(startup_pref.urls); 805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void StartupPagesHandler::InitializeHandler() { 835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Profile* profile = Profile::FromWebUI(web_ui()); 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) startup_custom_pages_table_model_.reset( 865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) new CustomHomePagesTableModel(profile)); 875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) startup_custom_pages_table_model_->SetObserver(this); 885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) pref_change_registrar_.Init(profile->GetPrefs()); 902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) pref_change_registrar_.Add( 912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) prefs::kURLsToRestoreOnStartup, 922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::Bind(&StartupPagesHandler::UpdateStartupPages, 932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::Unretained(this))); 945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) autocomplete_controller_.reset(new AutocompleteController(profile, this, 965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) AutocompleteClassifier::kDefaultOmniboxProviders)); 975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void StartupPagesHandler::InitializePage() { 1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) UpdateStartupPages(); 1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void StartupPagesHandler::OnModelChanged() { 1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ListValue startup_pages; 1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int page_count = startup_custom_pages_table_model_->RowCount(); 1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::vector<GURL> urls = startup_custom_pages_table_model_->GetURLs(); 1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) for (int i = 0; i < page_count; ++i) { 1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DictionaryValue* entry = new DictionaryValue(); 1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) entry->SetString("title", startup_custom_pages_table_model_->GetText(i, 0)); 1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) entry->SetString("url", urls[i].spec()); 1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) entry->SetString("tooltip", 1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) startup_custom_pages_table_model_->GetTooltip(i)); 1132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) entry->SetInteger("modelIndex", i); 1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) startup_pages.Append(entry); 1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) web_ui()->CallJavascriptFunction("StartupOverlay.updateStartupPages", 1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) startup_pages); 1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void StartupPagesHandler::OnItemsChanged(int start, int length) { 1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) OnModelChanged(); 1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void StartupPagesHandler::OnItemsAdded(int start, int length) { 1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) OnModelChanged(); 1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void StartupPagesHandler::OnItemsRemoved(int start, int length) { 1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) OnModelChanged(); 1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void StartupPagesHandler::SetStartupPagesToCurrentPages( 1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const ListValue* args) { 1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) startup_custom_pages_table_model_->SetToCurrentlyOpenPages(); 1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void StartupPagesHandler::RemoveStartupPages(const ListValue* args) { 1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) for (int i = args->GetSize() - 1; i >= 0; --i) { 1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int selected_index; 1412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CHECK(args->GetInteger(i, &selected_index)); 1422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (selected_index < 0 || 1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) selected_index >= startup_custom_pages_table_model_->RowCount()) { 1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NOTREACHED(); 1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return; 1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) startup_custom_pages_table_model_->Remove(selected_index); 1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void StartupPagesHandler::AddStartupPage(const ListValue* args) { 1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string url_string; 1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CHECK(args->GetString(0, &url_string)); 1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL url = URLFixerUpper::FixupURL(url_string, std::string()); 1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!url.is_valid()) 1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return; 1591e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 1601e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) int row_count = startup_custom_pages_table_model_->RowCount(); 1611e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) int index; 1621e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) if (!args->GetInteger(1, &index) || index > row_count) 1631e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) index = row_count; 1641e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) startup_custom_pages_table_model_->Add(index, url); 1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void StartupPagesHandler::EditStartupPage(const ListValue* args) { 1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string url_string; 1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int index; 1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CHECK_EQ(args->GetSize(), 2U); 1722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CHECK(args->GetInteger(0, &index)); 1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CHECK(args->GetString(1, &url_string)); 1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (index < 0 || index > startup_custom_pages_table_model_->RowCount()) { 1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NOTREACHED(); 1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return; 1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::vector<GURL> urls = startup_custom_pages_table_model_->GetURLs(); 1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) urls[index] = URLFixerUpper::FixupURL(url_string, std::string()); 1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) startup_custom_pages_table_model_->SetURLs(urls); 1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void StartupPagesHandler::DragDropStartupPage(const ListValue* args) { 1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CHECK_EQ(args->GetSize(), 2U); 1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int to_index; 1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CHECK(args->GetInteger(0, &to_index)); 1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const ListValue* selected; 1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CHECK(args->GetList(1, &selected)); 1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::vector<int> index_list; 1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) for (size_t i = 0; i < selected->GetSize(); ++i) { 1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int index; 1982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CHECK(selected->GetInteger(i, &index)); 1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) index_list.push_back(index); 2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) startup_custom_pages_table_model_->MoveURLs(to_index, index_list); 2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void StartupPagesHandler::SaveStartupPagesPref() { 2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs(); 2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SessionStartupPref pref = SessionStartupPref::GetStartupPref(prefs); 2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) pref.urls = startup_custom_pages_table_model_->GetURLs(); 2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (pref.urls.empty()) 2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) pref.type = SessionStartupPref::DEFAULT; 2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SessionStartupPref::SetStartupPref(prefs, pref); 2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void StartupPagesHandler::CommitChanges(const ListValue* args) { 2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SaveStartupPagesPref(); 2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void StartupPagesHandler::CancelChanges(const ListValue* args) { 2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) UpdateStartupPages(); 2235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void StartupPagesHandler::RequestAutocompleteSuggestions( 2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const ListValue* args) { 227a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 input; 2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CHECK_EQ(args->GetSize(), 1U); 2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CHECK(args->GetString(0, &input)); 2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) autocomplete_controller_->Start(AutocompleteInput( 232a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) input, base::string16::npos, base::string16(), GURL(), 233d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch AutocompleteInput::INVALID_SPEC, true, 2342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) false, false, AutocompleteInput::ALL_MATCHES)); 2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void StartupPagesHandler::OnResultChanged(bool default_match_changed) { 2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const AutocompleteResult& result = autocomplete_controller_->result(); 2395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ListValue suggestions; 2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) OptionsUI::ProcessAutocompleteSuggestions(result, &suggestions); 2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) web_ui()->CallJavascriptFunction( 2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) "StartupOverlay.updateAutocompleteSuggestions", suggestions); 2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace options 246