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.
5 #include "chrome/browser/ui/webui/settings/settings_startup_pages_handler.h"
7 #include "chrome/browser/profiles/profile.h"
8 #include "content/public/browser/web_ui.h"
12 StartupPagesHandler::StartupPagesHandler(content::WebUI
* webui
)
13 : startup_custom_pages_table_model_(Profile::FromWebUI(webui
)) {
14 startup_custom_pages_table_model_
.SetObserver(this);
17 StartupPagesHandler::~StartupPagesHandler() {
20 void StartupPagesHandler::RegisterMessages() {
21 DCHECK(!Profile::FromWebUI(web_ui())->IsOffTheRecord());
23 web_ui()->RegisterMessageCallback("setStartupPagesToCurrentPages",
24 base::Bind(&StartupPagesHandler::SetStartupPagesToCurrentPages
,
25 base::Unretained(this)));
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 scoped_ptr
<base::DictionaryValue
> entry(new base::DictionaryValue());
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
.release());
42 web_ui()->CallJavascriptFunction("Settings.updateStartupPages",
46 void StartupPagesHandler::OnItemsChanged(int start
, int length
) {
50 void StartupPagesHandler::OnItemsAdded(int start
, int length
) {
54 void StartupPagesHandler::OnItemsRemoved(int start
, int length
) {
58 void StartupPagesHandler::SetStartupPagesToCurrentPages(
59 const base::ListValue
* args
) {
60 startup_custom_pages_table_model_
.SetToCurrentlyOpenPages();
63 } // namespace settings