OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 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/settings_startup_pages_handler.h" | |
6 | |
7 #include "chrome/browser/profiles/profile.h" | |
8 #include "content/public/browser/web_ui.h" | |
9 | |
10 namespace settings { | |
11 | |
12 StartupPagesHandler::StartupPagesHandler(content::WebUI* webui) | |
13 : startup_custom_pages_table_model_(Profile::FromWebUI(webui)) { | |
14 startup_custom_pages_table_model_.SetObserver(this); | |
15 } | |
16 | |
17 StartupPagesHandler::~StartupPagesHandler() { | |
18 } | |
19 | |
20 void StartupPagesHandler::RegisterMessages() { | |
21 DCHECK(!Profile::FromWebUI(web_ui())->IsOffTheRecord()); | |
22 | |
23 web_ui()->RegisterMessageCallback("setStartupPagesToCurrentPages", | |
24 base::Bind(&StartupPagesHandler::SetStartupPagesToCurrentPages, | |
25 base::Unretained(this))); | |
26 } | |
27 | |
28 void StartupPagesHandler::OnModelChanged() { | |
29 base::ListValue startup_pages; | |
30 int page_count = startup_custom_pages_table_model_.RowCount(); | |
31 std::vector<GURL> urls = startup_custom_pages_table_model_.GetURLs(); | |
32 for (int i = 0; i < page_count; ++i) { | |
33 base::DictionaryValue* entry = new base::DictionaryValue(); | |
Dan Beam
2015/09/02 19:43:52
nit: use scoped_ptr<> to make ownership more expli
| |
34 entry->SetString("title", startup_custom_pages_table_model_.GetText(i, 0)); | |
35 entry->SetString("url", urls[i].spec()); | |
36 entry->SetString("tooltip", | |
37 startup_custom_pages_table_model_.GetTooltip(i)); | |
38 entry->SetInteger("modelIndex", i); | |
39 startup_pages.Append(entry); | |
Dan Beam
2015/09/02 19:43:52
Append(entry.release())
| |
40 } | |
41 | |
42 web_ui()->CallJavascriptFunction("Settings.updateStartupPages", | |
43 startup_pages); | |
44 } | |
45 | |
46 void StartupPagesHandler::OnItemsChanged(int start, int length) { | |
47 OnModelChanged(); | |
48 } | |
49 | |
50 void StartupPagesHandler::OnItemsAdded(int start, int length) { | |
51 OnModelChanged(); | |
52 } | |
53 | |
54 void StartupPagesHandler::OnItemsRemoved(int start, int length) { | |
55 OnModelChanged(); | |
56 } | |
57 | |
58 void StartupPagesHandler::SetStartupPagesToCurrentPages( | |
59 const base::ListValue* args) { | |
60 startup_custom_pages_table_model_.SetToCurrentlyOpenPages(); | |
61 } | |
62 | |
63 } // namespace settings | |
OLD | NEW |