diff options
11 files changed, 135 insertions, 10 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd index 106ba51..f3b6166 100644 --- a/chrome/app/generated_resources.grd +++ b/chrome/app/generated_resources.grd @@ -8808,6 +8808,9 @@ Keep your key file in a safe place. You will need it to create new versions of y </if> <!-- Chrome OS Strings --> <if expr="pp_ifdef('chromeos')"> + <message name="IDS_NETWORK_PURCHASE_MORE_MESSAGE" desc="Message for purchase more link"> + Purchase more... + </message> <message name="IDS_NETWORK_LOW_DATA_TITLE" desc="Title for network low data notification"> Low <ph name="network">$1<ex>YBH</ex></ph> data </message> diff --git a/chrome/browser/browser_resources.grd b/chrome/browser/browser_resources.grd index f2653d0..926e7cc 100644 --- a/chrome/browser/browser_resources.grd +++ b/chrome/browser/browser_resources.grd @@ -72,6 +72,7 @@ without changes to the corresponding grd file. eter --> <include name="IDR_MEDIAPLAYER_HTML" file="resources\mediaplayer.html" flattenhtml="true" type="BINDATA" /> <include name="IDR_MEDIAPLAYERPLAYLIST_HTML" file="resources\playlist.html" flattenhtml="true" type="BINDATA" /> <include name="IDR_MOBILE_SETUP_PAGE_HTML" file="resources\mobile_setup.html" flattenhtml="true" type="BINDATA" /> + <include name="IDR_NOTIFICATION_ICON_LINK_HTML" file="resources\notification_icon_link.html" type="BINDATA" /> <include name="IDR_OFFLINE_LOAD_HTML" file="resources\offline_load.html" flattenhtml="true" type="BINDATA" /> <include name="IDR_OS_CREDITS_HTML" file="resources\about_os_credits.html" flattenhtml="true" type="BINDATA" /> <include name="IDR_SLIDESHOW_HTML" file="resources\slideshow.html" flattenhtml="true" type="BINDATA" /> diff --git a/chrome/browser/chromeos/network_message_observer.cc b/chrome/browser/chromeos/network_message_observer.cc index e0bc9d9..c4df580 100644 --- a/chrome/browser/chromeos/network_message_observer.cc +++ b/chrome/browser/chromeos/network_message_observer.cc @@ -5,12 +5,15 @@ #include "chrome/browser/chromeos/network_message_observer.h" #include "app/l10n_util.h" +#include "base/callback.h" #include "base/string_number_conversions.h" #include "base/utf_string_conversions.h" +#include "chrome/browser/browser.h" #include "chrome/browser/browser_list.h" #include "chrome/browser/browser_window.h" #include "chrome/browser/chromeos/cros/cros_library.h" #include "chrome/browser/chromeos/cros/network_library.h" +#include "chrome/browser/chromeos/notifications/balloon_view_host.h" #include "chrome/browser/chromeos/options/network_config_view.h" #include "chrome/browser/views/window.h" #include "grit/generated_resources.h" @@ -55,6 +58,10 @@ void NetworkMessageObserver::CreateModalPopup(views::WindowDelegate* view) { window->Show(); } +void NetworkMessageObserver::MobileSetup(const ListValue* args) { + BrowserList::GetLastActive()->OpenMobilePlanTabAndActivate(); +} + void NetworkMessageObserver::NetworkChanged(NetworkLibrary* obj) { const WifiNetworkVector& wifi_networks = obj->wifi_networks(); const CellularNetworkVector& cellular_networks = obj->cellular_networks(); @@ -137,7 +144,9 @@ void NetworkMessageObserver::NetworkChanged(NetworkLibrary* obj) { } void NetworkMessageObserver::CellularDataPlanChanged( - const std::string& service_path, const CellularDataPlan& plan) { + const std::string& service_path, const CellularDataPlanList& plans) { + // Active plan is the first one in the list. Use empty one if none found. + CellularDataPlan plan = plans.empty() ? CellularDataPlan() : plans[0]; // If connected cellular network changed, or data plan is different, then // it's a new network. Then hide all previous notifications. bool new_plan = false; @@ -176,12 +185,16 @@ void NetworkMessageObserver::CellularDataPlanChanged( notification_low_data_.Hide(); notification_no_data_.Show(l10n_util::GetStringFUTF16( IDS_NETWORK_MINUTES_REMAINING_MESSAGE, ASCIIToUTF16("0")), + l10n_util::GetStringUTF16(IDS_NETWORK_PURCHASE_MORE_MESSAGE), + NewCallback(this, &NetworkMessageObserver::MobileSetup), false, false); } else if (time_left <= kDataNearingExpirationSecs) { notification_no_data_.Hide(); notification_low_data_.Show(l10n_util::GetStringFUTF16( IDS_NETWORK_MINUTES_UNTIL_EXPIRATION_MESSAGE, UTF8ToUTF16(base::Int64ToString(time_left/60))), + l10n_util::GetStringUTF16(IDS_NETWORK_PURCHASE_MORE_MESSAGE), + NewCallback(this, &NetworkMessageObserver::MobileSetup), false, false); } else { // Got more data, so hide notifications. @@ -196,12 +209,16 @@ void NetworkMessageObserver::CellularDataPlanChanged( notification_low_data_.Hide(); notification_no_data_.Show(l10n_util::GetStringFUTF16( IDS_NETWORK_DATA_REMAINING_MESSAGE, ASCIIToUTF16("0")), + l10n_util::GetStringUTF16(IDS_NETWORK_PURCHASE_MORE_MESSAGE), + NewCallback(this, &NetworkMessageObserver::MobileSetup), false, false); } else if (bytes_remaining <= kDataLowDataBytes) { notification_no_data_.Hide(); notification_low_data_.Show(l10n_util::GetStringFUTF16( IDS_NETWORK_DATA_REMAINING_MESSAGE, UTF8ToUTF16(base::Int64ToString(bytes_remaining/1024))), + l10n_util::GetStringUTF16(IDS_NETWORK_PURCHASE_MORE_MESSAGE), + NewCallback(this, &NetworkMessageObserver::MobileSetup), false, false); } else { // Got more data, so hide notifications. diff --git a/chrome/browser/chromeos/network_message_observer.h b/chrome/browser/chromeos/network_message_observer.h index 781d1a8..c92f6e2 100644 --- a/chrome/browser/chromeos/network_message_observer.h +++ b/chrome/browser/chromeos/network_message_observer.h @@ -38,11 +38,12 @@ class NetworkMessageObserver : public NetworkLibrary::Observer { typedef std::map<std::string, CellularNetwork> ServicePathCellularMap; private: virtual void CreateModalPopup(views::WindowDelegate* view); + virtual void MobileSetup(const ListValue* args); // NetworkLibrary::Observer implementation. virtual void NetworkChanged(NetworkLibrary* obj); virtual void CellularDataPlanChanged(const std::string& service_path, - const CellularDataPlan& plan); + const CellularDataPlanList& plans); bool initialized_; // Wifi networks by service path. diff --git a/chrome/browser/chromeos/notifications/system_notification.cc b/chrome/browser/chromeos/notifications/system_notification.cc index ad54253..f2b642e2 100644 --- a/chrome/browser/chromeos/notifications/system_notification.cc +++ b/chrome/browser/chromeos/notifications/system_notification.cc @@ -4,6 +4,7 @@ #include "chrome/browser/chromeos/notifications/system_notification.h" +#include "base/callback.h" #include "base/move.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/chromeos/notifications/system_notification_factory.h" @@ -35,8 +36,16 @@ SystemNotification::~SystemNotification() { void SystemNotification::Show(const string16& message, bool urgent, bool sticky) { + Show(message, string16(), NULL, urgent, sticky); +} + +void SystemNotification::Show(const string16& message, + const string16& link, + MessageCallback* callback, + bool urgent, + bool sticky) { Notification notify = SystemNotificationFactory::Create(icon_, - title_, message, delegate_.get()); + title_, message, link, delegate_.get()); if (visible_) { // Force showing a user hidden notification on an urgent transition. if (urgent && !urgent_) { @@ -48,6 +57,7 @@ void SystemNotification::Show(const string16& message, collection_->AddSystemNotification(notify, profile_, sticky, false /* no controls */); + collection_->AddDOMUIMessageCallback(notify, "link", callback); } visible_ = true; urgent_ = urgent; diff --git a/chrome/browser/chromeos/notifications/system_notification.h b/chrome/browser/chromeos/notifications/system_notification.h index fa323b6..82ca8f3 100644 --- a/chrome/browser/chromeos/notifications/system_notification.h +++ b/chrome/browser/chromeos/notifications/system_notification.h @@ -16,6 +16,7 @@ #include "chrome/browser/notifications/notification_delegate.h" #include "googleurl/src/gurl.h" +class MessageCallback; class Profile; namespace chromeos { @@ -39,6 +40,11 @@ class SystemNotification { // previously hidden or minimized by the user. void Show(const string16& message, bool urgent, bool sticky); + // Same as Show() above with a footer link at the bottom and a callback + // for when the link is clicked. + void Show(const string16& message, const string16& link_text, + MessageCallback* callback, bool urgent, bool sticky); + // Hide will dismiss the notification, if the notification is already // hidden it does nothing void Hide(); diff --git a/chrome/browser/chromeos/notifications/system_notification_factory.cc b/chrome/browser/chromeos/notifications/system_notification_factory.cc index 51b308f..65ea497 100644 --- a/chrome/browser/chromeos/notifications/system_notification_factory.cc +++ b/chrome/browser/chromeos/notifications/system_notification_factory.cc @@ -4,17 +4,50 @@ #include "chrome/browser/chromeos/notifications/system_notification_factory.h" +#include "base/utf_string_conversions.h" #include "chrome/browser/notifications/desktop_notification_service.h" +#include "grit/browser_resources.h" +#include "net/base/escape.h" namespace chromeos { +using WebKit::WebTextDirection; + // static Notification SystemNotificationFactory::Create( const GURL& icon, const string16& title, const string16& text, NotificationDelegate* delegate) { - string16 content_url = DesktopNotificationService::CreateDataUrl( - icon, title, text, WebKit::WebTextDirectionDefault); + return Create(icon, title, text, string16(), delegate); +} + +// static +Notification SystemNotificationFactory::Create( + const GURL& icon, const string16& title, + const string16& text, const string16& link, + NotificationDelegate* delegate) { + // Create an icon notification with or without a footer link + // See code in DesktopNotificationService::CreateDataUrl + WebTextDirection dir = WebKit::WebTextDirectionDefault; + std::vector<std::string> subst; + int resource = IDR_NOTIFICATION_ICON_HTML; + subst.push_back(icon.spec()); + subst.push_back(EscapeForHTML(UTF16ToUTF8(title))); + subst.push_back(EscapeForHTML(UTF16ToUTF8(text))); + // icon float position + subst.push_back(dir == WebKit::WebTextDirectionRightToLeft ? + "right" : "left"); + // body text direction + subst.push_back(dir == WebKit::WebTextDirectionRightToLeft ? + "rtl" : "ltr"); + // if link is not empty, then use template with link + if (!link.empty()) { + resource = IDR_NOTIFICATION_ICON_LINK_HTML; + subst.push_back(EscapeForHTML(UTF16ToUTF8(link))); + } + + string16 content_url = DesktopNotificationService::CreateDataUrl(resource, + subst); return Notification(GURL(), GURL(content_url), string16(), string16(), delegate); } diff --git a/chrome/browser/chromeos/notifications/system_notification_factory.h b/chrome/browser/chromeos/notifications/system_notification_factory.h index c81b07d..5ee83f7 100644 --- a/chrome/browser/chromeos/notifications/system_notification_factory.h +++ b/chrome/browser/chromeos/notifications/system_notification_factory.h @@ -23,6 +23,12 @@ class SystemNotificationFactory { const GURL& icon, const string16& title, const string16& text, NotificationDelegate* delegate); + + // Creates a system notification with a footer link. + static Notification Create( + const GURL& icon, const string16& title, + const string16& text, const string16& link, + NotificationDelegate* delegate); }; } // namespace chromeos diff --git a/chrome/browser/notifications/desktop_notification_service.cc b/chrome/browser/notifications/desktop_notification_service.cc index 351485f..a4c45d5 100644 --- a/chrome/browser/notifications/desktop_notification_service.cc +++ b/chrome/browser/notifications/desktop_notification_service.cc @@ -48,8 +48,6 @@ string16 DesktopNotificationService::CreateDataUrl( const GURL& icon_url, const string16& title, const string16& body, WebTextDirection dir) { int resource; - string16 line_name; - string16 line; std::vector<std::string> subst; if (icon_url.is_valid()) { resource = IDR_NOTIFICATION_ICON_HTML; @@ -61,10 +59,10 @@ string16 DesktopNotificationService::CreateDataUrl( "right" : "left"); } else if (title.empty() || body.empty()) { resource = IDR_NOTIFICATION_1LINE_HTML; - line = title.empty() ? body : title; + string16 line = title.empty() ? body : title; // Strings are div names in the template file. - line_name = title.empty() ? ASCIIToUTF16("description") - : ASCIIToUTF16("title"); + string16 line_name = title.empty() ? ASCIIToUTF16("description") + : ASCIIToUTF16("title"); subst.push_back(EscapeForHTML(UTF16ToUTF8(line_name))); subst.push_back(EscapeForHTML(UTF16ToUTF8(line))); } else { @@ -76,6 +74,12 @@ string16 DesktopNotificationService::CreateDataUrl( subst.push_back(dir == WebKit::WebTextDirectionRightToLeft ? "rtl" : "ltr"); + return CreateDataUrl(resource, subst); +} + +// static +string16 DesktopNotificationService::CreateDataUrl( + int resource, const std::vector<std::string>& subst) { const base::StringPiece template_html( ResourceBundle::GetSharedInstance().GetRawDataResource( resource)); diff --git a/chrome/browser/notifications/desktop_notification_service.h b/chrome/browser/notifications/desktop_notification_service.h index 2282cd2..a6815da 100644 --- a/chrome/browser/notifications/desktop_notification_service.h +++ b/chrome/browser/notifications/desktop_notification_service.h @@ -83,6 +83,12 @@ class DesktopNotificationService : public NotificationObserver { const string16& body, WebKit::WebTextDirection dir); + // Creates a data:xxxx URL which contains the full HTML for a notification + // using resource template which contains the standard formatting for + // notifications. + static string16 CreateDataUrl(int resource, + const std::vector<std::string>& subst); + // The default content setting determines how to handle origins that haven't // been allowed or denied yet. ContentSetting GetDefaultContentSetting(); diff --git a/chrome/browser/resources/notification_icon_link.html b/chrome/browser/resources/notification_icon_link.html new file mode 100644 index 0000000..882d673 --- /dev/null +++ b/chrome/browser/resources/notification_icon_link.html @@ -0,0 +1,38 @@ +<!DOCTYPE html> +<html> +<head> + <title>$2</title> + <style> + body { + direction: $5; + } + #icon { + height: 48px; + width: 48px; + float: $4; + } + #title { + margin-$4: 54px; + font-weight: bold; + font-size: 13px; + font-family: helvetica, arial, sans-serif; + } + #description { + margin-$4: 54px; + font-family: helvetica, arial, sans-serif; + font-size: 13px; + } + #link { + margin-$4: 54px; + font-family: helvetica, arial, sans-serif; + font-size: 13px; + } + </style> +</head> +<body> + <div id="icon"><img src="$1" width="48" height="48" /></div> + <div id="title">$2</div> + <div id="description">$3</div> + <div id="link"><a href="" onclick="chrome.send('link')">$6</a></div> +</body> +</html> |