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/register_page_ui.h" | 5 #include "chrome/browser/ui/webui/chromeos/register_page_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/chromeos/chromeos_version.h" | 11 #include "base/chromeos/chromeos_version.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/memory/ref_counted_memory.h" | 13 #include "base/memory/ref_counted_memory.h" |
14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
15 #include "base/message_loop.h" | 15 #include "base/message_loop.h" |
16 #include "base/string_piece.h" | 16 #include "base/string_piece.h" |
17 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
18 #include "base/values.h" | 18 #include "base/values.h" |
19 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
20 #include "chrome/browser/chromeos/cros/cros_library.h" | 20 #include "chrome/browser/chromeos/cros/cros_library.h" |
21 #include "chrome/browser/chromeos/cros/network_library.h" | 21 #include "chrome/browser/chromeos/cros/network_library.h" |
22 #include "chrome/browser/chromeos/customization_document.h" | 22 #include "chrome/browser/chromeos/customization_document.h" |
23 #include "chrome/browser/chromeos/login/wizard_controller.h" | 23 #include "chrome/browser/chromeos/login/wizard_controller.h" |
24 #include "chrome/browser/chromeos/system/statistics_provider.h" | 24 #include "chrome/browser/chromeos/system/statistics_provider.h" |
25 #include "chrome/browser/chromeos/version_loader.h" | 25 #include "chrome/browser/chromeos/version_loader.h" |
26 #include "chrome/browser/profiles/profile.h" | 26 #include "chrome/browser/profiles/profile.h" |
27 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | |
28 #include "chrome/common/cancelable_task_tracker.h" | 27 #include "chrome/common/cancelable_task_tracker.h" |
29 #include "chrome/common/url_constants.h" | 28 #include "chrome/common/url_constants.h" |
30 #include "content/public/browser/url_data_source_delegate.h" | 29 #include "content/public/browser/url_data_source.h" |
31 #include "content/public/browser/web_contents.h" | 30 #include "content/public/browser/web_contents.h" |
32 #include "content/public/browser/web_ui.h" | 31 #include "content/public/browser/web_ui.h" |
33 #include "content/public/browser/web_ui_message_handler.h" | 32 #include "content/public/browser/web_ui_message_handler.h" |
34 #include "googleurl/src/gurl.h" | 33 #include "googleurl/src/gurl.h" |
35 #include "grit/browser_resources.h" | 34 #include "grit/browser_resources.h" |
36 #include "ui/base/resource/resource_bundle.h" | 35 #include "ui/base/resource/resource_bundle.h" |
37 | 36 |
38 using content::WebContents; | 37 using content::WebContents; |
39 using content::WebUIMessageHandler; | 38 using content::WebUIMessageHandler; |
40 | 39 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 else if (network_lib->cellular_connecting()) | 88 else if (network_lib->cellular_connecting()) |
90 return kConnection3g; | 89 return kConnection3g; |
91 else if (network_lib->wimax_connecting()) | 90 else if (network_lib->wimax_connecting()) |
92 return kConnectionWimax; | 91 return kConnectionWimax; |
93 else | 92 else |
94 return kUndefinedValue; | 93 return kUndefinedValue; |
95 } | 94 } |
96 | 95 |
97 } // namespace | 96 } // namespace |
98 | 97 |
99 class RegisterPageUIHTMLSource : public content::URLDataSourceDelegate { | 98 class RegisterPageUIHTMLSource : public content::URLDataSource { |
100 public: | 99 public: |
101 RegisterPageUIHTMLSource(); | 100 RegisterPageUIHTMLSource(); |
102 | 101 |
103 // content::URLDataSourceDelegate implementation. | 102 // content::URLDataSource implementation. |
104 virtual std::string GetSource() OVERRIDE; | 103 virtual std::string GetSource() OVERRIDE; |
105 virtual void StartDataRequest(const std::string& path, | 104 virtual void StartDataRequest( |
106 bool is_incognito, | 105 const std::string& path, |
107 int request_id); | 106 bool is_incognito, |
| 107 const content::URLDataSource::GotDataCallback& callback); |
108 virtual std::string GetMimeType(const std::string&) const { | 108 virtual std::string GetMimeType(const std::string&) const { |
109 return "text/html"; | 109 return "text/html"; |
110 } | 110 } |
111 | 111 |
112 private: | 112 private: |
113 ~RegisterPageUIHTMLSource() {} | 113 ~RegisterPageUIHTMLSource() {} |
114 | 114 |
115 DISALLOW_COPY_AND_ASSIGN(RegisterPageUIHTMLSource); | 115 DISALLOW_COPY_AND_ASSIGN(RegisterPageUIHTMLSource); |
116 }; | 116 }; |
117 | 117 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 // | 156 // |
157 //////////////////////////////////////////////////////////////////////////////// | 157 //////////////////////////////////////////////////////////////////////////////// |
158 | 158 |
159 RegisterPageUIHTMLSource::RegisterPageUIHTMLSource() { | 159 RegisterPageUIHTMLSource::RegisterPageUIHTMLSource() { |
160 } | 160 } |
161 | 161 |
162 std::string RegisterPageUIHTMLSource::GetSource() { | 162 std::string RegisterPageUIHTMLSource::GetSource() { |
163 return chrome::kChromeUIRegisterPageHost; | 163 return chrome::kChromeUIRegisterPageHost; |
164 } | 164 } |
165 | 165 |
166 void RegisterPageUIHTMLSource::StartDataRequest(const std::string& path, | 166 void RegisterPageUIHTMLSource::StartDataRequest( |
167 bool is_incognito, | 167 const std::string& path, |
168 int request_id) { | 168 bool is_incognito, |
| 169 const content::URLDataSource::GotDataCallback& callback) { |
169 // Make sure that chrome://register is available only during | 170 // Make sure that chrome://register is available only during |
170 // OOBE wizard lifetime and when device has not been registered yet. | 171 // OOBE wizard lifetime and when device has not been registered yet. |
171 if (!chromeos::WizardController::default_controller() || | 172 if (!chromeos::WizardController::default_controller() || |
172 chromeos::WizardController::IsDeviceRegistered()) { | 173 chromeos::WizardController::IsDeviceRegistered()) { |
173 scoped_refptr<base::RefCountedBytes> empty_bytes(new base::RefCountedBytes); | 174 scoped_refptr<base::RefCountedBytes> empty_bytes(new base::RefCountedBytes); |
174 url_data_source()->SendResponse(request_id, empty_bytes); | 175 callback.Run(empty_bytes); |
175 return; | 176 return; |
176 } | 177 } |
177 | 178 |
178 scoped_refptr<base::RefCountedMemory> html_bytes( | 179 scoped_refptr<base::RefCountedMemory> html_bytes( |
179 ResourceBundle::GetSharedInstance().LoadDataResourceBytes( | 180 ResourceBundle::GetSharedInstance().LoadDataResourceBytes( |
180 IDR_HOST_REGISTRATION_PAGE_HTML)); | 181 IDR_HOST_REGISTRATION_PAGE_HTML)); |
181 | 182 |
182 url_data_source()->SendResponse(request_id, html_bytes); | 183 callback.Run(html_bytes); |
183 } | 184 } |
184 | 185 |
185 //////////////////////////////////////////////////////////////////////////////// | 186 //////////////////////////////////////////////////////////////////////////////// |
186 // | 187 // |
187 // RegisterPageHandler | 188 // RegisterPageHandler |
188 // | 189 // |
189 //////////////////////////////////////////////////////////////////////////////// | 190 //////////////////////////////////////////////////////////////////////////////// |
190 RegisterPageHandler::RegisterPageHandler() { | 191 RegisterPageHandler::RegisterPageHandler() { |
191 } | 192 } |
192 | 193 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 RegisterPageUI::RegisterPageUI(content::WebUI* web_ui) | 286 RegisterPageUI::RegisterPageUI(content::WebUI* web_ui) |
286 : WebUIController(web_ui) { | 287 : WebUIController(web_ui) { |
287 RegisterPageHandler* handler = new RegisterPageHandler(); | 288 RegisterPageHandler* handler = new RegisterPageHandler(); |
288 web_ui->AddMessageHandler(handler); | 289 web_ui->AddMessageHandler(handler); |
289 RegisterPageUIHTMLSource* html_source = new RegisterPageUIHTMLSource(); | 290 RegisterPageUIHTMLSource* html_source = new RegisterPageUIHTMLSource(); |
290 | 291 |
291 // Set up the chrome://register/ source. | 292 // Set up the chrome://register/ source. |
292 Profile* profile = Profile::FromWebUI(web_ui); | 293 Profile* profile = Profile::FromWebUI(web_ui); |
293 ChromeURLDataManager::AddDataSource(profile, html_source); | 294 ChromeURLDataManager::AddDataSource(profile, html_source); |
294 } | 295 } |
OLD | NEW |