Refactor WebsiteSettings to operate on a SecurityInfo
[chromium-blink-merge.git] / content / shell / browser / layout_test / layout_test_notification_manager.h
blobfdcdeb87af14accf9b1b517bf31848e95e143ff1
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
3 // found in the LICENSE file.
5 #ifndef CONTENT_SHELL_BROWSER_LAYOUT_TEST_LAYOUT_TEST_NOTIFICATION_MANAGER_H_
6 #define CONTENT_SHELL_BROWSER_LAYOUT_TEST_LAYOUT_TEST_NOTIFICATION_MANAGER_H_
8 #include <stdint.h>
9 #include <map>
10 #include <string>
12 #include "base/callback.h"
13 #include "base/memory/weak_ptr.h"
14 #include "content/public/browser/platform_notification_service.h"
15 #include "third_party/WebKit/public/platform/modules/notifications/WebNotificationPermission.h"
16 #include "url/gurl.h"
18 namespace content {
20 class DesktopNotificationDelegate;
21 struct PlatformNotificationData;
23 // Responsible for tracking active notifications and allowed origins for the
24 // Web Notification API when running layout tests.
25 class LayoutTestNotificationManager : public PlatformNotificationService {
26 public:
27 LayoutTestNotificationManager();
28 ~LayoutTestNotificationManager() override;
30 // Simulates a click on the notification titled |title|. |action_index|
31 // indicates which action was clicked, or -1 if the main notification body was
32 // clicked. Must be called on the UI thread.
33 void SimulateClick(const std::string& title, int action_index);
35 // PlatformNotificationService implementation.
36 blink::WebNotificationPermission CheckPermissionOnUIThread(
37 BrowserContext* browser_context,
38 const GURL& origin,
39 int render_process_id) override;
40 blink::WebNotificationPermission CheckPermissionOnIOThread(
41 ResourceContext* resource_context,
42 const GURL& origin,
43 int render_process_id) override;
44 void DisplayNotification(BrowserContext* browser_context,
45 const GURL& origin,
46 const SkBitmap& icon,
47 const PlatformNotificationData& notification_data,
48 scoped_ptr<DesktopNotificationDelegate> delegate,
49 base::Closure* cancel_callback) override;
50 void DisplayPersistentNotification(
51 BrowserContext* browser_context,
52 int64_t persistent_notification_id,
53 const GURL& origin,
54 const SkBitmap& icon,
55 const PlatformNotificationData& notification_data) override;
56 void ClosePersistentNotification(
57 BrowserContext* browser_context,
58 int64_t persistent_notification_id) override;
59 bool GetDisplayedPersistentNotifications(
60 BrowserContext* browser_context,
61 std::set<std::string>* displayed_notifications) override;
63 private:
64 // Structure to represent the information of a persistent notification.
65 struct PersistentNotification {
66 BrowserContext* browser_context = nullptr;
67 GURL origin;
68 int64_t persistent_id = 0;
71 // Closes the notification titled |title|. Must be called on the UI thread.
72 void Close(const std::string& title);
74 // Fakes replacing the notification identified by |params| when it has a tag
75 // and a previous notification has been displayed using the same tag. All
76 // notifications, both page and persistent ones, will be considered for this.
77 void ReplaceNotificationIfNeeded(
78 const PlatformNotificationData& notification_data);
80 // Checks if |origin| has permission to display notifications. May be called
81 // on both the IO and the UI threads.
82 blink::WebNotificationPermission CheckPermission(const GURL& origin);
84 std::map<std::string, DesktopNotificationDelegate*> page_notifications_;
85 std::map<std::string, PersistentNotification> persistent_notifications_;
87 std::map<std::string, std::string> replacements_;
89 base::WeakPtrFactory<LayoutTestNotificationManager> weak_factory_;
91 DISALLOW_COPY_AND_ASSIGN(LayoutTestNotificationManager);
94 } // content
96 #endif // CONTENT_SHELL_BROWSER_LAYOUT_TEST_LAYOUT_TEST_NOTIFICATION_MANAGER_H_