Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(214)

Side by Side Diff: chrome/browser/notifications/platform_notification_service_impl.cc

Issue 1509923002: Implement native web notifications for mac (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/notifications/platform_notification_service_impl.h" 5 #include "chrome/browser/notifications/platform_notification_service_impl.h"
6 6
7 #include "base/command_line.h"
8 #include "base/metrics/histogram_macros.h" 7 #include "base/metrics/histogram_macros.h"
9 #include "base/metrics/user_metrics_action.h" 8 #include "base/metrics/user_metrics_action.h"
10 #include "base/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
10 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "chrome/browser/browser_process.h" 12 #include "chrome/browser/browser_process.h"
13 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 13 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
14 #include "chrome/browser/notifications/desktop_notification_profile_util.h" 14 #include "chrome/browser/notifications/desktop_notification_profile_util.h"
15 #include "chrome/browser/notifications/notification_object_proxy.h" 15 #include "chrome/browser/notifications/notification_object_proxy.h"
16 #include "chrome/browser/notifications/notification_ui_manager.h" 16 #include "chrome/browser/notifications/notification_ui_manager.h"
17 #include "chrome/browser/notifications/persistent_notification_delegate.h" 17 #include "chrome/browser/notifications/persistent_notification_delegate.h"
18 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/profiles/profile_io_data.h" 19 #include "chrome/browser/profiles/profile_io_data.h"
20 #include "chrome/browser/ui/browser.h" 20 #include "chrome/browser/ui/browser.h"
21 #include "chrome/browser/ui/chrome_pages.h" 21 #include "chrome/browser/ui/chrome_pages.h"
22 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" 22 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h"
23 #include "chrome/common/chrome_switches.h" 23 #include "chrome/common/chrome_switches.h"
24 #include "chrome/common/pref_names.h" 24 #include "chrome/common/pref_names.h"
25 #include "chrome/grit/generated_resources.h"
26 #include "components/content_settings/core/browser/host_content_settings_map.h" 25 #include "components/content_settings/core/browser/host_content_settings_map.h"
27 #include "components/content_settings/core/common/content_settings.h" 26 #include "components/content_settings/core/common/content_settings.h"
28 #include "components/content_settings/core/common/content_settings_types.h" 27 #include "components/content_settings/core/common/content_settings_types.h"
29 #include "components/url_formatter/url_formatter.h" 28 #include "components/url_formatter/url_formatter.h"
30 #include "content/public/browser/browser_thread.h" 29 #include "content/public/browser/browser_thread.h"
31 #include "content/public/browser/desktop_notification_delegate.h" 30 #include "content/public/browser/desktop_notification_delegate.h"
32 #include "content/public/browser/notification_event_dispatcher.h" 31 #include "content/public/browser/notification_event_dispatcher.h"
33 #include "content/public/browser/platform_notification_context.h" 32 #include "content/public/browser/platform_notification_context.h"
34 #include "content/public/browser/storage_partition.h" 33 #include "content/public/browser/storage_partition.h"
35 #include "content/public/browser/user_metrics.h" 34 #include "content/public/browser/user_metrics.h"
36 #include "content/public/common/platform_notification_data.h" 35 #include "content/public/common/platform_notification_data.h"
37 #include "ui/base/l10n/l10n_util.h" 36 #include "ui/base/l10n/l10n_util.h"
38 #include "ui/base/resource/resource_bundle.h" 37 #include "ui/base/resource/resource_bundle.h"
39 #include "ui/message_center/notification_types.h" 38 #include "ui/message_center/notification_types.h"
40 #include "ui/message_center/notifier_settings.h" 39 #include "ui/message_center/notifier_settings.h"
41 #include "ui/resources/grit/ui_resources.h" 40 #include "ui/resources/grit/ui_resources.h"
42 #include "url/url_constants.h" 41 #include "url/url_constants.h"
43 42
44 #if defined(ENABLE_EXTENSIONS) 43 #if defined(ENABLE_EXTENSIONS)
45 #include "chrome/browser/notifications/notifier_state_tracker.h" 44 #include "chrome/browser/notifications/notifier_state_tracker.h"
46 #include "chrome/browser/notifications/notifier_state_tracker_factory.h" 45 #include "chrome/browser/notifications/notifier_state_tracker_factory.h"
47 #include "extensions/browser/extension_registry.h" 46 #include "extensions/browser/extension_registry.h"
48 #include "extensions/browser/info_map.h" 47 #include "extensions/browser/info_map.h"
49 #include "extensions/common/constants.h" 48 #include "extensions/common/constants.h"
50 #include "extensions/common/permissions/api_permission.h" 49 #include "extensions/common/permissions/api_permission.h"
51 #include "extensions/common/permissions/permissions_data.h" 50 #include "extensions/common/permissions/permissions_data.h"
52 #endif 51 #endif
53 52
54 #if defined(OS_ANDROID)
55 #include "base/strings/string_number_conversions.h"
56 #endif
57
58 using content::BrowserContext; 53 using content::BrowserContext;
59 using content::BrowserThread; 54 using content::BrowserThread;
60 using content::PlatformNotificationContext; 55 using content::PlatformNotificationContext;
61 using message_center::NotifierId; 56 using message_center::NotifierId;
62 57
63 namespace { 58 namespace {
64 59
65 // Invalid id for a renderer process. Used in cases where we need to check for 60 // Invalid id for a renderer process. Used in cases where we need to check for
66 // permission without having an associated renderer process yet. 61 // permission without having an associated renderer process yet.
67 const int kInvalidRenderProcessId = -1; 62 const int kInvalidRenderProcessId = -1;
(...skipping 21 matching lines...) Expand all
89 84
90 } // namespace 85 } // namespace
91 86
92 // static 87 // static
93 PlatformNotificationServiceImpl* 88 PlatformNotificationServiceImpl*
94 PlatformNotificationServiceImpl::GetInstance() { 89 PlatformNotificationServiceImpl::GetInstance() {
95 return base::Singleton<PlatformNotificationServiceImpl>::get(); 90 return base::Singleton<PlatformNotificationServiceImpl>::get();
96 } 91 }
97 92
98 PlatformNotificationServiceImpl::PlatformNotificationServiceImpl() 93 PlatformNotificationServiceImpl::PlatformNotificationServiceImpl()
99 : notification_ui_manager_for_tests_(nullptr) {} 94 : notification_ui_manager_for_tests_(nullptr) {
95 #if defined(OS_MACOSX)
96 native_notification_ui_manager_.reset(
97 NotificationUIManager::CreateNativeNotificationManager());
98 #endif
99 }
100 100
101 PlatformNotificationServiceImpl::~PlatformNotificationServiceImpl() {} 101 PlatformNotificationServiceImpl::~PlatformNotificationServiceImpl() {}
102 102
103 void PlatformNotificationServiceImpl::OnPersistentNotificationClick( 103 void PlatformNotificationServiceImpl::OnPersistentNotificationClick(
104 BrowserContext* browser_context, 104 BrowserContext* browser_context,
105 int64_t persistent_notification_id, 105 int64_t persistent_notification_id,
106 const GURL& origin, 106 const GURL& origin,
107 int action_index) { 107 int action_index) {
108 DCHECK_CURRENTLY_ON(BrowserThread::UI); 108 DCHECK_CURRENTLY_ON(BrowserThread::UI);
109 blink::WebNotificationPermission permission = 109 blink::WebNotificationPermission permission =
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 BrowserContext* browser_context, 326 BrowserContext* browser_context,
327 int64_t persistent_notification_id) { 327 int64_t persistent_notification_id) {
328 DCHECK_CURRENTLY_ON(BrowserThread::UI); 328 DCHECK_CURRENTLY_ON(BrowserThread::UI);
329 329
330 Profile* profile = Profile::FromBrowserContext(browser_context); 330 Profile* profile = Profile::FromBrowserContext(browser_context);
331 DCHECK(profile); 331 DCHECK(profile);
332 332
333 #if defined(OS_ANDROID) 333 #if defined(OS_ANDROID)
334 // TODO(peter): Remove this conversion when the notification ids are being 334 // TODO(peter): Remove this conversion when the notification ids are being
335 // generated by the caller of this method. 335 // generated by the caller of this method.
336 std::string textual_persistent_notification_id =
337 base::Int64ToString(persistent_notification_id);
338 GetNotificationUIManager()->CancelById( 336 GetNotificationUIManager()->CancelById(
339 textual_persistent_notification_id, 337 base::Int64ToString(persistent_notification_id),
340 NotificationUIManager::GetProfileID(profile)); 338 NotificationUIManager::GetProfileID(profile));
341 #else 339 #else
340 if (native_notification_ui_manager_ &&
341 native_notification_ui_manager_->AcceptNativeNotifications()) {
342 GetNotificationUIManager()->CancelById(
343 base::Int64ToString(persistent_notification_id),
344 NotificationUIManager::GetProfileID(profile));
345 }
346
342 auto iter = persistent_notifications_.find(persistent_notification_id); 347 auto iter = persistent_notifications_.find(persistent_notification_id);
343 if (iter == persistent_notifications_.end()) 348 if (iter == persistent_notifications_.end())
344 return; 349 return;
345 350
346 GetNotificationUIManager()->CancelById( 351 GetNotificationUIManager()->CancelById(
347 iter->second, NotificationUIManager::GetProfileID(profile)); 352 iter->second, NotificationUIManager::GetProfileID(profile));
348 353
349 persistent_notifications_.erase(iter); 354 persistent_notifications_.erase(iter);
350 #endif 355 #endif
351 } 356 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 notification.set_never_timeout(true); 421 notification.set_never_timeout(true);
417 422
418 return notification; 423 return notification;
419 } 424 }
420 425
421 NotificationUIManager* 426 NotificationUIManager*
422 PlatformNotificationServiceImpl::GetNotificationUIManager() const { 427 PlatformNotificationServiceImpl::GetNotificationUIManager() const {
423 if (notification_ui_manager_for_tests_) 428 if (notification_ui_manager_for_tests_)
424 return notification_ui_manager_for_tests_; 429 return notification_ui_manager_for_tests_;
425 430
431 if (native_notification_ui_manager_ &&
432 native_notification_ui_manager_->AcceptNativeNotifications()) {
433 return native_notification_ui_manager_.get();
434 }
435
426 return g_browser_process->notification_ui_manager(); 436 return g_browser_process->notification_ui_manager();
427 } 437 }
428 438
429 void PlatformNotificationServiceImpl::OpenNotificationSettings( 439 void PlatformNotificationServiceImpl::OpenNotificationSettings(
430 BrowserContext* browser_context) { 440 BrowserContext* browser_context) {
431 #if defined(OS_ANDROID) 441 #if defined(OS_ANDROID)
432 NOTIMPLEMENTED(); 442 NOTIMPLEMENTED();
433 #else 443 #else
434 444
435 Profile* profile = Profile::FromBrowserContext(browser_context); 445 Profile* profile = Profile::FromBrowserContext(browser_context);
(...skipping 27 matching lines...) Expand all
463 extensions::ExtensionRegistry::Get(profile)->GetExtensionById( 473 extensions::ExtensionRegistry::Get(profile)->GetExtensionById(
464 origin.host(), extensions::ExtensionRegistry::EVERYTHING); 474 origin.host(), extensions::ExtensionRegistry::EVERYTHING);
465 DCHECK(extension); 475 DCHECK(extension);
466 476
467 return base::UTF8ToUTF16(extension->name()); 477 return base::UTF8ToUTF16(extension->name());
468 } 478 }
469 #endif 479 #endif
470 480
471 return base::string16(); 481 return base::string16();
472 } 482 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698