Chromium Code Reviews| Index: chrome/browser/ui/webui/settings/startup_pages_handler.cc |
| diff --git a/chrome/browser/ui/webui/settings/startup_pages_handler.cc b/chrome/browser/ui/webui/settings/startup_pages_handler.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..1852059af1eeb9e235ef18c774374a96acd2a120 |
| --- /dev/null |
| +++ b/chrome/browser/ui/webui/settings/startup_pages_handler.cc |
| @@ -0,0 +1,69 @@ |
| +// Copyright (c) 2012-2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/ui/webui/settings/startup_pages_handler.h" |
| + |
| +#include "chrome/browser/custom_home_pages_table_model.h" |
| +#include "chrome/browser/profiles/profile.h" |
| +#include "content/public/browser/web_ui.h" |
| + |
| +namespace settings { |
| + |
| +StartupPagesHandler::StartupPagesHandler(content::WebUI* webui) { |
| + Profile* profile = Profile::FromWebUI(webui); |
| + startup_custom_pages_table_model_.reset( |
|
Dan Beam
2015/09/02 07:31:23
make this just a member rather than a scoped_ptr<>
dschuyler
2015/09/02 19:38:21
Done.
|
| + new CustomHomePagesTableModel(profile)); |
| + startup_custom_pages_table_model_->SetObserver(this); |
| +} |
| + |
| +StartupPagesHandler::~StartupPagesHandler() { |
| +} |
| + |
| +void StartupPagesHandler::RegisterMessages() { |
| + // Guest profiles should never have been displayed the option to set these |
| + // values. |
| + if (Profile::FromWebUI(web_ui())->IsOffTheRecord()) |
|
Dan Beam
2015/09/02 07:31:23
should this be a DCHECK() instead?
dschuyler
2015/09/02 19:38:21
Done.
Dan Beam
2015/12/02 02:07:20
no it should not!
|
| + return; |
| + |
| + web_ui()->RegisterMessageCallback("setStartupPagesToCurrentPages", |
| + base::Bind(&StartupPagesHandler::SetStartupPagesToCurrentPages, |
| + base::Unretained(this))); |
| +} |
| + |
| +void StartupPagesHandler::OnModelChanged() { |
| + base::ListValue startup_pages; |
| + int page_count = startup_custom_pages_table_model_->RowCount(); |
| + std::vector<GURL> urls = startup_custom_pages_table_model_->GetURLs(); |
| + for (int i = 0; i < page_count; ++i) { |
| + base::DictionaryValue* entry = new base::DictionaryValue(); |
| + entry->SetString("title", startup_custom_pages_table_model_->GetText(i, 0)); |
| + entry->SetString("url", urls[i].spec()); |
| + entry->SetString("tooltip", |
| + startup_custom_pages_table_model_->GetTooltip(i)); |
| + entry->SetInteger("modelIndex", i); |
| + startup_pages.Append(entry); |
| + } |
| + |
| + web_ui()->CallJavascriptFunction("Settings.updateStartupPages", |
| + startup_pages); |
| +} |
| + |
| +void StartupPagesHandler::OnItemsChanged(int start, int length) { |
| + OnModelChanged(); |
| +} |
| + |
| +void StartupPagesHandler::OnItemsAdded(int start, int length) { |
| + OnModelChanged(); |
| +} |
| + |
| +void StartupPagesHandler::OnItemsRemoved(int start, int length) { |
| + OnModelChanged(); |
| +} |
| + |
| +void StartupPagesHandler::SetStartupPagesToCurrentPages( |
| + const base::ListValue* args) { |
| + startup_custom_pages_table_model_->SetToCurrentlyOpenPages(); |
| +} |
| + |
| +} // namespace settings |