| 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/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "content/public/browser/browser_thread.h" | 9 #include "content/public/browser/browser_thread.h" |
| 10 #include "content/public/browser/desktop_notification_delegate.h" | 10 #include "content/public/browser/desktop_notification_delegate.h" |
| 11 #include "content/public/browser/notification_event_dispatcher.h" | 11 #include "content/public/browser/notification_event_dispatcher.h" |
| 12 #include "content/public/browser/permission_type.h" | 12 #include "content/public/browser/permission_type.h" |
| 13 #include "content/public/common/persistent_notification_status.h" | 13 #include "content/public/common/persistent_notification_status.h" |
| 14 #include "content/public/common/platform_notification_data.h" | 14 #include "content/public/common/platform_notification_data.h" |
| 15 #include "content/shell/browser/layout_test/layout_test_browser_context.h" | 15 #include "content/shell/browser/layout_test/layout_test_browser_context.h" |
| 16 #include "content/shell/browser/layout_test/layout_test_content_browser_client.h
" | 16 #include "content/shell/browser/layout_test/layout_test_content_browser_client.h
" |
| 17 #include "content/shell/browser/layout_test/layout_test_permission_manager.h" | 17 #include "content/shell/browser/layout_test/layout_test_permission_manager.h" |
| 18 | 18 |
| 19 namespace content { | 19 namespace content { |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 // The Web Notification layout tests don't care about the lifetime of the | 22 // The Web Notification layout tests don't care about the lifetime of the |
| 23 // Service Worker when a notificationclick event has been dispatched. | 23 // Service Worker when a notificationclick event has been dispatched. |
| 24 void OnEventDispatchComplete(PersistentNotificationStatus status) {} | 24 void OnEventDispatchComplete(PersistentNotificationStatus status) {} |
| 25 | 25 |
| 26 blink::WebNotificationPermission ToWebNotificationPermission( | |
| 27 blink::mojom::PermissionStatus status) { | |
| 28 switch (status) { | |
| 29 case blink::mojom::PermissionStatus::GRANTED: | |
| 30 return blink::WebNotificationPermissionAllowed; | |
| 31 case blink::mojom::PermissionStatus::DENIED: | |
| 32 return blink::WebNotificationPermissionDenied; | |
| 33 case blink::mojom::PermissionStatus::ASK: | |
| 34 return blink::WebNotificationPermissionDefault; | |
| 35 } | |
| 36 | |
| 37 NOTREACHED(); | |
| 38 return blink::WebNotificationPermissionLast; | |
| 39 } | |
| 40 | |
| 41 } // namespace | 26 } // namespace |
| 42 | 27 |
| 43 LayoutTestNotificationManager::LayoutTestNotificationManager() | 28 LayoutTestNotificationManager::LayoutTestNotificationManager() |
| 44 : weak_factory_(this) {} | 29 : weak_factory_(this) {} |
| 45 | 30 |
| 46 LayoutTestNotificationManager::~LayoutTestNotificationManager() {} | 31 LayoutTestNotificationManager::~LayoutTestNotificationManager() {} |
| 47 | 32 |
| 48 void LayoutTestNotificationManager::DisplayNotification( | 33 void LayoutTestNotificationManager::DisplayNotification( |
| 49 BrowserContext* browser_context, | 34 BrowserContext* browser_context, |
| 50 const GURL& origin, | 35 const GURL& origin, |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 const PersistentNotification& notification = persistent_iterator->second; | 130 const PersistentNotification& notification = persistent_iterator->second; |
| 146 content::NotificationEventDispatcher::GetInstance() | 131 content::NotificationEventDispatcher::GetInstance() |
| 147 ->DispatchNotificationCloseEvent( | 132 ->DispatchNotificationCloseEvent( |
| 148 notification.browser_context, | 133 notification.browser_context, |
| 149 notification.persistent_id, | 134 notification.persistent_id, |
| 150 notification.origin, | 135 notification.origin, |
| 151 by_user, | 136 by_user, |
| 152 base::Bind(&OnEventDispatchComplete)); | 137 base::Bind(&OnEventDispatchComplete)); |
| 153 } | 138 } |
| 154 | 139 |
| 155 blink::WebNotificationPermission | 140 blink::mojom::PermissionStatus |
| 156 LayoutTestNotificationManager::CheckPermissionOnUIThread( | 141 LayoutTestNotificationManager::CheckPermissionOnUIThread( |
| 157 BrowserContext* browser_context, | 142 BrowserContext* browser_context, |
| 158 const GURL& origin, | 143 const GURL& origin, |
| 159 int render_process_id) { | 144 int render_process_id) { |
| 160 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 145 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 161 return CheckPermission(origin); | 146 return CheckPermission(origin); |
| 162 } | 147 } |
| 163 | 148 |
| 164 blink::WebNotificationPermission | 149 blink::mojom::PermissionStatus |
| 165 LayoutTestNotificationManager::CheckPermissionOnIOThread( | 150 LayoutTestNotificationManager::CheckPermissionOnIOThread( |
| 166 ResourceContext* resource_context, | 151 ResourceContext* resource_context, |
| 167 const GURL& origin, | 152 const GURL& origin, |
| 168 int render_process_id) { | 153 int render_process_id) { |
| 169 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 154 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 170 return CheckPermission(origin); | 155 return CheckPermission(origin); |
| 171 } | 156 } |
| 172 | 157 |
| 173 void LayoutTestNotificationManager::Close(const std::string& title) { | 158 void LayoutTestNotificationManager::Close(const std::string& title) { |
| 174 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 159 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 203 | 188 |
| 204 const auto& persistent_notification_iter = | 189 const auto& persistent_notification_iter = |
| 205 persistent_notifications_.find(previous_title); | 190 persistent_notifications_.find(previous_title); |
| 206 if (persistent_notification_iter != persistent_notifications_.end()) | 191 if (persistent_notification_iter != persistent_notifications_.end()) |
| 207 persistent_notifications_.erase(persistent_notification_iter); | 192 persistent_notifications_.erase(persistent_notification_iter); |
| 208 } | 193 } |
| 209 | 194 |
| 210 replacements_[tag] = base::UTF16ToUTF8(notification_data.title); | 195 replacements_[tag] = base::UTF16ToUTF8(notification_data.title); |
| 211 } | 196 } |
| 212 | 197 |
| 213 blink::WebNotificationPermission | 198 blink::mojom::PermissionStatus |
| 214 LayoutTestNotificationManager::CheckPermission(const GURL& origin) { | 199 LayoutTestNotificationManager::CheckPermission(const GURL& origin) { |
| 215 return ToWebNotificationPermission(LayoutTestContentBrowserClient::Get() | 200 return LayoutTestContentBrowserClient::Get() |
| 216 ->GetLayoutTestBrowserContext() | 201 ->GetLayoutTestBrowserContext() |
| 217 ->GetLayoutTestPermissionManager() | 202 ->GetLayoutTestPermissionManager() |
| 218 ->GetPermissionStatus(PermissionType::NOTIFICATIONS, | 203 ->GetPermissionStatus(PermissionType::NOTIFICATIONS, |
| 219 origin, | 204 origin, |
| 220 origin)); | 205 origin); |
| 221 } | 206 } |
| 222 | 207 |
| 223 } // namespace content | 208 } // namespace content |
| OLD | NEW |