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/internet_options_handler.h" | 5 #include "chrome/browser/chromeos/dom_ui/internet_options_handler.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
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/base64.h" | 12 #include "base/base64.h" |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
14 #include "base/callback.h" | 14 #include "base/callback.h" |
15 #include "base/i18n/time_formatting.h" | 15 #include "base/i18n/time_formatting.h" |
16 #include "base/string16.h" | 16 #include "base/string16.h" |
17 #include "base/string_number_conversions.h" | 17 #include "base/string_number_conversions.h" |
18 #include "base/time.h" | 18 #include "base/time.h" |
19 #include "base/utf_string_conversions.h" | 19 #include "base/utf_string_conversions.h" |
20 #include "base/values.h" | 20 #include "base/values.h" |
21 #include "chrome/browser/browser.h" | 21 #include "chrome/browser/browser.h" |
22 #include "chrome/browser/browser_list.h" | 22 #include "chrome/browser/browser_list.h" |
23 #include "chrome/browser/browser_window.h" | 23 #include "chrome/browser/browser_window.h" |
24 #include "chrome/browser/chromeos/cros/cros_library.h" | 24 #include "chrome/browser/chromeos/cros/cros_library.h" |
25 #include "chrome/browser/chromeos/status/network_menu.h" | 25 #include "chrome/browser/chromeos/status/network_menu.h" |
| 26 #include "chrome/browser/chromeos/network_message_observer.h" |
26 #include "chrome/browser/dom_ui/dom_ui_util.h" | 27 #include "chrome/browser/dom_ui/dom_ui_util.h" |
27 #include "chrome/browser/tab_contents/tab_contents.h" | 28 #include "chrome/browser/tab_contents/tab_contents.h" |
28 #include "chrome/browser/tab_contents/tab_contents_view.h" | 29 #include "chrome/browser/tab_contents/tab_contents_view.h" |
29 #include "chrome/common/notification_service.h" | 30 #include "chrome/common/notification_service.h" |
30 #include "chrome/common/time_format.h" | 31 #include "chrome/common/time_format.h" |
31 #include "grit/browser_resources.h" | 32 #include "grit/browser_resources.h" |
32 #include "grit/chromium_strings.h" | 33 #include "grit/chromium_strings.h" |
33 #include "grit/generated_resources.h" | 34 #include "grit/generated_resources.h" |
34 #include "grit/locale_settings.h" | 35 #include "grit/locale_settings.h" |
35 #include "grit/theme_resources.h" | 36 #include "grit/theme_resources.h" |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 dictionary.Set("rememberedList", GetRememberedList()); | 319 dictionary.Set("rememberedList", GetRememberedList()); |
319 dictionary.SetBoolean("wifiAvailable", cros->wifi_available()); | 320 dictionary.SetBoolean("wifiAvailable", cros->wifi_available()); |
320 dictionary.SetBoolean("wifiEnabled", cros->wifi_enabled()); | 321 dictionary.SetBoolean("wifiEnabled", cros->wifi_enabled()); |
321 dictionary.SetBoolean("cellularAvailable", cros->cellular_available()); | 322 dictionary.SetBoolean("cellularAvailable", cros->cellular_available()); |
322 dictionary.SetBoolean("cellularEnabled", cros->cellular_enabled()); | 323 dictionary.SetBoolean("cellularEnabled", cros->cellular_enabled()); |
323 dom_ui_->CallJavascriptFunction( | 324 dom_ui_->CallJavascriptFunction( |
324 L"options.InternetOptions.refreshNetworkData", dictionary); | 325 L"options.InternetOptions.refreshNetworkData", dictionary); |
325 } | 326 } |
326 | 327 |
327 void InternetOptionsHandler::CellularDataPlanChanged( | 328 void InternetOptionsHandler::CellularDataPlanChanged( |
328 chromeos::NetworkLibrary* obj) { | 329 const std::string& service_path, |
| 330 const chromeos::CellularDataPlanList& plans) { |
329 if (!dom_ui_) | 331 if (!dom_ui_) |
330 return; | 332 return; |
331 const chromeos::CellularNetwork cellular = obj->cellular_network(); | |
332 const chromeos::CellularDataPlanList& plans = cellular.GetDataPlans(); | |
333 DictionaryValue connection_plans; | 333 DictionaryValue connection_plans; |
334 ListValue* plan_list = new ListValue(); | 334 ListValue* plan_list = new ListValue(); |
335 for (chromeos::CellularDataPlanList::const_iterator iter = plans.begin(); | 335 for (chromeos::CellularDataPlanList::const_iterator iter = plans.begin(); |
336 iter != plans.end(); | 336 iter != plans.end(); |
337 ++iter) { | 337 ++iter) { |
338 plan_list->Append(CellularDataPlanToDictionary(*iter)); | 338 plan_list->Append(CellularDataPlanToDictionary(*iter)); |
339 } | 339 } |
340 connection_plans.SetString("servicePath", cellular.service_path()); | 340 connection_plans.SetString("servicePath", service_path); |
341 connection_plans.Set("plans", plan_list); | 341 connection_plans.Set("plans", plan_list); |
342 dom_ui_->CallJavascriptFunction( | 342 dom_ui_->CallJavascriptFunction( |
343 L"options.InternetOptions.updateCellularPlans", connection_plans); | 343 L"options.InternetOptions.updateCellularPlans", connection_plans); |
344 } | 344 } |
345 | 345 |
346 DictionaryValue* InternetOptionsHandler::CellularDataPlanToDictionary( | 346 DictionaryValue* InternetOptionsHandler::CellularDataPlanToDictionary( |
347 const chromeos::CellularDataPlan& plan) { | 347 const chromeos::CellularDataPlan& plan) { |
348 | 348 |
349 DictionaryValue* plan_dict = new DictionaryValue(); | 349 DictionaryValue* plan_dict = new DictionaryValue(); |
350 plan_dict->SetInteger("plan_type", plan.plan_type); | 350 plan_dict->SetInteger("plan_type", plan.plan_type); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 } | 409 } |
410 | 410 |
411 string16 InternetOptionsHandler::GetPlanWarning( | 411 string16 InternetOptionsHandler::GetPlanWarning( |
412 const chromeos::CellularDataPlan& plan) { | 412 const chromeos::CellularDataPlan& plan) { |
413 if (plan.plan_type == chromeos::CELLULAR_DATA_PLAN_UNLIMITED) { | 413 if (plan.plan_type == chromeos::CELLULAR_DATA_PLAN_UNLIMITED) { |
414 // Time based plan. Show nearing expiration and data expiration. | 414 // Time based plan. Show nearing expiration and data expiration. |
415 int64 time_left = plan.plan_end_time - plan.update_time; | 415 int64 time_left = plan.plan_end_time - plan.update_time; |
416 if (time_left <= 0) { | 416 if (time_left <= 0) { |
417 return l10n_util::GetStringFUTF16( | 417 return l10n_util::GetStringFUTF16( |
418 IDS_NETWORK_MINUTES_REMAINING_MESSAGE, ASCIIToUTF16("0")); | 418 IDS_NETWORK_MINUTES_REMAINING_MESSAGE, ASCIIToUTF16("0")); |
419 } else if (time_left <= chromeos::kCellularDataVeryLowSecs) { | 419 } else if (time_left <= chromeos::kDataNearingExpirationSecs) { |
420 return l10n_util::GetStringFUTF16( | 420 return l10n_util::GetStringFUTF16( |
421 IDS_NETWORK_MINUTES_UNTIL_EXPIRATION_MESSAGE, | 421 IDS_NETWORK_MINUTES_UNTIL_EXPIRATION_MESSAGE, |
422 UTF8ToUTF16(base::Int64ToString(time_left/60))); | 422 UTF8ToUTF16(base::Int64ToString(time_left/60))); |
423 } | 423 } |
424 } else if (plan.plan_type == chromeos::CELLULAR_DATA_PLAN_METERED_PAID || | 424 } else if (plan.plan_type == chromeos::CELLULAR_DATA_PLAN_METERED_PAID || |
425 plan.plan_type == chromeos::CELLULAR_DATA_PLAN_METERED_BASE) { | 425 plan.plan_type == chromeos::CELLULAR_DATA_PLAN_METERED_BASE) { |
426 // Metered plan. Show low data and out of data. | 426 // Metered plan. Show low data and out of data. |
427 int64 bytes_remaining = plan.plan_data_bytes - plan.data_bytes_used; | 427 int64 bytes_remaining = plan.plan_data_bytes - plan.data_bytes_used; |
428 if (bytes_remaining <= 0) { | 428 if (bytes_remaining <= 0) { |
429 return l10n_util::GetStringFUTF16( | 429 return l10n_util::GetStringFUTF16( |
430 IDS_NETWORK_DATA_REMAINING_MESSAGE, ASCIIToUTF16("0")); | 430 IDS_NETWORK_DATA_REMAINING_MESSAGE, ASCIIToUTF16("0")); |
431 } else if (bytes_remaining <= chromeos::kCellularDataVeryLowBytes) { | 431 } else if (bytes_remaining <= chromeos::kDataLowDataBytes) { |
432 return l10n_util::GetStringFUTF16( | 432 return l10n_util::GetStringFUTF16( |
433 IDS_NETWORK_DATA_REMAINING_MESSAGE, | 433 IDS_NETWORK_DATA_REMAINING_MESSAGE, |
434 UTF8ToUTF16(base::Int64ToString(bytes_remaining/(1024*1024)))); | 434 UTF8ToUTF16(base::Int64ToString(bytes_remaining/1024))); |
435 } | 435 } |
436 } | 436 } |
437 return string16(); | 437 return string16(); |
438 } | 438 } |
439 | 439 |
440 void InternetOptionsHandler::SetDetailsCallback(const ListValue* args) { | 440 void InternetOptionsHandler::SetDetailsCallback(const ListValue* args) { |
441 | 441 |
442 std::string service_path; | 442 std::string service_path; |
443 | 443 |
444 if (!args->GetString(0, &service_path)) { | 444 if (!args->GetString(0, &service_path)) { |
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
943 icon, | 943 icon, |
944 it->name(), | 944 it->name(), |
945 it->connecting(), | 945 it->connecting(), |
946 it->connected(), | 946 it->connected(), |
947 chromeos::TYPE_CELLULAR, | 947 chromeos::TYPE_CELLULAR, |
948 true)); | 948 true)); |
949 } | 949 } |
950 | 950 |
951 return list; | 951 return list; |
952 } | 952 } |
OLD | NEW |