| 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/chrome_url_data_manager.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/web_contents.h" | 28 #include "content/public/browser/web_contents.h" |
| 28 #include "content/public/browser/web_ui.h" | 29 #include "content/public/browser/web_ui.h" |
| 29 #include "content/public/browser/web_ui_message_handler.h" | 30 #include "content/public/browser/web_ui_message_handler.h" |
| 30 #include "grit/browser_resources.h" | 31 #include "grit/browser_resources.h" |
| 31 #include "grit/generated_resources.h" | 32 #include "grit/generated_resources.h" |
| 32 #include "ui/base/l10n/l10n_util.h" | 33 #include "ui/base/l10n/l10n_util.h" |
| 33 #include "ui/base/resource/resource_bundle.h" | 34 #include "ui/base/resource/resource_bundle.h" |
| 34 | 35 |
| 35 using content::BrowserThread; | 36 using content::BrowserThread; |
| 36 using content::WebContents; | 37 using content::WebContents; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 63 chromeos::NetworkLibrary* lib = chromeos::CrosLibrary::Get()-> | 64 chromeos::NetworkLibrary* lib = chromeos::CrosLibrary::Get()-> |
| 64 GetNetworkLibrary(); | 65 GetNetworkLibrary(); |
| 65 CHECK(lib); | 66 CHECK(lib); |
| 66 return lib->FindCellularDevice(); | 67 return lib->FindCellularDevice(); |
| 67 } | 68 } |
| 68 | 69 |
| 69 } // namespace | 70 } // namespace |
| 70 | 71 |
| 71 namespace chromeos { | 72 namespace chromeos { |
| 72 | 73 |
| 73 class SimUnlockUIHTMLSource : public ChromeURLDataManager::DataSource { | 74 class SimUnlockUIHTMLSource : public content::URLDataSourceDelegate { |
| 74 public: | 75 public: |
| 75 SimUnlockUIHTMLSource(); | 76 SimUnlockUIHTMLSource(); |
| 76 | 77 |
| 77 // Called when the network layer has requested a resource underneath | 78 // content::URLDataSourceDelegate implementation. |
| 78 // the path we registered. | 79 virtual std::string GetSource() OVERRIDE; |
| 79 virtual void StartDataRequest(const std::string& path, | 80 virtual void StartDataRequest(const std::string& path, |
| 80 bool is_incognito, | 81 bool is_incognito, |
| 81 int request_id) OVERRIDE; | 82 int request_id) OVERRIDE; |
| 82 virtual std::string GetMimeType(const std::string&) const OVERRIDE { | 83 virtual std::string GetMimeType(const std::string&) const OVERRIDE { |
| 83 return "text/html"; | 84 return "text/html"; |
| 84 } | 85 } |
| 85 | 86 |
| 86 private: | 87 private: |
| 87 virtual ~SimUnlockUIHTMLSource() {} | 88 virtual ~SimUnlockUIHTMLSource() {} |
| 88 | 89 |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 // That means that SIM lock state change will be received 2 times: | 239 // That means that SIM lock state change will be received 2 times: |
| 239 // OnNetworkDeviceSimLockChanged and OnPinOperationCompleted. | 240 // OnNetworkDeviceSimLockChanged and OnPinOperationCompleted. |
| 240 // First one should be ignored. | 241 // First one should be ignored. |
| 241 bool pending_pin_operation_; | 242 bool pending_pin_operation_; |
| 242 | 243 |
| 243 DISALLOW_COPY_AND_ASSIGN(SimUnlockHandler); | 244 DISALLOW_COPY_AND_ASSIGN(SimUnlockHandler); |
| 244 }; | 245 }; |
| 245 | 246 |
| 246 // SimUnlockUIHTMLSource ------------------------------------------------------- | 247 // SimUnlockUIHTMLSource ------------------------------------------------------- |
| 247 | 248 |
| 248 SimUnlockUIHTMLSource::SimUnlockUIHTMLSource() | 249 SimUnlockUIHTMLSource::SimUnlockUIHTMLSource() { |
| 249 : DataSource(chrome::kChromeUISimUnlockHost, MessageLoop::current()) { | 250 } |
| 251 |
| 252 std::string SimUnlockUIHTMLSource::GetSource() { |
| 253 return chrome::kChromeUISimUnlockHost; |
| 250 } | 254 } |
| 251 | 255 |
| 252 void SimUnlockUIHTMLSource::StartDataRequest(const std::string& path, | 256 void SimUnlockUIHTMLSource::StartDataRequest(const std::string& path, |
| 253 bool is_incognito, | 257 bool is_incognito, |
| 254 int request_id) { | 258 int request_id) { |
| 255 DictionaryValue strings; | 259 DictionaryValue strings; |
| 256 strings.SetString("title", | 260 strings.SetString("title", |
| 257 l10n_util::GetStringUTF16(IDS_SIM_UNLOCK_ENTER_PIN_TITLE)); | 261 l10n_util::GetStringUTF16(IDS_SIM_UNLOCK_ENTER_PIN_TITLE)); |
| 258 strings.SetString("ok", l10n_util::GetStringUTF16(IDS_OK)); | 262 strings.SetString("ok", l10n_util::GetStringUTF16(IDS_OK)); |
| 259 strings.SetString("cancel", l10n_util::GetStringUTF16(IDS_CANCEL)); | 263 strings.SetString("cancel", l10n_util::GetStringUTF16(IDS_CANCEL)); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 strings.SetString("simDisabledMessage", | 302 strings.SetString("simDisabledMessage", |
| 299 l10n_util::GetStringUTF16(IDS_SIM_UNLOCK_SIM_DISABLED_MESSAGE)); | 303 l10n_util::GetStringUTF16(IDS_SIM_UNLOCK_SIM_DISABLED_MESSAGE)); |
| 300 | 304 |
| 301 strings.SetString("changePinTitle", l10n_util::GetStringUTF16( | 305 strings.SetString("changePinTitle", l10n_util::GetStringUTF16( |
| 302 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_CHANGE_PIN_TITLE)); | 306 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_CHANGE_PIN_TITLE)); |
| 303 strings.SetString("changePinMessage", l10n_util::GetStringUTF16( | 307 strings.SetString("changePinMessage", l10n_util::GetStringUTF16( |
| 304 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_CHANGE_PIN_MESSAGE)); | 308 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_CHANGE_PIN_MESSAGE)); |
| 305 strings.SetString("oldPin", l10n_util::GetStringUTF16( | 309 strings.SetString("oldPin", l10n_util::GetStringUTF16( |
| 306 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_CHANGE_PIN_OLD_PIN)); | 310 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_CHANGE_PIN_OLD_PIN)); |
| 307 | 311 |
| 308 SetFontAndTextDirection(&strings); | 312 URLDataSource::SetFontAndTextDirection(&strings); |
| 309 | 313 |
| 310 static const base::StringPiece html( | 314 static const base::StringPiece html( |
| 311 ResourceBundle::GetSharedInstance().GetRawDataResource( | 315 ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 312 IDR_SIM_UNLOCK_HTML)); | 316 IDR_SIM_UNLOCK_HTML)); |
| 313 | 317 |
| 314 std::string full_html = jstemplate_builder::GetI18nTemplateHtml(html, | 318 std::string full_html = jstemplate_builder::GetI18nTemplateHtml(html, |
| 315 &strings); | 319 &strings); |
| 316 | 320 |
| 317 SendResponse(request_id, base::RefCountedString::TakeString(&full_html)); | 321 url_data_source()->SendResponse( |
| 322 request_id, base::RefCountedString::TakeString(&full_html)); |
| 318 } | 323 } |
| 319 | 324 |
| 320 // SimUnlockHandler ------------------------------------------------------------ | 325 // SimUnlockHandler ------------------------------------------------------------ |
| 321 | 326 |
| 322 SimUnlockHandler::SimUnlockHandler() | 327 SimUnlockHandler::SimUnlockHandler() |
| 323 : state_(SIM_UNLOCK_LOADING), | 328 : state_(SIM_UNLOCK_LOADING), |
| 324 dialog_mode_(SimDialogDelegate::SIM_DIALOG_UNLOCK), | 329 dialog_mode_(SimDialogDelegate::SIM_DIALOG_UNLOCK), |
| 325 pending_pin_operation_(false) { | 330 pending_pin_operation_(false) { |
| 326 const chromeos::NetworkDevice* cellular = GetCellularDevice(); | 331 const chromeos::NetworkDevice* cellular = GetCellularDevice(); |
| 327 // One could just call us directly via chrome://sim-unlock. | 332 // One could just call us directly via chrome://sim-unlock. |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 672 SimUnlockHandler* handler = new SimUnlockHandler(); | 677 SimUnlockHandler* handler = new SimUnlockHandler(); |
| 673 web_ui->AddMessageHandler(handler); | 678 web_ui->AddMessageHandler(handler); |
| 674 SimUnlockUIHTMLSource* html_source = new SimUnlockUIHTMLSource(); | 679 SimUnlockUIHTMLSource* html_source = new SimUnlockUIHTMLSource(); |
| 675 | 680 |
| 676 // Set up the chrome://sim-unlock/ source. | 681 // Set up the chrome://sim-unlock/ source. |
| 677 Profile* profile = Profile::FromWebUI(web_ui); | 682 Profile* profile = Profile::FromWebUI(web_ui); |
| 678 ChromeURLDataManager::AddDataSource(profile, html_source); | 683 ChromeURLDataManager::AddDataSource(profile, html_source); |
| 679 } | 684 } |
| 680 | 685 |
| 681 } // namespace chromeos | 686 } // namespace chromeos |
| OLD | NEW |