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" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 | 74 |
75 void StartupPagesHandler::OnItemsAdded(int start, int length) { | 75 void StartupPagesHandler::OnItemsAdded(int start, int length) { |
76 OnModelChanged(); | 76 OnModelChanged(); |
77 } | 77 } |
78 | 78 |
79 void StartupPagesHandler::OnItemsRemoved(int start, int length) { | 79 void StartupPagesHandler::OnItemsRemoved(int start, int length) { |
80 OnModelChanged(); | 80 OnModelChanged(); |
81 } | 81 } |
82 | 82 |
83 void StartupPagesHandler::HandleAddStartupPage(const base::ListValue* args) { | 83 void StartupPagesHandler::HandleAddStartupPage(const base::ListValue* args) { |
| 84 CHECK_EQ(2U, args->GetSize()); |
| 85 |
| 86 const base::Value* callback_id; |
| 87 CHECK(args->Get(0, &callback_id)); |
| 88 |
84 std::string url_string; | 89 std::string url_string; |
85 if (!args->GetString(0, &url_string)) { | 90 CHECK(args->GetString(1, &url_string)); |
86 NOTREACHED(); | 91 |
| 92 GURL url; |
| 93 if (!settings_utils::FixupAndValidateStartupPage(url_string, &url)) { |
| 94 ResolveJavascriptCallback(*callback_id, base::FundamentalValue(false)); |
87 return; | 95 return; |
88 } | 96 } |
89 | 97 |
90 GURL url; | |
91 if (!settings_utils::FixupAndValidateStartupPage(url_string, &url)) { | |
92 NOTREACHED(); | |
93 return; | |
94 } | |
95 | |
96 int row_count = startup_custom_pages_table_model_.RowCount(); | 98 int row_count = startup_custom_pages_table_model_.RowCount(); |
97 int index; | 99 int index; |
98 if (!args->GetInteger(1, &index) || index > row_count) | 100 if (!args->GetInteger(1, &index) || index > row_count) |
99 index = row_count; | 101 index = row_count; |
100 | 102 |
101 startup_custom_pages_table_model_.Add(index, url); | 103 startup_custom_pages_table_model_.Add(index, url); |
102 SaveStartupPagesPref(); | 104 SaveStartupPagesPref(); |
| 105 ResolveJavascriptCallback(*callback_id, base::FundamentalValue(true)); |
103 } | 106 } |
104 | 107 |
105 void StartupPagesHandler::HandleOnStartupPrefsPageLoad( | 108 void StartupPagesHandler::HandleOnStartupPrefsPageLoad( |
106 const base::ListValue* args) { | 109 const base::ListValue* args) { |
107 startup_custom_pages_table_model_.SetObserver(this); | 110 startup_custom_pages_table_model_.SetObserver(this); |
108 | 111 |
109 PrefService* prefService = Profile::FromWebUI(web_ui())->GetPrefs(); | 112 PrefService* prefService = Profile::FromWebUI(web_ui())->GetPrefs(); |
110 SessionStartupPref pref = SessionStartupPref::GetStartupPref( | 113 SessionStartupPref pref = SessionStartupPref::GetStartupPref( |
111 prefService); | 114 prefService); |
112 startup_custom_pages_table_model_.SetURLs(pref.urls); | 115 startup_custom_pages_table_model_.SetURLs(pref.urls); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 | 179 |
177 void StartupPagesHandler::UpdateStartupPages() { | 180 void StartupPagesHandler::UpdateStartupPages() { |
178 const SessionStartupPref startup_pref = SessionStartupPref::GetStartupPref( | 181 const SessionStartupPref startup_pref = SessionStartupPref::GetStartupPref( |
179 Profile::FromWebUI(web_ui())->GetPrefs()); | 182 Profile::FromWebUI(web_ui())->GetPrefs()); |
180 startup_custom_pages_table_model_.SetURLs(startup_pref.urls); | 183 startup_custom_pages_table_model_.SetURLs(startup_pref.urls); |
181 // The change will go to the JS code in the | 184 // The change will go to the JS code in the |
182 // StartupPagesHandler::OnModelChanged() method. | 185 // StartupPagesHandler::OnModelChanged() method. |
183 } | 186 } |
184 | 187 |
185 } // namespace settings | 188 } // namespace settings |
OLD | NEW |