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

Side by Side Diff: chrome/browser/ui/webui/chromeos/register_page_ui.cc

Issue 11885021: Don't derive from ChromeURLDataManager::DataSource, and instead have these classes implement a dele… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix WebUISourcesTest unittest Created 7 years, 11 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 | Annotate | Revision Log
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/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" 27 #include "chrome/browser/ui/webui/chrome_url_data_manager.h"
28 #include "chrome/common/cancelable_task_tracker.h" 28 #include "chrome/common/cancelable_task_tracker.h"
29 #include "chrome/common/url_constants.h" 29 #include "chrome/common/url_constants.h"
30 #include "content/public/browser/url_data_source_delegate.h"
30 #include "content/public/browser/web_contents.h" 31 #include "content/public/browser/web_contents.h"
31 #include "content/public/browser/web_ui.h" 32 #include "content/public/browser/web_ui.h"
32 #include "content/public/browser/web_ui_message_handler.h" 33 #include "content/public/browser/web_ui_message_handler.h"
33 #include "googleurl/src/gurl.h" 34 #include "googleurl/src/gurl.h"
34 #include "grit/browser_resources.h" 35 #include "grit/browser_resources.h"
35 #include "ui/base/resource/resource_bundle.h" 36 #include "ui/base/resource/resource_bundle.h"
36 37
37 using content::WebContents; 38 using content::WebContents;
38 using content::WebUIMessageHandler; 39 using content::WebUIMessageHandler;
39 40
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 else if (network_lib->cellular_connecting()) 89 else if (network_lib->cellular_connecting())
89 return kConnection3g; 90 return kConnection3g;
90 else if (network_lib->wimax_connecting()) 91 else if (network_lib->wimax_connecting())
91 return kConnectionWimax; 92 return kConnectionWimax;
92 else 93 else
93 return kUndefinedValue; 94 return kUndefinedValue;
94 } 95 }
95 96
96 } // namespace 97 } // namespace
97 98
98 class RegisterPageUIHTMLSource : public ChromeURLDataManager::DataSource { 99 class RegisterPageUIHTMLSource : public content::URLDataSourceDelegate {
99 public: 100 public:
100 RegisterPageUIHTMLSource(); 101 RegisterPageUIHTMLSource();
101 102
102 // Called when the network layer has requested a resource underneath 103 // content::URLDataSourceDelegate implementation:
James Hawkins 2013/01/14 18:53:54 nit: Period at the end.
103 // the path we registered. 104 virtual std::string GetSource() OVERRIDE;
104 virtual void StartDataRequest(const std::string& path, 105 virtual void StartDataRequest(const std::string& path,
105 bool is_incognito, 106 bool is_incognito,
106 int request_id); 107 int request_id);
107 virtual std::string GetMimeType(const std::string&) const { 108 virtual std::string GetMimeType(const std::string&) const {
108 return "text/html"; 109 return "text/html";
109 } 110 }
110 111
111 private: 112 private:
112 ~RegisterPageUIHTMLSource() {} 113 ~RegisterPageUIHTMLSource() {}
113 114
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 149
149 DISALLOW_COPY_AND_ASSIGN(RegisterPageHandler); 150 DISALLOW_COPY_AND_ASSIGN(RegisterPageHandler);
150 }; 151 };
151 152
152 //////////////////////////////////////////////////////////////////////////////// 153 ////////////////////////////////////////////////////////////////////////////////
153 // 154 //
154 // RegisterPageUIHTMLSource 155 // RegisterPageUIHTMLSource
155 // 156 //
156 //////////////////////////////////////////////////////////////////////////////// 157 ////////////////////////////////////////////////////////////////////////////////
157 158
158 RegisterPageUIHTMLSource::RegisterPageUIHTMLSource() 159 RegisterPageUIHTMLSource::RegisterPageUIHTMLSource() {
159 : DataSource(chrome::kChromeUIRegisterPageHost, MessageLoop::current()) { 160 }
161
162 std::string RegisterPageUIHTMLSource::GetSource() {
163 return chrome::kChromeUIRegisterPageHost;
160 } 164 }
161 165
162 void RegisterPageUIHTMLSource::StartDataRequest(const std::string& path, 166 void RegisterPageUIHTMLSource::StartDataRequest(const std::string& path,
163 bool is_incognito, 167 bool is_incognito,
164 int request_id) { 168 int request_id) {
165 // Make sure that chrome://register is available only during 169 // Make sure that chrome://register is available only during
166 // OOBE wizard lifetime and when device has not been registered yet. 170 // OOBE wizard lifetime and when device has not been registered yet.
167 if (!chromeos::WizardController::default_controller() || 171 if (!chromeos::WizardController::default_controller() ||
168 chromeos::WizardController::IsDeviceRegistered()) { 172 chromeos::WizardController::IsDeviceRegistered()) {
169 scoped_refptr<base::RefCountedBytes> empty_bytes(new base::RefCountedBytes); 173 scoped_refptr<base::RefCountedBytes> empty_bytes(new base::RefCountedBytes);
170 SendResponse(request_id, empty_bytes); 174 url_data_source()->SendResponse(request_id, empty_bytes);
171 return; 175 return;
172 } 176 }
173 177
174 scoped_refptr<base::RefCountedMemory> html_bytes( 178 scoped_refptr<base::RefCountedMemory> html_bytes(
175 ResourceBundle::GetSharedInstance().LoadDataResourceBytes( 179 ResourceBundle::GetSharedInstance().LoadDataResourceBytes(
176 IDR_HOST_REGISTRATION_PAGE_HTML)); 180 IDR_HOST_REGISTRATION_PAGE_HTML));
177 181
178 SendResponse(request_id, html_bytes); 182 url_data_source()->SendResponse(request_id, html_bytes);
179 } 183 }
180 184
181 //////////////////////////////////////////////////////////////////////////////// 185 ////////////////////////////////////////////////////////////////////////////////
182 // 186 //
183 // RegisterPageHandler 187 // RegisterPageHandler
184 // 188 //
185 //////////////////////////////////////////////////////////////////////////////// 189 ////////////////////////////////////////////////////////////////////////////////
186 RegisterPageHandler::RegisterPageHandler() { 190 RegisterPageHandler::RegisterPageHandler() {
187 } 191 }
188 192
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 RegisterPageUI::RegisterPageUI(content::WebUI* web_ui) 285 RegisterPageUI::RegisterPageUI(content::WebUI* web_ui)
282 : WebUIController(web_ui) { 286 : WebUIController(web_ui) {
283 RegisterPageHandler* handler = new RegisterPageHandler(); 287 RegisterPageHandler* handler = new RegisterPageHandler();
284 web_ui->AddMessageHandler(handler); 288 web_ui->AddMessageHandler(handler);
285 RegisterPageUIHTMLSource* html_source = new RegisterPageUIHTMLSource(); 289 RegisterPageUIHTMLSource* html_source = new RegisterPageUIHTMLSource();
286 290
287 // Set up the chrome://register/ source. 291 // Set up the chrome://register/ source.
288 Profile* profile = Profile::FromWebUI(web_ui); 292 Profile* profile = Profile::FromWebUI(web_ui);
289 ChromeURLDataManager::AddDataSource(profile, html_source); 293 ChromeURLDataManager::AddDataSource(profile, html_source);
290 } 294 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698