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