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

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

Issue 2906883003: Deprecate per notification type delegates. (Closed)
Patch Set: review Created 3 years, 6 months 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
« no previous file with comments | « chrome/browser/notifications/web_notification_delegate.h ('k') | content/browser/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/web_notification_delegate.h" 5 #include "chrome/browser/notifications/web_notification_delegate.h"
6 6
7 #include "base/feature_list.h" 7 #include "base/feature_list.h"
8 #include "base/metrics/histogram_macros.h" 8 #include "base/metrics/histogram_macros.h"
9 #include "chrome/browser/notifications/notification_common.h" 9 #include "base/strings/nullable_string16.h"
10 #include "chrome/browser/notifications/notification_display_service.h"
11 #include "chrome/browser/notifications/notification_display_service_factory.h"
10 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/ui/browser.h" 13 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/browser_list.h" 14 #include "chrome/browser/ui/browser_list.h"
13 #include "chrome/browser/ui/browser_window.h" 15 #include "chrome/browser/ui/browser_window.h"
14 #include "chrome/browser/ui/exclusive_access/exclusive_access_context.h" 16 #include "chrome/browser/ui/exclusive_access/exclusive_access_context.h"
15 #include "chrome/browser/ui/exclusive_access/exclusive_access_manager.h" 17 #include "chrome/browser/ui/exclusive_access/exclusive_access_manager.h"
16 #include "chrome/browser/ui/tabs/tab_strip_model.h" 18 #include "chrome/browser/ui/tabs/tab_strip_model.h"
17 #include "content/public/browser/web_contents.h" 19 #include "content/public/browser/web_contents.h"
18 #include "ui/message_center/notifier_settings.h" 20 #include "ui/message_center/notifier_settings.h"
19 21
20 using message_center::NotifierId; 22 using message_center::NotifierId;
21 23
22 namespace features { 24 namespace features {
23 25
24 const base::Feature kAllowFullscreenWebNotificationsFeature{ 26 const base::Feature kAllowFullscreenWebNotificationsFeature{
25 "FSNotificationsWeb", base::FEATURE_ENABLED_BY_DEFAULT 27 "FSNotificationsWeb", base::FEATURE_ENABLED_BY_DEFAULT
26 }; 28 };
27 29
28 } // namespace features 30 } // namespace features
29 31
30
31 WebNotificationDelegate::WebNotificationDelegate( 32 WebNotificationDelegate::WebNotificationDelegate(
32 content::BrowserContext* browser_context, 33 NotificationCommon::Type notification_type,
34 Profile* profile,
33 const std::string& notification_id, 35 const std::string& notification_id,
34 const GURL& origin) 36 const GURL& origin)
35 : browser_context_(browser_context), 37 : notification_type_(notification_type),
38 profile_(profile),
36 notification_id_(notification_id), 39 notification_id_(notification_id),
37 origin_(origin) {} 40 origin_(origin) {}
38 41
39 WebNotificationDelegate::~WebNotificationDelegate() {} 42 WebNotificationDelegate::~WebNotificationDelegate() {}
40 43
41 std::string WebNotificationDelegate::id() const { 44 std::string WebNotificationDelegate::id() const {
42 return notification_id_; 45 return notification_id_;
43 } 46 }
44 47
45 bool WebNotificationDelegate::SettingsClick() { 48 bool WebNotificationDelegate::SettingsClick() {
46 #if !defined(OS_CHROMEOS) 49 #if !defined(OS_CHROMEOS)
47 NotificationCommon::OpenNotificationSettings(browser_context_); 50 NotificationCommon::OpenNotificationSettings(profile_);
48 return true; 51 return true;
49 #else 52 #else
50 return false; 53 return false;
51 #endif 54 #endif
52 } 55 }
53 56
54 bool WebNotificationDelegate::ShouldDisplaySettingsButton() { 57 bool WebNotificationDelegate::ShouldDisplaySettingsButton() {
55 return true; 58 return true;
56 } 59 }
57 60
58 bool WebNotificationDelegate::ShouldDisplayOverFullscreen() const { 61 bool WebNotificationDelegate::ShouldDisplayOverFullscreen() const {
59 #if !defined(OS_ANDROID) 62 #if !defined(OS_ANDROID)
60 Profile* profile = Profile::FromBrowserContext(browser_context_);
61 DCHECK(profile);
62 // Check to see if this notification comes from a webpage that is displaying 63 // Check to see if this notification comes from a webpage that is displaying
63 // fullscreen content. 64 // fullscreen content.
64 for (auto* browser : *BrowserList::GetInstance()) { 65 for (auto* browser : *BrowserList::GetInstance()) {
65 // Only consider the browsers for the profile that created the notification 66 // Only consider the browsers for the profile that created the notification
66 if (browser->profile() != profile) 67 if (browser->profile() != profile_)
67 continue; 68 continue;
68 69
69 const content::WebContents* active_contents = 70 const content::WebContents* active_contents =
70 browser->tab_strip_model()->GetActiveWebContents(); 71 browser->tab_strip_model()->GetActiveWebContents();
71 if (!active_contents) 72 if (!active_contents)
72 continue; 73 continue;
73 74
74 // Check to see if 75 // Check to see if
75 // (a) the active tab in the browser shares its origin with the 76 // (a) the active tab in the browser shares its origin with the
76 // notification. 77 // notification.
(...skipping 14 matching lines...) Expand all
91 NotifierId::WEB_PAGE, 92 NotifierId::WEB_PAGE,
92 NotifierId::SIZE); 93 NotifierId::SIZE);
93 } 94 }
94 return enabled; 95 return enabled;
95 } 96 }
96 } 97 }
97 #endif 98 #endif
98 99
99 return false; 100 return false;
100 } 101 }
102
103 void WebNotificationDelegate::Display() {}
104
105 void WebNotificationDelegate::Close(bool by_user) {
106 auto* display_service =
107 NotificationDisplayServiceFactory::GetForProfile(profile_);
108 display_service->ProcessNotificationOperation(
109 NotificationCommon::CLOSE, notification_type_, origin().spec(),
110 notification_id_, -1, base::NullableString16());
111 }
112
113 void WebNotificationDelegate::Click() {
114 auto* display_service =
115 NotificationDisplayServiceFactory::GetForProfile(profile_);
116 display_service->ProcessNotificationOperation(
117 NotificationCommon::CLICK, notification_type_, origin().spec(),
118 notification_id_, -1, base::NullableString16());
119 }
120
121 void WebNotificationDelegate::ButtonClick(int button_index) {
122 DCHECK(button_index >= 0);
123 auto* display_service =
124 NotificationDisplayServiceFactory::GetForProfile(profile_);
125 display_service->ProcessNotificationOperation(
126 NotificationCommon::CLICK, notification_type_, origin().spec(),
127 notification_id_, button_index, base::NullableString16());
128 }
129
130 void WebNotificationDelegate::ButtonClickWithReply(
131 int button_index,
132 const base::string16& reply) {
133 auto* display_service =
134 NotificationDisplayServiceFactory::GetForProfile(profile_);
135 display_service->ProcessNotificationOperation(
136 NotificationCommon::CLICK, notification_type_, origin().spec(),
137 notification_id_, button_index,
138 base::NullableString16(reply, false /* is_null */));
139 }
OLDNEW
« no previous file with comments | « chrome/browser/notifications/web_notification_delegate.h ('k') | content/browser/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698