Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012-2015 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/settings/startup_pages_handler.h" | |
| 6 | |
| 7 #include "chrome/browser/custom_home_pages_table_model.h" | |
| 8 #include "chrome/browser/profiles/profile.h" | |
| 9 #include "content/public/browser/web_ui.h" | |
| 10 | |
| 11 namespace settings { | |
| 12 | |
| 13 StartupPagesHandler::StartupPagesHandler(content::WebUI* webui) { | |
| 14 Profile* profile = Profile::FromWebUI(webui); | |
| 15 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.
| |
| 16 new CustomHomePagesTableModel(profile)); | |
| 17 startup_custom_pages_table_model_->SetObserver(this); | |
| 18 } | |
| 19 | |
| 20 StartupPagesHandler::~StartupPagesHandler() { | |
| 21 } | |
| 22 | |
| 23 void StartupPagesHandler::RegisterMessages() { | |
| 24 // Guest profiles should never have been displayed the option to set these | |
| 25 // values. | |
| 26 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!
| |
| 27 return; | |
| 28 | |
| 29 web_ui()->RegisterMessageCallback("setStartupPagesToCurrentPages", | |
| 30 base::Bind(&StartupPagesHandler::SetStartupPagesToCurrentPages, | |
| 31 base::Unretained(this))); | |
| 32 } | |
| 33 | |
| 34 void StartupPagesHandler::OnModelChanged() { | |
| 35 base::ListValue startup_pages; | |
| 36 int page_count = startup_custom_pages_table_model_->RowCount(); | |
| 37 std::vector<GURL> urls = startup_custom_pages_table_model_->GetURLs(); | |
| 38 for (int i = 0; i < page_count; ++i) { | |
| 39 base::DictionaryValue* entry = new base::DictionaryValue(); | |
| 40 entry->SetString("title", startup_custom_pages_table_model_->GetText(i, 0)); | |
| 41 entry->SetString("url", urls[i].spec()); | |
| 42 entry->SetString("tooltip", | |
| 43 startup_custom_pages_table_model_->GetTooltip(i)); | |
| 44 entry->SetInteger("modelIndex", i); | |
| 45 startup_pages.Append(entry); | |
| 46 } | |
| 47 | |
| 48 web_ui()->CallJavascriptFunction("Settings.updateStartupPages", | |
| 49 startup_pages); | |
| 50 } | |
| 51 | |
| 52 void StartupPagesHandler::OnItemsChanged(int start, int length) { | |
| 53 OnModelChanged(); | |
| 54 } | |
| 55 | |
| 56 void StartupPagesHandler::OnItemsAdded(int start, int length) { | |
| 57 OnModelChanged(); | |
| 58 } | |
| 59 | |
| 60 void StartupPagesHandler::OnItemsRemoved(int start, int length) { | |
| 61 OnModelChanged(); | |
| 62 } | |
| 63 | |
| 64 void StartupPagesHandler::SetStartupPagesToCurrentPages( | |
| 65 const base::ListValue* args) { | |
| 66 startup_custom_pages_table_model_->SetToCurrentlyOpenPages(); | |
| 67 } | |
| 68 | |
| 69 } // namespace settings | |
| OLD | NEW |