Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1392)

Side by Side Diff: chrome/browser/ui/webui/options/options_ui.cc

Issue 2236213002: Add quick unlock Settings in options page (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: incorporate comments from jdufault@ Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/options/options_ui.h" 5 #include "chrome/browser/ui/webui/options/options_ui.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 #include "chrome/grit/locale_settings.h" 56 #include "chrome/grit/locale_settings.h"
57 #include "components/omnibox/browser/autocomplete_match.h" 57 #include "components/omnibox/browser/autocomplete_match.h"
58 #include "components/omnibox/browser/autocomplete_result.h" 58 #include "components/omnibox/browser/autocomplete_result.h"
59 #include "components/strings/grit/components_strings.h" 59 #include "components/strings/grit/components_strings.h"
60 #include "content/public/browser/notification_types.h" 60 #include "content/public/browser/notification_types.h"
61 #include "content/public/browser/render_frame_host.h" 61 #include "content/public/browser/render_frame_host.h"
62 #include "content/public/browser/url_data_source.h" 62 #include "content/public/browser/url_data_source.h"
63 #include "content/public/browser/web_contents.h" 63 #include "content/public/browser/web_contents.h"
64 #include "content/public/browser/web_contents_delegate.h" 64 #include "content/public/browser/web_contents_delegate.h"
65 #include "content/public/browser/web_ui.h" 65 #include "content/public/browser/web_ui.h"
66 #include "content/public/browser/web_ui_data_source.h"
66 #include "grit/options_resources.h" 67 #include "grit/options_resources.h"
67 #include "grit/theme_resources.h" 68 #include "grit/theme_resources.h"
68 #include "net/base/escape.h" 69 #include "net/base/escape.h"
69 #include "ui/base/l10n/l10n_util.h" 70 #include "ui/base/l10n/l10n_util.h"
70 #include "ui/base/resource/resource_bundle.h" 71 #include "ui/base/resource/resource_bundle.h"
71 #include "ui/base/webui/jstemplate_builder.h" 72 #include "ui/base/webui/jstemplate_builder.h"
72 #include "ui/base/webui/web_ui_util.h" 73 #include "ui/base/webui/web_ui_util.h"
73 #include "url/gurl.h" 74 #include "url/gurl.h"
74 75
75 #if defined(ENABLE_SUPERVISED_USERS) 76 #if defined(ENABLE_SUPERVISED_USERS)
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 #include "chrome/browser/ui/webui/options/geolocation_options_handler.h" 110 #include "chrome/browser/ui/webui/options/geolocation_options_handler.h"
110 #endif 111 #endif
111 112
112 using content::RenderViewHost; 113 using content::RenderViewHost;
113 114
114 namespace { 115 namespace {
115 116
116 const char kLocalizedStringsFile[] = "strings.js"; 117 const char kLocalizedStringsFile[] = "strings.js";
117 const char kOptionsBundleJsFile[] = "options_bundle.js"; 118 const char kOptionsBundleJsFile[] = "options_bundle.js";
118 119
120 const char kPinKeyboardHTMLPath[] = "people_page/pin_keyboard.html";
xiyuan 2016/08/16 18:19:47 nit: constexpr char... here and other places
xiaoyinh(OOO Sep 11-29) 2016/08/17 20:52:11 Done.
121 const char kPinKeyboardJSPath[] = "people_page/pin_keyboard.js";
122 const char kPasswordPromptDialogHTMLPath[] =
123 "people_page/password_prompt_dialog.html";
124 const char kPasswordPromptDialogJSPath[] =
125 "people_page/password_prompt_dialog.js";
126 const char kLockStateBehaviorHTMLPath[] =
127 "people_page/lock_state_behavior.html";
128 const char kLockStateBehaviorJSPath[] = "people_page/lock_state_behavior.js";
129 const char kLockScreenHTMLPath[] = "people_page/lock_screen.html";
130 const char kLockScreenJSPath[] = "people_page/lock_screen.js";
131 const char kSetupPinHTMLPath[] = "people_page/setup_pin_dialog.html";
132 const char kSetupPinJSPath[] = "people_page/setup_pin_dialog.js";
133 const char kSettingsRouteHTMLPath[] = "route.html";
134 const char kSettingsRouteJSPath[] = "route_stub.js";
135 const char kSettingsSharedCSSHTMLPath[] = "settings_shared_css.html";
136 const char kSettingsVarsCSSHTMLPath[] = "settings_vars_css.html";
137 const char kSettingsPrefsBehaviorHTMLPath[] = "prefs/prefs_behavior.html";
138 const char kSettingsPrefsBehaviorJSPath[] = "prefs/prefs_behavior.js";
139 const char kSettingsPrefsTypesHTMLPath[] = "prefs/prefs_types.html";
140 const char kSettingsPrefsTypesJSPath[] = "prefs/prefs_types.js";
141
119 } // namespace 142 } // namespace
120 143
121 namespace options { 144 namespace options {
122 145
123 //////////////////////////////////////////////////////////////////////////////// 146 ////////////////////////////////////////////////////////////////////////////////
124 // 147 //
125 // OptionsUIHTMLSource 148 // OptionsUIHTMLSource
126 // 149 //
127 //////////////////////////////////////////////////////////////////////////////// 150 ////////////////////////////////////////////////////////////////////////////////
128 151
129 class OptionsUIHTMLSource : public content::URLDataSource { 152 class OptionsUIHTMLSource : public content::URLDataSource {
130 public: 153 public:
131 // The constructor takes over ownership of |localized_strings|. 154 // The constructor takes over ownership of |localized_strings|.
132 explicit OptionsUIHTMLSource(base::DictionaryValue* localized_strings); 155 explicit OptionsUIHTMLSource(base::DictionaryValue* localized_strings);
133 156
134 // content::URLDataSource implementation. 157 // content::URLDataSource implementation.
135 std::string GetSource() const override; 158 std::string GetSource() const override;
136 void StartDataRequest( 159 void StartDataRequest(
137 const std::string& path, 160 const std::string& path,
138 int render_process_id, 161 int render_process_id,
139 int render_frame_id, 162 int render_frame_id,
140 const content::URLDataSource::GotDataCallback& callback) override; 163 const content::URLDataSource::GotDataCallback& callback) override;
141 std::string GetMimeType(const std::string&) const override; 164 std::string GetMimeType(const std::string&) const override;
142 bool ShouldDenyXFrameOptions() const override; 165 bool ShouldDenyXFrameOptions() const override;
143 166
144 private: 167 private:
145 ~OptionsUIHTMLSource() override; 168 ~OptionsUIHTMLSource() override;
169 void CreateDataSourceMap();
146 170
147 // Localized strings collection. 171 // Localized strings collection.
148 std::unique_ptr<base::DictionaryValue> localized_strings_; 172 std::unique_ptr<base::DictionaryValue> localized_strings_;
173 std::map<std::string, int> path_to_idr_map_;
149 174
150 DISALLOW_COPY_AND_ASSIGN(OptionsUIHTMLSource); 175 DISALLOW_COPY_AND_ASSIGN(OptionsUIHTMLSource);
151 }; 176 };
152 177
153 OptionsUIHTMLSource::OptionsUIHTMLSource( 178 OptionsUIHTMLSource::OptionsUIHTMLSource(
154 base::DictionaryValue* localized_strings) { 179 base::DictionaryValue* localized_strings) {
155 DCHECK(localized_strings); 180 DCHECK(localized_strings);
156 localized_strings_.reset(localized_strings); 181 localized_strings_.reset(localized_strings);
182 CreateDataSourceMap();
157 } 183 }
158 184
159 std::string OptionsUIHTMLSource::GetSource() const { 185 std::string OptionsUIHTMLSource::GetSource() const {
160 return chrome::kChromeUISettingsFrameHost; 186 return chrome::kChromeUISettingsFrameHost;
161 } 187 }
162 188
163 void OptionsUIHTMLSource::StartDataRequest( 189 void OptionsUIHTMLSource::StartDataRequest(
164 const std::string& path, 190 const std::string& path,
165 int render_process_id, 191 int render_process_id,
166 int render_frame_id, 192 int render_frame_id,
167 const content::URLDataSource::GotDataCallback& callback) { 193 const content::URLDataSource::GotDataCallback& callback) {
168 scoped_refptr<base::RefCountedMemory> response_bytes; 194 scoped_refptr<base::RefCountedMemory> response_bytes;
169 const std::string& app_locale = g_browser_process->GetApplicationLocale(); 195 const std::string& app_locale = g_browser_process->GetApplicationLocale();
170 webui::SetLoadTimeDataDefaults(app_locale, localized_strings_.get()); 196 webui::SetLoadTimeDataDefaults(app_locale, localized_strings_.get());
171 197
198 std::map<std::string, int>::iterator result;
199 result = path_to_idr_map_.find(path);
200
172 if (path == kLocalizedStringsFile) { 201 if (path == kLocalizedStringsFile) {
173 // Return dynamically-generated strings from memory. 202 // Return dynamically-generated strings from memory.
174 std::string strings_js; 203 std::string strings_js;
175 webui::AppendJsonJS(localized_strings_.get(), &strings_js); 204 webui::AppendJsonJS(localized_strings_.get(), &strings_js);
176 response_bytes = base::RefCountedString::TakeString(&strings_js); 205 response_bytes = base::RefCountedString::TakeString(&strings_js);
177 } else if (path == kOptionsBundleJsFile) { 206 } else if (path == kOptionsBundleJsFile) {
178 // Return (and cache) the options javascript code. 207 // Return (and cache) the options javascript code.
179 response_bytes = ui::ResourceBundle::GetSharedInstance(). 208 response_bytes = ui::ResourceBundle::GetSharedInstance().
180 LoadDataResourceBytes(IDR_OPTIONS_BUNDLE_JS); 209 LoadDataResourceBytes(IDR_OPTIONS_BUNDLE_JS);
210 } else if (result != path_to_idr_map_.end()) {
211 response_bytes =
212 ui::ResourceBundle::GetSharedInstance().LoadDataResourceBytes(
213 result->second);
181 } else { 214 } else {
182 // Return (and cache) the main options html page as the default. 215 // Return (and cache) the main options html page as the default.
183 response_bytes = ui::ResourceBundle::GetSharedInstance(). 216 response_bytes = ui::ResourceBundle::GetSharedInstance().
184 LoadDataResourceBytes(IDR_OPTIONS_HTML); 217 LoadDataResourceBytes(IDR_OPTIONS_HTML);
185 } 218 }
186 219
187 callback.Run(response_bytes.get()); 220 callback.Run(response_bytes.get());
188 } 221 }
189 222
190 std::string OptionsUIHTMLSource::GetMimeType(const std::string& path) const { 223 std::string OptionsUIHTMLSource::GetMimeType(const std::string& path) const {
191 if (path == kLocalizedStringsFile || path == kOptionsBundleJsFile) 224 if (path == kLocalizedStringsFile || path == kOptionsBundleJsFile)
192 return "application/javascript"; 225 return "application/javascript";
193 226
194 return "text/html"; 227 return "text/html";
195 } 228 }
196 229
197 bool OptionsUIHTMLSource::ShouldDenyXFrameOptions() const { 230 bool OptionsUIHTMLSource::ShouldDenyXFrameOptions() const {
198 return false; 231 return false;
199 } 232 }
200 233
201 OptionsUIHTMLSource::~OptionsUIHTMLSource() {} 234 OptionsUIHTMLSource::~OptionsUIHTMLSource() {}
202 235
236 void OptionsUIHTMLSource::CreateDataSourceMap() {
237 path_to_idr_map_[kPinKeyboardHTMLPath] = IDR_OPTIONS_PIN_KEYBOARD_HTML;
xiyuan 2016/08/16 18:19:47 If we include these resources only for chormeos, t
xiaoyinh(OOO Sep 11-29) 2016/08/17 20:52:11 Done.
238 path_to_idr_map_[kPinKeyboardJSPath] = IDR_OPTIONS_PIN_KEYBOARD_JS;
239 path_to_idr_map_[kPasswordPromptDialogHTMLPath] =
240 IDR_OPTIONS_PASSWORD_PROMPT_DIALOG_HTML;
241 path_to_idr_map_[kPasswordPromptDialogJSPath] =
242 IDR_OPTIONS_PASSWORD_PROMPT_DIALOG_JS;
243 path_to_idr_map_[kLockStateBehaviorHTMLPath] =
244 IDR_OPTIONS_LOCK_STATE_BEHAVIOR_HTML;
245 path_to_idr_map_[kLockStateBehaviorJSPath] =
246 IDR_OPTIONS_LOCK_STATE_BEHAVIOR_JS;
247 path_to_idr_map_[kLockScreenHTMLPath] = IDR_OPTIONS_LOCK_SCREEN_HTML;
248 path_to_idr_map_[kLockScreenJSPath] = IDR_OPTIONS_LOCK_SCREEN_JS;
249 path_to_idr_map_[kSetupPinHTMLPath] = IDR_OPTIONS_SETUP_PIN_DIALOG_HTML;
250 path_to_idr_map_[kSetupPinJSPath] = IDR_OPTIONS_SETUP_PIN_DIALOG_JS;
251 path_to_idr_map_[kSettingsRouteHTMLPath] = IDR_OPTIONS_ROUTE_HTML;
252 path_to_idr_map_[kSettingsRouteJSPath] = IDR_OPTIONS_ROUTE_JS;
253 path_to_idr_map_[kSettingsSharedCSSHTMLPath] = IDR_SETTINGS_SHARED_CSS_HTML;
254 path_to_idr_map_[kSettingsVarsCSSHTMLPath] = IDR_SETTINGS_VARS_CSS_HTML;
255 path_to_idr_map_[kSettingsPrefsBehaviorHTMLPath] =
256 IDR_SETTINGS_PREFS_BEHAVIOR_HTML;
257 path_to_idr_map_[kSettingsPrefsBehaviorJSPath] =
258 IDR_SETTINGS_PREFS_BEHAVIOR_JS;
259 path_to_idr_map_[kSettingsPrefsTypesHTMLPath] = IDR_SETTINGS_PREFS_TYPES_HTML;
260 path_to_idr_map_[kSettingsPrefsTypesJSPath] = IDR_SETTINGS_PREFS_TYPES_JS;
261 }
262
203 //////////////////////////////////////////////////////////////////////////////// 263 ////////////////////////////////////////////////////////////////////////////////
204 // 264 //
205 // OptionsPageUIHandler 265 // OptionsPageUIHandler
206 // 266 //
207 //////////////////////////////////////////////////////////////////////////////// 267 ////////////////////////////////////////////////////////////////////////////////
208 268
209 OptionsPageUIHandler::OptionsPageUIHandler() { 269 OptionsPageUIHandler::OptionsPageUIHandler() {
210 } 270 }
211 271
212 OptionsPageUIHandler::~OptionsPageUIHandler() { 272 OptionsPageUIHandler::~OptionsPageUIHandler() {
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 // Add only if handler's service is enabled. 538 // Add only if handler's service is enabled.
479 if (handler->IsEnabled()) { 539 if (handler->IsEnabled()) {
480 // Add handler to the list and also pass the ownership. 540 // Add handler to the list and also pass the ownership.
481 web_ui()->AddMessageHandler(handler.release()); 541 web_ui()->AddMessageHandler(handler.release());
482 handler_raw->GetLocalizedValues(localized_strings); 542 handler_raw->GetLocalizedValues(localized_strings);
483 handlers_.push_back(handler_raw); 543 handlers_.push_back(handler_raw);
484 } 544 }
485 } 545 }
486 546
487 } // namespace options 547 } // namespace options
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698