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/imageburner/imageburner_ui.h" | 5 #include "chrome/browser/ui/webui/chromeos/imageburner/imageburner_ui.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 public BurnController::Delegate { | 89 public BurnController::Delegate { |
90 public: | 90 public: |
91 explicit WebUIHandler(content::WebContents* contents) | 91 explicit WebUIHandler(content::WebContents* contents) |
92 : burn_controller_(BurnController::CreateBurnController(contents, this)) { | 92 : burn_controller_(BurnController::CreateBurnController(contents, this)) { |
93 } | 93 } |
94 | 94 |
95 virtual ~WebUIHandler() { | 95 virtual ~WebUIHandler() { |
96 } | 96 } |
97 | 97 |
98 // WebUIMessageHandler implementation. | 98 // WebUIMessageHandler implementation. |
99 virtual void RegisterMessages() OVERRIDE { | 99 virtual void RegisterMessages() override { |
100 web_ui()->RegisterMessageCallback( | 100 web_ui()->RegisterMessageCallback( |
101 "getDevices", | 101 "getDevices", |
102 base::Bind(&WebUIHandler::HandleGetDevices, base::Unretained(this))); | 102 base::Bind(&WebUIHandler::HandleGetDevices, base::Unretained(this))); |
103 web_ui()->RegisterMessageCallback( | 103 web_ui()->RegisterMessageCallback( |
104 "burnImage", | 104 "burnImage", |
105 base::Bind(&WebUIHandler::HandleBurnImage, base::Unretained(this))); | 105 base::Bind(&WebUIHandler::HandleBurnImage, base::Unretained(this))); |
106 web_ui()->RegisterMessageCallback( | 106 web_ui()->RegisterMessageCallback( |
107 "cancelBurnImage", | 107 "cancelBurnImage", |
108 base::Bind(&WebUIHandler::HandleCancelBurnImage, | 108 base::Bind(&WebUIHandler::HandleCancelBurnImage, |
109 base::Unretained(this))); | 109 base::Unretained(this))); |
110 web_ui()->RegisterMessageCallback( | 110 web_ui()->RegisterMessageCallback( |
111 "webuiInitialized", | 111 "webuiInitialized", |
112 base::Bind(&WebUIHandler::HandleWebUIInitialized, | 112 base::Bind(&WebUIHandler::HandleWebUIInitialized, |
113 base::Unretained(this))); | 113 base::Unretained(this))); |
114 } | 114 } |
115 | 115 |
116 // BurnController::Delegate override. | 116 // BurnController::Delegate override. |
117 virtual void OnSuccess() OVERRIDE { | 117 virtual void OnSuccess() override { |
118 web_ui()->CallJavascriptFunction("browserBridge.reportSuccess"); | 118 web_ui()->CallJavascriptFunction("browserBridge.reportSuccess"); |
119 } | 119 } |
120 | 120 |
121 // BurnController::Delegate override. | 121 // BurnController::Delegate override. |
122 virtual void OnFail(int error_message_id) OVERRIDE { | 122 virtual void OnFail(int error_message_id) override { |
123 base::StringValue error_message( | 123 base::StringValue error_message( |
124 l10n_util::GetStringUTF16(error_message_id)); | 124 l10n_util::GetStringUTF16(error_message_id)); |
125 web_ui()->CallJavascriptFunction("browserBridge.reportFail", error_message); | 125 web_ui()->CallJavascriptFunction("browserBridge.reportFail", error_message); |
126 } | 126 } |
127 | 127 |
128 // BurnController::Delegate override. | 128 // BurnController::Delegate override. |
129 virtual void OnDeviceAdded(const disks::DiskMountManager::Disk& disk) | 129 virtual void OnDeviceAdded(const disks::DiskMountManager::Disk& disk) |
130 OVERRIDE { | 130 override { |
131 base::DictionaryValue disk_value; | 131 base::DictionaryValue disk_value; |
132 CreateDiskValue(disk, &disk_value); | 132 CreateDiskValue(disk, &disk_value); |
133 web_ui()->CallJavascriptFunction("browserBridge.deviceAdded", disk_value); | 133 web_ui()->CallJavascriptFunction("browserBridge.deviceAdded", disk_value); |
134 } | 134 } |
135 | 135 |
136 // BurnController::Delegate override. | 136 // BurnController::Delegate override. |
137 virtual void OnDeviceRemoved(const disks::DiskMountManager::Disk& disk) | 137 virtual void OnDeviceRemoved(const disks::DiskMountManager::Disk& disk) |
138 OVERRIDE { | 138 override { |
139 base::StringValue device_path_value(disk.device_path()); | 139 base::StringValue device_path_value(disk.device_path()); |
140 web_ui()->CallJavascriptFunction("browserBridge.deviceRemoved", | 140 web_ui()->CallJavascriptFunction("browserBridge.deviceRemoved", |
141 device_path_value); | 141 device_path_value); |
142 } | 142 } |
143 | 143 |
144 // BurnController::Delegate override. | 144 // BurnController::Delegate override. |
145 virtual void OnDeviceTooSmall(int64 device_size) OVERRIDE { | 145 virtual void OnDeviceTooSmall(int64 device_size) override { |
146 base::string16 size; | 146 base::string16 size; |
147 GetDataSizeText(device_size, &size); | 147 GetDataSizeText(device_size, &size); |
148 base::StringValue device_size_text(size); | 148 base::StringValue device_size_text(size); |
149 web_ui()->CallJavascriptFunction("browserBridge.reportDeviceTooSmall", | 149 web_ui()->CallJavascriptFunction("browserBridge.reportDeviceTooSmall", |
150 device_size_text); | 150 device_size_text); |
151 } | 151 } |
152 | 152 |
153 // BurnController::Delegate override. | 153 // BurnController::Delegate override. |
154 virtual void OnProgress(ProgressType progress_type, | 154 virtual void OnProgress(ProgressType progress_type, |
155 int64 amount_finished, | 155 int64 amount_finished, |
156 int64 amount_total) OVERRIDE { | 156 int64 amount_total) override { |
157 const base::string16 time_remaining_text = | 157 const base::string16 time_remaining_text = |
158 l10n_util::GetStringUTF16(IDS_IMAGEBURN_PROGRESS_TIME_UNKNOWN); | 158 l10n_util::GetStringUTF16(IDS_IMAGEBURN_PROGRESS_TIME_UNKNOWN); |
159 SendProgressSignal(progress_type, amount_finished, amount_total, | 159 SendProgressSignal(progress_type, amount_finished, amount_total, |
160 time_remaining_text); | 160 time_remaining_text); |
161 } | 161 } |
162 | 162 |
163 // BurnController::Delegate override. | 163 // BurnController::Delegate override. |
164 virtual void OnProgressWithRemainingTime( | 164 virtual void OnProgressWithRemainingTime( |
165 ProgressType progress_type, | 165 ProgressType progress_type, |
166 int64 amount_finished, | 166 int64 amount_finished, |
167 int64 amount_total, | 167 int64 amount_total, |
168 const base::TimeDelta& time_remaining) OVERRIDE { | 168 const base::TimeDelta& time_remaining) override { |
169 const base::string16 time_remaining_text = l10n_util::GetStringFUTF16( | 169 const base::string16 time_remaining_text = l10n_util::GetStringFUTF16( |
170 IDS_IMAGEBURN_DOWNLOAD_TIME_REMAINING, | 170 IDS_IMAGEBURN_DOWNLOAD_TIME_REMAINING, |
171 ui::TimeFormat::Simple(ui::TimeFormat::FORMAT_REMAINING, | 171 ui::TimeFormat::Simple(ui::TimeFormat::FORMAT_REMAINING, |
172 ui::TimeFormat::LENGTH_SHORT, time_remaining)); | 172 ui::TimeFormat::LENGTH_SHORT, time_remaining)); |
173 SendProgressSignal(progress_type, amount_finished, amount_total, | 173 SendProgressSignal(progress_type, amount_finished, amount_total, |
174 time_remaining_text); | 174 time_remaining_text); |
175 } | 175 } |
176 | 176 |
177 // BurnController::Delegate override. | 177 // BurnController::Delegate override. |
178 virtual void OnNetworkDetected() OVERRIDE { | 178 virtual void OnNetworkDetected() override { |
179 web_ui()->CallJavascriptFunction("browserBridge.reportNetworkDetected"); | 179 web_ui()->CallJavascriptFunction("browserBridge.reportNetworkDetected"); |
180 } | 180 } |
181 | 181 |
182 // BurnController::Delegate override. | 182 // BurnController::Delegate override. |
183 virtual void OnNoNetwork() OVERRIDE { | 183 virtual void OnNoNetwork() override { |
184 web_ui()->CallJavascriptFunction("browserBridge.reportNoNetwork"); | 184 web_ui()->CallJavascriptFunction("browserBridge.reportNoNetwork"); |
185 } | 185 } |
186 | 186 |
187 private: | 187 private: |
188 void CreateDiskValue(const disks::DiskMountManager::Disk& disk, | 188 void CreateDiskValue(const disks::DiskMountManager::Disk& disk, |
189 base::DictionaryValue* disk_value) { | 189 base::DictionaryValue* disk_value) { |
190 base::string16 label = base::ASCIIToUTF16(disk.drive_label()); | 190 base::string16 label = base::ASCIIToUTF16(disk.drive_label()); |
191 base::i18n::AdjustStringForLocaleDirection(&label); | 191 base::i18n::AdjustStringForLocaleDirection(&label); |
192 disk_value->SetString(std::string(kPropertyLabel), label); | 192 disk_value->SetString(std::string(kPropertyLabel), label); |
193 disk_value->SetString(std::string(kPropertyFilePath), disk.file_path()); | 193 disk_value->SetString(std::string(kPropertyFilePath), disk.file_path()); |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 | 323 |
324 ImageBurnUI::ImageBurnUI(content::WebUI* web_ui) : WebUIController(web_ui) { | 324 ImageBurnUI::ImageBurnUI(content::WebUI* web_ui) : WebUIController(web_ui) { |
325 chromeos::imageburner::WebUIHandler* handler = | 325 chromeos::imageburner::WebUIHandler* handler = |
326 new chromeos::imageburner::WebUIHandler(web_ui->GetWebContents()); | 326 new chromeos::imageburner::WebUIHandler(web_ui->GetWebContents()); |
327 web_ui->AddMessageHandler(handler); | 327 web_ui->AddMessageHandler(handler); |
328 | 328 |
329 Profile* profile = Profile::FromWebUI(web_ui); | 329 Profile* profile = Profile::FromWebUI(web_ui); |
330 content::WebUIDataSource::Add( | 330 content::WebUIDataSource::Add( |
331 profile, chromeos::imageburner::CreateImageburnerUIHTMLSource()); | 331 profile, chromeos::imageburner::CreateImageburnerUIHTMLSource()); |
332 } | 332 } |
OLD | NEW |