OLD | NEW |
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 "content/shell/browser/layout_test/layout_test_notification_manager.h" | 5 #include "content/shell/browser/layout_test/layout_test_notification_manager.h" |
6 | 6 |
7 #include "base/guid.h" | 7 #include "base/guid.h" |
8 #include "base/strings/nullable_string16.h" | 8 #include "base/strings/nullable_string16.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 } | 76 } |
77 | 77 |
78 void LayoutTestNotificationManager::ClosePersistentNotification( | 78 void LayoutTestNotificationManager::ClosePersistentNotification( |
79 BrowserContext* browser_context, | 79 BrowserContext* browser_context, |
80 const std::string& notification_id) { | 80 const std::string& notification_id) { |
81 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 81 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
82 | 82 |
83 persistent_notifications_.erase(notification_id); | 83 persistent_notifications_.erase(notification_id); |
84 } | 84 } |
85 | 85 |
86 bool LayoutTestNotificationManager::GetDisplayedNotifications( | 86 void LayoutTestNotificationManager::GetDisplayedNotifications( |
87 BrowserContext* browser_context, | 87 BrowserContext* browser_context, |
88 std::set<std::string>* displayed_notifications) { | 88 const DisplayedNotificationsCallback& callback) { |
89 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 89 auto displayed_notifications = base::MakeUnique<std::set<std::string>>(); |
90 DCHECK(displayed_notifications); | 90 BrowserThread::PostTask( |
91 | 91 BrowserThread::UI, FROM_HERE, |
92 // Notifications will never outlive the lifetime of running layout tests. | 92 base::Bind(callback, base::Passed(&displayed_notifications), |
93 return false; | 93 false /* supports_synchronization */)); |
94 } | 94 } |
95 | 95 |
96 void LayoutTestNotificationManager::SimulateClick( | 96 void LayoutTestNotificationManager::SimulateClick( |
97 const std::string& title, | 97 const std::string& title, |
98 int action_index, | 98 int action_index, |
99 const base::NullableString16& reply) { | 99 const base::NullableString16& reply) { |
100 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 100 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
101 | 101 |
102 const auto notification_id_iter = notification_id_map_.find(title); | 102 const auto notification_id_iter = notification_id_map_.find(title); |
103 if (notification_id_iter == notification_id_map_.end()) | 103 if (notification_id_iter == notification_id_map_.end()) |
104 return; | 104 return; |
105 | 105 |
106 const std::string& notification_id = notification_id_iter->second; | 106 const std::string& notification_id = notification_id_iter->second; |
107 | 107 |
108 const auto persistent_iter = persistent_notifications_.find(notification_id); | 108 const auto persistent_iter = persistent_notifications_.find(notification_id); |
109 const auto non_persistent_iter = | 109 const auto non_persistent_iter = |
110 non_persistent_notifications_.find(notification_id); | 110 non_persistent_notifications_.find(notification_id); |
111 | 111 |
112 if (persistent_iter != persistent_notifications_.end()) { | 112 if (persistent_iter != persistent_notifications_.end()) { |
113 DCHECK(non_persistent_iter == non_persistent_notifications_.end()); | 113 DCHECK(non_persistent_iter == non_persistent_notifications_.end()); |
114 | 114 |
115 const PersistentNotification& notification = persistent_iter->second; | 115 const PersistentNotification& notification = persistent_iter->second; |
116 content::NotificationEventDispatcher::GetInstance() | 116 NotificationEventDispatcher::GetInstance()->DispatchNotificationClickEvent( |
117 ->DispatchNotificationClickEvent( | 117 notification.browser_context, notification_id, notification.origin, |
118 notification.browser_context, notification_id, notification.origin, | 118 action_index, reply, base::Bind(&OnEventDispatchComplete)); |
119 action_index, reply, base::Bind(&OnEventDispatchComplete)); | |
120 } else if (non_persistent_iter != non_persistent_notifications_.end()) { | 119 } else if (non_persistent_iter != non_persistent_notifications_.end()) { |
121 DCHECK_EQ(action_index, -1) << "Action buttons are only supported for " | 120 DCHECK_EQ(action_index, -1) << "Action buttons are only supported for " |
122 "persistent notifications"; | 121 "persistent notifications"; |
123 | 122 |
124 non_persistent_iter->second->NotificationClick(); | 123 non_persistent_iter->second->NotificationClick(); |
125 } | 124 } |
126 } | 125 } |
127 | 126 |
128 void LayoutTestNotificationManager::SimulateClose(const std::string& title, | 127 void LayoutTestNotificationManager::SimulateClose(const std::string& title, |
129 bool by_user) { | 128 bool by_user) { |
130 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 129 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
131 | 130 |
132 const auto notification_id_iter = notification_id_map_.find(title); | 131 const auto notification_id_iter = notification_id_map_.find(title); |
133 if (notification_id_iter == notification_id_map_.end()) | 132 if (notification_id_iter == notification_id_map_.end()) |
134 return; | 133 return; |
135 | 134 |
136 const std::string& notification_id = notification_id_iter->second; | 135 const std::string& notification_id = notification_id_iter->second; |
137 | 136 |
138 const auto& persistent_iter = persistent_notifications_.find(notification_id); | 137 const auto& persistent_iter = persistent_notifications_.find(notification_id); |
139 if (persistent_iter == persistent_notifications_.end()) | 138 if (persistent_iter == persistent_notifications_.end()) |
140 return; | 139 return; |
141 | 140 |
142 const PersistentNotification& notification = persistent_iter->second; | 141 const PersistentNotification& notification = persistent_iter->second; |
143 content::NotificationEventDispatcher::GetInstance() | 142 NotificationEventDispatcher::GetInstance()->DispatchNotificationCloseEvent( |
144 ->DispatchNotificationCloseEvent( | 143 notification.browser_context, notification_id, notification.origin, |
145 notification.browser_context, notification_id, notification.origin, | 144 by_user, base::Bind(&OnEventDispatchComplete)); |
146 by_user, base::Bind(&OnEventDispatchComplete)); | |
147 } | 145 } |
148 | 146 |
149 blink::mojom::PermissionStatus | 147 blink::mojom::PermissionStatus |
150 LayoutTestNotificationManager::CheckPermissionOnUIThread( | 148 LayoutTestNotificationManager::CheckPermissionOnUIThread( |
151 BrowserContext* browser_context, | 149 BrowserContext* browser_context, |
152 const GURL& origin, | 150 const GURL& origin, |
153 int render_process_id) { | 151 int render_process_id) { |
154 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 152 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
155 return CheckPermission(origin); | 153 return CheckPermission(origin); |
156 } | 154 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 LayoutTestNotificationManager::CheckPermission(const GURL& origin) { | 190 LayoutTestNotificationManager::CheckPermission(const GURL& origin) { |
193 return LayoutTestContentBrowserClient::Get() | 191 return LayoutTestContentBrowserClient::Get() |
194 ->GetLayoutTestBrowserContext() | 192 ->GetLayoutTestBrowserContext() |
195 ->GetLayoutTestPermissionManager() | 193 ->GetLayoutTestPermissionManager() |
196 ->GetPermissionStatus(PermissionType::NOTIFICATIONS, | 194 ->GetPermissionStatus(PermissionType::NOTIFICATIONS, |
197 origin, | 195 origin, |
198 origin); | 196 origin); |
199 } | 197 } |
200 | 198 |
201 } // namespace content | 199 } // namespace content |
OLD | NEW |