OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/webui/settings/settings_startup_pages_handler.h" | 5 #include "chrome/browser/ui/webui/settings/settings_startup_pages_handler.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "chrome/browser/prefs/session_startup_pref.h" | 10 #include "chrome/browser/prefs/session_startup_pref.h" |
11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/common/pref_names.h" | 12 #include "chrome/common/pref_names.h" |
13 #include "components/url_formatter/url_fixer.h" | 13 #include "components/url_formatter/url_fixer.h" |
14 #include "content/public/browser/web_ui.h" | 14 #include "content/public/browser/web_ui.h" |
15 | 15 |
16 namespace settings { | 16 namespace settings { |
17 | 17 |
18 StartupPagesHandler::StartupPagesHandler(content::WebUI* webui) | 18 StartupPagesHandler::StartupPagesHandler(content::WebUI* webui) |
19 : startup_custom_pages_table_model_(Profile::FromWebUI(webui)) { | 19 : startup_custom_pages_table_model_(Profile::FromWebUI(webui)) { |
20 } | 20 } |
21 | 21 |
22 StartupPagesHandler::~StartupPagesHandler() { | 22 StartupPagesHandler::~StartupPagesHandler() { |
23 } | 23 } |
24 | 24 |
25 void StartupPagesHandler::RegisterMessages() { | 25 void StartupPagesHandler::RegisterMessages() { |
26 if (Profile::FromWebUI(web_ui())->IsOffTheRecord()) | 26 if (Profile::FromWebUI(web_ui())->IsOffTheRecord()) |
27 return; | 27 return; |
28 | 28 |
29 startup_custom_pages_table_model_.SetObserver(this); | |
30 | |
31 PrefService* prefService = Profile::FromWebUI(web_ui())->GetPrefs(); | |
32 SessionStartupPref pref = SessionStartupPref::GetStartupPref( | |
33 prefService); | |
34 startup_custom_pages_table_model_.SetURLs(pref.urls); | |
35 | |
36 if (pref.urls.empty()) | |
37 pref.type = SessionStartupPref::DEFAULT; | |
38 | |
39 pref_change_registrar_.Init(prefService); | |
40 pref_change_registrar_.Add( | |
41 prefs::kURLsToRestoreOnStartup, | |
42 base::Bind(&StartupPagesHandler::UpdateStartupPages, | |
43 base::Unretained(this))); | |
44 | |
45 web_ui()->RegisterMessageCallback("addStartupPage", | 29 web_ui()->RegisterMessageCallback("addStartupPage", |
46 base::Bind(&StartupPagesHandler::AddStartupPage, | 30 base::Bind(&StartupPagesHandler::AddStartupPage, |
47 base::Unretained(this))); | 31 base::Unretained(this))); |
48 web_ui()->RegisterMessageCallback("onStartupPrefsPageLoad", | 32 web_ui()->RegisterMessageCallback("onStartupPrefsPageLoad", |
49 base::Bind(&StartupPagesHandler::OnStartupPrefsPageLoad, | 33 base::Bind(&StartupPagesHandler::OnStartupPrefsPageLoad, |
50 base::Unretained(this))); | 34 base::Unretained(this))); |
51 web_ui()->RegisterMessageCallback("removeStartupPage", | 35 web_ui()->RegisterMessageCallback("removeStartupPage", |
52 base::Bind(&StartupPagesHandler::RemoveStartupPage, | 36 base::Bind(&StartupPagesHandler::RemoveStartupPage, |
53 base::Unretained(this))); | 37 base::Unretained(this))); |
54 web_ui()->RegisterMessageCallback("setStartupPagesToCurrentPages", | 38 web_ui()->RegisterMessageCallback("setStartupPagesToCurrentPages", |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
102 int row_count = startup_custom_pages_table_model_.RowCount(); | 86 int row_count = startup_custom_pages_table_model_.RowCount(); |
103 int index; | 87 int index; |
104 if (!args->GetInteger(1, &index) || index > row_count) | 88 if (!args->GetInteger(1, &index) || index > row_count) |
105 index = row_count; | 89 index = row_count; |
106 | 90 |
107 startup_custom_pages_table_model_.Add(index, url); | 91 startup_custom_pages_table_model_.Add(index, url); |
108 SaveStartupPagesPref(); | 92 SaveStartupPagesPref(); |
109 } | 93 } |
110 | 94 |
111 void StartupPagesHandler::OnStartupPrefsPageLoad(const base::ListValue* args) { | 95 void StartupPagesHandler::OnStartupPrefsPageLoad(const base::ListValue* args) { |
96 startup_custom_pages_table_model_.SetObserver(this); | |
97 | |
98 PrefService* prefService = Profile::FromWebUI(web_ui())->GetPrefs(); | |
99 SessionStartupPref pref = SessionStartupPref::GetStartupPref( | |
100 prefService); | |
101 startup_custom_pages_table_model_.SetURLs(pref.urls); | |
102 | |
103 if (pref.urls.empty()) | |
104 pref.type = SessionStartupPref::DEFAULT; | |
105 | |
106 pref_change_registrar_.Init(prefService); | |
107 pref_change_registrar_.Add( | |
108 prefs::kURLsToRestoreOnStartup, | |
109 base::Bind(&StartupPagesHandler::UpdateStartupPages, | |
110 base::Unretained(this))); | |
Dan Beam
2016/01/26 23:34:27
nit: \n
dschuyler
2016/01/26 23:40:16
Done.
| |
112 const SessionStartupPref startup_pref = SessionStartupPref::GetStartupPref( | 111 const SessionStartupPref startup_pref = SessionStartupPref::GetStartupPref( |
113 Profile::FromWebUI(web_ui())->GetPrefs()); | 112 Profile::FromWebUI(web_ui())->GetPrefs()); |
114 startup_custom_pages_table_model_.SetURLs(startup_pref.urls); | 113 startup_custom_pages_table_model_.SetURLs(startup_pref.urls); |
115 } | 114 } |
116 | 115 |
117 void StartupPagesHandler::RemoveStartupPage(const base::ListValue* args) { | 116 void StartupPagesHandler::RemoveStartupPage(const base::ListValue* args) { |
118 int selected_index; | 117 int selected_index; |
119 if (!args->GetInteger(0, &selected_index)) { | 118 if (!args->GetInteger(0, &selected_index)) { |
120 DLOG(ERROR) << "Missing index parameter"; | 119 DLOG(ERROR) << "Missing index parameter"; |
121 return; | 120 return; |
(...skipping 29 matching lines...) Expand all Loading... | |
151 | 150 |
152 void StartupPagesHandler::UpdateStartupPages() { | 151 void StartupPagesHandler::UpdateStartupPages() { |
153 const SessionStartupPref startup_pref = SessionStartupPref::GetStartupPref( | 152 const SessionStartupPref startup_pref = SessionStartupPref::GetStartupPref( |
154 Profile::FromWebUI(web_ui())->GetPrefs()); | 153 Profile::FromWebUI(web_ui())->GetPrefs()); |
155 startup_custom_pages_table_model_.SetURLs(startup_pref.urls); | 154 startup_custom_pages_table_model_.SetURLs(startup_pref.urls); |
156 // The change will go to the JS code in the | 155 // The change will go to the JS code in the |
157 // StartupPagesHandler::OnModelChanged() method. | 156 // StartupPagesHandler::OnModelChanged() method. |
158 } | 157 } |
159 | 158 |
160 } // namespace settings | 159 } // namespace settings |
OLD | NEW |