| 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 |
| 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/json/json_writer.h" | 13 #include "base/json/json_writer.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/memory/ref_counted_memory.h" | 15 #include "base/memory/ref_counted_memory.h" |
| 16 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
| 17 #include "base/metrics/histogram.h" | 17 #include "base/metrics/histogram.h" |
| 18 #include "base/strings/string_piece.h" | 18 #include "base/strings/string_piece.h" |
| 19 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
| 20 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
| 21 #include "base/values.h" | 21 #include "base/values.h" |
| 22 #include "chrome/browser/chromeos/cros/network_library.h" | |
| 23 #include "chrome/browser/chromeos/mobile/mobile_activator.h" | 22 #include "chrome/browser/chromeos/mobile/mobile_activator.h" |
| 24 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
| 25 #include "chrome/browser/ui/browser_list.h" | 24 #include "chrome/browser/ui/browser_list.h" |
| 26 #include "chrome/common/pref_names.h" | 25 #include "chrome/common/pref_names.h" |
| 27 #include "chrome/common/render_messages.h" | 26 #include "chrome/common/render_messages.h" |
| 28 #include "chrome/common/url_constants.h" | 27 #include "chrome/common/url_constants.h" |
| 28 #include "chromeos/network/device_state.h" |
| 29 #include "chromeos/network/network_state.h" |
| 30 #include "chromeos/network/network_state_handler.h" |
| 31 #include "chromeos/network/network_state_handler_observer.h" |
| 29 #include "content/public/browser/browser_thread.h" | 32 #include "content/public/browser/browser_thread.h" |
| 30 #include "content/public/browser/render_view_host_observer.h" | 33 #include "content/public/browser/render_view_host_observer.h" |
| 31 #include "content/public/browser/url_data_source.h" | 34 #include "content/public/browser/url_data_source.h" |
| 32 #include "content/public/browser/web_contents.h" | 35 #include "content/public/browser/web_contents.h" |
| 33 #include "content/public/browser/web_ui.h" | 36 #include "content/public/browser/web_ui.h" |
| 34 #include "content/public/browser/web_ui_message_handler.h" | 37 #include "content/public/browser/web_ui_message_handler.h" |
| 35 #include "grit/browser_resources.h" | 38 #include "grit/browser_resources.h" |
| 36 #include "grit/chromium_strings.h" | 39 #include "grit/chromium_strings.h" |
| 37 #include "grit/generated_resources.h" | 40 #include "grit/generated_resources.h" |
| 38 #include "grit/locale_settings.h" | 41 #include "grit/locale_settings.h" |
| 42 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 39 #include "ui/base/l10n/l10n_util.h" | 43 #include "ui/base/l10n/l10n_util.h" |
| 40 #include "ui/base/resource/resource_bundle.h" | 44 #include "ui/base/resource/resource_bundle.h" |
| 41 #include "ui/webui/jstemplate_builder.h" | 45 #include "ui/webui/jstemplate_builder.h" |
| 42 #include "ui/webui/web_ui_util.h" | 46 #include "ui/webui/web_ui_util.h" |
| 43 #include "url/gurl.h" | 47 #include "url/gurl.h" |
| 44 | 48 |
| 45 using chromeos::CellularNetwork; | |
| 46 using chromeos::MobileActivator; | 49 using chromeos::MobileActivator; |
| 47 using chromeos::NetworkLibrary; | 50 using chromeos::NetworkHandler; |
| 51 using chromeos::NetworkState; |
| 48 using content::BrowserThread; | 52 using content::BrowserThread; |
| 49 using content::RenderViewHost; | 53 using content::RenderViewHost; |
| 50 using content::WebContents; | 54 using content::WebContents; |
| 51 using content::WebUIMessageHandler; | 55 using content::WebUIMessageHandler; |
| 52 | 56 |
| 53 namespace { | 57 namespace { |
| 54 | 58 |
| 55 // Host page JS API function names. | 59 // Host page JS API function names. |
| 56 const char kJsApiStartActivation[] = "startActivation"; | 60 const char kJsApiStartActivation[] = "startActivation"; |
| 57 const char kJsApiSetTransactionStatus[] = "setTransactionStatus"; | 61 const char kJsApiSetTransactionStatus[] = "setTransactionStatus"; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 private: | 142 private: |
| 139 virtual ~MobileSetupUIHTMLSource() {} | 143 virtual ~MobileSetupUIHTMLSource() {} |
| 140 | 144 |
| 141 DISALLOW_COPY_AND_ASSIGN(MobileSetupUIHTMLSource); | 145 DISALLOW_COPY_AND_ASSIGN(MobileSetupUIHTMLSource); |
| 142 }; | 146 }; |
| 143 | 147 |
| 144 // The handler for Javascript messages related to the "register" view. | 148 // The handler for Javascript messages related to the "register" view. |
| 145 class MobileSetupHandler | 149 class MobileSetupHandler |
| 146 : public WebUIMessageHandler, | 150 : public WebUIMessageHandler, |
| 147 public MobileActivator::Observer, | 151 public MobileActivator::Observer, |
| 148 public NetworkLibrary::NetworkManagerObserver, | 152 public chromeos::NetworkStateHandlerObserver, |
| 149 public base::SupportsWeakPtr<MobileSetupHandler> { | 153 public base::SupportsWeakPtr<MobileSetupHandler> { |
| 150 public: | 154 public: |
| 151 MobileSetupHandler(); | 155 MobileSetupHandler(); |
| 152 virtual ~MobileSetupHandler(); | 156 virtual ~MobileSetupHandler(); |
| 153 | 157 |
| 154 // WebUIMessageHandler implementation. | 158 // WebUIMessageHandler implementation. |
| 155 virtual void RegisterMessages() OVERRIDE; | 159 virtual void RegisterMessages() OVERRIDE; |
| 156 | 160 |
| 157 private: | 161 private: |
| 158 enum Type { | 162 enum Type { |
| 159 TYPE_UNDETERMINED, | 163 TYPE_UNDETERMINED, |
| 160 // The network is not yet activated, and the webui is in activation flow. | 164 // The network is not yet activated, and the webui is in activation flow. |
| 161 TYPE_ACTIVATION, | 165 TYPE_ACTIVATION, |
| 162 // The network is activated, the webui displays network portal. | 166 // The network is activated, the webui displays network portal. |
| 163 TYPE_PORTAL, | 167 TYPE_PORTAL, |
| 164 // Same as TYPE_PORTAL, but the network technology is LTE. The webui is | 168 // Same as TYPE_PORTAL, but the network technology is LTE. The webui is |
| 165 // additionally aware of network manager state and whether the portal can be | 169 // additionally aware of network manager state and whether the portal can be |
| 166 // reached. | 170 // reached. |
| 167 TYPE_PORTAL_LTE | 171 TYPE_PORTAL_LTE |
| 168 }; | 172 }; |
| 169 | 173 |
| 170 // Changes internal state. | 174 // MobileActivator::Observer. |
| 171 virtual void OnActivationStateChanged( | 175 virtual void OnActivationStateChanged( |
| 172 CellularNetwork* network, | 176 const NetworkState* network, |
| 173 MobileActivator::PlanActivationState new_state, | 177 MobileActivator::PlanActivationState new_state, |
| 174 const std::string& error_description) OVERRIDE; | 178 const std::string& error_description) OVERRIDE; |
| 175 | 179 |
| 176 // Handlers for JS WebUI messages. | 180 // Handlers for JS WebUI messages. |
| 177 void HandleSetTransactionStatus(const ListValue* args); | 181 void HandleSetTransactionStatus(const ListValue* args); |
| 178 void HandleStartActivation(const ListValue* args); | 182 void HandleStartActivation(const ListValue* args); |
| 179 void HandlePaymentPortalLoad(const ListValue* args); | 183 void HandlePaymentPortalLoad(const ListValue* args); |
| 180 void HandleGetDeviceInfo(const ListValue* args); | 184 void HandleGetDeviceInfo(const ListValue* args); |
| 181 | 185 |
| 182 // NetworkLibrary::NetworkManagerObserver implementation. | 186 // NetworkStateHandlerObserver implementation. |
| 183 virtual void OnNetworkManagerChanged(NetworkLibrary* network_lib) OVERRIDE; | 187 virtual void NetworkManagerChanged() OVERRIDE; |
| 188 virtual void DefaultNetworkChanged( |
| 189 const NetworkState* default_network) OVERRIDE; |
| 184 | 190 |
| 185 // Updates |lte_portal_reachable_| for lte network |network| and notifies | 191 // Updates |lte_portal_reachable_| for lte network |network| and notifies |
| 186 // webui of the new state if the reachability changed or |force_notification| | 192 // webui of the new state if the reachability changed or |force_notification| |
| 187 // is set. | 193 // is set. |
| 188 void UpdatePortalReachability(NetworkLibrary* network_lib, | 194 void UpdatePortalReachability(const NetworkState* network, |
| 189 CellularNetwork* network, | |
| 190 bool force_notification); | 195 bool force_notification); |
| 191 | 196 |
| 192 // Sends message to host registration page with system/user info data. | 197 // Sends message to host registration page with system/user info data. |
| 193 void SendDeviceInfo(); | 198 void SendDeviceInfo(); |
| 194 | 199 |
| 195 // Converts the currently active CellularNetwork device into a JS object. | 200 // Converts the currently active CellularNetwork device into a JS object. |
| 196 static void GetDeviceInfo(CellularNetwork* network, | 201 static void GetDeviceInfo(const NetworkState* network, |
| 197 DictionaryValue* value); | 202 DictionaryValue* value); |
| 198 | 203 |
| 199 // Type of the mobilesetup webui deduced from received messages. | 204 // Type of the mobilesetup webui deduced from received messages. |
| 200 Type type_; | 205 Type type_; |
| 201 // Whether portal page for lte networks can be reached in current network | 206 // Whether portal page for lte networks can be reached in current network |
| 202 // connection state. This value is reflected in portal webui for lte networks. | 207 // connection state. This value is reflected in portal webui for lte networks. |
| 203 // Initial value is true. | 208 // Initial value is true. |
| 204 bool lte_portal_reachable_; | 209 bool lte_portal_reachable_; |
| 205 | 210 |
| 206 DISALLOW_COPY_AND_ASSIGN(MobileSetupHandler); | 211 DISALLOW_COPY_AND_ASSIGN(MobileSetupHandler); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 217 | 222 |
| 218 std::string MobileSetupUIHTMLSource::GetSource() const { | 223 std::string MobileSetupUIHTMLSource::GetSource() const { |
| 219 return chrome::kChromeUIMobileSetupHost; | 224 return chrome::kChromeUIMobileSetupHost; |
| 220 } | 225 } |
| 221 | 226 |
| 222 void MobileSetupUIHTMLSource::StartDataRequest( | 227 void MobileSetupUIHTMLSource::StartDataRequest( |
| 223 const std::string& path, | 228 const std::string& path, |
| 224 int render_process_id, | 229 int render_process_id, |
| 225 int render_view_id, | 230 int render_view_id, |
| 226 const content::URLDataSource::GotDataCallback& callback) { | 231 const content::URLDataSource::GotDataCallback& callback) { |
| 227 CellularNetwork* network = NULL; | 232 const NetworkState* network = NULL; |
| 228 if (!path.empty()) { | 233 if (!path.empty()) { |
| 229 network = NetworkLibrary::Get()-> FindCellularNetworkByPath(path); | 234 network = NetworkHandler::Get()->network_state_handler()->GetNetworkState( |
| 235 path); |
| 230 } | 236 } |
| 231 | 237 |
| 232 if (!network || (!network->SupportsActivation() && !network->activated())) { | 238 if (!network || |
| 239 (network->payment_url().empty() && network->usage_url().empty() && |
| 240 network->activation_state() != flimflam::kActivationStateActivated)) { |
| 233 LOG(WARNING) << "Can't find device to activate for service path " << path; | 241 LOG(WARNING) << "Can't find device to activate for service path " << path; |
| 234 scoped_refptr<base::RefCountedBytes> html_bytes(new base::RefCountedBytes); | 242 scoped_refptr<base::RefCountedBytes> html_bytes(new base::RefCountedBytes); |
| 235 callback.Run(html_bytes.get()); | 243 callback.Run(html_bytes.get()); |
| 236 return; | 244 return; |
| 237 } | 245 } |
| 238 | 246 |
| 239 LOG(WARNING) << "Starting mobile setup for " << path; | 247 LOG(WARNING) << "Starting mobile setup for " << path; |
| 240 DictionaryValue strings; | 248 DictionaryValue strings; |
| 241 | 249 |
| 242 strings.SetString("connecting_header", | 250 strings.SetString("connecting_header", |
| (...skipping 19 matching lines...) Expand all Loading... |
| 262 strings.SetString("cancel_button", | 270 strings.SetString("cancel_button", |
| 263 l10n_util::GetStringUTF16(IDS_CANCEL)); | 271 l10n_util::GetStringUTF16(IDS_CANCEL)); |
| 264 strings.SetString("ok_button", | 272 strings.SetString("ok_button", |
| 265 l10n_util::GetStringUTF16(IDS_OK)); | 273 l10n_util::GetStringUTF16(IDS_OK)); |
| 266 webui::SetFontAndTextDirection(&strings); | 274 webui::SetFontAndTextDirection(&strings); |
| 267 | 275 |
| 268 // The webui differs based on whether the network is activated or not. If the | 276 // The webui differs based on whether the network is activated or not. If the |
| 269 // network is activated, the webui goes straight to portal. Otherwise the | 277 // network is activated, the webui goes straight to portal. Otherwise the |
| 270 // webui is used for activation flow. | 278 // webui is used for activation flow. |
| 271 std::string full_html; | 279 std::string full_html; |
| 272 if (network->activated()) { | 280 if (network->activation_state() == flimflam::kActivationStateActivated) { |
| 273 static const base::StringPiece html_for_activated( | 281 static const base::StringPiece html_for_activated( |
| 274 ResourceBundle::GetSharedInstance().GetRawDataResource( | 282 ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 275 IDR_MOBILE_SETUP_PORTAL_PAGE_HTML)); | 283 IDR_MOBILE_SETUP_PORTAL_PAGE_HTML)); |
| 276 full_html = webui::GetI18nTemplateHtml(html_for_activated, &strings); | 284 full_html = webui::GetI18nTemplateHtml(html_for_activated, &strings); |
| 277 } else { | 285 } else { |
| 278 static const base::StringPiece html_for_non_activated( | 286 static const base::StringPiece html_for_non_activated( |
| 279 ResourceBundle::GetSharedInstance().GetRawDataResource( | 287 ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 280 IDR_MOBILE_SETUP_PAGE_HTML)); | 288 IDR_MOBILE_SETUP_PAGE_HTML)); |
| 281 full_html = webui::GetI18nTemplateHtml(html_for_non_activated, &strings); | 289 full_html = webui::GetI18nTemplateHtml(html_for_non_activated, &strings); |
| 282 } | 290 } |
| 283 | 291 |
| 284 callback.Run(base::RefCountedString::TakeString(&full_html)); | 292 callback.Run(base::RefCountedString::TakeString(&full_html)); |
| 285 } | 293 } |
| 286 | 294 |
| 287 //////////////////////////////////////////////////////////////////////////////// | 295 //////////////////////////////////////////////////////////////////////////////// |
| 288 // | 296 // |
| 289 // MobileSetupHandler | 297 // MobileSetupHandler |
| 290 // | 298 // |
| 291 //////////////////////////////////////////////////////////////////////////////// | 299 //////////////////////////////////////////////////////////////////////////////// |
| 292 MobileSetupHandler::MobileSetupHandler() | 300 MobileSetupHandler::MobileSetupHandler() |
| 293 : type_(TYPE_UNDETERMINED), | 301 : type_(TYPE_UNDETERMINED), |
| 294 lte_portal_reachable_(true) { | 302 lte_portal_reachable_(true) { |
| 295 } | 303 } |
| 296 | 304 |
| 297 MobileSetupHandler::~MobileSetupHandler() { | 305 MobileSetupHandler::~MobileSetupHandler() { |
| 298 if (type_ == TYPE_ACTIVATION) { | 306 if (type_ == TYPE_ACTIVATION) { |
| 299 MobileActivator::GetInstance()->RemoveObserver(this); | 307 MobileActivator::GetInstance()->RemoveObserver(this); |
| 300 MobileActivator::GetInstance()->TerminateActivation(); | 308 MobileActivator::GetInstance()->TerminateActivation(); |
| 301 } else if (type_ == TYPE_PORTAL_LTE) { | 309 } else if (type_ == TYPE_PORTAL_LTE) { |
| 302 NetworkLibrary::Get()->RemoveNetworkManagerObserver(this); | 310 NetworkHandler::Get()->network_state_handler()->RemoveObserver(this, |
| 311 FROM_HERE); |
| 303 } | 312 } |
| 304 } | 313 } |
| 305 | 314 |
| 306 void MobileSetupHandler::OnActivationStateChanged( | 315 void MobileSetupHandler::OnActivationStateChanged( |
| 307 CellularNetwork* network, | 316 const NetworkState* network, |
| 308 MobileActivator::PlanActivationState state, | 317 MobileActivator::PlanActivationState state, |
| 309 const std::string& error_description) { | 318 const std::string& error_description) { |
| 310 DCHECK_EQ(TYPE_ACTIVATION, type_); | 319 DCHECK_EQ(TYPE_ACTIVATION, type_); |
| 311 if (!web_ui()) | 320 if (!web_ui()) |
| 312 return; | 321 return; |
| 313 | 322 |
| 314 DictionaryValue device_dict; | 323 DictionaryValue device_dict; |
| 315 if (network) | 324 if (network) |
| 316 GetDeviceInfo(network, &device_dict); | 325 GetDeviceInfo(network, &device_dict); |
| 317 device_dict.SetInteger("state", state); | 326 device_dict.SetInteger("state", state); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 | 398 |
| 390 void MobileSetupHandler::HandleGetDeviceInfo(const ListValue* args) { | 399 void MobileSetupHandler::HandleGetDeviceInfo(const ListValue* args) { |
| 391 DCHECK_NE(TYPE_ACTIVATION, type_); | 400 DCHECK_NE(TYPE_ACTIVATION, type_); |
| 392 if (!web_ui()) | 401 if (!web_ui()) |
| 393 return; | 402 return; |
| 394 | 403 |
| 395 std::string path = web_ui()->GetWebContents()->GetURL().path(); | 404 std::string path = web_ui()->GetWebContents()->GetURL().path(); |
| 396 if (path.empty()) | 405 if (path.empty()) |
| 397 return; | 406 return; |
| 398 | 407 |
| 399 NetworkLibrary* network_lib = NetworkLibrary::Get(); | 408 chromeos::NetworkStateHandler* nsh = |
| 400 CellularNetwork* network = | 409 NetworkHandler::Get()->network_state_handler(); |
| 401 network_lib->FindCellularNetworkByPath(path.substr(1)); | 410 // TODO: Figure out why the path has an extra '/' in the front. (e.g. It is |
| 411 // '//service/5' instead of '/service/5'. |
| 412 const NetworkState* network = nsh->GetNetworkState(path.substr(1)); |
| 402 if (!network) { | 413 if (!network) { |
| 403 web_ui()->GetWebContents()->Close(); | 414 web_ui()->GetWebContents()->Close(); |
| 404 return; | 415 return; |
| 405 } | 416 } |
| 406 | 417 |
| 407 // If this is the initial call, update the network status and start observing | 418 // If this is the initial call, update the network status and start observing |
| 408 // network changes, but only for LTE networks. The other networks should | 419 // network changes, but only for LTE networks. The other networks should |
| 409 // ignore network status. | 420 // ignore network status. |
| 410 if (type_ == TYPE_UNDETERMINED) { | 421 if (type_ == TYPE_UNDETERMINED) { |
| 411 if (network->network_technology() == chromeos::NETWORK_TECHNOLOGY_LTE || | 422 if (network->network_technology() == flimflam::kNetworkTechnologyLte || |
| 412 network->network_technology() == | 423 network->network_technology() == |
| 413 chromeos::NETWORK_TECHNOLOGY_LTE_ADVANCED) { | 424 flimflam::kNetworkTechnologyLteAdvanced) { |
| 414 type_ = TYPE_PORTAL_LTE; | 425 type_ = TYPE_PORTAL_LTE; |
| 415 network_lib->AddNetworkManagerObserver(this); | 426 nsh->AddObserver(this, FROM_HERE); |
| 416 // Update the network status and notify the webui. This is the initial | 427 // Update the network status and notify the webui. This is the initial |
| 417 // network state so the webui should be notified no matter what. | 428 // network state so the webui should be notified no matter what. |
| 418 UpdatePortalReachability(network_lib, | 429 UpdatePortalReachability(network, |
| 419 network, | 430 true /* force notification */); |
| 420 true /*force notification*/); | |
| 421 } else { | 431 } else { |
| 422 type_ = TYPE_PORTAL; | 432 type_ = TYPE_PORTAL; |
| 423 // For non-LTE networks network state is ignored, so report the portal is | 433 // For non-LTE networks network state is ignored, so report the portal is |
| 424 // reachable, so it gets shown. | 434 // reachable, so it gets shown. |
| 425 web_ui()->CallJavascriptFunction(kJsConnectivityChangedCallback, | 435 web_ui()->CallJavascriptFunction(kJsConnectivityChangedCallback, |
| 426 base::FundamentalValue(true)); | 436 base::FundamentalValue(true)); |
| 427 } | 437 } |
| 428 } | 438 } |
| 429 | 439 |
| 430 DictionaryValue device_info; | 440 DictionaryValue device_info; |
| 431 GetDeviceInfo(network, &device_info); | 441 GetDeviceInfo(network, &device_info); |
| 432 web_ui()->CallJavascriptFunction(kJsGetDeviceInfoCallback, device_info); | 442 web_ui()->CallJavascriptFunction(kJsGetDeviceInfoCallback, device_info); |
| 433 } | 443 } |
| 434 | 444 |
| 435 void MobileSetupHandler::OnNetworkManagerChanged(NetworkLibrary* network_lib) { | 445 void MobileSetupHandler::NetworkManagerChanged() { |
| 436 if (!web_ui()) | 446 if (!web_ui()) |
| 437 return; | 447 return; |
| 438 | 448 |
| 439 std::string path = web_ui()->GetWebContents()->GetURL().path(); | 449 std::string path = web_ui()->GetWebContents()->GetURL().path(); |
| 440 if (path.empty()) | 450 if (path.empty()) |
| 441 return; | 451 return; |
| 442 | 452 |
| 443 CellularNetwork* network = | 453 const NetworkState* network = |
| 444 network_lib->FindCellularNetworkByPath(path.substr(1)); | 454 NetworkHandler::Get()->network_state_handler()->GetNetworkState( |
| 455 path.substr(1)); |
| 445 if (!network) { | 456 if (!network) { |
| 446 LOG(ERROR) << "Service path lost"; | 457 LOG(ERROR) << "Service path lost"; |
| 447 web_ui()->GetWebContents()->Close(); | 458 web_ui()->GetWebContents()->Close(); |
| 448 return; | 459 return; |
| 449 } | 460 } |
| 450 | 461 |
| 451 UpdatePortalReachability(network_lib, network, false /*force notification*/); | 462 UpdatePortalReachability(network, |
| 463 false /* do not force notification */); |
| 452 } | 464 } |
| 453 | 465 |
| 454 void MobileSetupHandler::UpdatePortalReachability(NetworkLibrary* network_lib, | 466 void MobileSetupHandler::DefaultNetworkChanged( |
| 455 CellularNetwork* network, | 467 const NetworkState* default_network) { |
| 456 bool force_notification) { | 468 NetworkManagerChanged(); |
| 469 } |
| 470 |
| 471 void MobileSetupHandler::UpdatePortalReachability( |
| 472 const NetworkState* network, |
| 473 bool force_notification) { |
| 457 DCHECK(web_ui()); | 474 DCHECK(web_ui()); |
| 458 | 475 |
| 459 DCHECK_EQ(type_, TYPE_PORTAL_LTE); | 476 DCHECK_EQ(type_, TYPE_PORTAL_LTE); |
| 460 | 477 |
| 461 bool portal_reachable = network->connected() || | 478 chromeos::NetworkStateHandler* nsh = |
| 462 (network_lib->connected_network() && | 479 NetworkHandler::Get()->network_state_handler(); |
| 463 network_lib->connected_network()->online()); | 480 bool portal_reachable = |
| 481 (network->IsConnectedState() || |
| 482 (nsh->DefaultNetwork() && |
| 483 nsh->DefaultNetwork()->connection_state() == flimflam::kStateOnline)); |
| 464 | 484 |
| 465 if (force_notification || portal_reachable != lte_portal_reachable_) { | 485 if (force_notification || portal_reachable != lte_portal_reachable_) { |
| 466 web_ui()->CallJavascriptFunction(kJsConnectivityChangedCallback, | 486 web_ui()->CallJavascriptFunction(kJsConnectivityChangedCallback, |
| 467 base::FundamentalValue(portal_reachable)); | 487 base::FundamentalValue(portal_reachable)); |
| 468 } | 488 } |
| 469 | 489 |
| 470 lte_portal_reachable_ = portal_reachable; | 490 lte_portal_reachable_ = portal_reachable; |
| 471 } | 491 } |
| 472 | 492 |
| 473 void MobileSetupHandler::GetDeviceInfo(CellularNetwork* network, | 493 void MobileSetupHandler::GetDeviceInfo(const NetworkState* network, |
| 474 DictionaryValue* value) { | 494 DictionaryValue* value) { |
| 475 DCHECK(network); | 495 DCHECK(network); |
| 476 chromeos::NetworkLibrary* cros = | |
| 477 chromeos::NetworkLibrary::Get(); | |
| 478 if (!cros) | |
| 479 return; | |
| 480 value->SetBoolean("activate_over_non_cellular_network", | 496 value->SetBoolean("activate_over_non_cellular_network", |
| 481 network->activate_over_non_cellular_network()); | 497 network->activate_over_non_cellular_networks()); |
| 482 value->SetString("carrier", network->name()); | 498 value->SetString("carrier", network->name()); |
| 483 value->SetString("payment_url", network->payment_url()); | 499 value->SetString("payment_url", network->payment_url()); |
| 484 if (network->using_post() && network->post_data().length()) | 500 if (network->post_method() == "post" && !network->post_data().empty()) |
| 485 value->SetString("post_data", network->post_data()); | 501 value->SetString("post_data", network->post_data()); |
| 486 | 502 |
| 487 const chromeos::NetworkDevice* device = | 503 const chromeos::DeviceState* device = |
| 488 cros->FindNetworkDeviceByPath(network->device_path()); | 504 NetworkHandler::Get()->network_state_handler()->GetDeviceState( |
| 505 network->device_path()); |
| 489 if (device) { | 506 if (device) { |
| 490 value->SetString("MEID", device->meid()); | 507 value->SetString("MEID", device->meid()); |
| 491 value->SetString("IMEI", device->imei()); | 508 value->SetString("IMEI", device->imei()); |
| 492 value->SetString("MDN", device->mdn()); | 509 value->SetString("MDN", device->mdn()); |
| 493 } | 510 } |
| 494 } | 511 } |
| 495 | 512 |
| 496 //////////////////////////////////////////////////////////////////////////////// | 513 //////////////////////////////////////////////////////////////////////////////// |
| 497 // | 514 // |
| 498 // MobileSetupUI | 515 // MobileSetupUI |
| 499 // | 516 // |
| 500 //////////////////////////////////////////////////////////////////////////////// | 517 //////////////////////////////////////////////////////////////////////////////// |
| 501 | 518 |
| 502 MobileSetupUI::MobileSetupUI(content::WebUI* web_ui) | 519 MobileSetupUI::MobileSetupUI(content::WebUI* web_ui) |
| 503 : WebUIController(web_ui) { | 520 : WebUIController(web_ui) { |
| 504 web_ui->AddMessageHandler(new MobileSetupHandler()); | 521 web_ui->AddMessageHandler(new MobileSetupHandler()); |
| 505 MobileSetupUIHTMLSource* html_source = new MobileSetupUIHTMLSource(); | 522 MobileSetupUIHTMLSource* html_source = new MobileSetupUIHTMLSource(); |
| 506 | 523 |
| 507 // Set up the chrome://mobilesetup/ source. | 524 // Set up the chrome://mobilesetup/ source. |
| 508 Profile* profile = Profile::FromWebUI(web_ui); | 525 Profile* profile = Profile::FromWebUI(web_ui); |
| 509 content::URLDataSource::Add(profile, html_source); | 526 content::URLDataSource::Add(profile, html_source); |
| 510 } | 527 } |
| 511 | 528 |
| 512 void MobileSetupUI::RenderViewCreated(RenderViewHost* host) { | 529 void MobileSetupUI::RenderViewCreated(RenderViewHost* host) { |
| 513 // Destroyed by the corresponding RenderViewHost | 530 // Destroyed by the corresponding RenderViewHost |
| 514 new PortalFrameLoadObserver(AsWeakPtr(), host); | 531 new PortalFrameLoadObserver(AsWeakPtr(), host); |
| 515 } | 532 } |
| OLD | NEW |