| 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 #ifndef CONTENT_SHELL_BROWSER_LAYOUT_TEST_LAYOUT_TEST_NOTIFICATION_MANAGER_H_ | 5 #ifndef CONTENT_SHELL_BROWSER_LAYOUT_TEST_LAYOUT_TEST_NOTIFICATION_MANAGER_H_ |
| 6 #define CONTENT_SHELL_BROWSER_LAYOUT_TEST_LAYOUT_TEST_NOTIFICATION_MANAGER_H_ | 6 #define CONTENT_SHELL_BROWSER_LAYOUT_TEST_LAYOUT_TEST_NOTIFICATION_MANAGER_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/containers/scoped_ptr_hash_map.h" |
| 14 #include "content/public/browser/platform_notification_service.h" | 14 #include "content/public/browser/platform_notification_service.h" |
| 15 #include "third_party/WebKit/public/platform/modules/notifications/WebNotificati
onPermission.h" | 15 #include "third_party/WebKit/public/platform/modules/notifications/WebNotificati
onPermission.h" |
| 16 #include "ui/message_center/notification.h" |
| 16 #include "url/gurl.h" | 17 #include "url/gurl.h" |
| 17 | 18 |
| 18 namespace content { | 19 namespace content { |
| 19 | 20 |
| 20 class DesktopNotificationDelegate; | |
| 21 struct PlatformNotificationData; | |
| 22 | |
| 23 // Responsible for tracking active notifications and allowed origins for the | 21 // Responsible for tracking active notifications and allowed origins for the |
| 24 // Web Notification API when running layout tests. | 22 // Web Notification API when running layout tests. |
| 25 class LayoutTestNotificationManager : public PlatformNotificationService { | 23 class LayoutTestNotificationManager : public PlatformNotificationService { |
| 26 public: | 24 public: |
| 27 LayoutTestNotificationManager(); | 25 LayoutTestNotificationManager(); |
| 28 ~LayoutTestNotificationManager() override; | 26 ~LayoutTestNotificationManager() override; |
| 29 | 27 |
| 30 // Simulates a click on the notification titled |title|. Must be called on the | 28 // Simulates a click on the notification titled |title|. Must be called on the |
| 31 // UI thread. | 29 // UI thread. |
| 32 void SimulateClick(const std::string& title); | 30 void SimulateClick(const std::string& title); |
| 33 | 31 |
| 34 // PlatformNotificationService implementation. | 32 // PlatformNotificationService implementation. |
| 35 blink::WebNotificationPermission CheckPermissionOnUIThread( | 33 blink::WebNotificationPermission CheckPermissionOnUIThread( |
| 36 BrowserContext* browser_context, | 34 BrowserContext* browser_context, |
| 37 const GURL& origin, | 35 const GURL& origin, |
| 38 int render_process_id) override; | 36 int render_process_id) override; |
| 39 blink::WebNotificationPermission CheckPermissionOnIOThread( | 37 blink::WebNotificationPermission CheckPermissionOnIOThread( |
| 40 ResourceContext* resource_context, | 38 ResourceContext* resource_context, |
| 41 const GURL& origin, | 39 const GURL& origin, |
| 42 int render_process_id) override; | 40 int render_process_id) override; |
| 43 void DisplayNotification(BrowserContext* browser_context, | 41 void DisplayNotification( |
| 44 const GURL& origin, | |
| 45 const SkBitmap& icon, | |
| 46 const PlatformNotificationData& notification_data, | |
| 47 scoped_ptr<DesktopNotificationDelegate> delegate, | |
| 48 base::Closure* cancel_callback) override; | |
| 49 void DisplayPersistentNotification( | |
| 50 BrowserContext* browser_context, | 42 BrowserContext* browser_context, |
| 51 int64_t persistent_notification_id, | 43 const message_center::Notification& notification) override; |
| 52 const GURL& origin, | 44 void CloseNotification( |
| 53 const SkBitmap& icon, | |
| 54 const PlatformNotificationData& notification_data) override; | |
| 55 void ClosePersistentNotification( | |
| 56 BrowserContext* browser_context, | 45 BrowserContext* browser_context, |
| 57 int64_t persistent_notification_id) override; | 46 const std::string& notification_id) override; |
| 58 | 47 |
| 59 private: | 48 private: |
| 60 // Structure to represent the information of a persistent notification. | |
| 61 struct PersistentNotification { | |
| 62 BrowserContext* browser_context = nullptr; | |
| 63 GURL origin; | |
| 64 int64_t persistent_id = 0; | |
| 65 }; | |
| 66 | |
| 67 // Closes the notification titled |title|. Must be called on the UI thread. | |
| 68 void Close(const std::string& title); | |
| 69 | |
| 70 // Fakes replacing the notification identified by |params| when it has a tag | |
| 71 // and a previous notification has been displayed using the same tag. All | |
| 72 // notifications, both page and persistent ones, will be considered for this. | |
| 73 void ReplaceNotificationIfNeeded( | |
| 74 const PlatformNotificationData& notification_data); | |
| 75 | |
| 76 // Checks if |origin| has permission to display notifications. May be called | 49 // Checks if |origin| has permission to display notifications. May be called |
| 77 // on both the IO and the UI threads. | 50 // on both the IO and the UI threads. |
| 78 blink::WebNotificationPermission CheckPermission(const GURL& origin); | 51 blink::WebNotificationPermission CheckPermission(const GURL& origin); |
| 79 | 52 |
| 80 std::map<std::string, DesktopNotificationDelegate*> page_notifications_; | 53 base::ScopedPtrHashMap<std::string, scoped_ptr<message_center::Notification>> |
| 81 std::map<std::string, PersistentNotification> persistent_notifications_; | 54 notifications_; |
| 82 | |
| 83 std::map<std::string, std::string> replacements_; | |
| 84 | |
| 85 base::WeakPtrFactory<LayoutTestNotificationManager> weak_factory_; | |
| 86 | 55 |
| 87 DISALLOW_COPY_AND_ASSIGN(LayoutTestNotificationManager); | 56 DISALLOW_COPY_AND_ASSIGN(LayoutTestNotificationManager); |
| 88 }; | 57 }; |
| 89 | 58 |
| 90 } // content | 59 } // content |
| 91 | 60 |
| 92 #endif // CONTENT_SHELL_BROWSER_LAYOUT_TEST_LAYOUT_TEST_NOTIFICATION_MANAGER_H_ | 61 #endif // CONTENT_SHELL_BROWSER_LAYOUT_TEST_LAYOUT_TEST_NOTIFICATION_MANAGER_H_ |
| OLD | NEW |