summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorananta@chromium.org <ananta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-10 00:08:42 +0000
committerananta@chromium.org <ananta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-10 00:08:42 +0000
commitda7c6b51086d02e35f7240f619704d7f4ede7493 (patch)
tree6300b59d17e275682e492861953b24bea23eab79
parentf58b6b6dbbec20b456b0b6f02347ff5fc5e0c2b6 (diff)
downloadchromium_src-da7c6b51086d02e35f7240f619704d7f4ede7493.zip
chromium_src-da7c6b51086d02e35f7240f619704d7f4ede7493.tar.gz
chromium_src-da7c6b51086d02e35f7240f619704d7f4ede7493.tar.bz2
Add functionality to the Windows 8 notification display functionality to invoke a caller specified handler function
with a string parameter. Currently the only consumer of this functionality is the download notification display code which when invoked displays the downloaded file in the shell. BUG=151141 R=cpu Review URL: https://codereview.chromium.org/11096013 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@160988 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--base/win/metro.h8
-rw-r--r--chrome/browser/download/download_status_updater_win.cc20
-rw-r--r--chrome/browser/ui/views/status_icons/status_icon_win.cc2
-rw-r--r--win8/metro_driver/chrome_app_view.cc13
-rw-r--r--win8/metro_driver/toast_notification_handler.cc19
-rw-r--r--win8/metro_driver/toast_notification_handler.h11
6 files changed, 60 insertions, 13 deletions
diff --git a/base/win/metro.h b/base/win/metro.h
index b401b42..41404a8 100644
--- a/base/win/metro.h
+++ b/base/win/metro.h
@@ -84,14 +84,18 @@ BASE_EXPORT MetroLaunchType GetMetroLaunchParams(string16* params);
// Handler function for the buttons on a metro dialog box
typedef void (*MetroDialogButtonPressedHandler)();
+// Handler function invoked when a metro style notification is clicked.
+typedef void (*MetroNotificationClickedHandler)(const wchar_t* context);
+
// Function to display metro style notifications.
typedef void (*MetroNotification)(const char* origin_url,
const char* icon_url,
const wchar_t* title,
const wchar_t* body,
const wchar_t* display_source,
- const char* notification_id);
-
+ const char* notification_id,
+ MetroNotificationClickedHandler handler,
+ const wchar_t* handler_context);
} // namespace win
} // namespace base
diff --git a/chrome/browser/download/download_status_updater_win.cc b/chrome/browser/download/download_status_updater_win.cc
index 3e28d6f..0bf177e 100644
--- a/chrome/browser/download/download_status_updater_win.cc
+++ b/chrome/browser/download/download_status_updater_win.cc
@@ -7,15 +7,18 @@
#include <string>
#include <shobjidl.h>
+#include "base/file_path.h"
#include "base/logging.h"
#include "base/stl_util.h"
#include "base/string_number_conversions.h"
#include "base/win/metro.h"
#include "base/win/scoped_comptr.h"
#include "base/win/windows_version.h"
+#include "chrome/browser/platform_util.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_window.h"
+#include "content/public/browser/browser_thread.h"
#include "googleurl/src/gurl.h"
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
@@ -67,20 +70,29 @@ void UpdateTaskbarProgressBar(int download_count,
}
}
+void MetroDownloadNotificationClickedHandler(const wchar_t* download_path) {
+ // Metro chrome will invoke these handlers on the metro thread.
+ DCHECK(!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
+
+ // Ensure that we invoke the function to display the downloaded item on the
+ // UI thread.
+ content::BrowserThread::PostTask(
+ content::BrowserThread::UI, FROM_HERE,
+ base::Bind(platform_util::ShowItemInFolder, FilePath(download_path)));
+}
+
} // namespace
void DownloadStatusUpdater::UpdateAppIconDownloadProgress(
content::DownloadItem* download) {
// Always update overall progress.
-
float progress = 0;
int download_count = 0;
bool progress_known = GetProgress(&progress, &download_count);
UpdateTaskbarProgressBar(download_count, progress_known, progress);
// Fire notifications when downloads complete.
-
if (!base::win::IsMetroProcess())
return;
@@ -116,7 +128,9 @@ void DownloadStatusUpdater::UpdateAppIconDownloadProgress(
title.c_str(),
body.c_str(),
L"",
- notification_id.c_str());
+ notification_id.c_str(),
+ MetroDownloadNotificationClickedHandler,
+ download->GetTargetFilePath().value().c_str());
}
}
diff --git a/chrome/browser/ui/views/status_icons/status_icon_win.cc b/chrome/browser/ui/views/status_icons/status_icon_win.cc
index 7f0f317..d154f59 100644
--- a/chrome/browser/ui/views/status_icons/status_icon_win.cc
+++ b/chrome/browser/ui/views/status_icons/status_icon_win.cc
@@ -199,7 +199,7 @@ void StatusIconMetro::DisplayBalloon(const gfx::ImageSkia& icon,
::GetProcAddress(metro_module, "DisplayNotification"));
DCHECK(notification);
notification("", "", title.c_str(), contents.c_str(), L"",
- base::IntToString(id_).c_str());
+ base::IntToString(id_).c_str(), NULL, NULL);
}
}
diff --git a/win8/metro_driver/chrome_app_view.cc b/win8/metro_driver/chrome_app_view.cc
index 71392d0..28e9e76 100644
--- a/win8/metro_driver/chrome_app_view.cc
+++ b/win8/metro_driver/chrome_app_view.cc
@@ -519,7 +519,9 @@ extern "C" __declspec(dllexport)
void DisplayNotification(const char* origin_url, const char* icon_url,
const wchar_t* title, const wchar_t* body,
const wchar_t* display_source,
- const char* notification_id) {
+ const char* notification_id,
+ base::win::MetroNotificationClickedHandler handler,
+ const wchar_t* handler_context) {
// TODO(ananta)
// Needs implementation.
DVLOG(1) << __FUNCTION__;
@@ -529,7 +531,9 @@ void DisplayNotification(const char* origin_url, const char* icon_url,
title,
body,
display_source,
- notification_id);
+ notification_id,
+ handler,
+ handler_context);
globals.appview_msg_loop->PostTask(
FROM_HERE, base::Bind(&ChromeAppView::DisplayNotification,
globals.view, notification));
@@ -843,6 +847,9 @@ ChromeAppView::Run() {
options.message_loop_type = MessageLoop::TYPE_IO;
thread.StartWithOptions(options);
+ // The viewer channel opened below only applies when we are launched as an
+ // AURA viewer process.
+#if defined(USE_AURA)
ChromeChannelListener channel_listener;
IPC::ChannelProxy chan("viewer", IPC::Channel::MODE_NAMED_CLIENT,
&channel_listener, thread.message_loop_proxy());
@@ -851,7 +858,7 @@ ChromeAppView::Run() {
gfx::NativeViewId(globals.core_window)));
DVLOG(1) << "ICoreWindow sent " << globals.core_window;
-
+#endif
// And post the task that'll do the inner Metro message pumping to it.
msg_loop.PostTask(FROM_HERE, base::Bind(&RunMessageLoop, dispatcher.Get()));
diff --git a/win8/metro_driver/toast_notification_handler.cc b/win8/metro_driver/toast_notification_handler.cc
index 36bddd5..5545cd2 100644
--- a/win8/metro_driver/toast_notification_handler.cc
+++ b/win8/metro_driver/toast_notification_handler.cc
@@ -100,15 +100,23 @@ ToastNotificationHandler::DesktopNotification::DesktopNotification(
const wchar_t* notification_title,
const wchar_t* notification_body,
const wchar_t* notification_display_source,
- const char* notification_id)
+ const char* notification_id,
+ base::win::MetroNotificationClickedHandler handler,
+ const wchar_t* handler_context)
: origin_url(notification_origin),
icon_url(notification_icon),
title(notification_title),
body(notification_body),
display_source(notification_display_source),
- id(notification_id) {
+ id(notification_id),
+ notification_handler(handler) {
+ if (handler_context)
+ notification_context = handler_context;
}
+ToastNotificationHandler::DesktopNotification::DesktopNotification()
+ : notification_handler(NULL) {
+}
ToastNotificationHandler::ToastNotificationHandler() {
DVLOG(1) << __FUNCTION__;
@@ -128,6 +136,8 @@ void ToastNotificationHandler::DisplayNotification(
DCHECK(notifier_.Get() == NULL);
DCHECK(notification_.Get() == NULL);
+ notification_info_ = notification;
+
mswr::ComPtr<winui::Notifications::IToastNotificationManagerStatics>
toast_manager;
@@ -230,5 +240,10 @@ HRESULT ToastNotificationHandler::OnActivate(
// etc to ChromeAppView which would enable it to ensure that the
// correct tab in chrome is activated.
DVLOG(1) << __FUNCTION__;
+
+ if (notification_info_.notification_handler) {
+ notification_info_.notification_handler(
+ notification_info_.notification_context.c_str());
+ }
return S_OK;
}
diff --git a/win8/metro_driver/toast_notification_handler.h b/win8/metro_driver/toast_notification_handler.h
index f560e34..b1ef338 100644
--- a/win8/metro_driver/toast_notification_handler.h
+++ b/win8/metro_driver/toast_notification_handler.h
@@ -8,6 +8,7 @@
#include <windows.ui.notifications.h>
#include "base/string16.h"
+#include "base/win/metro.h"
// Provides functionality to display a metro style toast notification.
class ToastNotificationHandler {
@@ -20,13 +21,19 @@ class ToastNotificationHandler {
string16 body;
string16 display_source;
std::string id;
+ base::win::MetroNotificationClickedHandler notification_handler;
+ string16 notification_context;
DesktopNotification(const char* notification_origin,
const char* notification_icon,
const wchar_t* notification_title,
const wchar_t* notification_body,
const wchar_t* notification_display_source,
- const char* notification_id);
+ const char* notification_id,
+ base::win::MetroNotificationClickedHandler handler,
+ const wchar_t* handler_context);
+
+ DesktopNotification();
};
ToastNotificationHandler();
@@ -41,8 +48,8 @@ class ToastNotificationHandler {
private:
mswr::ComPtr<winui::Notifications::IToastNotifier> notifier_;
mswr::ComPtr<winui::Notifications::IToastNotification> notification_;
-
EventRegistrationToken activated_token_;
+ DesktopNotification notification_info_;
};
#endif // CHROME_BROWSER_UI_METRO_DRIVER_TOAST_NOTIFICATION_HANDLER_H_