summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsatish@chromium.org <satish@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-06 21:24:02 +0000
committersatish@chromium.org <satish@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-06 21:24:02 +0000
commit560e503e6d6f128eca0f4c3675428eaf0c1c7e7e (patch)
treeef51f273d0d3df29df33b4e912b317cf3a0ecd91
parent234900cd8aca4d8327005e68f364e261253c4d0b (diff)
downloadchromium_src-560e503e6d6f128eca0f4c3675428eaf0c1c7e7e.zip
chromium_src-560e503e6d6f128eca0f4c3675428eaf0c1c7e7e.tar.gz
chromium_src-560e503e6d6f128eca0f4c3675428eaf0c1c7e7e.tar.bz2
Adds a GYP flag for desktop notifications (enabled by default) and stub out relevant code if set to 0.
In chrome/browser/task_manager I moved notifications related code to their own files and allow exclusion and stubbing via GYP. Similarly I have added stubs for other parts including a chrome/browser/notifications/notification_stubs.cc which takes care of classes within that directory. I also created some static methods in DesktopNotificationService to wrap commonly used notification related code so that we reduce the amount of stubs required. BUG=none TEST=existing notification tests succeed Review URL: http://codereview.chromium.org/7053041 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@88040 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--build/common.gypi3
-rw-r--r--chrome/browser/chrome_content_browser_client.cc2
-rw-r--r--chrome/browser/desktop_notification_handler.cc12
-rw-r--r--chrome/browser/desktop_notification_handler.h4
-rw-r--r--chrome/browser/desktop_notification_handler_stub.cc12
-rw-r--r--chrome/browser/notifications/desktop_notification_service.cc5
-rw-r--r--chrome/browser/notifications/desktop_notification_service.h7
-rw-r--r--chrome/browser/notifications/desktop_notifications_unittest.cc5
-rw-r--r--chrome/browser/notifications/notification_stubs.cc176
-rw-r--r--chrome/browser/notifications/notification_ui_manager.cc8
-rw-r--r--chrome/browser/notifications/notification_ui_manager.h9
-rw-r--r--chrome/browser/task_manager/task_manager.cc7
-rw-r--r--chrome/browser/task_manager/task_manager_browsertest.cc33
-rw-r--r--chrome/browser/task_manager/task_manager_notification_browsertest.cc106
-rw-r--r--chrome/browser/task_manager/task_manager_notification_resource_provider.cc171
-rw-r--r--chrome/browser/task_manager/task_manager_notification_resource_provider_stub.cc11
-rw-r--r--chrome/browser/task_manager/task_manager_resource_providers.cc148
-rw-r--r--chrome/browser/task_manager/task_manager_resource_providers.h4
-rw-r--r--chrome/chrome_browser.gypi21
-rw-r--r--chrome/chrome_tests.gypi25
-rw-r--r--content/browser/DEPS1
-rw-r--r--content/browser/renderer_host/render_message_filter.cc11
-rw-r--r--content/browser/renderer_host/render_message_filter.h6
23 files changed, 575 insertions, 212 deletions
diff --git a/build/common.gypi b/build/common.gypi
index 6083fab..387cd78 100644
--- a/build/common.gypi
+++ b/build/common.gypi
@@ -437,6 +437,9 @@
# Point to ICU directory.
'icu_src_dir': '../third_party/icu',
+ # Enable desktop notifications.
+ 'enable_desktop_notifications%': 1,
+
'conditions': [
['os_posix==1 and OS!="mac"', {
# This will set gcc_version to XY if you are running gcc X.Y.*.
diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc
index 692f406..c61aa45 100644
--- a/chrome/browser/chrome_content_browser_client.cc
+++ b/chrome/browser/chrome_content_browser_client.cc
@@ -124,7 +124,7 @@ namespace chrome {
void ChromeContentBrowserClient::RenderViewHostCreated(
RenderViewHost* render_view_host) {
new ChromeRenderViewHostObserver(render_view_host);
- new DesktopNotificationHandler(render_view_host);
+ DesktopNotificationHandler::Create(render_view_host);
new DevToolsHandler(render_view_host);
new ExtensionMessageHandler(render_view_host);
diff --git a/chrome/browser/desktop_notification_handler.cc b/chrome/browser/desktop_notification_handler.cc
index da6f2e8..6c27029 100644
--- a/chrome/browser/desktop_notification_handler.cc
+++ b/chrome/browser/desktop_notification_handler.cc
@@ -13,14 +13,20 @@
#include "content/browser/renderer_host/render_view_host_delegate.h"
#include "content/common/desktop_notification_messages.h"
-DesktopNotificationHandler::DesktopNotificationHandler(
- RenderViewHost* render_view_host)
- : RenderViewHostObserver(render_view_host) {
+// static
+DesktopNotificationHandler*
+DesktopNotificationHandler::Create(RenderViewHost* render_view_host) {
+ return new DesktopNotificationHandler(render_view_host);
}
DesktopNotificationHandler::~DesktopNotificationHandler() {
}
+DesktopNotificationHandler::DesktopNotificationHandler(
+ RenderViewHost* render_view_host)
+ : RenderViewHostObserver(render_view_host) {
+}
+
bool DesktopNotificationHandler::OnMessageReceived(
const IPC::Message& message) {
bool handled = true;
diff --git a/chrome/browser/desktop_notification_handler.h b/chrome/browser/desktop_notification_handler.h
index d956ec0..51ce7e8 100644
--- a/chrome/browser/desktop_notification_handler.h
+++ b/chrome/browser/desktop_notification_handler.h
@@ -15,10 +15,12 @@ struct DesktopNotificationHostMsg_Show_Params;
// coming in from the renderer.
class DesktopNotificationHandler : public RenderViewHostObserver {
public:
- explicit DesktopNotificationHandler(RenderViewHost* render_view_host);
+ static DesktopNotificationHandler* Create(RenderViewHost* render_view_host);
virtual ~DesktopNotificationHandler();
private:
+ explicit DesktopNotificationHandler(RenderViewHost* render_view_host);
+
// RenderViewHostObserver implementation.
virtual bool OnMessageReceived(const IPC::Message& message);
diff --git a/chrome/browser/desktop_notification_handler_stub.cc b/chrome/browser/desktop_notification_handler_stub.cc
new file mode 100644
index 0000000..9966b45
--- /dev/null
+++ b/chrome/browser/desktop_notification_handler_stub.cc
@@ -0,0 +1,12 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/desktop_notification_handler.h"
+
+// static
+DesktopNotificationHandler*
+DesktopNotificationHandler::Create(RenderViewHost* render_view_host) {
+ return NULL;
+}
+
diff --git a/chrome/browser/notifications/desktop_notification_service.cc b/chrome/browser/notifications/desktop_notification_service.cc
index 205afb6..06e3775 100644
--- a/chrome/browser/notifications/desktop_notification_service.cc
+++ b/chrome/browser/notifications/desktop_notification_service.cc
@@ -591,3 +591,8 @@ void DesktopNotificationService::NotifySettingsChange() {
Source<DesktopNotificationService>(this),
NotificationService::NoDetails());
}
+
+int DesktopNotificationService::HasPermission(const GURL& origin) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ return prefs_cache()->HasPermission(origin.GetOrigin());
+}
diff --git a/chrome/browser/notifications/desktop_notification_service.h b/chrome/browser/notifications/desktop_notification_service.h
index 50f28f5..ae2738d 100644
--- a/chrome/browser/notifications/desktop_notification_service.h
+++ b/chrome/browser/notifications/desktop_notification_service.h
@@ -23,7 +23,9 @@
#include "googleurl/src/gurl.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebTextDirection.h"
+class Extension;
class Notification;
+class NotificationDelegate;
class NotificationUIManager;
class NotificationsPrefsCache;
class PrefService;
@@ -124,6 +126,11 @@ class DesktopNotificationService : public NotificationObserver,
ContentSetting GetContentSetting(const GURL& origin);
+ // Checks to see if a given origin has permission to create desktop
+ // notifications. Returns a constant from WebNotificationPresenter
+ // class.
+ int HasPermission(const GURL& origin);
+
private:
void InitPrefs();
void StartObserving();
diff --git a/chrome/browser/notifications/desktop_notifications_unittest.cc b/chrome/browser/notifications/desktop_notifications_unittest.cc
index b3d72ff..6e73693 100644
--- a/chrome/browser/notifications/desktop_notifications_unittest.cc
+++ b/chrome/browser/notifications/desktop_notifications_unittest.cc
@@ -85,9 +85,8 @@ void DesktopNotificationsTest::SetUp() {
browser::RegisterLocalState(&local_state_);
profile_.reset(new TestingProfile());
balloon_collection_ = new MockBalloonCollection();
- ui_manager_.reset(new NotificationUIManager(&local_state_));
- ui_manager_->Initialize(balloon_collection_);
- balloon_collection_->set_space_change_listener(ui_manager_.get());
+ ui_manager_.reset(NotificationUIManager::Create(&local_state_,
+ balloon_collection_));
service_.reset(new DesktopNotificationService(profile(), ui_manager_.get()));
log_output_.clear();
}
diff --git a/chrome/browser/notifications/notification_stubs.cc b/chrome/browser/notifications/notification_stubs.cc
new file mode 100644
index 0000000..bb2586d
--- /dev/null
+++ b/chrome/browser/notifications/notification_stubs.cc
@@ -0,0 +1,176 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/notifications/balloon_host.h"
+#include "chrome/browser/notifications/desktop_notification_service.h"
+#include "chrome/browser/notifications/desktop_notification_service_factory.h"
+#include "chrome/browser/notifications/notification.h"
+#include "chrome/browser/notifications/notification_ui_manager.h"
+#include "chrome/browser/notifications/notifications_prefs_cache.h"
+#include "chrome/browser/prefs/pref_service.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/profiles/profile_dependency_manager.h"
+#include "chrome/common/pref_names.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebNotificationPresenter.h"
+
+////////////////////////// NotificationUIManager //////////////////////////////
+
+// static
+NotificationUIManager* NotificationUIManager::Create(PrefService* local_state) {
+ return new NotificationUIManager(local_state);
+}
+
+NotificationUIManager::NotificationUIManager(PrefService* local_state) {
+}
+
+NotificationUIManager::~NotificationUIManager() {
+}
+
+// static
+void NotificationUIManager::RegisterPrefs(PrefService* prefs) {
+}
+
+void NotificationUIManager::Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+}
+
+void NotificationUIManager::Add(const Notification& notification,
+ Profile* profile) {
+}
+
+bool NotificationUIManager::CancelById(const std::string& notification_id) {
+ return true;
+}
+
+bool NotificationUIManager::CancelAllBySourceOrigin(const GURL& source_origin) {
+ return true;
+}
+
+void NotificationUIManager::OnBalloonSpaceChanged() {
+}
+
+/////////////////////////// DesktopNotificationService ////////////////////////
+
+DesktopNotificationService::DesktopNotificationService(Profile* profile,
+ NotificationUIManager* ui_manager) {
+}
+
+DesktopNotificationService::~DesktopNotificationService() {
+}
+
+void DesktopNotificationService::RequestPermission(
+ const GURL& origin, int process_id, int route_id, int callback_context,
+ TabContents* tab) {
+}
+
+void DesktopNotificationService::RegisterUserPrefs(PrefService* user_prefs) {
+ content_settings::NotificationProvider::RegisterUserPrefs(user_prefs);
+}
+
+void DesktopNotificationService::GrantPermission(const GURL& origin) {
+}
+
+void DesktopNotificationService::DenyPermission(const GURL& origin) {
+}
+
+void DesktopNotificationService::Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+}
+
+ContentSetting DesktopNotificationService::GetDefaultContentSetting() {
+ return CONTENT_SETTING_DEFAULT;
+}
+
+void DesktopNotificationService::SetDefaultContentSetting(
+ ContentSetting setting) {
+}
+
+bool DesktopNotificationService::IsDefaultContentSettingManaged() const {
+ return false;
+}
+
+std::vector<GURL> DesktopNotificationService::GetAllowedOrigins() {
+ return std::vector<GURL>();
+}
+
+std::vector<GURL> DesktopNotificationService::GetBlockedOrigins() {
+ return std::vector<GURL>();
+}
+
+void DesktopNotificationService::ResetAllowedOrigin(const GURL& origin) {
+}
+
+void DesktopNotificationService::ResetBlockedOrigin(const GURL& origin) {
+}
+
+int DesktopNotificationService::HasPermission(const GURL& origin) {
+ return WebKit::WebNotificationPresenter::PermissionNotAllowed;
+}
+
+// static
+DesktopNotificationService* DesktopNotificationServiceFactory::GetForProfile(
+ Profile* profile) {
+ return NULL;
+}
+
+// static
+string16 DesktopNotificationService::CreateDataUrl(
+ const GURL& icon_url,
+ const string16& title,
+ const string16& body,
+ WebKit::WebTextDirection dir) {
+ return string16();
+}
+
+///////////////////// DesktopNotificationServiceFactory ///////////////////////
+
+// static
+DesktopNotificationServiceFactory* DesktopNotificationServiceFactory::
+ GetInstance() {
+ return Singleton<DesktopNotificationServiceFactory>::get();
+}
+
+DesktopNotificationServiceFactory::DesktopNotificationServiceFactory()
+ : ProfileKeyedServiceFactory(ProfileDependencyManager::GetInstance()) {
+}
+
+DesktopNotificationServiceFactory::~DesktopNotificationServiceFactory() {
+}
+
+ProfileKeyedService* DesktopNotificationServiceFactory::BuildServiceInstanceFor(
+ Profile* profile) const {
+ return NULL;
+}
+
+bool DesktopNotificationServiceFactory::ServiceHasOwnInstanceInIncognito() {
+ return true;
+}
+
+/////////////////////////////////// BalloonHost ///////////////////////////////
+
+// static
+bool BalloonHost::IsRenderViewReady() const {
+ return true;
+}
+
+//////////////////////////// NotificationsPrefsCache //////////////////////////
+
+// static
+void NotificationsPrefsCache::ListValueToGurlVector(
+ const ListValue& origin_list,
+ std::vector<GURL>* origin_vector) {
+}
+
+
+Notification::Notification(const GURL& origin_url,
+ const GURL& content_url,
+ const string16& display_source,
+ const string16& replace_id,
+ NotificationDelegate* delegate) {
+}
+
+Notification::~Notification() {
+}
diff --git a/chrome/browser/notifications/notification_ui_manager.cc b/chrome/browser/notifications/notification_ui_manager.cc
index 56c90f2..a5afc4c 100644
--- a/chrome/browser/notifications/notification_ui_manager.cc
+++ b/chrome/browser/notifications/notification_ui_manager.cc
@@ -67,7 +67,13 @@ NotificationUIManager::~NotificationUIManager() {
// static
NotificationUIManager* NotificationUIManager::Create(PrefService* local_state) {
- BalloonCollection* balloons = BalloonCollection::Create();
+ return Create(local_state, BalloonCollection::Create());
+}
+
+// static
+NotificationUIManager* NotificationUIManager::Create(
+ PrefService* local_state,
+ BalloonCollection* balloons) {
NotificationUIManager* instance = new NotificationUIManager(local_state);
instance->Initialize(balloons);
balloons->set_space_change_listener(instance);
diff --git a/chrome/browser/notifications/notification_ui_manager.h b/chrome/browser/notifications/notification_ui_manager.h
index fb78473..2c6d931 100644
--- a/chrome/browser/notifications/notification_ui_manager.h
+++ b/chrome/browser/notifications/notification_ui_manager.h
@@ -30,7 +30,6 @@ class NotificationUIManager
: public BalloonCollection::BalloonSpaceChangeListener,
public NotificationObserver {
public:
- explicit NotificationUIManager(PrefService* local_state);
virtual ~NotificationUIManager();
// Creates an initialized UI manager with a new balloon collection
@@ -38,6 +37,12 @@ class NotificationUIManager
// Except for unit tests, this is the way to construct the object.
static NotificationUIManager* Create(PrefService* local_state);
+ // Creates an initialized UI manager with the given balloon collection
+ // and the listener relationship setup.
+ // Used primarily by unit tests.
+ static NotificationUIManager* Create(PrefService* local_state,
+ BalloonCollection* balloons);
+
// Registers preferences.
static void RegisterPrefs(PrefService* prefs);
@@ -75,6 +80,8 @@ class NotificationUIManager
void SetPositionPreference(BalloonCollection::PositionPreference preference);
private:
+ explicit NotificationUIManager(PrefService* local_state);
+
// NotificationObserver override.
virtual void Observe(NotificationType type,
const NotificationSource& source,
diff --git a/chrome/browser/task_manager/task_manager.cc b/chrome/browser/task_manager/task_manager.cc
index 61166ea..4fe6403 100644
--- a/chrome/browser/task_manager/task_manager.cc
+++ b/chrome/browser/task_manager/task_manager.cc
@@ -86,8 +86,11 @@ TaskManagerModel::TaskManagerModel(TaskManager* task_manager)
new TaskManagerChildProcessResourceProvider(task_manager));
AddResourceProvider(
new TaskManagerExtensionProcessResourceProvider(task_manager));
- AddResourceProvider(
- new TaskManagerNotificationResourceProvider(task_manager));
+
+ TaskManager::ResourceProvider* provider =
+ TaskManagerNotificationResourceProvider::Create(task_manager);
+ if (provider)
+ AddResourceProvider(provider);
}
TaskManagerModel::~TaskManagerModel() {
diff --git a/chrome/browser/task_manager/task_manager_browsertest.cc b/chrome/browser/task_manager/task_manager_browsertest.cc
index 4bd10d4..8a060d9 100644
--- a/chrome/browser/task_manager/task_manager_browsertest.cc
+++ b/chrome/browser/task_manager/task_manager_browsertest.cc
@@ -365,39 +365,6 @@ IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeHostedAppTabs) {
ASSERT_TRUE(StartsWith(model()->GetResourceTitle(2), tab_prefix, true));
}
-IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeNotificationChanges) {
- EXPECT_EQ(0, model()->ResourceCount());
-
- // Show the task manager.
- browser()->window()->ShowTaskManager();
- // Expect to see the browser and the New Tab Page renderer.
- WaitForResourceChange(2);
-
- // Show a notification.
- NotificationUIManager* notifications =
- g_browser_process->notification_ui_manager();
-
- string16 content = DesktopNotificationService::CreateDataUrl(
- GURL(), ASCIIToUTF16("Hello World!"), string16(),
- WebKit::WebTextDirectionDefault);
-
- scoped_refptr<NotificationDelegate> del1(new MockNotificationDelegate("n1"));
- Notification n1(
- GURL(), GURL(content), ASCIIToUTF16("Test 1"), string16(), del1.get());
- scoped_refptr<NotificationDelegate> del2(new MockNotificationDelegate("n2"));
- Notification n2(
- GURL(), GURL(content), ASCIIToUTF16("Test 2"), string16(), del2.get());
-
- notifications->Add(n1, browser()->profile());
- WaitForResourceChange(3);
- notifications->Add(n2, browser()->profile());
- WaitForResourceChange(4);
- notifications->CancelById(n1.notification_id());
- WaitForResourceChange(3);
- notifications->CancelById(n2.notification_id());
- WaitForResourceChange(2);
-}
-
IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, KillExtension) {
EXPECT_EQ(0, TaskManager::GetBackgroundPageCount());
// Show the task manager. This populates the model, and helps with debugging
diff --git a/chrome/browser/task_manager/task_manager_notification_browsertest.cc b/chrome/browser/task_manager/task_manager_notification_browsertest.cc
new file mode 100644
index 0000000..c9e858b
--- /dev/null
+++ b/chrome/browser/task_manager/task_manager_notification_browsertest.cc
@@ -0,0 +1,106 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/task_manager/task_manager.h"
+
+#include "base/utf_string_conversions.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/extensions/extension_browsertest.h"
+#include "chrome/browser/notifications/desktop_notification_service.h"
+#include "chrome/browser/notifications/notification.h"
+#include "chrome/browser/notifications/notification_test_util.h"
+#include "chrome/browser/notifications/notification_ui_manager.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/browser_window.h"
+#include "chrome/test/in_process_browser_test.h"
+#include "chrome/test/ui_test_utils.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+
+class ResourceChangeObserver : public TaskManagerModelObserver {
+ public:
+ ResourceChangeObserver(const TaskManagerModel* model,
+ int target_resource_count)
+ : model_(model),
+ target_resource_count_(target_resource_count) {
+ }
+
+ virtual void OnModelChanged() {
+ OnResourceChange();
+ }
+
+ virtual void OnItemsChanged(int start, int length) {
+ OnResourceChange();
+ }
+
+ virtual void OnItemsAdded(int start, int length) {
+ OnResourceChange();
+ }
+
+ virtual void OnItemsRemoved(int start, int length) {
+ OnResourceChange();
+ }
+
+ private:
+ void OnResourceChange() {
+ if (model_->ResourceCount() == target_resource_count_)
+ MessageLoopForUI::current()->Quit();
+ }
+
+ const TaskManagerModel* model_;
+ const int target_resource_count_;
+};
+
+} // namespace
+
+class TaskManagerNotificationBrowserTest : public ExtensionBrowserTest {
+ public:
+ TaskManagerModel* model() const {
+ return TaskManager::GetInstance()->model();
+ }
+
+ void WaitForResourceChange(int target_count) {
+ if (model()->ResourceCount() == target_count)
+ return;
+ ResourceChangeObserver observer(model(), target_count);
+ model()->AddObserver(&observer);
+ ui_test_utils::RunMessageLoop();
+ model()->RemoveObserver(&observer);
+ }
+};
+
+IN_PROC_BROWSER_TEST_F(TaskManagerNotificationBrowserTest,
+ NoticeNotificationChanges) {
+ EXPECT_EQ(0, model()->ResourceCount());
+
+ // Show the task manager.
+ browser()->window()->ShowTaskManager();
+ // Expect to see the browser and the New Tab Page renderer.
+ WaitForResourceChange(2);
+
+ // Show a notification.
+ NotificationUIManager* notifications =
+ g_browser_process->notification_ui_manager();
+
+ string16 content = DesktopNotificationService::CreateDataUrl(
+ GURL(), ASCIIToUTF16("Hello World!"), string16(),
+ WebKit::WebTextDirectionDefault);
+
+ scoped_refptr<NotificationDelegate> del1(new MockNotificationDelegate("n1"));
+ Notification n1(
+ GURL(), GURL(content), ASCIIToUTF16("Test 1"), string16(), del1.get());
+ scoped_refptr<NotificationDelegate> del2(new MockNotificationDelegate("n2"));
+ Notification n2(
+ GURL(), GURL(content), ASCIIToUTF16("Test 2"), string16(), del2.get());
+
+ notifications->Add(n1, browser()->profile());
+ WaitForResourceChange(3);
+ notifications->Add(n2, browser()->profile());
+ WaitForResourceChange(4);
+ notifications->CancelById(n1.notification_id());
+ WaitForResourceChange(3);
+ notifications->CancelById(n2.notification_id());
+ WaitForResourceChange(2);
+}
diff --git a/chrome/browser/task_manager/task_manager_notification_resource_provider.cc b/chrome/browser/task_manager/task_manager_notification_resource_provider.cc
new file mode 100644
index 0000000..457d8a2
--- /dev/null
+++ b/chrome/browser/task_manager/task_manager_notification_resource_provider.cc
@@ -0,0 +1,171 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/task_manager/task_manager_resource_providers.h"
+
+#include "base/basictypes.h"
+#include "base/stl_util-inl.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/notifications/balloon_collection.h"
+#include "chrome/browser/notifications/balloon_host.h"
+#include "chrome/browser/notifications/notification_ui_manager.h"
+#include "content/browser/renderer_host/render_process_host.h"
+#include "content/browser/renderer_host/render_view_host.h"
+#include "content/common/notification_service.h"
+#include "grit/generated_resources.h"
+#include "grit/theme_resources.h"
+#include "third_party/skia/include/core/SkBitmap.h"
+#include "ui/base/l10n/l10n_util.h"
+#include "ui/base/resource/resource_bundle.h"
+
+////////////////////////////////////////////////////////////////////////////////
+// TaskManagerNotificationResource class
+////////////////////////////////////////////////////////////////////////////////
+
+SkBitmap* TaskManagerNotificationResource::default_icon_ = NULL;
+
+TaskManagerNotificationResource::TaskManagerNotificationResource(
+ BalloonHost* balloon_host)
+ : balloon_host_(balloon_host) {
+ if (!default_icon_) {
+ ResourceBundle& rb = ResourceBundle::GetSharedInstance();
+ default_icon_ = rb.GetBitmapNamed(IDR_PLUGIN);
+ }
+ process_handle_ = balloon_host_->render_view_host()->process()->GetHandle();
+ pid_ = base::GetProcId(process_handle_);
+ title_ = l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_NOTIFICATION_PREFIX,
+ balloon_host_->GetSource());
+}
+
+TaskManagerNotificationResource::~TaskManagerNotificationResource() {
+}
+
+string16 TaskManagerNotificationResource::GetTitle() const {
+ return title_;
+}
+
+SkBitmap TaskManagerNotificationResource::GetIcon() const {
+ return *default_icon_;
+}
+
+base::ProcessHandle TaskManagerNotificationResource::GetProcess() const {
+ return process_handle_;
+}
+
+TaskManager::Resource::Type TaskManagerNotificationResource::GetType() const {
+ return NOTIFICATION;
+}
+
+bool TaskManagerNotificationResource::SupportNetworkUsage() const {
+ return false;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// TaskManagerNotificationResourceProvider class
+////////////////////////////////////////////////////////////////////////////////
+
+// static
+TaskManagerNotificationResourceProvider*
+TaskManagerNotificationResourceProvider::Create(TaskManager* task_manager) {
+ return new TaskManagerNotificationResourceProvider(task_manager);
+}
+
+TaskManagerNotificationResourceProvider::
+ TaskManagerNotificationResourceProvider(TaskManager* task_manager)
+ : task_manager_(task_manager),
+ updating_(false) {
+}
+
+TaskManagerNotificationResourceProvider::
+ ~TaskManagerNotificationResourceProvider() {
+}
+
+TaskManager::Resource* TaskManagerNotificationResourceProvider::GetResource(
+ int origin_pid,
+ int render_process_host_id,
+ int routing_id) {
+ // TODO(johnnyg): provide resources by pid if necessary.
+ return NULL;
+}
+
+void TaskManagerNotificationResourceProvider::StartUpdating() {
+ DCHECK(!updating_);
+ updating_ = true;
+
+ // Add all the existing BalloonHosts.
+ BalloonCollection* collection =
+ g_browser_process->notification_ui_manager()->balloon_collection();
+ const BalloonCollection::Balloons& balloons = collection->GetActiveBalloons();
+ for (BalloonCollection::Balloons::const_iterator it = balloons.begin();
+ it != balloons.end(); ++it) {
+ AddToTaskManager((*it)->view()->GetHost());
+ }
+
+ // Register for notifications about extension process changes.
+ registrar_.Add(this, NotificationType::NOTIFY_BALLOON_CONNECTED,
+ NotificationService::AllSources());
+ registrar_.Add(this, NotificationType::NOTIFY_BALLOON_DISCONNECTED,
+ NotificationService::AllSources());
+}
+
+void TaskManagerNotificationResourceProvider::StopUpdating() {
+ DCHECK(updating_);
+ updating_ = false;
+
+ // Unregister for notifications about extension process changes.
+ registrar_.Remove(this, NotificationType::NOTIFY_BALLOON_CONNECTED,
+ NotificationService::AllSources());
+ registrar_.Remove(this, NotificationType::NOTIFY_BALLOON_DISCONNECTED,
+ NotificationService::AllSources());
+
+ // Delete all the resources.
+ STLDeleteContainerPairSecondPointers(resources_.begin(), resources_.end());
+ resources_.clear();
+}
+
+void TaskManagerNotificationResourceProvider::Observe(
+ NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ switch (type.value) {
+ case NotificationType::NOTIFY_BALLOON_CONNECTED:
+ AddToTaskManager(Source<BalloonHost>(source).ptr());
+ break;
+ case NotificationType::NOTIFY_BALLOON_DISCONNECTED:
+ RemoveFromTaskManager(Source<BalloonHost>(source).ptr());
+ break;
+ default:
+ NOTREACHED() << "Unexpected notification.";
+ return;
+ }
+}
+
+void TaskManagerNotificationResourceProvider::AddToTaskManager(
+ BalloonHost* balloon_host) {
+ TaskManagerNotificationResource* resource =
+ new TaskManagerNotificationResource(balloon_host);
+ DCHECK(resources_.find(balloon_host) == resources_.end());
+ resources_[balloon_host] = resource;
+ task_manager_->AddResource(resource);
+}
+
+void TaskManagerNotificationResourceProvider::RemoveFromTaskManager(
+ BalloonHost* balloon_host) {
+ if (!updating_)
+ return;
+ std::map<BalloonHost*, TaskManagerNotificationResource*>::iterator iter =
+ resources_.find(balloon_host);
+ if (iter == resources_.end())
+ return;
+
+ // Remove the resource from the Task Manager.
+ TaskManagerNotificationResource* resource = iter->second;
+ task_manager_->RemoveResource(resource);
+
+ // Remove it from the map.
+ resources_.erase(iter);
+
+ // Finally, delete the resource.
+ delete resource;
+}
diff --git a/chrome/browser/task_manager/task_manager_notification_resource_provider_stub.cc b/chrome/browser/task_manager/task_manager_notification_resource_provider_stub.cc
new file mode 100644
index 0000000..f6b9c31
--- /dev/null
+++ b/chrome/browser/task_manager/task_manager_notification_resource_provider_stub.cc
@@ -0,0 +1,11 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/task_manager/task_manager_resource_providers.h"
+
+// static
+TaskManagerNotificationResourceProvider*
+TaskManagerNotificationResourceProvider::Create(TaskManager* task_manager) {
+ return NULL;
+}
diff --git a/chrome/browser/task_manager/task_manager_resource_providers.cc b/chrome/browser/task_manager/task_manager_resource_providers.cc
index 0dba1f1..f385823 100644
--- a/chrome/browser/task_manager/task_manager_resource_providers.cc
+++ b/chrome/browser/task_manager/task_manager_resource_providers.cc
@@ -21,9 +21,6 @@
#include "chrome/browser/extensions/extension_process_manager.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/favicon/favicon_tab_helper.h"
-#include "chrome/browser/notifications/balloon_collection.h"
-#include "chrome/browser/notifications/balloon_host.h"
-#include "chrome/browser/notifications/notification_ui_manager.h"
#include "chrome/browser/prerender/prerender_manager.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/tab_contents/background_contents.h"
@@ -1182,151 +1179,6 @@ void TaskManagerExtensionProcessResourceProvider::RemoveFromTaskManager(
}
////////////////////////////////////////////////////////////////////////////////
-// TaskManagerNotificationResource class
-////////////////////////////////////////////////////////////////////////////////
-
-SkBitmap* TaskManagerNotificationResource::default_icon_ = NULL;
-
-TaskManagerNotificationResource::TaskManagerNotificationResource(
- BalloonHost* balloon_host)
- : balloon_host_(balloon_host) {
- if (!default_icon_) {
- ResourceBundle& rb = ResourceBundle::GetSharedInstance();
- default_icon_ = rb.GetBitmapNamed(IDR_PLUGIN);
- }
- process_handle_ = balloon_host_->render_view_host()->process()->GetHandle();
- pid_ = base::GetProcId(process_handle_);
- title_ = l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_NOTIFICATION_PREFIX,
- balloon_host_->GetSource());
-}
-
-TaskManagerNotificationResource::~TaskManagerNotificationResource() {
-}
-
-string16 TaskManagerNotificationResource::GetTitle() const {
- return title_;
-}
-
-SkBitmap TaskManagerNotificationResource::GetIcon() const {
- return *default_icon_;
-}
-
-base::ProcessHandle TaskManagerNotificationResource::GetProcess() const {
- return process_handle_;
-}
-
-TaskManager::Resource::Type TaskManagerNotificationResource::GetType() const {
- return NOTIFICATION;
-}
-
-bool TaskManagerNotificationResource::SupportNetworkUsage() const {
- return false;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// TaskManagerNotificationResourceProvider class
-////////////////////////////////////////////////////////////////////////////////
-
-TaskManagerNotificationResourceProvider::
- TaskManagerNotificationResourceProvider(TaskManager* task_manager)
- : task_manager_(task_manager),
- updating_(false) {
-}
-
-TaskManagerNotificationResourceProvider::
- ~TaskManagerNotificationResourceProvider() {
-}
-
-TaskManager::Resource* TaskManagerNotificationResourceProvider::GetResource(
- int origin_pid,
- int render_process_host_id,
- int routing_id) {
- // TODO(johnnyg): provide resources by pid if necessary.
- return NULL;
-}
-
-void TaskManagerNotificationResourceProvider::StartUpdating() {
- DCHECK(!updating_);
- updating_ = true;
-
- // Add all the existing BalloonHosts.
- BalloonCollection* collection =
- g_browser_process->notification_ui_manager()->balloon_collection();
- const BalloonCollection::Balloons& balloons = collection->GetActiveBalloons();
- for (BalloonCollection::Balloons::const_iterator it = balloons.begin();
- it != balloons.end(); ++it) {
- AddToTaskManager((*it)->view()->GetHost());
- }
-
- // Register for notifications about extension process changes.
- registrar_.Add(this, NotificationType::NOTIFY_BALLOON_CONNECTED,
- NotificationService::AllSources());
- registrar_.Add(this, NotificationType::NOTIFY_BALLOON_DISCONNECTED,
- NotificationService::AllSources());
-}
-
-void TaskManagerNotificationResourceProvider::StopUpdating() {
- DCHECK(updating_);
- updating_ = false;
-
- // Unregister for notifications about extension process changes.
- registrar_.Remove(this, NotificationType::NOTIFY_BALLOON_CONNECTED,
- NotificationService::AllSources());
- registrar_.Remove(this, NotificationType::NOTIFY_BALLOON_DISCONNECTED,
- NotificationService::AllSources());
-
- // Delete all the resources.
- STLDeleteContainerPairSecondPointers(resources_.begin(), resources_.end());
- resources_.clear();
-}
-
-void TaskManagerNotificationResourceProvider::Observe(
- NotificationType type,
- const NotificationSource& source,
- const NotificationDetails& details) {
- switch (type.value) {
- case NotificationType::NOTIFY_BALLOON_CONNECTED:
- AddToTaskManager(Source<BalloonHost>(source).ptr());
- break;
- case NotificationType::NOTIFY_BALLOON_DISCONNECTED:
- RemoveFromTaskManager(Source<BalloonHost>(source).ptr());
- break;
- default:
- NOTREACHED() << "Unexpected notification.";
- return;
- }
-}
-
-void TaskManagerNotificationResourceProvider::AddToTaskManager(
- BalloonHost* balloon_host) {
- TaskManagerNotificationResource* resource =
- new TaskManagerNotificationResource(balloon_host);
- DCHECK(resources_.find(balloon_host) == resources_.end());
- resources_[balloon_host] = resource;
- task_manager_->AddResource(resource);
-}
-
-void TaskManagerNotificationResourceProvider::RemoveFromTaskManager(
- BalloonHost* balloon_host) {
- if (!updating_)
- return;
- std::map<BalloonHost*, TaskManagerNotificationResource*>::iterator iter =
- resources_.find(balloon_host);
- if (iter == resources_.end())
- return;
-
- // Remove the resource from the Task Manager.
- TaskManagerNotificationResource* resource = iter->second;
- task_manager_->RemoveResource(resource);
-
- // Remove it from the map.
- resources_.erase(iter);
-
- // Finally, delete the resource.
- delete resource;
-}
-
-////////////////////////////////////////////////////////////////////////////////
// TaskManagerBrowserProcessResource class
////////////////////////////////////////////////////////////////////////////////
diff --git a/chrome/browser/task_manager/task_manager_resource_providers.h b/chrome/browser/task_manager/task_manager_resource_providers.h
index f6251f7..a14498e 100644
--- a/chrome/browser/task_manager/task_manager_resource_providers.h
+++ b/chrome/browser/task_manager/task_manager_resource_providers.h
@@ -416,7 +416,8 @@ class TaskManagerNotificationResourceProvider
: public TaskManager::ResourceProvider,
public NotificationObserver {
public:
- explicit TaskManagerNotificationResourceProvider(TaskManager* task_manager);
+ static TaskManagerNotificationResourceProvider* Create(
+ TaskManager* task_manager);
// TaskManager::ResourceProvider interface
virtual TaskManager::Resource* GetResource(int origin_pid,
@@ -431,6 +432,7 @@ class TaskManagerNotificationResourceProvider
const NotificationDetails& details);
private:
+ explicit TaskManagerNotificationResourceProvider(TaskManager* task_manager);
virtual ~TaskManagerNotificationResourceProvider();
void AddToTaskManager(BalloonHost* balloon_host);
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 1870402..c95defc 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -799,6 +799,7 @@
'browser/defaults.h',
'browser/desktop_notification_handler.cc',
'browser/desktop_notification_handler.h',
+ 'browser/desktop_notification_handler_stub.cc',
'browser/diagnostics/diagnostics_main.cc',
'browser/diagnostics/diagnostics_main.h',
'browser/diagnostics/diagnostics_model.cc',
@@ -1471,6 +1472,7 @@
'browser/notifications/notification_object_proxy.h',
'browser/notifications/notification_options_menu_model.cc',
'browser/notifications/notification_options_menu_model.h',
+ 'browser/notifications/notification_stubs.cc',
'browser/notifications/notification_ui_manager.cc',
'browser/notifications/notification_ui_manager.h',
'browser/notifications/notifications_prefs_cache.cc',
@@ -2100,6 +2102,8 @@
'browser/tabs/tab_strip_selection_model.h',
'browser/task_manager/task_manager.cc',
'browser/task_manager/task_manager.h',
+ 'browser/task_manager/task_manager_notification_resource_provider.cc',
+ 'browser/task_manager/task_manager_notification_resource_provider_stub.cc',
'browser/task_manager/task_manager_resource_providers.cc',
'browser/task_manager/task_manager_resource_providers.h',
'browser/themes/browser_theme_pack.cc',
@@ -4451,6 +4455,23 @@
['exclude', '^browser/ui/views/file_manager_dialog.h'],
]}
],
+ ['enable_desktop_notifications==0', {
+ 'sources/': [
+ ['exclude', '^browser/desktop_notification_handler.cc'],
+ ['exclude', '^browser/notifications/'],
+ ['exclude', '^browser/ui/cocoa/notifications/'],
+ ['exclude', '^browser/ui/gtk/notifications/'],
+ ['exclude', '^browser/ui/views/notifications/'],
+ ['include', '^browser/notifications/notification_stubs.cc'],
+ ['exclude', '^browser/task_manager/task_manager_notification_resource_provider.cc'],
+ ]
+ }, { # enable_desktop_notifications==0
+ 'sources!': [
+ 'browser/desktop_notification_handler_stub.cc',
+ 'browser/notifications/notification_stubs.cc',
+ 'browser/task_manager/task_manager_notification_resource_provider_stub.cc',
+ ]
+ }],
],
},
{
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index a8a3b77..b6be89f 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -1470,11 +1470,6 @@
'browser/net/sqlite_persistent_cookie_store_unittest.cc',
'browser/net/url_fixer_upper_unittest.cc',
'browser/net/url_info_unittest.cc',
- 'browser/notifications/desktop_notification_service_unittest.cc',
- 'browser/notifications/desktop_notifications_unittest.cc',
- 'browser/notifications/desktop_notifications_unittest.h',
- 'browser/notifications/notification_exceptions_table_model_unittest.cc',
- 'browser/notifications/notifications_prefs_cache_unittest.cc',
'browser/parsers/metadata_parser_filebase_unittest.cc',
'browser/password_manager/encryptor_password_mac_unittest.cc',
'browser/password_manager/encryptor_unittest.cc',
@@ -1756,7 +1751,6 @@
'browser/ui/cocoa/location_bar/selected_keyword_decoration_unittest.mm',
'browser/ui/cocoa/menu_button_unittest.mm',
'browser/ui/cocoa/menu_controller_unittest.mm',
- 'browser/ui/cocoa/notifications/balloon_controller_unittest.mm',
'browser/ui/cocoa/nsimage_cache_unittest.mm',
'browser/ui/cocoa/nsmenuitem_additions_unittest.mm',
'browser/ui/cocoa/objc_method_swizzle_unittest.mm',
@@ -2003,6 +1997,16 @@
'../webkit/fileapi/file_system_test_helper.h',
],
'conditions': [
+ ['enable_desktop_notifications==1', {
+ 'sources': [
+ 'browser/notifications/desktop_notification_service_unittest.cc',
+ 'browser/notifications/desktop_notifications_unittest.cc',
+ 'browser/notifications/desktop_notifications_unittest.h',
+ 'browser/notifications/notification_exceptions_table_model_unittest.cc',
+ 'browser/notifications/notifications_prefs_cache_unittest.cc',
+ 'browser/ui/cocoa/notifications/balloon_controller_unittest.mm',
+ ]
+ }],
['p2p_apis==1', {
'sources': [
'../content/browser/renderer_host/p2p/socket_host_test_utils.h',
@@ -2378,7 +2382,6 @@
'browser/extensions/extension_context_menu_browsertest.cc',
'browser/extensions/extension_cookies_apitest.cc',
'browser/extensions/extension_cookies_unittest.cc',
- 'browser/extensions/extension_crash_recovery_browsertest.cc',
'browser/extensions/extension_debugger_apitest.cc',
'browser/extensions/extension_decode_jpeg_apitest.cc',
'browser/extensions/extension_fileapi_apitest.cc',
@@ -2426,7 +2429,6 @@
'browser/extensions/extension_webstore_private_apitest.cc',
'browser/extensions/extension_webstore_private_browsertest.cc',
'browser/extensions/isolated_app_apitest.cc',
- 'browser/extensions/notifications_apitest.cc',
'browser/extensions/page_action_apitest.cc',
'browser/extensions/permissions_apitest.cc',
'browser/extensions/stubs_apitest.cc',
@@ -2678,6 +2680,13 @@
'../webkit/webkit.gyp:copy_npapi_test_plugin',
],
}],
+ ['enable_desktop_notifications==1', {
+ 'sources': [
+ 'browser/extensions/extension_crash_recovery_browsertest.cc',
+ 'browser/extensions/notifications_apitest.cc',
+ 'browser/task_manager/task_manager_notification_browsertest.cc',
+ ]
+ }],
], # conditions
}, # target browser_tests
{
diff --git a/content/browser/DEPS b/content/browser/DEPS
index 3372e14..92f5f13 100644
--- a/content/browser/DEPS
+++ b/content/browser/DEPS
@@ -38,7 +38,6 @@ include_rules = [
"+chrome/browser/notifications/desktop_notification_service.h",
"+chrome/browser/notifications/desktop_notification_service_factory.h",
- "+chrome/browser/notifications/notifications_prefs_cache.h",
# http://crbug.com/76788
"+chrome/browser/profiles/profile.h",
diff --git a/content/browser/renderer_host/render_message_filter.cc b/content/browser/renderer_host/render_message_filter.cc
index e82efdc..83385fc 100644
--- a/content/browser/renderer_host/render_message_filter.cc
+++ b/content/browser/renderer_host/render_message_filter.cc
@@ -18,7 +18,6 @@
#include "chrome/browser/extensions/extension_info_map.h"
#include "chrome/browser/notifications/desktop_notification_service.h"
#include "chrome/browser/notifications/desktop_notification_service_factory.h"
-#include "chrome/browser/notifications/notifications_prefs_cache.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/extensions/extension.h"
@@ -285,14 +284,14 @@ RenderMessageFilter::RenderMessageFilter(
resource_context_(profile->GetResourceContext()),
extensions_request_context_(profile->GetRequestContextForExtensions()),
render_widget_helper_(render_widget_helper),
- notification_prefs_(
- DesktopNotificationServiceFactory::GetForProfile(profile)->
- prefs_cache()),
+ notification_service_(
+ DesktopNotificationServiceFactory::GetForProfile(profile)),
incognito_(profile->IsOffTheRecord()),
webkit_context_(profile->GetWebKitContext()),
render_process_id_(render_process_id) {
DCHECK(request_context_);
+ profile_->GetPrefs();
render_widget_helper_->Init(render_process_id_, resource_dispatcher_host_);
}
@@ -627,7 +626,9 @@ void RenderMessageFilter::OnCheckNotificationPermission(
// Fall back to the regular notification preferences, which works on an
// origin basis.
- *result = notification_prefs_->HasPermission(source_url.GetOrigin());
+ *result = notification_service_ ?
+ notification_service_->HasPermission(source_url.GetOrigin()) :
+ WebKit::WebNotificationPresenter::PermissionNotAllowed;
}
void RenderMessageFilter::OnAllocateSharedMemoryBuffer(
diff --git a/content/browser/renderer_host/render_message_filter.h b/content/browser/renderer_host/render_message_filter.h
index 08741b6..6207ba7 100644
--- a/content/browser/renderer_host/render_message_filter.h
+++ b/content/browser/renderer_host/render_message_filter.h
@@ -26,10 +26,10 @@
#include "ui/gfx/native_widget_types.h"
#include "ui/gfx/surface/transport_dib.h"
+class DesktopNotificationService;
struct FontDescriptor;
class ExtensionInfoMap;
class HostContentSettingsMap;
-class NotificationsPrefsCache;
class Profile;
class RenderWidgetHelper;
struct ViewHostMsg_CreateWindow_Params;
@@ -238,9 +238,7 @@ class RenderMessageFilter : public BrowserMessageFilter {
scoped_refptr<RenderWidgetHelper> render_widget_helper_;
- // A cache of notifications preferences which is used to handle
- // Desktop Notifications permission messages.
- scoped_refptr<NotificationsPrefsCache> notification_prefs_;
+ DesktopNotificationService* notification_service_;
// Whether this process is used for incognito tabs.
bool incognito_;