Add ICU message format support
[chromium-blink-merge.git] / content / shell / browser / layout_test / layout_test_notification_manager.h
blob53c59309642cf2e46ac743306bb1f2f206dde040
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|. Must be called on the
31 // UI thread.
32 void SimulateClick(const std::string& title);
34 // PlatformNotificationService implementation.
35 blink::WebNotificationPermission CheckPermissionOnUIThread(
36 BrowserContext* browser_context,
37 const GURL& origin,
38 int render_process_id) override;
39 blink::WebNotificationPermission CheckPermissionOnIOThread(
40 ResourceContext* resource_context,
41 const GURL& origin,
42 int render_process_id) override;
43 void DisplayNotification(BrowserContext* browser_context,
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,
51 int64_t persistent_notification_id,
52 const GURL& origin,
53 const SkBitmap& icon,
54 const PlatformNotificationData& notification_data) override;
55 void ClosePersistentNotification(
56 BrowserContext* browser_context,
57 int64_t persistent_notification_id) override;
58 bool GetDisplayedPersistentNotifications(
59 BrowserContext* browser_context,
60 std::set<std::string>* displayed_notifications) override;
62 private:
63 // Structure to represent the information of a persistent notification.
64 struct PersistentNotification {
65 BrowserContext* browser_context = nullptr;
66 GURL origin;
67 int64_t persistent_id = 0;
70 // Closes the notification titled |title|. Must be called on the UI thread.
71 void Close(const std::string& title);
73 // Fakes replacing the notification identified by |params| when it has a tag
74 // and a previous notification has been displayed using the same tag. All
75 // notifications, both page and persistent ones, will be considered for this.
76 void ReplaceNotificationIfNeeded(
77 const PlatformNotificationData& notification_data);
79 // Checks if |origin| has permission to display notifications. May be called
80 // on both the IO and the UI threads.
81 blink::WebNotificationPermission CheckPermission(const GURL& origin);
83 std::map<std::string, DesktopNotificationDelegate*> page_notifications_;
84 std::map<std::string, PersistentNotification> persistent_notifications_;
86 std::map<std::string, std::string> replacements_;
88 base::WeakPtrFactory<LayoutTestNotificationManager> weak_factory_;
90 DISALLOW_COPY_AND_ASSIGN(LayoutTestNotificationManager);
93 } // content
95 #endif // CONTENT_SHELL_BROWSER_LAYOUT_TEST_LAYOUT_TEST_NOTIFICATION_MANAGER_H_