| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/logging.h" | 12 #include "base/logging.h" |
| 12 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 13 #include "base/string_piece.h" | 14 #include "base/string_piece.h" |
| 14 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
| 15 #include "base/values.h" | 16 #include "base/values.h" |
| 16 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
| 17 #include "chrome/browser/chromeos/cros/cros_library.h" | 18 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 18 #include "chrome/browser/chromeos/cros/network_library.h" | 19 #include "chrome/browser/chromeos/cros/network_library.h" |
| 19 #include "chrome/browser/chromeos/customization_document.h" | 20 #include "chrome/browser/chromeos/customization_document.h" |
| 20 #include "chrome/browser/chromeos/login/wizard_controller.h" | 21 #include "chrome/browser/chromeos/login/wizard_controller.h" |
| 21 #include "chrome/browser/chromeos/system/runtime_environment.h" | |
| 22 #include "chrome/browser/chromeos/system/statistics_provider.h" | 22 #include "chrome/browser/chromeos/system/statistics_provider.h" |
| 23 #include "chrome/browser/chromeos/version_loader.h" | 23 #include "chrome/browser/chromeos/version_loader.h" |
| 24 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
| 25 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 25 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
| 26 #include "chrome/common/url_constants.h" | 26 #include "chrome/common/url_constants.h" |
| 27 #include "content/public/browser/browser_thread.h" | 27 #include "content/public/browser/browser_thread.h" |
| 28 #include "content/public/browser/web_contents.h" | 28 #include "content/public/browser/web_contents.h" |
| 29 #include "content/public/browser/web_ui.h" | 29 #include "content/public/browser/web_ui.h" |
| 30 #include "content/public/browser/web_ui_message_handler.h" | 30 #include "content/public/browser/web_ui_message_handler.h" |
| 31 #include "googleurl/src/gurl.h" | 31 #include "googleurl/src/gurl.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 59 const char kConnection3g[] = "3g"; | 59 const char kConnection3g[] = "3g"; |
| 60 const char kUndefinedValue[] = "undefined"; | 60 const char kUndefinedValue[] = "undefined"; |
| 61 | 61 |
| 62 // Utility function that returns string corresponding to currently active | 62 // Utility function that returns string corresponding to currently active |
| 63 // connection type |kConnectionEthernet|kConnectionWifi|kConnection3g|. | 63 // connection type |kConnectionEthernet|kConnectionWifi|kConnection3g|. |
| 64 // If multiple interfaces are connected, result is based on the | 64 // If multiple interfaces are connected, result is based on the |
| 65 // priority Ethernet-Wifi-Cellular. | 65 // priority Ethernet-Wifi-Cellular. |
| 66 // If there's no interface that's connected, interface that's in connecting | 66 // If there's no interface that's connected, interface that's in connecting |
| 67 // state is considered as the active one. | 67 // state is considered as the active one. |
| 68 // Otherwise |kUndefinedValue| is returned. | 68 // Otherwise |kUndefinedValue| is returned. |
| 69 #if defined(OS_CHROMEOS) | |
| 70 static std::string GetConnectionType() { | 69 static std::string GetConnectionType() { |
| 71 chromeos::NetworkLibrary* network_lib = | 70 chromeos::NetworkLibrary* network_lib = |
| 72 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); | 71 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); |
| 73 if (network_lib->ethernet_connected()) | 72 if (network_lib->ethernet_connected()) |
| 74 return kConnectionEthernet; | 73 return kConnectionEthernet; |
| 75 else if (network_lib->wifi_connected()) | 74 else if (network_lib->wifi_connected()) |
| 76 return kConnectionWifi; | 75 return kConnectionWifi; |
| 77 else if (network_lib->cellular_connected()) | 76 else if (network_lib->cellular_connected()) |
| 78 return kConnection3g; | 77 return kConnection3g; |
| 79 // Connection might have been lost and is in reconnecting state at this point. | 78 // Connection might have been lost and is in reconnecting state at this point. |
| 80 else if (network_lib->ethernet_connecting()) | 79 else if (network_lib->ethernet_connecting()) |
| 81 return kConnectionEthernet; | 80 return kConnectionEthernet; |
| 82 else if (network_lib->wifi_connecting()) | 81 else if (network_lib->wifi_connecting()) |
| 83 return kConnectionWifi; | 82 return kConnectionWifi; |
| 84 else if (network_lib->cellular_connecting()) | 83 else if (network_lib->cellular_connecting()) |
| 85 return kConnection3g; | 84 return kConnection3g; |
| 86 else | 85 else |
| 87 return kUndefinedValue; | 86 return kUndefinedValue; |
| 88 } | 87 } |
| 89 #endif | |
| 90 | 88 |
| 91 } // namespace | 89 } // namespace |
| 92 | 90 |
| 93 class RegisterPageUIHTMLSource : public ChromeURLDataManager::DataSource { | 91 class RegisterPageUIHTMLSource : public ChromeURLDataManager::DataSource { |
| 94 public: | 92 public: |
| 95 RegisterPageUIHTMLSource(); | 93 RegisterPageUIHTMLSource(); |
| 96 | 94 |
| 97 // Called when the network layer has requested a resource underneath | 95 // Called when the network layer has requested a resource underneath |
| 98 // the path we registered. | 96 // the path we registered. |
| 99 virtual void StartDataRequest(const std::string& path, | 97 virtual void StartDataRequest(const std::string& path, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 117 virtual ~RegisterPageHandler(); | 115 virtual ~RegisterPageHandler(); |
| 118 | 116 |
| 119 // WebUIMessageHandler implementation. | 117 // WebUIMessageHandler implementation. |
| 120 virtual void RegisterMessages() OVERRIDE; | 118 virtual void RegisterMessages() OVERRIDE; |
| 121 | 119 |
| 122 private: | 120 private: |
| 123 // Handlers for JS WebUI messages. | 121 // Handlers for JS WebUI messages. |
| 124 void HandleGetRegistrationUrl(const ListValue* args); | 122 void HandleGetRegistrationUrl(const ListValue* args); |
| 125 void HandleGetUserInfo(const ListValue* args); | 123 void HandleGetUserInfo(const ListValue* args); |
| 126 | 124 |
| 127 #if defined(OS_CHROMEOS) | |
| 128 // Callback from chromeos::VersionLoader giving the version. | 125 // Callback from chromeos::VersionLoader giving the version. |
| 129 void OnVersion(chromeos::VersionLoader::Handle handle, std::string version); | 126 void OnVersion(chromeos::VersionLoader::Handle handle, std::string version); |
| 130 #endif | |
| 131 | 127 |
| 132 // Skips registration logging |error_msg| with log type ERROR. | 128 // Skips registration logging |error_msg| with log type ERROR. |
| 133 void SkipRegistration(const std::string& error_msg); | 129 void SkipRegistration(const std::string& error_msg); |
| 134 | 130 |
| 135 // Sends message to host registration page with system/user info data. | 131 // Sends message to host registration page with system/user info data. |
| 136 void SendUserInfo(); | 132 void SendUserInfo(); |
| 137 | 133 |
| 138 #if defined(OS_CHROMEOS) | |
| 139 // Handles asynchronously loading the version. | 134 // Handles asynchronously loading the version. |
| 140 chromeos::VersionLoader version_loader_; | 135 chromeos::VersionLoader version_loader_; |
| 141 #endif | |
| 142 | 136 |
| 143 // Used to request the version. | 137 // Used to request the version. |
| 144 CancelableRequestConsumer version_consumer_; | 138 CancelableRequestConsumer version_consumer_; |
| 145 | 139 |
| 146 std::string version_; | 140 std::string version_; |
| 147 | 141 |
| 148 DISALLOW_COPY_AND_ASSIGN(RegisterPageHandler); | 142 DISALLOW_COPY_AND_ASSIGN(RegisterPageHandler); |
| 149 }; | 143 }; |
| 150 | 144 |
| 151 //////////////////////////////////////////////////////////////////////////////// | 145 //////////////////////////////////////////////////////////////////////////////// |
| 152 // | 146 // |
| 153 // RegisterPageUIHTMLSource | 147 // RegisterPageUIHTMLSource |
| 154 // | 148 // |
| 155 //////////////////////////////////////////////////////////////////////////////// | 149 //////////////////////////////////////////////////////////////////////////////// |
| 156 | 150 |
| 157 RegisterPageUIHTMLSource::RegisterPageUIHTMLSource() | 151 RegisterPageUIHTMLSource::RegisterPageUIHTMLSource() |
| 158 : DataSource(chrome::kChromeUIRegisterPageHost, MessageLoop::current()) { | 152 : DataSource(chrome::kChromeUIRegisterPageHost, MessageLoop::current()) { |
| 159 } | 153 } |
| 160 | 154 |
| 161 void RegisterPageUIHTMLSource::StartDataRequest(const std::string& path, | 155 void RegisterPageUIHTMLSource::StartDataRequest(const std::string& path, |
| 162 bool is_incognito, | 156 bool is_incognito, |
| 163 int request_id) { | 157 int request_id) { |
| 164 // Make sure that chrome://register is available only during | 158 // Make sure that chrome://register is available only during |
| 165 // OOBE wizard lifetime and when device has not been registered yet. | 159 // OOBE wizard lifetime and when device has not been registered yet. |
| 166 #if defined(OS_CHROMEOS) | |
| 167 if (!chromeos::WizardController::default_controller() || | 160 if (!chromeos::WizardController::default_controller() || |
| 168 chromeos::WizardController::IsDeviceRegistered()) { | 161 chromeos::WizardController::IsDeviceRegistered()) { |
| 169 scoped_refptr<RefCountedBytes> empty_bytes(new RefCountedBytes); | 162 scoped_refptr<RefCountedBytes> empty_bytes(new RefCountedBytes); |
| 170 SendResponse(request_id, empty_bytes); | 163 SendResponse(request_id, empty_bytes); |
| 171 return; | 164 return; |
| 172 } | 165 } |
| 173 | 166 |
| 174 scoped_refptr<RefCountedMemory> html_bytes( | 167 scoped_refptr<RefCountedMemory> html_bytes( |
| 175 ResourceBundle::GetSharedInstance().LoadDataResourceBytes( | 168 ResourceBundle::GetSharedInstance().LoadDataResourceBytes( |
| 176 IDR_HOST_REGISTRATION_PAGE_HTML)); | 169 IDR_HOST_REGISTRATION_PAGE_HTML)); |
| 177 | 170 |
| 178 SendResponse(request_id, html_bytes); | 171 SendResponse(request_id, html_bytes); |
| 179 #else | |
| 180 scoped_refptr<RefCountedBytes> empty_bytes(new RefCountedBytes); | |
| 181 SendResponse(request_id, empty_bytes); | |
| 182 #endif | |
| 183 } | 172 } |
| 184 | 173 |
| 185 //////////////////////////////////////////////////////////////////////////////// | 174 //////////////////////////////////////////////////////////////////////////////// |
| 186 // | 175 // |
| 187 // RegisterPageHandler | 176 // RegisterPageHandler |
| 188 // | 177 // |
| 189 //////////////////////////////////////////////////////////////////////////////// | 178 //////////////////////////////////////////////////////////////////////////////// |
| 190 RegisterPageHandler::RegisterPageHandler() { | 179 RegisterPageHandler::RegisterPageHandler() { |
| 191 } | 180 } |
| 192 | 181 |
| 193 RegisterPageHandler::~RegisterPageHandler() { | 182 RegisterPageHandler::~RegisterPageHandler() { |
| 194 } | 183 } |
| 195 | 184 |
| 196 void RegisterPageHandler::RegisterMessages() { | 185 void RegisterPageHandler::RegisterMessages() { |
| 197 #if defined(OS_CHROMEOS) | |
| 198 web_ui()->RegisterMessageCallback(kJsCallbackGetRegistrationUrl, | 186 web_ui()->RegisterMessageCallback(kJsCallbackGetRegistrationUrl, |
| 199 base::Bind(&RegisterPageHandler::HandleGetRegistrationUrl, | 187 base::Bind(&RegisterPageHandler::HandleGetRegistrationUrl, |
| 200 base::Unretained(this))); | 188 base::Unretained(this))); |
| 201 web_ui()->RegisterMessageCallback(kJsCallbackUserInfo, | 189 web_ui()->RegisterMessageCallback(kJsCallbackUserInfo, |
| 202 base::Bind(&RegisterPageHandler::HandleGetUserInfo, | 190 base::Bind(&RegisterPageHandler::HandleGetUserInfo, |
| 203 base::Unretained(this))); | 191 base::Unretained(this))); |
| 204 #endif | |
| 205 } | 192 } |
| 206 | 193 |
| 207 void RegisterPageHandler::HandleGetRegistrationUrl(const ListValue* args) { | 194 void RegisterPageHandler::HandleGetRegistrationUrl(const ListValue* args) { |
| 208 #if defined(OS_CHROMEOS) | |
| 209 chromeos::StartupCustomizationDocument* customization = | 195 chromeos::StartupCustomizationDocument* customization = |
| 210 chromeos::StartupCustomizationDocument::GetInstance(); | 196 chromeos::StartupCustomizationDocument::GetInstance(); |
| 211 if (chromeos::WizardController::default_controller() && | 197 if (chromeos::WizardController::default_controller() && |
| 212 customization->IsReady()) { | 198 customization->IsReady()) { |
| 213 const std::string& url = customization->registration_url(); | 199 const std::string& url = customization->registration_url(); |
| 214 VLOG(1) << "Loading registration form with URL: " << url; | 200 VLOG(1) << "Loading registration form with URL: " << url; |
| 215 GURL register_url(url); | 201 GURL register_url(url); |
| 216 if (!register_url.is_valid()) { | 202 if (!register_url.is_valid()) { |
| 217 SkipRegistration("Registration URL defined in manifest is invalid."); | 203 SkipRegistration("Registration URL defined in manifest is invalid."); |
| 218 return; | 204 return; |
| 219 } | 205 } |
| 220 StringValue url_value(url); | 206 StringValue url_value(url); |
| 221 web_ui()->CallJavascriptFunction(kJsApiSetRegistrationUrl, url_value); | 207 web_ui()->CallJavascriptFunction(kJsApiSetRegistrationUrl, url_value); |
| 222 } else { | 208 } else { |
| 223 SkipRegistration("Startup manifest not defined."); | 209 SkipRegistration("Startup manifest not defined."); |
| 224 } | 210 } |
| 225 #endif | |
| 226 } | 211 } |
| 227 | 212 |
| 228 void RegisterPageHandler::HandleGetUserInfo(const ListValue* args) { | 213 void RegisterPageHandler::HandleGetUserInfo(const ListValue* args) { |
| 229 #if defined(OS_CHROMEOS) | 214 if (base::chromeos::IsRunningOnChromeOS()) { |
| 230 if (chromeos::system::runtime_environment::IsRunningOnChromeOS()) { | |
| 231 version_loader_.GetVersion( | 215 version_loader_.GetVersion( |
| 232 &version_consumer_, | 216 &version_consumer_, |
| 233 base::Bind(&RegisterPageHandler::OnVersion, base::Unretained(this)), | 217 base::Bind(&RegisterPageHandler::OnVersion, base::Unretained(this)), |
| 234 chromeos::VersionLoader::VERSION_FULL); | 218 chromeos::VersionLoader::VERSION_FULL); |
| 235 } else { | 219 } else { |
| 236 SkipRegistration("Not running on ChromeOS."); | 220 SkipRegistration("Not running on ChromeOS."); |
| 237 } | 221 } |
| 238 #endif | |
| 239 } | 222 } |
| 240 | 223 |
| 241 #if defined(OS_CHROMEOS) | |
| 242 void RegisterPageHandler::OnVersion(chromeos::VersionLoader::Handle handle, | 224 void RegisterPageHandler::OnVersion(chromeos::VersionLoader::Handle handle, |
| 243 std::string version) { | 225 std::string version) { |
| 244 version_ = version; | 226 version_ = version; |
| 245 SendUserInfo(); | 227 SendUserInfo(); |
| 246 } | 228 } |
| 247 #endif | |
| 248 | 229 |
| 249 void RegisterPageHandler::SkipRegistration(const std::string& error_msg) { | 230 void RegisterPageHandler::SkipRegistration(const std::string& error_msg) { |
| 250 #if defined(OS_CHROMEOS) | |
| 251 LOG(ERROR) << error_msg; | 231 LOG(ERROR) << error_msg; |
| 252 if (chromeos::WizardController::default_controller()) | 232 if (chromeos::WizardController::default_controller()) |
| 253 chromeos::WizardController::default_controller()->SkipRegistration(); | 233 chromeos::WizardController::default_controller()->SkipRegistration(); |
| 254 else | 234 else |
| 255 web_ui()->CallJavascriptFunction(kJsApiSkipRegistration); | 235 web_ui()->CallJavascriptFunction(kJsApiSkipRegistration); |
| 256 #endif | |
| 257 } | 236 } |
| 258 | 237 |
| 259 void RegisterPageHandler::SendUserInfo() { | 238 void RegisterPageHandler::SendUserInfo() { |
| 260 #if defined(OS_CHROMEOS) | |
| 261 DictionaryValue value; | 239 DictionaryValue value; |
| 262 | 240 |
| 263 chromeos::system::StatisticsProvider * provider = | 241 chromeos::system::StatisticsProvider * provider = |
| 264 chromeos::system::StatisticsProvider::GetInstance(); | 242 chromeos::system::StatisticsProvider::GetInstance(); |
| 265 | 243 |
| 266 // Required info. | 244 // Required info. |
| 267 std::string system_hwqual; | 245 std::string system_hwqual; |
| 268 std::string serial_number; | 246 std::string serial_number; |
| 269 if (!provider->GetMachineStatistic(kMachineInfoSystemHwqual, | 247 if (!provider->GetMachineStatistic(kMachineInfoSystemHwqual, |
| 270 &system_hwqual) || | 248 &system_hwqual) || |
| 271 !provider->GetMachineStatistic(kMachineInfoSerialNumber, | 249 !provider->GetMachineStatistic(kMachineInfoSerialNumber, |
| 272 &serial_number)) { | 250 &serial_number)) { |
| 273 SkipRegistration("Failed to get required machine info."); | 251 SkipRegistration("Failed to get required machine info."); |
| 274 return; | 252 return; |
| 275 } | 253 } |
| 276 value.SetString("system_hwqual", system_hwqual); | 254 value.SetString("system_hwqual", system_hwqual); |
| 277 value.SetString("system_serial", serial_number); | 255 value.SetString("system_serial", serial_number); |
| 278 value.SetString("os_language", g_browser_process->GetApplicationLocale()); | 256 value.SetString("os_language", g_browser_process->GetApplicationLocale()); |
| 279 value.SetString("os_name", kOSName); | 257 value.SetString("os_name", kOSName); |
| 280 value.SetString("os_version", version_); | 258 value.SetString("os_version", version_); |
| 281 value.SetString("os_connection", GetConnectionType()); | 259 value.SetString("os_connection", GetConnectionType()); |
| 282 value.SetString("user_email", ""); | 260 value.SetString("user_email", ""); |
| 283 | 261 |
| 284 // Optional info. | 262 // Optional info. |
| 285 value.SetString("user_first_name", ""); | 263 value.SetString("user_first_name", ""); |
| 286 value.SetString("user_last_name", ""); | 264 value.SetString("user_last_name", ""); |
| 287 | 265 |
| 288 web_ui()->CallJavascriptFunction(kJsApiSetUserInfo, value); | 266 web_ui()->CallJavascriptFunction(kJsApiSetUserInfo, value); |
| 289 #endif | |
| 290 } | 267 } |
| 291 | 268 |
| 292 //////////////////////////////////////////////////////////////////////////////// | 269 //////////////////////////////////////////////////////////////////////////////// |
| 293 // | 270 // |
| 294 // RegisterPageUI | 271 // RegisterPageUI |
| 295 // | 272 // |
| 296 //////////////////////////////////////////////////////////////////////////////// | 273 //////////////////////////////////////////////////////////////////////////////// |
| 297 | 274 |
| 298 RegisterPageUI::RegisterPageUI(content::WebUI* web_ui) | 275 RegisterPageUI::RegisterPageUI(content::WebUI* web_ui) |
| 299 : WebUIController(web_ui) { | 276 : WebUIController(web_ui) { |
| 300 RegisterPageHandler* handler = new RegisterPageHandler(); | 277 RegisterPageHandler* handler = new RegisterPageHandler(); |
| 301 web_ui->AddMessageHandler(handler); | 278 web_ui->AddMessageHandler(handler); |
| 302 RegisterPageUIHTMLSource* html_source = new RegisterPageUIHTMLSource(); | 279 RegisterPageUIHTMLSource* html_source = new RegisterPageUIHTMLSource(); |
| 303 | 280 |
| 304 // Set up the chrome://register/ source. | 281 // Set up the chrome://register/ source. |
| 305 Profile* profile = Profile::FromWebUI(web_ui); | 282 Profile* profile = Profile::FromWebUI(web_ui); |
| 306 profile->GetChromeURLDataManager()->AddDataSource(html_source); | 283 profile->GetChromeURLDataManager()->AddDataSource(html_source); |
| 307 } | 284 } |
| OLD | NEW |