| 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/chromeos/status/network_menu_button.h" | 5 #include "chrome/browser/chromeos/status/network_menu_button.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
| 14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
| 15 #include "base/stringprintf.h" | 15 #include "base/stringprintf.h" |
| 16 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
| 17 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
| 18 #include "chrome/browser/chromeos/cros/cros_library.h" | 18 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 19 #include "chrome/browser/chromeos/login/base_login_display_host.h" | 19 #include "chrome/browser/chromeos/login/base_login_display_host.h" |
| 20 #include "chrome/browser/chromeos/login/helper.h" | 20 #include "chrome/browser/chromeos/login/helper.h" |
| 21 #include "chrome/browser/chromeos/login/user_manager.h" | 21 #include "chrome/browser/chromeos/login/user_manager.h" |
| 22 #include "chrome/browser/chromeos/options/network_config_view.h" | 22 #include "chrome/browser/chromeos/options/network_config_view.h" |
| 23 #include "chrome/browser/chromeos/sim_dialog_delegate.h" | 23 #include "chrome/browser/chromeos/sim_dialog_delegate.h" |
| 24 #include "chrome/browser/chromeos/status/status_area_view_chromeos.h" | 24 #include "chrome/browser/chromeos/status/status_area_view_chromeos.h" |
| 25 #include "chrome/browser/chromeos/view_ids.h" | 25 #include "chrome/browser/chromeos/view_ids.h" |
| 26 #include "chrome/browser/prefs/pref_service.h" | 26 #include "chrome/browser/prefs/pref_service.h" |
| 27 #include "chrome/browser/profiles/profile.h" | 27 #include "chrome/browser/profiles/profile.h" |
| 28 #include "chrome/browser/ui/browser.h" | 28 #include "chrome/browser/ui/browser.h" |
| 29 #include "chrome/browser/ui/browser_list.h" | 29 #include "chrome/browser/ui/browser_list.h" |
| 30 #include "chrome/browser/ui/views/window.h" |
| 30 #include "chrome/common/pref_names.h" | 31 #include "chrome/common/pref_names.h" |
| 31 #include "grit/generated_resources.h" | 32 #include "grit/generated_resources.h" |
| 32 #include "grit/theme_resources.h" | 33 #include "grit/theme_resources.h" |
| 33 #include "ui/base/l10n/l10n_util.h" | 34 #include "ui/base/l10n/l10n_util.h" |
| 34 #include "ui/base/resource/resource_bundle.h" | 35 #include "ui/base/resource/resource_bundle.h" |
| 35 #include "ui/views/widget/widget.h" | 36 #include "ui/views/widget/widget.h" |
| 36 | 37 |
| 37 namespace { | 38 namespace { |
| 38 | 39 |
| 39 // Time in milliseconds to delay showing of promo | 40 // Time in milliseconds to delay showing of promo |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 } | 123 } |
| 123 | 124 |
| 124 NetworkMenuButton::~NetworkMenuButton() { | 125 NetworkMenuButton::~NetworkMenuButton() { |
| 125 NetworkLibrary* netlib = CrosLibrary::Get()->GetNetworkLibrary(); | 126 NetworkLibrary* netlib = CrosLibrary::Get()->GetNetworkLibrary(); |
| 126 netlib->RemoveNetworkManagerObserver(this); | 127 netlib->RemoveNetworkManagerObserver(this); |
| 127 netlib->RemoveObserverForAllNetworks(this); | 128 netlib->RemoveObserverForAllNetworks(this); |
| 128 netlib->RemoveCellularDataPlanObserver(this); | 129 netlib->RemoveCellularDataPlanObserver(this); |
| 129 if (!cellular_device_path_.empty()) | 130 if (!cellular_device_path_.empty()) |
| 130 netlib->RemoveNetworkDeviceObserver(cellular_device_path_, this); | 131 netlib->RemoveNetworkDeviceObserver(cellular_device_path_, this); |
| 131 if (mobile_data_bubble_) | 132 if (mobile_data_bubble_) |
| 132 mobile_data_bubble_->Close(); | 133 mobile_data_bubble_->GetWidget()->Close(); |
| 133 } | 134 } |
| 134 | 135 |
| 135 // static | 136 // static |
| 136 void NetworkMenuButton::RegisterPrefs(PrefService* local_state) { | 137 void NetworkMenuButton::RegisterPrefs(PrefService* local_state) { |
| 137 // Carrier deal notification shown count defaults to 0. | 138 // Carrier deal notification shown count defaults to 0. |
| 138 local_state->RegisterIntegerPref(prefs::kCarrierDealPromoShown, 0); | 139 local_state->RegisterIntegerPref(prefs::kCarrierDealPromoShown, 0); |
| 139 } | 140 } |
| 140 | 141 |
| 141 //////////////////////////////////////////////////////////////////////////////// | 142 //////////////////////////////////////////////////////////////////////////////// |
| 142 // NetworkLibrary::NetworkDeviceObserver implementation: | 143 // NetworkLibrary::NetworkDeviceObserver implementation: |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 | 232 |
| 232 //////////////////////////////////////////////////////////////////////////////// | 233 //////////////////////////////////////////////////////////////////////////////// |
| 233 // NetworkMenuButton, NetworkMenuIcon::Delegate implementation: | 234 // NetworkMenuButton, NetworkMenuIcon::Delegate implementation: |
| 234 void NetworkMenuButton::NetworkMenuIconChanged() { | 235 void NetworkMenuButton::NetworkMenuIconChanged() { |
| 235 const SkBitmap bitmap = network_icon_->GetIconAndText(NULL); | 236 const SkBitmap bitmap = network_icon_->GetIconAndText(NULL); |
| 236 SetIcon(bitmap); | 237 SetIcon(bitmap); |
| 237 SchedulePaint(); | 238 SchedulePaint(); |
| 238 } | 239 } |
| 239 | 240 |
| 240 //////////////////////////////////////////////////////////////////////////////// | 241 //////////////////////////////////////////////////////////////////////////////// |
| 241 // MessageBubbleDelegate implementation: | 242 // views::Widget::Observer implementation: |
| 242 | 243 |
| 243 void NetworkMenuButton::BubbleClosing(Bubble* bubble, bool closed_by_escape) { | 244 void NetworkMenuButton::OnWidgetClosing(views::Widget* widget) { |
| 245 if (!mobile_data_bubble_ || mobile_data_bubble_->GetWidget() != widget) |
| 246 return; |
| 247 |
| 244 mobile_data_bubble_ = NULL; | 248 mobile_data_bubble_ = NULL; |
| 245 deal_info_url_.clear(); | 249 deal_info_url_.clear(); |
| 246 deal_topup_url_.clear(); | 250 deal_topup_url_.clear(); |
| 247 } | 251 } |
| 248 | 252 |
| 249 bool NetworkMenuButton::CloseOnEscape() { | 253 //////////////////////////////////////////////////////////////////////////////// |
| 250 return true; | 254 // MessageBubbleLinkListener implementation: |
| 251 } | |
| 252 | |
| 253 bool NetworkMenuButton::FadeInOnShow() { | |
| 254 return false; | |
| 255 } | |
| 256 | 255 |
| 257 void NetworkMenuButton::OnLinkActivated(size_t index) { | 256 void NetworkMenuButton::OnLinkActivated(size_t index) { |
| 258 // If we have deal info URL defined that means that there're | 257 // If we have deal info URL defined that means that there're |
| 259 // 2 links in bubble. Let the user close it manually then thus giving ability | 258 // 2 links in bubble. Let the user close it manually then thus giving ability |
| 260 // to navigate to second link. | 259 // to navigate to second link. |
| 261 // mobile_data_bubble_ will be set to NULL in BubbleClosing callback. | 260 // mobile_data_bubble_ will be set to NULL in BubbleClosing callback. |
| 262 if (deal_info_url_.empty() && mobile_data_bubble_) | 261 if (deal_info_url_.empty() && mobile_data_bubble_) |
| 263 mobile_data_bubble_->Close(); | 262 mobile_data_bubble_->GetWidget()->Close(); |
| 264 | 263 |
| 265 std::string deal_url_to_open; | 264 std::string deal_url_to_open; |
| 266 if (index == 0) { | 265 if (index == 0) { |
| 267 if (!deal_topup_url_.empty()) { | 266 if (!deal_topup_url_.empty()) { |
| 268 deal_url_to_open = deal_topup_url_; | 267 deal_url_to_open = deal_topup_url_; |
| 269 } else { | 268 } else { |
| 270 const Network* cellular = | 269 const Network* cellular = |
| 271 CrosLibrary::Get()->GetNetworkLibrary()->cellular_network(); | 270 CrosLibrary::Get()->GetNetworkLibrary()->cellular_network(); |
| 272 if (!cellular) | 271 if (!cellular) |
| 273 return; | 272 return; |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 base::Bind( | 402 base::Bind( |
| 404 &NetworkMenuButton::ShowOptionalMobileDataPromoNotification, | 403 &NetworkMenuButton::ShowOptionalMobileDataPromoNotification, |
| 405 weak_ptr_factory_.GetWeakPtr(), | 404 weak_ptr_factory_.GetWeakPtr(), |
| 406 cros), | 405 cros), |
| 407 kPromoShowDelayMs); | 406 kPromoShowDelayMs); |
| 408 } | 407 } |
| 409 return; | 408 return; |
| 410 } | 409 } |
| 411 | 410 |
| 412 // Add deal text if it's defined. | 411 // Add deal text if it's defined. |
| 413 std::wstring notification_text; | 412 string16 notification_text; |
| 414 std::wstring default_text = | 413 string16 default_text = |
| 415 UTF16ToWide(l10n_util::GetStringUTF16(IDS_3G_NOTIFICATION_MESSAGE)); | 414 l10n_util::GetStringUTF16(IDS_3G_NOTIFICATION_MESSAGE); |
| 416 if (!deal_text.empty()) { | 415 if (!deal_text.empty()) { |
| 417 notification_text = StringPrintf(L"%ls\n\n%ls", | 416 notification_text = |
| 418 UTF8ToWide(deal_text).c_str(), | 417 UTF8ToUTF16(deal_text) + UTF8ToUTF16("\n\n") + default_text; |
| 419 default_text.c_str()); | |
| 420 } else { | 418 } else { |
| 421 notification_text = default_text; | 419 notification_text = default_text; |
| 422 } | 420 } |
| 423 | 421 |
| 424 // Use deal URL if it's defined or general "Network Settings" URL. | 422 // Use deal URL if it's defined or general "Network Settings" URL. |
| 425 int link_message_id; | 423 int link_message_id; |
| 426 if (deal_topup_url_.empty()) | 424 if (deal_topup_url_.empty()) |
| 427 link_message_id = IDS_OFFLINE_NETWORK_SETTINGS; | 425 link_message_id = IDS_OFFLINE_NETWORK_SETTINGS; |
| 428 else | 426 else |
| 429 link_message_id = IDS_STATUSBAR_NETWORK_VIEW_ACCOUNT; | 427 link_message_id = IDS_STATUSBAR_NETWORK_VIEW_ACCOUNT; |
| 430 | 428 |
| 431 std::vector<std::wstring> links; | 429 std::vector<string16> links; |
| 432 links.push_back(UTF16ToWide(l10n_util::GetStringUTF16(link_message_id))); | 430 links.push_back(l10n_util::GetStringUTF16(link_message_id)); |
| 433 if (!deal_info_url_.empty()) | 431 if (!deal_info_url_.empty()) |
| 434 links.push_back(UTF16ToWide(l10n_util::GetStringUTF16(IDS_LEARN_MORE))); | 432 links.push_back(l10n_util::GetStringUTF16(IDS_LEARN_MORE)); |
| 435 mobile_data_bubble_ = MessageBubble::ShowWithLinks( | 433 mobile_data_bubble_ = new MessageBubble( |
| 436 GetWidget(), | 434 this, |
| 437 button_bounds, | 435 views::BubbleBorder::TOP_RIGHT, |
| 438 views::BubbleBorder::TOP_RIGHT , | |
| 439 ResourceBundle::GetSharedInstance().GetBitmapNamed(IDR_NOTIFICATION_3G), | 436 ResourceBundle::GetSharedInstance().GetBitmapNamed(IDR_NOTIFICATION_3G), |
| 440 notification_text, | 437 notification_text, |
| 441 links, | 438 links); |
| 442 this); | 439 mobile_data_bubble_->set_link_listener(this); |
| 440 browser::CreateViewsBubbleAboveLockScreen(mobile_data_bubble_); |
| 441 mobile_data_bubble_->Show(); |
| 442 mobile_data_bubble_->GetWidget()->AddObserver(this); |
| 443 | 443 |
| 444 check_for_promo_ = false; | 444 check_for_promo_ = false; |
| 445 SetShow3gPromoNotification(false); | 445 SetShow3gPromoNotification(false); |
| 446 if (carrier_deal_promo_pref != kNotificationCountPrefDefault) | 446 if (carrier_deal_promo_pref != kNotificationCountPrefDefault) |
| 447 SetCarrierDealPromoShown(carrier_deal_promo_pref + 1); | 447 SetCarrierDealPromoShown(carrier_deal_promo_pref + 1); |
| 448 } | 448 } |
| 449 } | 449 } |
| 450 | 450 |
| 451 void NetworkMenuButton::SetTooltipAndAccessibleName(const string16& label) { | 451 void NetworkMenuButton::SetTooltipAndAccessibleName(const string16& label) { |
| 452 SetTooltipText(label); | 452 SetTooltipText(label); |
| 453 SetAccessibleName(label); | 453 SetAccessibleName(label); |
| 454 } | 454 } |
| 455 | 455 |
| 456 } // namespace chromeos | 456 } // namespace chromeos |
| OLD | NEW |