diff options
-rw-r--r-- | chrome/app/theme/notification_3g.png | bin | 0 -> 1613 bytes | |||
-rw-r--r-- | chrome/app/theme/theme_resources.grd | 1 | ||||
-rw-r--r-- | chrome/browser/chromeos/cros/cros_mock.cc | 4 | ||||
-rw-r--r-- | chrome/browser/chromeos/login/network_screen_browsertest.cc | 3 | ||||
-rw-r--r-- | chrome/browser/chromeos/login/user_manager.cc | 2 | ||||
-rw-r--r-- | chrome/browser/chromeos/preferences.cc | 3 | ||||
-rw-r--r-- | chrome/browser/chromeos/status/network_menu.cc | 32 | ||||
-rw-r--r-- | chrome/browser/chromeos/status/network_menu.h | 7 | ||||
-rw-r--r-- | chrome/browser/chromeos/status/network_menu_button.cc | 110 | ||||
-rw-r--r-- | chrome/browser/chromeos/status/network_menu_button.h | 22 | ||||
-rw-r--r-- | chrome/browser/sync/glue/synchronized_preferences.h | 4 | ||||
-rw-r--r-- | chrome/common/pref_names.cc | 4 | ||||
-rw-r--r-- | chrome/common/pref_names.h | 1 |
13 files changed, 168 insertions, 25 deletions
diff --git a/chrome/app/theme/notification_3g.png b/chrome/app/theme/notification_3g.png Binary files differnew file mode 100644 index 0000000..cf0bdd1 --- /dev/null +++ b/chrome/app/theme/notification_3g.png diff --git a/chrome/app/theme/theme_resources.grd b/chrome/app/theme/theme_resources.grd index 496c3ce..e2e79528 100644 --- a/chrome/app/theme/theme_resources.grd +++ b/chrome/app/theme/theme_resources.grd @@ -462,6 +462,7 @@ <include name="IDR_LOGIN_GUEST" file="login_guest.png" type="BINDATA" /> <include name="IDR_LOGIN_ADD_USER" file="login_add_user.png" type="BINDATA" /> <include name="IDR_LOGIN_ADD_USER_HOVER" file="login_add_user_hover.png" type="BINDATA" /> + <include name="IDR_NOTIFICATION_3G" file="notification_sms.png" type="BINDATA" /> <include name="IDR_NOTIFICATION_BARS_EMPTY" file="notification_bars_empty.png" type="BINDATA" /> <include name="IDR_NOTIFICATION_BARS_CRITICAL" file="notification_bars_critical.png" type="BINDATA" /> <include name="IDR_NOTIFICATION_LOCALE_CHANGE" file="notification_locale_change.png" type="BINDATA" /> diff --git a/chrome/browser/chromeos/cros/cros_mock.cc b/chrome/browser/chromeos/cros/cros_mock.cc index be8fab3..bcd24fc 100644 --- a/chrome/browser/chromeos/cros/cros_mock.cc +++ b/chrome/browser/chromeos/cros/cros_mock.cc @@ -285,6 +285,10 @@ void CrosMock::SetNetworkLibraryStatusAreaExpectations() { .Times(AnyNumber()) .WillRepeatedly((Return(false))) .RetiresOnSaturation(); + EXPECT_CALL(*mock_network_library_, cellular_connected()) + .Times(AnyNumber()) + .WillRepeatedly((Return(false))) + .RetiresOnSaturation(); // NetworkMenu::InitMenuItems() calls: EXPECT_CALL(*mock_network_library_, IsLocked()) diff --git a/chrome/browser/chromeos/login/network_screen_browsertest.cc b/chrome/browser/chromeos/login/network_screen_browsertest.cc index b017147..9be51ab 100644 --- a/chrome/browser/chromeos/login/network_screen_browsertest.cc +++ b/chrome/browser/chromeos/login/network_screen_browsertest.cc @@ -73,9 +73,6 @@ class NetworkScreenTest : public WizardInProcessBrowserTest { EXPECT_CALL(*mock_network_library_, wifi_connected()) .Times(1) .WillRepeatedly(Return(false)); - EXPECT_CALL(*mock_network_library_, cellular_connected()) - .Times(1) - .WillRepeatedly(Return(false)); EXPECT_CALL(*mock_network_library_, FindWifiDevice()) .Times(AnyNumber()); EXPECT_CALL(*mock_network_library_, FindEthernetDevice()) diff --git a/chrome/browser/chromeos/login/user_manager.cc b/chrome/browser/chromeos/login/user_manager.cc index 6c18822..483cb8c 100644 --- a/chrome/browser/chromeos/login/user_manager.cc +++ b/chrome/browser/chromeos/login/user_manager.cc @@ -517,7 +517,7 @@ void UserManager::OnImageLoaded(const std::string& username, } bool UserManager::IsLoggedInAsGuest() const { - return logged_in_user().email() == kGuestUser; + return user_is_logged_in() && logged_in_user().email() == kGuestUser; } // Private constructor and destructor. Do nothing. diff --git a/chrome/browser/chromeos/preferences.cc b/chrome/browser/chromeos/preferences.cc index 6ae904f..c0b5588 100644 --- a/chrome/browser/chromeos/preferences.cc +++ b/chrome/browser/chromeos/preferences.cc @@ -127,6 +127,9 @@ void Preferences::RegisterUserPrefs(PrefService* prefs) { // Mobile plan notifications default to on. prefs->RegisterBooleanPref(prefs::kShowPlanNotifications, true); + + // 3G first-time usage promo will be shown at least once. + prefs->RegisterBooleanPref(prefs::kShow3gPromoNotification, true); } void Preferences::Init(PrefService* prefs) { diff --git a/chrome/browser/chromeos/status/network_menu.cc b/chrome/browser/chromeos/status/network_menu.cc index b638fe9..34cbfad 100644 --- a/chrome/browser/chromeos/status/network_menu.cc +++ b/chrome/browser/chromeos/status/network_menu.cc @@ -93,7 +93,7 @@ bool NetworkMenuModel::ConnectToNetworkAt(int index, wifi->SetAutoConnect(auto_connect ? true : false); if (wifi->connecting_or_connected()) { // Show the config settings for the active network. - ShowTabbedNetworkSettings(wifi); + owner_->ShowTabbedNetworkSettings(wifi); return true; } if (wifi->IsPassphraseRequired()) { @@ -125,7 +125,7 @@ bool NetworkMenuModel::ConnectToNetworkAt(int index, } else if (cellular->connecting_or_connected()) { // Cellular network is connecting or connected, // so we show the config settings for the cellular network. - ShowTabbedNetworkSettings(cellular); + owner_->ShowTabbedNetworkSettings(cellular); return true; } // Clicked on a disconnected cellular network, so connect to it. @@ -150,7 +150,7 @@ bool NetworkMenuModel::ConnectToNetworkAt(int index, if (vpn->connecting_or_connected()) { // Show the config settings for the connected network. if (cros->connected_network()) - ShowTabbedNetworkSettings(cros->connected_network()); + owner_->ShowTabbedNetworkSettings(cros->connected_network()); return true; } // Show the connection UI if info for a field is missing. @@ -245,7 +245,7 @@ void NetworkMenuModel::ActivatedAt(int index) { cros->EnableOfflineMode(!cros->offline_mode()); } else if (flags & FLAG_ETHERNET) { if (cros->ethernet_connected()) { - ShowTabbedNetworkSettings(cros->ethernet_network()); + owner_->ShowTabbedNetworkSettings(cros->ethernet_network()); } } else if (flags & (FLAG_WIFI | FLAG_ADD_WIFI | FLAG_CELLULAR | FLAG_ADD_CELLULAR | @@ -261,18 +261,6 @@ void NetworkMenuModel::ActivatedAt(int index) { //////////////////////////////////////////////////////////////////////////////// // NetworkMenuModel, private methods: -void NetworkMenuModel::ShowTabbedNetworkSettings(const Network* network) const { - DCHECK(network); - Browser* browser = BrowserList::GetLastActive(); - if (!browser) - return; - std::string page = StringPrintf("%s?servicePath=%s&networkType=%d", - chrome::kInternetOptionsSubPage, - EscapeUrlEncodedData(network->service_path()).c_str(), - network->type()); - browser->ShowOptionsTab(page); -} - // TODO(stevenjb): deprecate this once we've committed to tabbed settings // and the embedded menu UI (and fully deprecated NetworkConfigView). // Meanwhile, if MenuUI::IsEnabled() is true, always show the settings UI, @@ -1050,6 +1038,18 @@ SkBitmap NetworkMenu::IconForDisplay(const SkBitmap* icon, return canvas.ExtractBitmap(); } +void NetworkMenu::ShowTabbedNetworkSettings(const Network* network) const { + DCHECK(network); + Browser* browser = BrowserList::GetLastActive(); + if (!browser) + return; + std::string page = StringPrintf("%s?servicePath=%s&networkType=%d", + chrome::kInternetOptionsSubPage, + EscapeUrlEncodedData(network->service_path()).c_str(), + network->type()); + browser->ShowOptionsTab(page); +} + //////////////////////////////////////////////////////////////////////////////// // NetworkMenu, views::ViewMenuDelegate implementation: diff --git a/chrome/browser/chromeos/status/network_menu.h b/chrome/browser/chromeos/status/network_menu.h index 893bdbc..fc80127 100644 --- a/chrome/browser/chromeos/status/network_menu.h +++ b/chrome/browser/chromeos/status/network_menu.h @@ -144,9 +144,6 @@ class NetworkMenuModel : public ui::MenuModel { NetworkMenu* owner_; // Weak pointer to NetworkMenu that owns this MenuModel. private: - // Shows network details in Web UI options window. - void ShowTabbedNetworkSettings(const Network* network) const; - // Show a NetworkConfigView modal dialog instance. void ShowNetworkConfigView(NetworkConfigView* view) const; @@ -260,6 +257,10 @@ class NetworkMenu : public views::ViewMenuDelegate { // Notify subclasses that connection to |network| was initiated. virtual void OnConnectNetwork(const Network* network, SkBitmap selected_icon_) {} + + // Shows network details in Web UI options window. + void ShowTabbedNetworkSettings(const Network* network) const; + // Update the menu (e.g. when the network list or status has changed). void UpdateMenu(); diff --git a/chrome/browser/chromeos/status/network_menu_button.cc b/chrome/browser/chromeos/status/network_menu_button.cc index 97682c5..b81e0d5 100644 --- a/chrome/browser/chromeos/status/network_menu_button.cc +++ b/chrome/browser/chromeos/status/network_menu_button.cc @@ -8,11 +8,19 @@ #include <limits> #include "base/logging.h" +#include "base/message_loop.h" #include "base/string_util.h" #include "base/utf_string_conversions.h" #include "chrome/browser/chromeos/cros/cros_library.h" +#include "chrome/browser/chromeos/login/helper.h" +#include "chrome/browser/chromeos/login/user_manager.h" #include "chrome/browser/chromeos/options/network_config_view.h" #include "chrome/browser/chromeos/status/status_area_host.h" +#include "chrome/browser/prefs/pref_service.h" +#include "chrome/browser/profiles/profile.h" +#include "chrome/browser/ui/browser.h" +#include "chrome/browser/ui/browser_list.h" +#include "chrome/common/pref_names.h" #include "grit/generated_resources.h" #include "grit/theme_resources.h" #include "ui/base/l10n/l10n_util.h" @@ -20,6 +28,41 @@ #include "ui/gfx/canvas_skia.h" #include "views/window/window.h" +namespace { + +// Time in milliseconds to delay showing of promo +// notification when Chrome window is not on screen. +const int kPromoShowDelayMs = 5000; + +bool GetBooleanPref(const char* pref_name) { + Browser* browser = BrowserList::GetLastActive(); + if (!browser || !browser->profile()) + return true; + + PrefService* prefs = browser->profile()->GetPrefs(); + return prefs->GetBoolean(pref_name); +} + +void SetBooleanPref(const char* pref_name, bool value) { + Browser* browser = BrowserList::GetLastActive(); + if (!browser || !browser->profile()) + return; + + PrefService* prefs = browser->profile()->GetPrefs(); + prefs->SetBoolean(pref_name, value); +} + +// Returns prefs::kShow3gPromoNotification or true if there's no active browser. +bool ShouldShow3gPromoNotification() { + return GetBooleanPref(prefs::kShow3gPromoNotification); +} + +void SetShow3gPromoNotification(bool value) { + SetBooleanPref(prefs::kShow3gPromoNotification, value); +} + +} // namespace + namespace chromeos { //////////////////////////////////////////////////////////////////////////////// @@ -35,7 +78,9 @@ NetworkMenuButton::NetworkMenuButton(StatusAreaHost* host) icon_(NULL), right_badge_(NULL), left_badge_(NULL), - ALLOW_THIS_IN_INITIALIZER_LIST(animation_connecting_(this)) { + mobile_data_bubble_(NULL), + ALLOW_THIS_IN_INITIALIZER_LIST(animation_connecting_(this)), + ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { animation_connecting_.SetThrobDuration(kThrobDuration); animation_connecting_.SetTweenType(ui::Tween::EASE_IN_OUT); NetworkLibrary* network_library = CrosLibrary::Get()->GetNetworkLibrary(); @@ -56,6 +101,8 @@ NetworkMenuButton::~NetworkMenuButton() { netlib->RemoveCellularDataPlanObserver(this); if (!cellular_device_path_.empty()) netlib->RemoveNetworkDeviceObserver(cellular_device_path_, this); + if (mobile_data_bubble_) + mobile_data_bubble_->Close(); } //////////////////////////////////////////////////////////////////////////////// @@ -86,6 +133,7 @@ void NetworkMenuButton::OnNetworkDeviceChanged(NetworkLibrary* cros, void NetworkMenuButton::OnNetworkManagerChanged(NetworkLibrary* cros) { OnNetworkChanged(cros, cros->active_network()); + ShowOptionalMobileDataPromoNotification(cros); } //////////////////////////////////////////////////////////////////////////////// @@ -134,6 +182,20 @@ void NetworkMenuButton::OnLocaleChanged() { } //////////////////////////////////////////////////////////////////////////////// +// MessageBubbleDelegate implementation: + +void NetworkMenuButton::OnHelpLinkActivated() { + // mobile_data_bubble_ will be set to NULL in callback. + if (mobile_data_bubble_) + mobile_data_bubble_->Close(); + const Network* cellular = + CrosLibrary::Get()->GetNetworkLibrary()->cellular_network(); + if (!cellular) + return; + ShowTabbedNetworkSettings(cellular); +} + +//////////////////////////////////////////////////////////////////////////////// // NetworkMenuButton, private methods void NetworkMenuButton::SetIconAndBadges(const SkBitmap* icon, @@ -269,4 +331,50 @@ void NetworkMenuButton::RefreshNetworkDeviceObserver(NetworkLibrary* cros) { } } +void NetworkMenuButton::ShowOptionalMobileDataPromoNotification( + NetworkLibrary* cros) { + // Display one-time notification for non-Guest users on first use + // of Mobile Data connection. + if (IsBrowserMode() && !UserManager::Get()->IsLoggedInAsGuest() && + ShouldShow3gPromoNotification() && + cros->cellular_connected() && !cros->ethernet_connected() && + !cros->wifi_connected()) { + const CellularNetwork* cellular = cros->cellular_network(); + if (!cellular) + return; + + gfx::Rect button_bounds = GetScreenBounds(); + // StatusArea button Y position is usually -1, fix it so that + // Contains() method for screen bounds works correctly. + button_bounds.set_y(button_bounds.y() + 1); + gfx::Rect screen_bounds(chromeos::CalculateScreenBounds(gfx::Size())); + + // Chrome window is initialized in visible state off screen and then is + // moved into visible screen area. Make sure that we're on screen + // so that bubble is shown correctly. + if (!screen_bounds.Contains(button_bounds)) { + // If we're not on screen yet, delay notification display. + // It may be shown earlier, on next NetworkLibrary callback processing. + if (method_factory_.empty()) { + MessageLoop::current()->PostDelayedTask(FROM_HERE, + method_factory_.NewRunnableMethod( + &NetworkMenuButton::ShowOptionalMobileDataPromoNotification, + cros), + kPromoShowDelayMs); + } + return; + } + + mobile_data_bubble_ = MessageBubble::Show( + GetWidget(), + button_bounds, + BubbleBorder::TOP_RIGHT , + ResourceBundle::GetSharedInstance().GetBitmapNamed(IDR_NOTIFICATION_3G), + UTF16ToWide(l10n_util::GetStringUTF16(IDS_3G_NOTIFICATION_MESSAGE)), + UTF16ToWide(l10n_util::GetStringUTF16(IDS_OFFLINE_NETWORK_SETTINGS)), + this); + SetShow3gPromoNotification(false); + } +} + } // namespace chromeos diff --git a/chrome/browser/chromeos/status/network_menu_button.h b/chrome/browser/chromeos/status/network_menu_button.h index 61f024c..eb78c6f 100644 --- a/chrome/browser/chromeos/status/network_menu_button.h +++ b/chrome/browser/chromeos/status/network_menu_button.h @@ -8,8 +8,10 @@ #include <string> +#include "base/task.h" #include "base/timer.h" #include "chrome/browser/chromeos/cros/network_library.h" +#include "chrome/browser/chromeos/login/message_bubble.h" #include "chrome/browser/chromeos/status/network_menu.h" #include "chrome/browser/chromeos/status/status_area_button.h" #include "ui/base/animation/throb_animation.h" @@ -51,7 +53,8 @@ class NetworkMenuButton : public StatusAreaButton, public NetworkLibrary::NetworkDeviceObserver, public NetworkLibrary::NetworkManagerObserver, public NetworkLibrary::NetworkObserver, - public NetworkLibrary::CellularDataPlanObserver { + public NetworkLibrary::CellularDataPlanObserver, + public MessageBubbleDelegate { public: explicit NetworkMenuButton(StatusAreaHost* host); virtual ~NetworkMenuButton(); @@ -81,6 +84,14 @@ class NetworkMenuButton : public StatusAreaButton, // views::View virtual void OnLocaleChanged() OVERRIDE; + // MessageBubbleDelegate implementation: + virtual void BubbleClosing(Bubble* bubble, bool closed_by_escape) { + mobile_data_bubble_ = NULL; + } + virtual bool CloseOnEscape() { return true; } + virtual bool FadeInOnShow() { return false; } + virtual void OnHelpLinkActivated(); + private: // Sets the icon and the badges (badges are at the bottom of the icon). void SetIconAndBadges(const SkBitmap* icon, @@ -102,6 +113,9 @@ class NetworkMenuButton : public StatusAreaButton, // old network observer and add a network observer for the active network. void RefreshNetworkObserver(NetworkLibrary* cros); + // Shows 3G promo notification if needed. + void ShowOptionalMobileDataPromoNotification(NetworkLibrary* cros); + // The status area host, StatusAreaHost* host_; @@ -115,6 +129,9 @@ class NetworkMenuButton : public StatusAreaButton, // A badge icon displayed on top of icon, in bottom-left corner. const SkBitmap* left_badge_; + // Notification bubble for 3G promo. + MessageBubble* mobile_data_bubble_; + // The throb animation that does the wifi connecting animation. ui::ThrobAnimation animation_connecting_; @@ -125,6 +142,9 @@ class NetworkMenuButton : public StatusAreaButton, // whose status is displayed in the network menu button. std::string active_network_; + // Factory for delaying showing promo notification. + ScopedRunnableMethodFactory<NetworkMenuButton> method_factory_; + DISALLOW_COPY_AND_ASSIGN(NetworkMenuButton); }; diff --git a/chrome/browser/sync/glue/synchronized_preferences.h b/chrome/browser/sync/glue/synchronized_preferences.h index beb8166..ffe9fb1 100644 --- a/chrome/browser/sync/glue/synchronized_preferences.h +++ b/chrome/browser/sync/glue/synchronized_preferences.h @@ -186,6 +186,10 @@ static const char* kSynchronizedPreferences[] = { // Settings -> Internet -> Mobile plan details prefs::kShowPlanNotifications, + // Whether to show 3G promo notification. By default this notification is + // shown only once to user on a first usage of Mobile Data. + prefs::kShow3gPromoNotification, + // Whether to require password to wake up from sleep // Settings -> Personal Stuff -> Account prefs::kEnableScreenLock, diff --git a/chrome/common/pref_names.cc b/chrome/common/pref_names.cc index 26d43c4..f1869af 100644 --- a/chrome/common/pref_names.cc +++ b/chrome/common/pref_names.cc @@ -474,6 +474,10 @@ const char kEnableScreenLock[] = "settings.enable_screen_lock"; const char kShowPlanNotifications[] = "settings.internet.mobile.show_plan_notifications"; +// A boolean pref of whether to show 3G promo notification. +const char kShow3gPromoNotification[] = + "settings.internet.mobile.show_3g_promo_notification"; + #endif // defined(OS_CHROMEOS) // The disabled messages in IPC logging. diff --git a/chrome/common/pref_names.h b/chrome/common/pref_names.h index dc10567..53da7bb 100644 --- a/chrome/common/pref_names.h +++ b/chrome/common/pref_names.h @@ -163,6 +163,7 @@ extern const char kLabsAdvancedFilesystemEnabled[]; extern const char kLabsMediaplayerEnabled[]; extern const char kEnableScreenLock[]; extern const char kShowPlanNotifications[]; +extern const char kShow3gPromoNotification[]; #endif extern const char kIpcDisabledMessages[]; extern const char kShowHomeButton[]; |