| 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/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 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 return; | 106 return; |
| 107 | 107 |
| 108 parent_->web_ui()->CallJavascriptFunction( | 108 parent_->web_ui()->CallJavascriptFunction( |
| 109 kJsPortalFrameLoadCompletedCallback); | 109 kJsPortalFrameLoadCompletedCallback); |
| 110 } | 110 } |
| 111 | 111 |
| 112 base::WeakPtr<MobileSetupUI> parent_; | 112 base::WeakPtr<MobileSetupUI> parent_; |
| 113 DISALLOW_COPY_AND_ASSIGN(PortalFrameLoadObserver); | 113 DISALLOW_COPY_AND_ASSIGN(PortalFrameLoadObserver); |
| 114 }; | 114 }; |
| 115 | 115 |
| 116 class MobileSetupUIHTMLSource : public ChromeURLDataManager::DataSource { | 116 class MobileSetupUIHTMLSource : public content::URLDataSourceDelegate { |
| 117 public: | 117 public: |
| 118 MobileSetupUIHTMLSource(); | 118 MobileSetupUIHTMLSource(); |
| 119 | 119 |
| 120 // Called when the network layer has requested a resource underneath | 120 // content::URLDataSourceDelegate implementation: |
| 121 // the path we registered. | 121 virtual std::string GetSource() OVERRIDE; |
| 122 virtual void StartDataRequest(const std::string& path, | 122 virtual void StartDataRequest(const std::string& path, |
| 123 bool is_incognito, | 123 bool is_incognito, |
| 124 int request_id); | 124 int request_id); |
| 125 virtual std::string GetMimeType(const std::string&) const { | 125 virtual std::string GetMimeType(const std::string&) const { |
| 126 return "text/html"; | 126 return "text/html"; |
| 127 } | 127 } |
| 128 | 128 |
| 129 private: | 129 private: |
| 130 virtual ~MobileSetupUIHTMLSource() {} | 130 virtual ~MobileSetupUIHTMLSource() {} |
| 131 | 131 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 | 164 |
| 165 DISALLOW_COPY_AND_ASSIGN(MobileSetupHandler); | 165 DISALLOW_COPY_AND_ASSIGN(MobileSetupHandler); |
| 166 }; | 166 }; |
| 167 | 167 |
| 168 //////////////////////////////////////////////////////////////////////////////// | 168 //////////////////////////////////////////////////////////////////////////////// |
| 169 // | 169 // |
| 170 // MobileSetupUIHTMLSource | 170 // MobileSetupUIHTMLSource |
| 171 // | 171 // |
| 172 //////////////////////////////////////////////////////////////////////////////// | 172 //////////////////////////////////////////////////////////////////////////////// |
| 173 | 173 |
| 174 MobileSetupUIHTMLSource::MobileSetupUIHTMLSource() | 174 MobileSetupUIHTMLSource::MobileSetupUIHTMLSource() { |
| 175 : DataSource(chrome::kChromeUIMobileSetupHost, MessageLoop::current()) { | 175 } |
| 176 |
| 177 std::string MobileSetupUIHTMLSource::GetSource() OVERRIDE { |
| 178 return chrome::kChromeUIMobileSetupHost; |
| 176 } | 179 } |
| 177 | 180 |
| 178 void MobileSetupUIHTMLSource::StartDataRequest(const std::string& path, | 181 void MobileSetupUIHTMLSource::StartDataRequest(const std::string& path, |
| 179 bool is_incognito, | 182 bool is_incognito, |
| 180 int request_id) { | 183 int request_id) { |
| 181 CellularNetwork* network = !path.size() ? NULL : | 184 CellularNetwork* network = !path.size() ? NULL : |
| 182 CrosLibrary::Get()-> | 185 CrosLibrary::Get()-> |
| 183 GetNetworkLibrary()->FindCellularNetworkByPath(path); | 186 GetNetworkLibrary()->FindCellularNetworkByPath(path); |
| 184 if (!network || !network->SupportsActivation()) { | 187 if (!network || !network->SupportsActivation()) { |
| 185 LOG(WARNING) << "Can't find device to activate for service path " << path; | 188 LOG(WARNING) << "Can't find device to activate for service path " << path; |
| 186 scoped_refptr<base::RefCountedBytes> html_bytes(new base::RefCountedBytes); | 189 scoped_refptr<base::RefCountedBytes> html_bytes(new base::RefCountedBytes); |
| 187 SendResponse(request_id, html_bytes); | 190 url_data_source()->SendResponse(request_id, html_bytes); |
| 188 return; | 191 return; |
| 189 } | 192 } |
| 190 | 193 |
| 191 LOG(WARNING) << "Activating mobile service " << path; | 194 LOG(WARNING) << "Activating mobile service " << path; |
| 192 DictionaryValue strings; | 195 DictionaryValue strings; |
| 193 strings.SetString("title", l10n_util::GetStringUTF16(IDS_MOBILE_SETUP_TITLE)); | 196 strings.SetString("title", l10n_util::GetStringUTF16(IDS_MOBILE_SETUP_TITLE)); |
| 194 strings.SetString("connecting_header", | 197 strings.SetString("connecting_header", |
| 195 l10n_util::GetStringFUTF16(IDS_MOBILE_CONNECTING_HEADER, | 198 l10n_util::GetStringFUTF16(IDS_MOBILE_CONNECTING_HEADER, |
| 196 network ? UTF8ToUTF16(network->name()) : string16())); | 199 network ? UTF8ToUTF16(network->name()) : string16())); |
| 197 strings.SetString("error_header", | 200 strings.SetString("error_header", |
| 198 l10n_util::GetStringUTF16(IDS_MOBILE_ERROR_HEADER)); | 201 l10n_util::GetStringUTF16(IDS_MOBILE_ERROR_HEADER)); |
| 199 strings.SetString("activating_header", | 202 strings.SetString("activating_header", |
| 200 l10n_util::GetStringUTF16(IDS_MOBILE_ACTIVATING_HEADER)); | 203 l10n_util::GetStringUTF16(IDS_MOBILE_ACTIVATING_HEADER)); |
| 201 strings.SetString("completed_header", | 204 strings.SetString("completed_header", |
| 202 l10n_util::GetStringUTF16(IDS_MOBILE_COMPLETED_HEADER)); | 205 l10n_util::GetStringUTF16(IDS_MOBILE_COMPLETED_HEADER)); |
| 203 strings.SetString("please_wait", | 206 strings.SetString("please_wait", |
| 204 l10n_util::GetStringUTF16(IDS_MOBILE_PLEASE_WAIT)); | 207 l10n_util::GetStringUTF16(IDS_MOBILE_PLEASE_WAIT)); |
| 205 strings.SetString("completed_text", | 208 strings.SetString("completed_text", |
| 206 l10n_util::GetStringUTF16(IDS_MOBILE_COMPLETED_TEXT)); | 209 l10n_util::GetStringUTF16(IDS_MOBILE_COMPLETED_TEXT)); |
| 207 strings.SetString("close_button", | 210 strings.SetString("close_button", |
| 208 l10n_util::GetStringUTF16(IDS_CLOSE)); | 211 l10n_util::GetStringUTF16(IDS_CLOSE)); |
| 209 strings.SetString("cancel_button", | 212 strings.SetString("cancel_button", |
| 210 l10n_util::GetStringUTF16(IDS_CANCEL)); | 213 l10n_util::GetStringUTF16(IDS_CANCEL)); |
| 211 strings.SetString("ok_button", | 214 strings.SetString("ok_button", |
| 212 l10n_util::GetStringUTF16(IDS_OK)); | 215 l10n_util::GetStringUTF16(IDS_OK)); |
| 213 SetFontAndTextDirection(&strings); | 216 URLDataSource::SetFontAndTextDirection(&strings); |
| 214 | 217 |
| 215 static const base::StringPiece html( | 218 static const base::StringPiece html( |
| 216 ResourceBundle::GetSharedInstance().GetRawDataResource( | 219 ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 217 IDR_MOBILE_SETUP_PAGE_HTML)); | 220 IDR_MOBILE_SETUP_PAGE_HTML)); |
| 218 | 221 |
| 219 std::string full_html = jstemplate_builder::GetI18nTemplateHtml(html, | 222 std::string full_html = jstemplate_builder::GetI18nTemplateHtml(html, |
| 220 &strings); | 223 &strings); |
| 221 | 224 |
| 222 SendResponse(request_id, base::RefCountedString::TakeString(&full_html)); | 225 url_data_source()->SendResponse( |
| 226 request_id, base::RefCountedString::TakeString(&full_html)); |
| 223 } | 227 } |
| 224 | 228 |
| 225 //////////////////////////////////////////////////////////////////////////////// | 229 //////////////////////////////////////////////////////////////////////////////// |
| 226 // | 230 // |
| 227 // MobileSetupHandler | 231 // MobileSetupHandler |
| 228 // | 232 // |
| 229 //////////////////////////////////////////////////////////////////////////////// | 233 //////////////////////////////////////////////////////////////////////////////// |
| 230 MobileSetupHandler::MobileSetupHandler() { | 234 MobileSetupHandler::MobileSetupHandler() { |
| 231 MobileActivator::GetInstance()->AddObserver(this); | 235 MobileActivator::GetInstance()->AddObserver(this); |
| 232 } | 236 } |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 | 342 |
| 339 // Set up the chrome://mobilesetup/ source. | 343 // Set up the chrome://mobilesetup/ source. |
| 340 Profile* profile = Profile::FromWebUI(web_ui); | 344 Profile* profile = Profile::FromWebUI(web_ui); |
| 341 ChromeURLDataManager::AddDataSource(profile, html_source); | 345 ChromeURLDataManager::AddDataSource(profile, html_source); |
| 342 } | 346 } |
| 343 | 347 |
| 344 void MobileSetupUI::RenderViewCreated(RenderViewHost* host) { | 348 void MobileSetupUI::RenderViewCreated(RenderViewHost* host) { |
| 345 // Destroyed by the corresponding RenderViewHost | 349 // Destroyed by the corresponding RenderViewHost |
| 346 new PortalFrameLoadObserver(AsWeakPtr(), host); | 350 new PortalFrameLoadObserver(AsWeakPtr(), host); |
| 347 } | 351 } |
| OLD | NEW |