OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/chromeos/dom_ui/mobile_setup_ui.h" | 5 #include "chrome/browser/chromeos/dom_ui/mobile_setup_ui.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "app/l10n_util.h" | 10 #include "app/l10n_util.h" |
11 #include "app/resource_bundle.h" | 11 #include "app/resource_bundle.h" |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
13 #include "base/file_util.h" | 13 #include "base/file_util.h" |
14 #include "base/json/json_reader.h" | 14 #include "base/json/json_reader.h" |
15 #include "base/json/json_writer.h" | 15 #include "base/json/json_writer.h" |
16 #include "base/logging.h" | 16 #include "base/logging.h" |
17 #include "base/string_piece.h" | 17 #include "base/string_piece.h" |
18 #include "base/string_util.h" | 18 #include "base/string_util.h" |
| 19 #include "base/thread_restrictions.h" |
19 #include "base/utf_string_conversions.h" | 20 #include "base/utf_string_conversions.h" |
20 #include "base/values.h" | 21 #include "base/values.h" |
21 #include "base/weak_ptr.h" | 22 #include "base/weak_ptr.h" |
22 #include "chrome/browser/browser.h" | 23 #include "chrome/browser/browser.h" |
23 #include "chrome/browser/browser_list.h" | 24 #include "chrome/browser/browser_list.h" |
24 #include "chrome/browser/browser_process.h" | 25 #include "chrome/browser/browser_process.h" |
25 #include "chrome/browser/browser_thread.h" | 26 #include "chrome/browser/browser_thread.h" |
26 #include "chrome/browser/chromeos/cros/cros_library.h" | 27 #include "chrome/browser/chromeos/cros/cros_library.h" |
27 #include "chrome/browser/chromeos/cros/network_library.h" | 28 #include "chrome/browser/chromeos/cros/network_library.h" |
28 #include "chrome/browser/chromeos/cros/system_library.h" | 29 #include "chrome/browser/chromeos/cros/system_library.h" |
29 #include "chrome/browser/dom_ui/chrome_url_data_manager.h" | 30 #include "chrome/browser/dom_ui/chrome_url_data_manager.h" |
30 #include "chrome/browser/tab_contents/tab_contents.h" | 31 #include "chrome/browser/tab_contents/tab_contents.h" |
31 #include "chrome/common/jstemplate_builder.h" | 32 #include "chrome/common/jstemplate_builder.h" |
32 #include "chrome/common/url_constants.h" | 33 #include "chrome/common/url_constants.h" |
33 #include "googleurl/src/gurl.h" | 34 #include "googleurl/src/gurl.h" |
34 #include "grit/browser_resources.h" | 35 #include "grit/browser_resources.h" |
35 #include "grit/chromium_strings.h" | 36 #include "grit/chromium_strings.h" |
36 #include "grit/generated_resources.h" | 37 #include "grit/generated_resources.h" |
37 #include "grit/locale_settings.h" | 38 #include "grit/locale_settings.h" |
| 39 #include "net/base/ssl_config_service.h" |
38 | 40 |
39 namespace { | 41 namespace { |
40 | 42 |
41 // Host page JS API function names. | 43 // Host page JS API function names. |
42 const char kJsApiStartActivation[] = "startActivation"; | 44 const char kJsApiStartActivation[] = "startActivation"; |
43 const char kJsApiCloseTab[] = "closeTab"; | 45 const char kJsApiCloseTab[] = "closeTab"; |
44 const char kJsApiSetTransactionStatus[] = "setTransactionStatus"; | 46 const char kJsApiSetTransactionStatus[] = "setTransactionStatus"; |
45 | 47 |
46 const wchar_t kJsDeviceStatusChangedHandler[] = | 48 const wchar_t kJsDeviceStatusChangedHandler[] = |
47 L"mobile.MobileSetup.deviceStateChanged"; | 49 L"mobile.MobileSetup.deviceStateChanged"; |
(...skipping 20 matching lines...) Expand all Loading... |
68 const char kFailedPaymentError[] = "failed_payment"; | 70 const char kFailedPaymentError[] = "failed_payment"; |
69 | 71 |
70 // Cellular configuration file path. | 72 // Cellular configuration file path. |
71 const char kCellularConfigPath[] = | 73 const char kCellularConfigPath[] = |
72 "/usr/share/chromeos-assets/mobile/mobile_config.json"; | 74 "/usr/share/chromeos-assets/mobile/mobile_config.json"; |
73 | 75 |
74 // Cellular config file field names. | 76 // Cellular config file field names. |
75 const char kVersionField[] = "version"; | 77 const char kVersionField[] = "version"; |
76 const char kErrorsField[] = "errors"; | 78 const char kErrorsField[] = "errors"; |
77 | 79 |
| 80 chromeos::CellularNetwork* GetCellularNetwork() { |
| 81 chromeos::NetworkLibrary* lib = chromeos::CrosLibrary::Get()-> |
| 82 GetNetworkLibrary(); |
| 83 if (lib->cellular_networks().begin() != lib->cellular_networks().end()) { |
| 84 return *(lib->cellular_networks().begin()); |
| 85 } |
| 86 return NULL; |
| 87 } |
| 88 |
| 89 chromeos::CellularNetwork* GetCellularNetwork(const std::string& service_path) { |
| 90 return chromeos::CrosLibrary::Get()-> |
| 91 GetNetworkLibrary()->FindCellularNetworkByPath(service_path); |
| 92 } |
| 93 |
78 } // namespace | 94 } // namespace |
79 | 95 |
80 class CellularConfigDocument { | 96 class CellularConfigDocument { |
81 public: | 97 public: |
82 CellularConfigDocument() {} | 98 CellularConfigDocument() {} |
83 | 99 |
84 // Return error message for a given code. | 100 // Return error message for a given code. |
85 std::string GetErrorMessage(const std::string& code); | 101 std::string GetErrorMessage(const std::string& code); |
86 const std::string& version() { return version_; } | 102 const std::string& version() { return version_; } |
87 | 103 |
88 bool LoadFromFile(const FilePath& config_path); | 104 bool LoadFromFile(const FilePath& config_path); |
89 | 105 |
90 private: | 106 private: |
91 std::string version_; | 107 std::string version_; |
92 std::map<std::string, std::string> error_map_; | 108 std::map<std::string, std::string> error_map_; |
93 | 109 |
94 DISALLOW_COPY_AND_ASSIGN(CellularConfigDocument); | 110 DISALLOW_COPY_AND_ASSIGN(CellularConfigDocument); |
95 }; | 111 }; |
96 | 112 |
97 static std::map<std::string, std::string> error_messages_; | 113 static std::map<std::string, std::string> error_messages_; |
98 | 114 |
99 class MobileSetupUIHTMLSource : public ChromeURLDataManager::DataSource { | 115 class MobileSetupUIHTMLSource : public ChromeURLDataManager::DataSource { |
100 public: | 116 public: |
101 MobileSetupUIHTMLSource(); | 117 explicit MobileSetupUIHTMLSource(const std::string& service_path); |
102 | 118 |
103 // Called when the network layer has requested a resource underneath | 119 // Called when the network layer has requested a resource underneath |
104 // the path we registered. | 120 // the path we registered. |
105 virtual void StartDataRequest(const std::string& path, | 121 virtual void StartDataRequest(const std::string& path, |
106 bool is_off_the_record, | 122 bool is_off_the_record, |
107 int request_id); | 123 int request_id); |
108 virtual std::string GetMimeType(const std::string&) const { | 124 virtual std::string GetMimeType(const std::string&) const { |
109 return "text/html"; | 125 return "text/html"; |
110 } | 126 } |
111 | 127 |
112 private: | 128 private: |
113 ~MobileSetupUIHTMLSource() {} | 129 virtual ~MobileSetupUIHTMLSource() {} |
114 | 130 |
| 131 std::string service_path_; |
115 DISALLOW_COPY_AND_ASSIGN(MobileSetupUIHTMLSource); | 132 DISALLOW_COPY_AND_ASSIGN(MobileSetupUIHTMLSource); |
116 }; | 133 }; |
117 | 134 |
118 // The handler for Javascript messages related to the "register" view. | 135 // The handler for Javascript messages related to the "register" view. |
119 class MobileSetupHandler : public DOMMessageHandler, | 136 class MobileSetupHandler : public DOMMessageHandler, |
120 public chromeos::NetworkLibrary::Observer, | 137 public chromeos::NetworkLibrary::Observer, |
121 public chromeos::NetworkLibrary::PropertyObserver, | 138 public chromeos::NetworkLibrary::PropertyObserver, |
122 public base::SupportsWeakPtr<MobileSetupHandler> { | 139 public base::SupportsWeakPtr<MobileSetupHandler> { |
123 public: | 140 public: |
124 MobileSetupHandler(); | 141 explicit MobileSetupHandler(const std::string& service_path); |
125 virtual ~MobileSetupHandler(); | 142 virtual ~MobileSetupHandler(); |
126 | 143 |
127 // Init work after Attach. | 144 // Init work after Attach. |
128 void Init(TabContents* contents); | 145 void Init(TabContents* contents); |
129 | 146 |
130 // DOMMessageHandler implementation. | 147 // DOMMessageHandler implementation. |
131 virtual DOMMessageHandler* Attach(DOMUI* dom_ui); | 148 virtual DOMMessageHandler* Attach(DOMUI* dom_ui); |
132 virtual void RegisterMessages(); | 149 virtual void RegisterMessages(); |
133 | 150 |
134 // NetworkLibrary::Observer implementation. | 151 // NetworkLibrary::Observer implementation. |
135 virtual void NetworkChanged(chromeos::NetworkLibrary* obj); | 152 virtual void NetworkChanged(chromeos::NetworkLibrary* obj); |
136 // NetworkLibrary::PropertyObserver implementation. | 153 // NetworkLibrary::PropertyObserver implementation. |
137 virtual void PropertyChanged(const char* service_path, | 154 virtual void PropertyChanged(const char* service_path, |
138 const char* key, | 155 const char* key, |
139 const Value* value); | 156 const Value* value); |
140 | 157 |
141 // Returns currently present cellular network, NULL if no network found. | |
142 static const chromeos::CellularNetwork* GetNetwork(); | |
143 | |
144 private: | 158 private: |
145 typedef enum PlanActivationState { | 159 typedef enum PlanActivationState { |
146 PLAN_ACTIVATION_PAGE_LOADING = -1, | 160 PLAN_ACTIVATION_PAGE_LOADING = -1, |
147 PLAN_ACTIVATION_START = 0, | 161 PLAN_ACTIVATION_START = 0, |
148 PLAN_ACTIVATION_INITIATING_ACTIVATION = 1, | 162 PLAN_ACTIVATION_INITIATING_ACTIVATION = 1, |
149 PLAN_ACTIVATION_ACTIVATING = 2, | 163 PLAN_ACTIVATION_ACTIVATING = 2, |
150 PLAN_ACTIVATION_SHOWING_PAYMENT = 3, | 164 PLAN_ACTIVATION_SHOWING_PAYMENT = 3, |
151 PLAN_ACTIVATION_DONE = 4, | 165 PLAN_ACTIVATION_DONE = 4, |
152 PLAN_ACTIVATION_ERROR = 5, | 166 PLAN_ACTIVATION_ERROR = 5, |
153 } PlanActivationState; | 167 } PlanActivationState; |
154 | 168 |
155 // Handlers for JS DOMUI messages. | 169 // Handlers for JS DOMUI messages. |
156 void HandleStartActivation(const ListValue* args); | 170 void HandleStartActivation(const ListValue* args); |
157 void HandleCloseTab(const ListValue* args); | 171 void HandleCloseTab(const ListValue* args); |
158 void HandleSetTransactionStatus(const ListValue* args); | 172 void HandleSetTransactionStatus(const ListValue* args); |
159 | 173 |
160 // Sends message to host registration page with system/user info data. | 174 // Sends message to host registration page with system/user info data. |
161 void SendDeviceInfo(); | 175 void SendDeviceInfo(); |
162 | 176 |
163 // Verify the state of cellular network and modify internal state. | 177 // Verify the state of cellular network and modify internal state. |
164 void EvaluateCellularNetwork(); | 178 void EvaluateCellularNetwork(const chromeos::CellularNetwork* network); |
165 // Check the current cellular network for error conditions. | 179 // Check the current cellular network for error conditions. |
166 bool GotActivationError(const chromeos::CellularNetwork* network, | 180 bool GotActivationError(const chromeos::CellularNetwork* network, |
167 std::string* error); | 181 std::string* error); |
168 void ChangeState(const chromeos::CellularNetwork* network, | 182 void ChangeState(const chromeos::CellularNetwork* network, |
169 PlanActivationState new_state, | 183 PlanActivationState new_state, |
170 const std::string& error_description); | 184 const std::string& error_description); |
171 | 185 |
| 186 // Control routines for handling other types of connections during |
| 187 // cellular activation. |
| 188 void ReEnableOtherConnections(); |
| 189 void DisableOtherConnections(); |
| 190 |
172 // Converts the currently active CellularNetwork device into a JS object. | 191 // Converts the currently active CellularNetwork device into a JS object. |
173 static void GetDeviceInfo(const chromeos::CellularNetwork* network, | 192 static void GetDeviceInfo(const chromeos::CellularNetwork* network, |
174 DictionaryValue* value); | 193 DictionaryValue* value); |
175 static bool ShouldReportDeviceState(std::string* state, std::string* error); | 194 static bool ShouldReportDeviceState(std::string* state, std::string* error); |
176 | 195 |
177 // Performs activation state cellular device evaluation. | 196 // Performs activation state cellular device evaluation. |
178 // Returns false if device activation failed. In this case |error| | 197 // Returns false if device activation failed. In this case |error| |
179 // will contain error message to be reported to DOM UI. | 198 // will contain error message to be reported to DOM UI. |
180 static bool EvaluateCellularDeviceState(bool* report_status, | 199 static bool EvaluateCellularDeviceState(bool* report_status, |
181 std::string* state, | 200 std::string* state, |
182 std::string* error); | 201 std::string* error); |
183 | 202 |
184 // Return error message for a given code. | 203 // Return error message for a given code. |
185 static std::string GetErrorMessage(const std::string& code); | 204 static std::string GetErrorMessage(const std::string& code); |
186 static void LoadCellularConfig(); | 205 static void LoadCellularConfig(); |
187 | 206 |
188 static const char* GetStateDescription(PlanActivationState state); | 207 static const char* GetStateDescription(PlanActivationState state); |
189 | 208 |
190 static scoped_ptr<CellularConfigDocument> cellular_config_; | 209 static scoped_ptr<CellularConfigDocument> cellular_config_; |
191 | 210 |
192 TabContents* tab_contents_; | 211 TabContents* tab_contents_; |
193 // Internal handler state. | 212 // Internal handler state. |
194 PlanActivationState state_; | 213 PlanActivationState state_; |
| 214 std::string service_path_; |
| 215 // Flags that control if wifi and ethernet connection needs to be restored |
| 216 // after the activation of cellular network. |
| 217 bool reenable_wifi_; |
| 218 bool reenable_ethernet_; |
195 DISALLOW_COPY_AND_ASSIGN(MobileSetupHandler); | 219 DISALLOW_COPY_AND_ASSIGN(MobileSetupHandler); |
196 }; | 220 }; |
197 | 221 |
198 scoped_ptr<CellularConfigDocument> MobileSetupHandler::cellular_config_; | 222 scoped_ptr<CellularConfigDocument> MobileSetupHandler::cellular_config_; |
199 | 223 |
200 //////////////////////////////////////////////////////////////////////////////// | 224 //////////////////////////////////////////////////////////////////////////////// |
201 // | 225 // |
202 // CellularConfigDocument | 226 // CellularConfigDocument |
203 // | 227 // |
204 //////////////////////////////////////////////////////////////////////////////// | 228 //////////////////////////////////////////////////////////////////////////////// |
205 | 229 |
206 std::string CellularConfigDocument::GetErrorMessage(const std::string& code) { | 230 std::string CellularConfigDocument::GetErrorMessage(const std::string& code) { |
207 std::map<std::string, std::string>::iterator iter = error_map_.find(code); | 231 std::map<std::string, std::string>::iterator iter = error_map_.find(code); |
208 if (iter == error_map_.end()) | 232 if (iter == error_map_.end()) |
209 return code; | 233 return code; |
210 return iter->second; | 234 return iter->second; |
211 } | 235 } |
212 | 236 |
213 bool CellularConfigDocument::LoadFromFile(const FilePath& config_path) { | 237 bool CellularConfigDocument::LoadFromFile(const FilePath& config_path) { |
214 error_map_.clear(); | 238 error_map_.clear(); |
| 239 base::ThreadRestrictions::ScopedAllowIO allow_io; |
215 | 240 |
216 std::string config; | 241 std::string config; |
217 if (!file_util::ReadFileToString(config_path, &config)) | 242 if (!file_util::ReadFileToString(config_path, &config)) |
218 return false; | 243 return false; |
219 | 244 |
220 scoped_ptr<Value> root(base::JSONReader::Read(config, true)); | 245 scoped_ptr<Value> root(base::JSONReader::Read(config, true)); |
221 DCHECK(root.get() != NULL); | 246 DCHECK(root.get() != NULL); |
222 if (!root.get() || root->GetType() != Value::TYPE_DICTIONARY) { | 247 if (!root.get() || root->GetType() != Value::TYPE_DICTIONARY) { |
223 VLOG(1) << "Bad cellular config file"; | 248 LOG(WARNING) << "Bad cellular config file"; |
224 return false; | 249 return false; |
225 } | 250 } |
226 | 251 |
227 DictionaryValue* root_dict = static_cast<DictionaryValue*>(root.get()); | 252 DictionaryValue* root_dict = static_cast<DictionaryValue*>(root.get()); |
228 if (!root_dict->GetString(kVersionField, &version_)) { | 253 if (!root_dict->GetString(kVersionField, &version_)) { |
229 VLOG(1) << "Cellular config file missing version"; | 254 LOG(WARNING) << "Cellular config file missing version"; |
230 return false; | 255 return false; |
231 } | 256 } |
232 DictionaryValue* errors = NULL; | 257 DictionaryValue* errors = NULL; |
233 if (!root_dict->GetDictionary(kErrorsField, &errors)) | 258 if (!root_dict->GetDictionary(kErrorsField, &errors)) |
234 return false; | 259 return false; |
235 for (DictionaryValue::key_iterator keys = errors->begin_keys(); | 260 for (DictionaryValue::key_iterator keys = errors->begin_keys(); |
236 keys != errors->end_keys(); | 261 keys != errors->end_keys(); |
237 ++keys) { | 262 ++keys) { |
238 std::string value; | 263 std::string value; |
239 if (!errors->GetString(*keys, &value)) { | 264 if (!errors->GetString(*keys, &value)) { |
240 VLOG(1) << "Bad cellular config error value"; | 265 LOG(WARNING) << "Bad cellular config error value"; |
241 error_map_.clear(); | 266 error_map_.clear(); |
242 return false; | 267 return false; |
243 } | 268 } |
244 | 269 |
245 error_map_.insert(std::pair<std::string, std::string>(*keys, value)); | 270 error_map_.insert(std::pair<std::string, std::string>(*keys, value)); |
246 } | 271 } |
247 return true; | 272 return true; |
248 } | 273 } |
249 | 274 |
250 //////////////////////////////////////////////////////////////////////////////// | 275 //////////////////////////////////////////////////////////////////////////////// |
251 // | 276 // |
252 // MobileSetupUIHTMLSource | 277 // MobileSetupUIHTMLSource |
253 // | 278 // |
254 //////////////////////////////////////////////////////////////////////////////// | 279 //////////////////////////////////////////////////////////////////////////////// |
255 | 280 |
256 MobileSetupUIHTMLSource::MobileSetupUIHTMLSource() | 281 MobileSetupUIHTMLSource::MobileSetupUIHTMLSource( |
257 : DataSource(chrome::kChromeUIMobileSetupHost, MessageLoop::current()) { | 282 const std::string& service_path) |
| 283 : DataSource(chrome::kChromeUIMobileSetupHost, MessageLoop::current()), |
| 284 service_path_(service_path) { |
258 } | 285 } |
259 | 286 |
260 void MobileSetupUIHTMLSource::StartDataRequest(const std::string& path, | 287 void MobileSetupUIHTMLSource::StartDataRequest(const std::string& path, |
261 bool is_off_the_record, | 288 bool is_off_the_record, |
262 int request_id) { | 289 int request_id) { |
263 const chromeos::CellularNetwork* network = MobileSetupHandler::GetNetwork(); | 290 const chromeos::CellularNetwork* network = GetCellularNetwork(service_path_); |
264 | 291 |
265 DictionaryValue strings; | 292 DictionaryValue strings; |
266 strings.SetString("title", l10n_util::GetStringUTF16(IDS_MOBILE_SETUP_TITLE)); | 293 strings.SetString("title", l10n_util::GetStringUTF16(IDS_MOBILE_SETUP_TITLE)); |
267 strings.SetString("connecting_header", | 294 strings.SetString("connecting_header", |
268 l10n_util::GetStringFUTF16(IDS_MOBILE_CONNECTING_HEADER, | 295 l10n_util::GetStringFUTF16(IDS_MOBILE_CONNECTING_HEADER, |
269 network ? UTF8ToUTF16(network->name()) : string16())); | 296 network ? UTF8ToUTF16(network->name()) : string16())); |
270 strings.SetString("error_header", | 297 strings.SetString("error_header", |
271 l10n_util::GetStringUTF16(IDS_MOBILE_ERROR_HEADER)); | 298 l10n_util::GetStringUTF16(IDS_MOBILE_ERROR_HEADER)); |
272 strings.SetString("activating_header", | 299 strings.SetString("activating_header", |
273 l10n_util::GetStringUTF16(IDS_MOBILE_ACTIVATING_HEADER)); | 300 l10n_util::GetStringUTF16(IDS_MOBILE_ACTIVATING_HEADER)); |
274 strings.SetString("completed_header", | 301 strings.SetString("completed_header", |
275 l10n_util::GetStringUTF16(IDS_MOBILE_COMPLETED_HEADER)); | 302 l10n_util::GetStringUTF16(IDS_MOBILE_COMPLETED_HEADER)); |
276 strings.SetString("completed_text", | 303 strings.SetString("completed_text", |
277 l10n_util::GetStringUTF16(IDS_MOBILE_COMPLETED_TEXT)); | 304 l10n_util::GetStringUTF16(IDS_MOBILE_COMPLETED_TEXT)); |
278 SetFontAndTextDirection(&strings); | 305 SetFontAndTextDirection(&strings); |
279 | 306 |
280 static const base::StringPiece html( | 307 static const base::StringPiece html( |
281 ResourceBundle::GetSharedInstance().GetRawDataResource( | 308 ResourceBundle::GetSharedInstance().GetRawDataResource( |
282 IDR_MOBILE_SETUP_PAGE_HTML)); | 309 IDR_MOBILE_SETUP_PAGE_HTML)); |
283 const std::string full_html = jstemplate_builder::GetTemplatesHtml( | 310 const std::string full_html = jstemplate_builder::GetTemplatesHtml( |
284 html, &strings, "t" /* template root node id */); | 311 html, &strings, "t" /* template root node id */); |
285 | 312 |
286 scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); | 313 scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); |
287 html_bytes->data.resize(full_html.size()); | 314 html_bytes->data.resize(full_html.size()); |
288 std::copy(full_html.begin(), full_html.end(), html_bytes->data.begin()); | 315 std::copy(full_html.begin(), full_html.end(), html_bytes->data.begin()); |
289 | 316 |
290 SendResponse(request_id, html_bytes); | 317 SendResponse(request_id, html_bytes); |
291 } | 318 } |
292 | 319 |
293 //////////////////////////////////////////////////////////////////////////////// | 320 //////////////////////////////////////////////////////////////////////////////// |
294 // | 321 // |
295 // MobileSetupHandler | 322 // MobileSetupHandler |
296 // | 323 // |
297 //////////////////////////////////////////////////////////////////////////////// | 324 //////////////////////////////////////////////////////////////////////////////// |
298 MobileSetupHandler::MobileSetupHandler() | 325 MobileSetupHandler::MobileSetupHandler(const std::string& service_path) |
299 : tab_contents_(NULL), state_(PLAN_ACTIVATION_PAGE_LOADING) { | 326 : tab_contents_(NULL), |
| 327 state_(PLAN_ACTIVATION_PAGE_LOADING), |
| 328 service_path_(service_path), |
| 329 reenable_wifi_(false), |
| 330 reenable_ethernet_(false) { |
300 } | 331 } |
301 | 332 |
302 MobileSetupHandler::~MobileSetupHandler() { | 333 MobileSetupHandler::~MobileSetupHandler() { |
303 chromeos::NetworkLibrary* lib = | 334 chromeos::NetworkLibrary* lib = |
304 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); | 335 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); |
305 lib->RemoveObserver(this); | 336 lib->RemoveObserver(this); |
306 lib->RemoveProperyObserver(this); | 337 lib->RemoveProperyObserver(this); |
| 338 net::SSLConfigService::AllowRevChecking(); |
| 339 ReEnableOtherConnections(); |
307 } | 340 } |
308 | 341 |
309 DOMMessageHandler* MobileSetupHandler::Attach(DOMUI* dom_ui) { | 342 DOMMessageHandler* MobileSetupHandler::Attach(DOMUI* dom_ui) { |
310 return DOMMessageHandler::Attach(dom_ui); | 343 return DOMMessageHandler::Attach(dom_ui); |
311 } | 344 } |
312 | 345 |
313 void MobileSetupHandler::Init(TabContents* contents) { | 346 void MobileSetupHandler::Init(TabContents* contents) { |
314 tab_contents_ = contents; | 347 tab_contents_ = contents; |
315 LoadCellularConfig(); | 348 LoadCellularConfig(); |
316 } | 349 } |
317 | 350 |
318 void MobileSetupHandler::RegisterMessages() { | 351 void MobileSetupHandler::RegisterMessages() { |
319 dom_ui_->RegisterMessageCallback(kJsApiStartActivation, | 352 dom_ui_->RegisterMessageCallback(kJsApiStartActivation, |
320 NewCallback(this, &MobileSetupHandler::HandleStartActivation)); | 353 NewCallback(this, &MobileSetupHandler::HandleStartActivation)); |
321 dom_ui_->RegisterMessageCallback(kJsApiCloseTab, | 354 dom_ui_->RegisterMessageCallback(kJsApiCloseTab, |
322 NewCallback(this, &MobileSetupHandler::HandleCloseTab)); | 355 NewCallback(this, &MobileSetupHandler::HandleCloseTab)); |
323 dom_ui_->RegisterMessageCallback(kJsApiSetTransactionStatus, | 356 dom_ui_->RegisterMessageCallback(kJsApiSetTransactionStatus, |
324 NewCallback(this, &MobileSetupHandler::HandleSetTransactionStatus)); | 357 NewCallback(this, &MobileSetupHandler::HandleSetTransactionStatus)); |
325 } | 358 } |
326 | 359 |
327 void MobileSetupHandler::NetworkChanged(chromeos::NetworkLibrary* cros) { | 360 void MobileSetupHandler::NetworkChanged(chromeos::NetworkLibrary* lib) { |
328 if (state_ == PLAN_ACTIVATION_PAGE_LOADING) | 361 if (state_ == PLAN_ACTIVATION_PAGE_LOADING) |
329 return; | 362 return; |
330 EvaluateCellularNetwork(); | 363 EvaluateCellularNetwork(GetCellularNetwork(service_path_)); |
331 } | 364 } |
332 | 365 |
333 void MobileSetupHandler::PropertyChanged(const char* service_path, | 366 void MobileSetupHandler::PropertyChanged(const char* service_path, |
334 const char* key, | 367 const char* key, |
335 const Value* value) { | 368 const Value* value) { |
| 369 |
336 if (state_ == PLAN_ACTIVATION_PAGE_LOADING) | 370 if (state_ == PLAN_ACTIVATION_PAGE_LOADING) |
337 return; | 371 return; |
338 const chromeos::CellularNetwork* network = GetNetwork(); | 372 chromeos::CellularNetwork* network = GetCellularNetwork(service_path_); |
| 373 if (!network) { |
| 374 EvaluateCellularNetwork(NULL); |
| 375 return; |
| 376 } |
339 if (network->service_path() != service_path) { | 377 if (network->service_path() != service_path) { |
340 NOTREACHED(); | 378 NOTREACHED(); |
341 return; | 379 return; |
342 } | 380 } |
343 std::string value_string; | 381 std::string value_string; |
344 VLOG(1) << "Cellular property change: " << key << " = " << value_string; | 382 VLOG(1) << "Cellular property change: " << key << " = " << |
345 // Force status updates. | 383 value_string.c_str(); |
| 384 |
| 385 // TODO(zelidrag, ers): Remove this once we flip the notification machanism. |
346 chromeos::CrosLibrary::Get()->GetNetworkLibrary()->UpdateSystemInfo(); | 386 chromeos::CrosLibrary::Get()->GetNetworkLibrary()->UpdateSystemInfo(); |
347 EvaluateCellularNetwork(); | 387 EvaluateCellularNetwork(network); |
348 } | 388 } |
349 | 389 |
350 void MobileSetupHandler::HandleCloseTab(const ListValue* args) { | 390 void MobileSetupHandler::HandleCloseTab(const ListValue* args) { |
351 if (!dom_ui_) | 391 if (!dom_ui_) |
352 return; | 392 return; |
353 Browser* browser = BrowserList::FindBrowserWithFeature( | 393 Browser* browser = BrowserList::FindBrowserWithFeature( |
354 dom_ui_->GetProfile(), Browser::FEATURE_TABSTRIP); | 394 dom_ui_->GetProfile(), Browser::FEATURE_TABSTRIP); |
355 if (browser) | 395 if (browser) |
356 browser->CloseTabContents(tab_contents_); | 396 browser->CloseTabContents(tab_contents_); |
357 } | 397 } |
358 | 398 |
359 void MobileSetupHandler::HandleStartActivation(const ListValue* args) { | 399 void MobileSetupHandler::HandleStartActivation(const ListValue* args) { |
360 const chromeos::CellularNetwork* network = GetNetwork(); | 400 chromeos::CellularNetwork* network = GetCellularNetwork(service_path_); |
361 if (!network) { | 401 if (!network) { |
362 ChangeState(NULL, PLAN_ACTIVATION_ERROR, std::string()); | 402 ChangeState(NULL, PLAN_ACTIVATION_ERROR, std::string()); |
363 return; | 403 return; |
364 } | 404 } |
365 | 405 chromeos::NetworkLibrary* lib = chromeos::CrosLibrary::Get()-> |
| 406 GetNetworkLibrary(); |
| 407 lib->RemoveObserver(this); |
| 408 lib->RemoveProperyObserver(this); |
366 // Start monitoring network and service property changes. | 409 // Start monitoring network and service property changes. |
367 chromeos::NetworkLibrary* lib = | |
368 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); | |
369 lib->AddObserver(this); | 410 lib->AddObserver(this); |
370 lib->AddProperyObserver(network->service_path().c_str(), | 411 lib->AddProperyObserver(network->service_path().c_str(), |
371 this); | 412 this); |
372 state_ = PLAN_ACTIVATION_START; | 413 state_ = PLAN_ACTIVATION_START; |
373 EvaluateCellularNetwork(); | 414 EvaluateCellularNetwork(network); |
374 } | 415 } |
375 | 416 |
376 void MobileSetupHandler::HandleSetTransactionStatus(const ListValue* args) { | 417 void MobileSetupHandler::HandleSetTransactionStatus(const ListValue* args) { |
377 const size_t kSetTransactionStatusParamCount = 1; | 418 const size_t kSetTransactionStatusParamCount = 1; |
378 if (args->GetSize() != kSetTransactionStatusParamCount) | 419 if (args->GetSize() != kSetTransactionStatusParamCount) |
379 return; | 420 return; |
380 | 421 |
381 // Get change callback function name. | 422 // Get change callback function name. |
382 std::string status; | 423 std::string status; |
383 if (!args->GetString(0, &status)) | 424 if (!args->GetString(0, &status)) |
384 return; | 425 return; |
385 | 426 |
386 // The payment is received, try to reconnect and check the status all over | 427 // The payment is received, try to reconnect and check the status all over |
387 // again. | 428 // again. |
388 if (LowerCaseEqualsASCII(status, "OK")) { | 429 if (LowerCaseEqualsASCII(status, "OK")) { |
389 ChangeState(GetNetwork(), PLAN_ACTIVATION_START, std::string()); | 430 chromeos::NetworkLibrary* lib = chromeos::CrosLibrary::Get()-> |
| 431 GetNetworkLibrary(); |
| 432 ChangeState( |
| 433 lib->cellular_network(), |
| 434 PLAN_ACTIVATION_START, std::string()); |
390 } | 435 } |
391 } | 436 } |
392 | 437 |
393 | 438 |
394 void MobileSetupHandler::EvaluateCellularNetwork() { | 439 void MobileSetupHandler::EvaluateCellularNetwork( |
| 440 const chromeos::CellularNetwork* network) { |
395 if (!dom_ui_) | 441 if (!dom_ui_) |
396 return; | 442 return; |
397 | 443 |
398 PlanActivationState new_state = state_; | 444 PlanActivationState new_state = state_; |
399 const chromeos::CellularNetwork* network = GetNetwork(); | |
400 if (network) { | 445 if (network) { |
401 VLOG(1) << "Cellular:\n service=" << network->GetStateString() | 446 VLOG(1) << "Cellular:\n service=" << network->GetStateString().c_str() |
402 << "\n ui=" << GetStateDescription(state_) | 447 << "\n ui=" << GetStateDescription(state_) |
403 << "\n activation=" << network->GetActivationStateString() | 448 << "\n activation=" << network->GetActivationStateString().c_str() |
404 << "\n restricted=" << (network->restricted_pool() ? "yes" : "no") | 449 << "\n restricted=" << (network->restricted_pool() ? "yes" : "no") |
405 << "\n error=" << network->GetErrorString() | 450 << "\n error=" << network->GetErrorString().c_str() |
406 << "\n setvice_path=" << network->service_path(); | 451 << "\n setvice_path=" << network->service_path().c_str(); |
407 } else { | 452 } else { |
408 LOG(WARNING) << "Cellular service lost"; | 453 LOG(WARNING) << "Cellular service lost"; |
409 } | 454 } |
410 switch (state_) { | 455 switch (state_) { |
411 case PLAN_ACTIVATION_START: | 456 case PLAN_ACTIVATION_START: |
412 if (network) { | 457 if (network) { |
413 switch (network->activation_state()) { | 458 switch (network->activation_state()) { |
414 case chromeos::ACTIVATION_STATE_PARTIALLY_ACTIVATED: | 459 case chromeos::ACTIVATION_STATE_PARTIALLY_ACTIVATED: |
415 case chromeos::ACTIVATION_STATE_ACTIVATED: | 460 case chromeos::ACTIVATION_STATE_ACTIVATED: |
416 if (network->failed_or_disconnected()) { | 461 if (network->failed_or_disconnected()) { |
417 new_state = PLAN_ACTIVATION_ACTIVATING; | 462 new_state = PLAN_ACTIVATION_ACTIVATING; |
418 } else if (network->connection_state() == chromeos::STATE_READY) { | 463 } else if (network->connection_state() == chromeos::STATE_READY) { |
419 new_state = network->restricted_pool() ? | 464 new_state = network->restricted_pool() ? |
420 PLAN_ACTIVATION_SHOWING_PAYMENT : PLAN_ACTIVATION_DONE; | 465 PLAN_ACTIVATION_SHOWING_PAYMENT : PLAN_ACTIVATION_DONE; |
421 } | 466 } |
422 break; | 467 break; |
423 case chromeos::ACTIVATION_STATE_UNKNOWN: | 468 case chromeos::ACTIVATION_STATE_UNKNOWN: |
424 case chromeos::ACTIVATION_STATE_NOT_ACTIVATED: | 469 case chromeos::ACTIVATION_STATE_NOT_ACTIVATED: |
425 if (network->failed_or_disconnected()) { | 470 if (network->failed_or_disconnected()) { |
426 new_state = PLAN_ACTIVATION_INITIATING_ACTIVATION; | 471 new_state = PLAN_ACTIVATION_INITIATING_ACTIVATION; |
427 } if (network->connected()) { | 472 } else if (network->connected()) { |
428 VLOG(1) << "Disconnecting from " << network->service_path(); | 473 VLOG(1) << "Disconnecting from " << |
| 474 network->service_path().c_str(); |
429 chromeos::CrosLibrary::Get()->GetNetworkLibrary()-> | 475 chromeos::CrosLibrary::Get()->GetNetworkLibrary()-> |
430 DisconnectFromWirelessNetwork(*network); | 476 DisconnectFromWirelessNetwork(network); |
431 } | 477 } |
432 break; | 478 break; |
433 default: | 479 default: |
434 new_state = PLAN_ACTIVATION_INITIATING_ACTIVATION; | 480 new_state = PLAN_ACTIVATION_INITIATING_ACTIVATION; |
435 break; | 481 break; |
436 } | 482 } |
437 } | 483 } |
438 break; | 484 break; |
439 case PLAN_ACTIVATION_INITIATING_ACTIVATION: | 485 case PLAN_ACTIVATION_INITIATING_ACTIVATION: |
440 if (network) { | 486 if (network) { |
(...skipping 11 matching lines...) Expand all Loading... |
452 break; | 498 break; |
453 case chromeos::ACTIVATION_STATE_PARTIALLY_ACTIVATED: | 499 case chromeos::ACTIVATION_STATE_PARTIALLY_ACTIVATED: |
454 if (network->connected()) | 500 if (network->connected()) |
455 new_state = PLAN_ACTIVATION_SHOWING_PAYMENT; | 501 new_state = PLAN_ACTIVATION_SHOWING_PAYMENT; |
456 else | 502 else |
457 new_state = PLAN_ACTIVATION_ACTIVATING; | 503 new_state = PLAN_ACTIVATION_ACTIVATING; |
458 break; | 504 break; |
459 case chromeos::ACTIVATION_STATE_NOT_ACTIVATED: | 505 case chromeos::ACTIVATION_STATE_NOT_ACTIVATED: |
460 // Wait in this state until activation state changes. | 506 // Wait in this state until activation state changes. |
461 break; | 507 break; |
| 508 case chromeos::ACTIVATION_STATE_ACTIVATING: |
| 509 break; |
462 default: | 510 default: |
463 NOTREACHED(); | |
464 break; | 511 break; |
465 } | 512 } |
466 } | 513 } |
467 break; | 514 break; |
468 case PLAN_ACTIVATION_ACTIVATING: | 515 case PLAN_ACTIVATION_ACTIVATING: |
469 // Wait until the service shows up and gets activated. | 516 // Wait until the service shows up and gets activated. |
470 if (network) { | 517 if (network) { |
471 switch (network->activation_state()) { | 518 switch (network->activation_state()) { |
472 case chromeos::ACTIVATION_STATE_ACTIVATED: | 519 case chromeos::ACTIVATION_STATE_ACTIVATED: |
473 if (network->connection_state() == chromeos::STATE_READY) { | 520 if (network->connection_state() == chromeos::STATE_READY) { |
474 if (network->restricted_pool()) { | 521 if (network->restricted_pool()) { |
475 new_state = PLAN_ACTIVATION_SHOWING_PAYMENT; | 522 new_state = PLAN_ACTIVATION_SHOWING_PAYMENT; |
476 } else { | 523 } else { |
477 new_state = PLAN_ACTIVATION_DONE; | 524 new_state = PLAN_ACTIVATION_DONE; |
478 } | 525 } |
479 } | 526 } |
480 break; | 527 break; |
481 case chromeos::ACTIVATION_STATE_PARTIALLY_ACTIVATED: | 528 case chromeos::ACTIVATION_STATE_PARTIALLY_ACTIVATED: |
482 if (network->connected()) { | 529 if (network->connected()) { |
483 if (network->restricted_pool()) | 530 if (network->restricted_pool()) |
484 new_state = PLAN_ACTIVATION_SHOWING_PAYMENT; | 531 new_state = PLAN_ACTIVATION_SHOWING_PAYMENT; |
485 } | 532 } |
486 break; | 533 break; |
487 default: | 534 default: |
488 NOTREACHED(); | |
489 break; | 535 break; |
490 } | 536 } |
491 } | 537 } |
492 break; | 538 break; |
493 case PLAN_ACTIVATION_PAGE_LOADING: | 539 case PLAN_ACTIVATION_PAGE_LOADING: |
494 break; | 540 break; |
495 // Just ignore all signals until the site confirms payment. | 541 // Just ignore all signals until the site confirms payment. |
496 case PLAN_ACTIVATION_SHOWING_PAYMENT: | 542 case PLAN_ACTIVATION_SHOWING_PAYMENT: |
497 // Activation completed/failed, ignore network changes. | 543 // Activation completed/failed, ignore network changes. |
498 case PLAN_ACTIVATION_DONE: | 544 case PLAN_ACTIVATION_DONE: |
(...skipping 29 matching lines...) Expand all Loading... |
528 } | 574 } |
529 return "UNKNOWN"; | 575 return "UNKNOWN"; |
530 } | 576 } |
531 | 577 |
532 void MobileSetupHandler::ChangeState(const chromeos::CellularNetwork* network, | 578 void MobileSetupHandler::ChangeState(const chromeos::CellularNetwork* network, |
533 PlanActivationState new_state, | 579 PlanActivationState new_state, |
534 const std::string& error_description) { | 580 const std::string& error_description) { |
535 static bool first_time = true; | 581 static bool first_time = true; |
536 if (state_ == new_state && !first_time) | 582 if (state_ == new_state && !first_time) |
537 return; | 583 return; |
538 VLOG(1) << "Activation state flip old = " << GetStateDescription(state_) | 584 VLOG(1) << "Activation state flip old = " << |
539 << ", new = " << GetStateDescription(new_state); | 585 GetStateDescription(state_) << ", new = " << |
| 586 GetStateDescription(new_state); |
540 first_time = false; | 587 first_time = false; |
541 state_ = new_state; | 588 state_ = new_state; |
542 switch (new_state) { | 589 switch (new_state) { |
543 case PLAN_ACTIVATION_START: | 590 case PLAN_ACTIVATION_START: |
| 591 DisableOtherConnections(); |
544 break; | 592 break; |
545 case PLAN_ACTIVATION_INITIATING_ACTIVATION: | 593 case PLAN_ACTIVATION_INITIATING_ACTIVATION: |
546 DCHECK(network); | 594 DCHECK(network); |
547 VLOG(1) << "Activating service " << network->service_path(); | 595 LOG(INFO) << "Activating service " << network->service_path().c_str(); |
548 if (!network->StartActivation()) | 596 if (!network->StartActivation()) |
549 new_state = PLAN_ACTIVATION_ERROR; | 597 new_state = PLAN_ACTIVATION_ERROR; |
550 break; | 598 break; |
551 case PLAN_ACTIVATION_ACTIVATING: | 599 case PLAN_ACTIVATION_ACTIVATING: |
552 DCHECK(network); | 600 DCHECK(network); |
553 if (network) { | 601 if (network) { |
554 chromeos::CrosLibrary::Get()->GetNetworkLibrary()-> | 602 chromeos::CrosLibrary::Get()->GetNetworkLibrary()-> |
555 ConnectToCellularNetwork(*network); | 603 ConnectToCellularNetwork(network); |
556 } | 604 } |
557 break; | 605 break; |
558 case PLAN_ACTIVATION_PAGE_LOADING: | 606 case PLAN_ACTIVATION_PAGE_LOADING: |
559 return; | 607 return; |
560 case PLAN_ACTIVATION_SHOWING_PAYMENT: | 608 case PLAN_ACTIVATION_SHOWING_PAYMENT: |
| 609 // Fix for fix SSL for the walled gardens where cert chain verification |
| 610 // might not work. |
| 611 net::SSLConfigService::DisallowRevChecking(); |
| 612 break; |
561 case PLAN_ACTIVATION_DONE: | 613 case PLAN_ACTIVATION_DONE: |
562 case PLAN_ACTIVATION_ERROR: | 614 case PLAN_ACTIVATION_ERROR: { |
| 615 net::SSLConfigService::AllowRevChecking(); |
| 616 // Remove observers, we are done with this page. |
| 617 chromeos::NetworkLibrary* lib = chromeos::CrosLibrary::Get()-> |
| 618 GetNetworkLibrary(); |
| 619 lib->RemoveObserver(this); |
| 620 lib->RemoveProperyObserver(this); |
| 621 // Reactivate other types of connections if we have |
| 622 // shut them down previously. |
| 623 ReEnableOtherConnections(); |
563 break; | 624 break; |
| 625 } |
564 } | 626 } |
565 | |
566 DictionaryValue device_dict; | 627 DictionaryValue device_dict; |
567 if (network) | 628 if (network) |
568 GetDeviceInfo(network, &device_dict); | 629 GetDeviceInfo(network, &device_dict); |
569 device_dict.SetInteger("state", new_state); | 630 device_dict.SetInteger("state", new_state); |
570 if (error_description.length()) | 631 if (error_description.length()) |
571 device_dict.SetString("error", error_description); | 632 device_dict.SetString("error", error_description); |
572 dom_ui_->CallJavascriptFunction( | 633 dom_ui_->CallJavascriptFunction( |
573 kJsDeviceStatusChangedHandler, device_dict); | 634 kJsDeviceStatusChangedHandler, device_dict); |
574 } | 635 } |
575 | 636 |
| 637 void MobileSetupHandler::ReEnableOtherConnections() { |
| 638 chromeos::NetworkLibrary* lib = chromeos::CrosLibrary::Get()-> |
| 639 GetNetworkLibrary(); |
| 640 if (reenable_ethernet_) { |
| 641 reenable_ethernet_ = false; |
| 642 lib->EnableEthernetNetworkDevice(true); |
| 643 } |
| 644 if (reenable_wifi_) { |
| 645 reenable_wifi_ = false; |
| 646 lib->EnableCellularNetworkDevice(true); |
| 647 } |
| 648 } |
| 649 |
| 650 void MobileSetupHandler::DisableOtherConnections() { |
| 651 chromeos::NetworkLibrary* lib = chromeos::CrosLibrary::Get()-> |
| 652 GetNetworkLibrary(); |
| 653 if (!reenable_ethernet_ && lib->ethernet_enabled()) { |
| 654 reenable_ethernet_ = true; |
| 655 lib->EnableEthernetNetworkDevice(false); |
| 656 } |
| 657 if (!reenable_wifi_ && lib->wifi_enabled()) { |
| 658 reenable_wifi_ = true; |
| 659 lib->EnableCellularNetworkDevice(false); |
| 660 } |
| 661 } |
576 | 662 |
577 bool MobileSetupHandler::GotActivationError( | 663 bool MobileSetupHandler::GotActivationError( |
578 const chromeos::CellularNetwork* network, std::string* error) { | 664 const chromeos::CellularNetwork* network, std::string* error) { |
579 if (network) | 665 if (!network) |
580 return false; | 666 return false; |
581 bool got_error = false; | 667 bool got_error = false; |
582 const char* error_code = kErrorDefault; | 668 const char* error_code = kErrorDefault; |
583 | 669 |
584 // This is the magic for detection of errors in during activation process. | 670 // This is the magic for detection of errors in during activation process. |
585 if (network->connection_state() == chromeos::STATE_FAILURE && | 671 if (network->connection_state() == chromeos::STATE_FAILURE && |
586 network->error() == chromeos::ERROR_AAA_FAILED ) { | 672 network->error() == chromeos::ERROR_AAA_FAILED ) { |
587 if (network->activation_state() == | 673 if (network->activation_state() == |
588 chromeos::ACTIVATION_STATE_PARTIALLY_ACTIVATED) { | 674 chromeos::ACTIVATION_STATE_PARTIALLY_ACTIVATED) { |
589 error_code = kErrorBadConnectionPartial; | 675 error_code = kErrorBadConnectionPartial; |
(...skipping 23 matching lines...) Expand all Loading... |
613 } | 699 } |
614 got_error = true; | 700 got_error = true; |
615 } | 701 } |
616 | 702 |
617 if (got_error) | 703 if (got_error) |
618 *error = GetErrorMessage(error_code); | 704 *error = GetErrorMessage(error_code); |
619 | 705 |
620 return got_error; | 706 return got_error; |
621 } | 707 } |
622 | 708 |
623 const chromeos::CellularNetwork* MobileSetupHandler::GetNetwork() { | |
624 chromeos::NetworkLibrary* network_lib = | |
625 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); | |
626 | |
627 const chromeos::CellularNetworkVector& cell_networks = | |
628 network_lib->cellular_networks(); | |
629 if (!cell_networks.size()) | |
630 return NULL; | |
631 return &(*(cell_networks.begin())); | |
632 } | |
633 | |
634 void MobileSetupHandler::GetDeviceInfo(const chromeos::CellularNetwork* network, | 709 void MobileSetupHandler::GetDeviceInfo(const chromeos::CellularNetwork* network, |
635 DictionaryValue* value) { | 710 DictionaryValue* value) { |
636 if (!network) | |
637 return; | |
638 value->SetString("carrier", network->name()); | 711 value->SetString("carrier", network->name()); |
639 value->SetString("payment_url", network->payment_url()); | 712 value->SetString("payment_url", network->payment_url()); |
640 value->SetString("MEID", network->meid()); | 713 value->SetString("MEID", network->meid()); |
641 value->SetString("IMEI", network->imei()); | 714 value->SetString("IMEI", network->imei()); |
642 value->SetString("MDN", network->mdn()); | 715 value->SetString("MDN", network->mdn()); |
643 } | 716 } |
644 | 717 |
645 std::string MobileSetupHandler::GetErrorMessage(const std::string& code) { | 718 std::string MobileSetupHandler::GetErrorMessage(const std::string& code) { |
646 if (!cellular_config_.get()) | 719 if (!cellular_config_.get()) |
647 return ""; | 720 return ""; |
648 return cellular_config_->GetErrorMessage(code); | 721 return cellular_config_->GetErrorMessage(code); |
649 } | 722 } |
650 | 723 |
651 void MobileSetupHandler::LoadCellularConfig() { | 724 void MobileSetupHandler::LoadCellularConfig() { |
652 static bool config_loaded = false; | 725 static bool config_loaded = false; |
653 if (config_loaded) | 726 if (config_loaded) |
654 return; | 727 return; |
655 config_loaded = true; | 728 config_loaded = true; |
656 // Load partner customization startup manifest if it is available. | 729 // Load partner customization startup manifest if it is available. |
657 FilePath config_path(kCellularConfigPath); | 730 FilePath config_path(kCellularConfigPath); |
658 if (file_util::PathExists(config_path)) { | 731 if (file_util::PathExists(config_path)) { |
659 scoped_ptr<CellularConfigDocument> config(new CellularConfigDocument()); | 732 scoped_ptr<CellularConfigDocument> config(new CellularConfigDocument()); |
660 bool config_loaded = config->LoadFromFile(config_path); | 733 bool config_loaded = config->LoadFromFile(config_path); |
661 if (config_loaded) { | 734 if (config_loaded) { |
662 VLOG(1) << "Cellular config file loaded: " << kCellularConfigPath; | 735 LOG(INFO) << "Cellular config file loaded: " << kCellularConfigPath; |
663 // lock | 736 // lock |
664 cellular_config_.reset(config.release()); | 737 cellular_config_.reset(config.release()); |
665 } else { | 738 } else { |
666 LOG(ERROR) << "Error loading cellular config file: " << | 739 LOG(ERROR) << "Error loading cellular config file: " << |
667 kCellularConfigPath; | 740 kCellularConfigPath; |
668 } | 741 } |
669 } | 742 } |
670 } | 743 } |
671 | 744 |
672 | 745 |
673 //////////////////////////////////////////////////////////////////////////////// | 746 //////////////////////////////////////////////////////////////////////////////// |
674 // | 747 // |
675 // MobileSetupUI | 748 // MobileSetupUI |
676 // | 749 // |
677 //////////////////////////////////////////////////////////////////////////////// | 750 //////////////////////////////////////////////////////////////////////////////// |
678 | 751 |
679 MobileSetupUI::MobileSetupUI(TabContents* contents) : DOMUI(contents){ | 752 MobileSetupUI::MobileSetupUI(TabContents* contents) : DOMUI(contents){ |
680 MobileSetupHandler* handler = new MobileSetupHandler(); | 753 const chromeos::CellularNetwork* network = GetCellularNetwork(); |
| 754 std::string service_path = network ? network->service_path() : std::string(); |
| 755 MobileSetupHandler* handler = new MobileSetupHandler(service_path); |
681 AddMessageHandler((handler)->Attach(this)); | 756 AddMessageHandler((handler)->Attach(this)); |
682 handler->Init(contents); | 757 handler->Init(contents); |
683 MobileSetupUIHTMLSource* html_source = new MobileSetupUIHTMLSource(); | 758 MobileSetupUIHTMLSource* html_source = |
| 759 new MobileSetupUIHTMLSource(service_path); |
684 | 760 |
685 // Set up the chrome://mobilesetup/ source. | 761 // Set up the chrome://mobilesetup/ source. |
686 BrowserThread::PostTask( | 762 BrowserThread::PostTask( |
687 BrowserThread::IO, FROM_HERE, | 763 BrowserThread::IO, FROM_HERE, |
688 NewRunnableMethod( | 764 NewRunnableMethod( |
689 Singleton<ChromeURLDataManager>::get(), | 765 Singleton<ChromeURLDataManager>::get(), |
690 &ChromeURLDataManager::AddDataSource, | 766 &ChromeURLDataManager::AddDataSource, |
691 make_scoped_refptr(html_source))); | 767 make_scoped_refptr(html_source))); |
692 } | 768 } |
OLD | NEW |