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

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

Issue 11881055: Simplify WebUI data sources. Currently WebUI data sources implement a URLDataSourceDelegate interfa… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix issue in about_ui exposed by cros tests 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/mobile_setup_ui.h" 5 #include "chrome/browser/ui/webui/chromeos/mobile_setup_ui.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/bind_helpers.h" 12 #include "base/bind_helpers.h"
13 #include "base/file_util.h" 13 #include "base/file_util.h"
14 #include "base/json/json_writer.h" 14 #include "base/json/json_writer.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/memory/ref_counted_memory.h" 16 #include "base/memory/ref_counted_memory.h"
17 #include "base/message_loop.h" 17 #include "base/message_loop.h"
18 #include "base/metrics/histogram.h" 18 #include "base/metrics/histogram.h"
19 #include "base/string_piece.h" 19 #include "base/string_piece.h"
20 #include "base/string_util.h" 20 #include "base/string_util.h"
21 #include "base/utf_string_conversions.h" 21 #include "base/utf_string_conversions.h"
22 #include "base/values.h" 22 #include "base/values.h"
23 #include "chrome/browser/chromeos/cros/cros_library.h" 23 #include "chrome/browser/chromeos/cros/cros_library.h"
24 #include "chrome/browser/chromeos/cros/network_library.h" 24 #include "chrome/browser/chromeos/cros/network_library.h"
25 #include "chrome/browser/chromeos/mobile/mobile_activator.h" 25 #include "chrome/browser/chromeos/mobile/mobile_activator.h"
26 #include "chrome/browser/profiles/profile.h" 26 #include "chrome/browser/profiles/profile.h"
27 #include "chrome/browser/ui/browser_list.h" 27 #include "chrome/browser/ui/browser_list.h"
28 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" 28 #include "chrome/browser/ui/webui/web_ui_util.h"
29 #include "chrome/common/jstemplate_builder.h" 29 #include "chrome/common/jstemplate_builder.h"
30 #include "chrome/common/pref_names.h" 30 #include "chrome/common/pref_names.h"
31 #include "chrome/common/render_messages.h" 31 #include "chrome/common/render_messages.h"
32 #include "chrome/common/url_constants.h" 32 #include "chrome/common/url_constants.h"
33 #include "content/public/browser/browser_thread.h" 33 #include "content/public/browser/browser_thread.h"
34 #include "content/public/browser/render_view_host_observer.h" 34 #include "content/public/browser/render_view_host_observer.h"
35 #include "content/public/browser/url_data_source_delegate.h" 35 #include "content/public/browser/url_data_source.h"
36 #include "content/public/browser/web_contents.h" 36 #include "content/public/browser/web_contents.h"
37 #include "content/public/browser/web_ui.h" 37 #include "content/public/browser/web_ui.h"
38 #include "content/public/browser/web_ui_message_handler.h" 38 #include "content/public/browser/web_ui_message_handler.h"
39 #include "googleurl/src/gurl.h" 39 #include "googleurl/src/gurl.h"
40 #include "grit/browser_resources.h" 40 #include "grit/browser_resources.h"
41 #include "grit/chromium_strings.h" 41 #include "grit/chromium_strings.h"
42 #include "grit/generated_resources.h" 42 #include "grit/generated_resources.h"
43 #include "grit/locale_settings.h" 43 #include "grit/locale_settings.h"
44 #include "ui/base/l10n/l10n_util.h" 44 #include "ui/base/l10n/l10n_util.h"
45 #include "ui/base/resource/resource_bundle.h" 45 #include "ui/base/resource/resource_bundle.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 return; 107 return;
108 108
109 parent_->web_ui()->CallJavascriptFunction( 109 parent_->web_ui()->CallJavascriptFunction(
110 kJsPortalFrameLoadCompletedCallback); 110 kJsPortalFrameLoadCompletedCallback);
111 } 111 }
112 112
113 base::WeakPtr<MobileSetupUI> parent_; 113 base::WeakPtr<MobileSetupUI> parent_;
114 DISALLOW_COPY_AND_ASSIGN(PortalFrameLoadObserver); 114 DISALLOW_COPY_AND_ASSIGN(PortalFrameLoadObserver);
115 }; 115 };
116 116
117 class MobileSetupUIHTMLSource : public content::URLDataSourceDelegate { 117 class MobileSetupUIHTMLSource : public content::URLDataSource {
118 public: 118 public:
119 MobileSetupUIHTMLSource(); 119 MobileSetupUIHTMLSource();
120 120
121 // content::URLDataSourceDelegate implementation. 121 // content::URLDataSource implementation.
122 virtual std::string GetSource() OVERRIDE; 122 virtual std::string GetSource() OVERRIDE;
123 virtual void StartDataRequest(const std::string& path, 123 virtual void StartDataRequest(
124 bool is_incognito, 124 const std::string& path,
125 int request_id); 125 bool is_incognito,
126 const content::URLDataSource::GotDataCallback& callback);
126 virtual std::string GetMimeType(const std::string&) const { 127 virtual std::string GetMimeType(const std::string&) const {
127 return "text/html"; 128 return "text/html";
128 } 129 }
129 130
130 private: 131 private:
131 virtual ~MobileSetupUIHTMLSource() {} 132 virtual ~MobileSetupUIHTMLSource() {}
132 133
133 DISALLOW_COPY_AND_ASSIGN(MobileSetupUIHTMLSource); 134 DISALLOW_COPY_AND_ASSIGN(MobileSetupUIHTMLSource);
134 }; 135 };
135 136
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 // 173 //
173 //////////////////////////////////////////////////////////////////////////////// 174 ////////////////////////////////////////////////////////////////////////////////
174 175
175 MobileSetupUIHTMLSource::MobileSetupUIHTMLSource() { 176 MobileSetupUIHTMLSource::MobileSetupUIHTMLSource() {
176 } 177 }
177 178
178 std::string MobileSetupUIHTMLSource::GetSource() { 179 std::string MobileSetupUIHTMLSource::GetSource() {
179 return chrome::kChromeUIMobileSetupHost; 180 return chrome::kChromeUIMobileSetupHost;
180 } 181 }
181 182
182 void MobileSetupUIHTMLSource::StartDataRequest(const std::string& path, 183 void MobileSetupUIHTMLSource::StartDataRequest(
183 bool is_incognito, 184 const std::string& path,
184 int request_id) { 185 bool is_incognito,
186 const content::URLDataSource::GotDataCallback& callback) {
185 CellularNetwork* network = !path.size() ? NULL : 187 CellularNetwork* network = !path.size() ? NULL :
186 CrosLibrary::Get()-> 188 CrosLibrary::Get()->
187 GetNetworkLibrary()->FindCellularNetworkByPath(path); 189 GetNetworkLibrary()->FindCellularNetworkByPath(path);
188 if (!network || !network->SupportsActivation()) { 190 if (!network || !network->SupportsActivation()) {
189 LOG(WARNING) << "Can't find device to activate for service path " << path; 191 LOG(WARNING) << "Can't find device to activate for service path " << path;
190 scoped_refptr<base::RefCountedBytes> html_bytes(new base::RefCountedBytes); 192 scoped_refptr<base::RefCountedBytes> html_bytes(new base::RefCountedBytes);
191 url_data_source()->SendResponse(request_id, html_bytes); 193 callback.Run(html_bytes);
192 return; 194 return;
193 } 195 }
194 196
195 LOG(WARNING) << "Activating mobile service " << path; 197 LOG(WARNING) << "Activating mobile service " << path;
196 DictionaryValue strings; 198 DictionaryValue strings;
197 strings.SetString("title", l10n_util::GetStringUTF16(IDS_MOBILE_SETUP_TITLE)); 199 strings.SetString("title", l10n_util::GetStringUTF16(IDS_MOBILE_SETUP_TITLE));
198 strings.SetString("connecting_header", 200 strings.SetString("connecting_header",
199 l10n_util::GetStringFUTF16(IDS_MOBILE_CONNECTING_HEADER, 201 l10n_util::GetStringFUTF16(IDS_MOBILE_CONNECTING_HEADER,
200 network ? UTF8ToUTF16(network->name()) : string16())); 202 network ? UTF8ToUTF16(network->name()) : string16()));
201 strings.SetString("error_header", 203 strings.SetString("error_header",
202 l10n_util::GetStringUTF16(IDS_MOBILE_ERROR_HEADER)); 204 l10n_util::GetStringUTF16(IDS_MOBILE_ERROR_HEADER));
203 strings.SetString("activating_header", 205 strings.SetString("activating_header",
204 l10n_util::GetStringUTF16(IDS_MOBILE_ACTIVATING_HEADER)); 206 l10n_util::GetStringUTF16(IDS_MOBILE_ACTIVATING_HEADER));
205 strings.SetString("completed_header", 207 strings.SetString("completed_header",
206 l10n_util::GetStringUTF16(IDS_MOBILE_COMPLETED_HEADER)); 208 l10n_util::GetStringUTF16(IDS_MOBILE_COMPLETED_HEADER));
207 strings.SetString("please_wait", 209 strings.SetString("please_wait",
208 l10n_util::GetStringUTF16(IDS_MOBILE_PLEASE_WAIT)); 210 l10n_util::GetStringUTF16(IDS_MOBILE_PLEASE_WAIT));
209 strings.SetString("completed_text", 211 strings.SetString("completed_text",
210 l10n_util::GetStringUTF16(IDS_MOBILE_COMPLETED_TEXT)); 212 l10n_util::GetStringUTF16(IDS_MOBILE_COMPLETED_TEXT));
211 strings.SetString("close_button", 213 strings.SetString("close_button",
212 l10n_util::GetStringUTF16(IDS_CLOSE)); 214 l10n_util::GetStringUTF16(IDS_CLOSE));
213 strings.SetString("cancel_button", 215 strings.SetString("cancel_button",
214 l10n_util::GetStringUTF16(IDS_CANCEL)); 216 l10n_util::GetStringUTF16(IDS_CANCEL));
215 strings.SetString("ok_button", 217 strings.SetString("ok_button",
216 l10n_util::GetStringUTF16(IDS_OK)); 218 l10n_util::GetStringUTF16(IDS_OK));
217 URLDataSource::SetFontAndTextDirection(&strings); 219 web_ui_util::SetFontAndTextDirection(&strings);
218 220
219 static const base::StringPiece html( 221 static const base::StringPiece html(
220 ResourceBundle::GetSharedInstance().GetRawDataResource( 222 ResourceBundle::GetSharedInstance().GetRawDataResource(
221 IDR_MOBILE_SETUP_PAGE_HTML)); 223 IDR_MOBILE_SETUP_PAGE_HTML));
222 224
223 std::string full_html = jstemplate_builder::GetI18nTemplateHtml(html, 225 std::string full_html = jstemplate_builder::GetI18nTemplateHtml(html,
224 &strings); 226 &strings);
225 227
226 url_data_source()->SendResponse( 228 callback.Run(base::RefCountedString::TakeString(&full_html));
227 request_id, base::RefCountedString::TakeString(&full_html));
228 } 229 }
229 230
230 //////////////////////////////////////////////////////////////////////////////// 231 ////////////////////////////////////////////////////////////////////////////////
231 // 232 //
232 // MobileSetupHandler 233 // MobileSetupHandler
233 // 234 //
234 //////////////////////////////////////////////////////////////////////////////// 235 ////////////////////////////////////////////////////////////////////////////////
235 MobileSetupHandler::MobileSetupHandler() { 236 MobileSetupHandler::MobileSetupHandler() {
236 MobileActivator::GetInstance()->AddObserver(this); 237 MobileActivator::GetInstance()->AddObserver(this);
237 } 238 }
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 344
344 // Set up the chrome://mobilesetup/ source. 345 // Set up the chrome://mobilesetup/ source.
345 Profile* profile = Profile::FromWebUI(web_ui); 346 Profile* profile = Profile::FromWebUI(web_ui);
346 ChromeURLDataManager::AddDataSource(profile, html_source); 347 ChromeURLDataManager::AddDataSource(profile, html_source);
347 } 348 }
348 349
349 void MobileSetupUI::RenderViewCreated(RenderViewHost* host) { 350 void MobileSetupUI::RenderViewCreated(RenderViewHost* host) {
350 // Destroyed by the corresponding RenderViewHost 351 // Destroyed by the corresponding RenderViewHost
351 new PortalFrameLoadObserver(AsWeakPtr(), host); 352 new PortalFrameLoadObserver(AsWeakPtr(), host);
352 } 353 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698