OLD | NEW |
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/chromeos/sim_unlock_ui.h" | 5 #include "chrome/browser/ui/webui/chromeos/sim_unlock_ui.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/memory/ref_counted_memory.h" | 12 #include "base/memory/ref_counted_memory.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
14 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
15 #include "base/string_piece.h" | 15 #include "base/string_piece.h" |
16 #include "base/values.h" | 16 #include "base/values.h" |
17 #include "chrome/browser/chromeos/cros/cros_library.h" | 17 #include "chrome/browser/chromeos/cros/cros_library.h" |
18 #include "chrome/browser/chromeos/cros/network_library.h" | 18 #include "chrome/browser/chromeos/cros/network_library.h" |
19 #include "chrome/browser/chromeos/sim_dialog_delegate.h" | 19 #include "chrome/browser/chromeos/sim_dialog_delegate.h" |
20 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
21 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 21 #include "chrome/browser/ui/webui/web_ui_util.h" |
22 #include "chrome/common/chrome_notification_types.h" | 22 #include "chrome/common/chrome_notification_types.h" |
23 #include "chrome/common/jstemplate_builder.h" | 23 #include "chrome/common/jstemplate_builder.h" |
24 #include "chrome/common/url_constants.h" | 24 #include "chrome/common/url_constants.h" |
25 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
26 #include "content/public/browser/notification_service.h" | 26 #include "content/public/browser/notification_service.h" |
27 #include "content/public/browser/url_data_source_delegate.h" | 27 #include "content/public/browser/url_data_source.h" |
28 #include "content/public/browser/web_contents.h" | 28 #include "content/public/browser/web_contents.h" |
29 #include "content/public/browser/web_ui.h" | 29 #include "content/public/browser/web_ui.h" |
30 #include "content/public/browser/web_ui_message_handler.h" | 30 #include "content/public/browser/web_ui_message_handler.h" |
31 #include "grit/browser_resources.h" | 31 #include "grit/browser_resources.h" |
32 #include "grit/generated_resources.h" | 32 #include "grit/generated_resources.h" |
33 #include "ui/base/l10n/l10n_util.h" | 33 #include "ui/base/l10n/l10n_util.h" |
34 #include "ui/base/resource/resource_bundle.h" | 34 #include "ui/base/resource/resource_bundle.h" |
35 | 35 |
36 using content::BrowserThread; | 36 using content::BrowserThread; |
37 using content::WebContents; | 37 using content::WebContents; |
(...skipping 26 matching lines...) Expand all Loading... |
64 chromeos::NetworkLibrary* lib = chromeos::CrosLibrary::Get()-> | 64 chromeos::NetworkLibrary* lib = chromeos::CrosLibrary::Get()-> |
65 GetNetworkLibrary(); | 65 GetNetworkLibrary(); |
66 CHECK(lib); | 66 CHECK(lib); |
67 return lib->FindCellularDevice(); | 67 return lib->FindCellularDevice(); |
68 } | 68 } |
69 | 69 |
70 } // namespace | 70 } // namespace |
71 | 71 |
72 namespace chromeos { | 72 namespace chromeos { |
73 | 73 |
74 class SimUnlockUIHTMLSource : public content::URLDataSourceDelegate { | 74 class SimUnlockUIHTMLSource : public content::URLDataSource { |
75 public: | 75 public: |
76 SimUnlockUIHTMLSource(); | 76 SimUnlockUIHTMLSource(); |
77 | 77 |
78 // content::URLDataSourceDelegate implementation. | 78 // content::URLDataSource implementation. |
79 virtual std::string GetSource() OVERRIDE; | 79 virtual std::string GetSource() OVERRIDE; |
80 virtual void StartDataRequest(const std::string& path, | 80 virtual void StartDataRequest( |
81 bool is_incognito, | 81 const std::string& path, |
82 int request_id) OVERRIDE; | 82 bool is_incognito, |
| 83 const content::URLDataSource::GotDataCallback& callback) OVERRIDE; |
83 virtual std::string GetMimeType(const std::string&) const OVERRIDE { | 84 virtual std::string GetMimeType(const std::string&) const OVERRIDE { |
84 return "text/html"; | 85 return "text/html"; |
85 } | 86 } |
86 | 87 |
87 private: | 88 private: |
88 virtual ~SimUnlockUIHTMLSource() {} | 89 virtual ~SimUnlockUIHTMLSource() {} |
89 | 90 |
90 std::string service_path_; | 91 std::string service_path_; |
91 DISALLOW_COPY_AND_ASSIGN(SimUnlockUIHTMLSource); | 92 DISALLOW_COPY_AND_ASSIGN(SimUnlockUIHTMLSource); |
92 }; | 93 }; |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 | 247 |
247 // SimUnlockUIHTMLSource ------------------------------------------------------- | 248 // SimUnlockUIHTMLSource ------------------------------------------------------- |
248 | 249 |
249 SimUnlockUIHTMLSource::SimUnlockUIHTMLSource() { | 250 SimUnlockUIHTMLSource::SimUnlockUIHTMLSource() { |
250 } | 251 } |
251 | 252 |
252 std::string SimUnlockUIHTMLSource::GetSource() { | 253 std::string SimUnlockUIHTMLSource::GetSource() { |
253 return chrome::kChromeUISimUnlockHost; | 254 return chrome::kChromeUISimUnlockHost; |
254 } | 255 } |
255 | 256 |
256 void SimUnlockUIHTMLSource::StartDataRequest(const std::string& path, | 257 void SimUnlockUIHTMLSource::StartDataRequest( |
257 bool is_incognito, | 258 const std::string& path, |
258 int request_id) { | 259 bool is_incognito, |
| 260 const content::URLDataSource::GotDataCallback& callback) { |
259 DictionaryValue strings; | 261 DictionaryValue strings; |
260 strings.SetString("title", | 262 strings.SetString("title", |
261 l10n_util::GetStringUTF16(IDS_SIM_UNLOCK_ENTER_PIN_TITLE)); | 263 l10n_util::GetStringUTF16(IDS_SIM_UNLOCK_ENTER_PIN_TITLE)); |
262 strings.SetString("ok", l10n_util::GetStringUTF16(IDS_OK)); | 264 strings.SetString("ok", l10n_util::GetStringUTF16(IDS_OK)); |
263 strings.SetString("cancel", l10n_util::GetStringUTF16(IDS_CANCEL)); | 265 strings.SetString("cancel", l10n_util::GetStringUTF16(IDS_CANCEL)); |
264 strings.SetString("enterPinTitle", | 266 strings.SetString("enterPinTitle", |
265 l10n_util::GetStringUTF16(IDS_SIM_UNLOCK_ENTER_PIN_TITLE)); | 267 l10n_util::GetStringUTF16(IDS_SIM_UNLOCK_ENTER_PIN_TITLE)); |
266 strings.SetString("enterPinMessage", | 268 strings.SetString("enterPinMessage", |
267 l10n_util::GetStringUTF16(IDS_SIM_ENTER_PIN_MESSAGE)); | 269 l10n_util::GetStringUTF16(IDS_SIM_ENTER_PIN_MESSAGE)); |
268 strings.SetString("enterPinTriesMessage", | 270 strings.SetString("enterPinTriesMessage", |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 strings.SetString("simDisabledMessage", | 304 strings.SetString("simDisabledMessage", |
303 l10n_util::GetStringUTF16(IDS_SIM_UNLOCK_SIM_DISABLED_MESSAGE)); | 305 l10n_util::GetStringUTF16(IDS_SIM_UNLOCK_SIM_DISABLED_MESSAGE)); |
304 | 306 |
305 strings.SetString("changePinTitle", l10n_util::GetStringUTF16( | 307 strings.SetString("changePinTitle", l10n_util::GetStringUTF16( |
306 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_CHANGE_PIN_TITLE)); | 308 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_CHANGE_PIN_TITLE)); |
307 strings.SetString("changePinMessage", l10n_util::GetStringUTF16( | 309 strings.SetString("changePinMessage", l10n_util::GetStringUTF16( |
308 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_CHANGE_PIN_MESSAGE)); | 310 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_CHANGE_PIN_MESSAGE)); |
309 strings.SetString("oldPin", l10n_util::GetStringUTF16( | 311 strings.SetString("oldPin", l10n_util::GetStringUTF16( |
310 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_CHANGE_PIN_OLD_PIN)); | 312 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_CHANGE_PIN_OLD_PIN)); |
311 | 313 |
312 URLDataSource::SetFontAndTextDirection(&strings); | 314 web_ui_util::SetFontAndTextDirection(&strings); |
313 | 315 |
314 static const base::StringPiece html( | 316 static const base::StringPiece html( |
315 ResourceBundle::GetSharedInstance().GetRawDataResource( | 317 ResourceBundle::GetSharedInstance().GetRawDataResource( |
316 IDR_SIM_UNLOCK_HTML)); | 318 IDR_SIM_UNLOCK_HTML)); |
317 | 319 |
318 std::string full_html = jstemplate_builder::GetI18nTemplateHtml(html, | 320 std::string full_html = jstemplate_builder::GetI18nTemplateHtml(html, |
319 &strings); | 321 &strings); |
320 | 322 |
321 url_data_source()->SendResponse( | 323 callback.Run(base::RefCountedString::TakeString(&full_html)); |
322 request_id, base::RefCountedString::TakeString(&full_html)); | |
323 } | 324 } |
324 | 325 |
325 // SimUnlockHandler ------------------------------------------------------------ | 326 // SimUnlockHandler ------------------------------------------------------------ |
326 | 327 |
327 SimUnlockHandler::SimUnlockHandler() | 328 SimUnlockHandler::SimUnlockHandler() |
328 : state_(SIM_UNLOCK_LOADING), | 329 : state_(SIM_UNLOCK_LOADING), |
329 dialog_mode_(SimDialogDelegate::SIM_DIALOG_UNLOCK), | 330 dialog_mode_(SimDialogDelegate::SIM_DIALOG_UNLOCK), |
330 pending_pin_operation_(false) { | 331 pending_pin_operation_(false) { |
331 const chromeos::NetworkDevice* cellular = GetCellularDevice(); | 332 const chromeos::NetworkDevice* cellular = GetCellularDevice(); |
332 // One could just call us directly via chrome://sim-unlock. | 333 // One could just call us directly via chrome://sim-unlock. |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
677 SimUnlockHandler* handler = new SimUnlockHandler(); | 678 SimUnlockHandler* handler = new SimUnlockHandler(); |
678 web_ui->AddMessageHandler(handler); | 679 web_ui->AddMessageHandler(handler); |
679 SimUnlockUIHTMLSource* html_source = new SimUnlockUIHTMLSource(); | 680 SimUnlockUIHTMLSource* html_source = new SimUnlockUIHTMLSource(); |
680 | 681 |
681 // Set up the chrome://sim-unlock/ source. | 682 // Set up the chrome://sim-unlock/ source. |
682 Profile* profile = Profile::FromWebUI(web_ui); | 683 Profile* profile = Profile::FromWebUI(web_ui); |
683 ChromeURLDataManager::AddDataSource(profile, html_source); | 684 ChromeURLDataManager::AddDataSource(profile, html_source); |
684 } | 685 } |
685 | 686 |
686 } // namespace chromeos | 687 } // namespace chromeos |
OLD | NEW |