OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 CHROME_BROWSER_PUSH_MESSAGING_PUSH_MESSAGING_NOTIFICATION_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_PUSH_MESSAGING_PUSH_MESSAGING_NOTIFICATION_MANAGER_H_ |
6 #define CHROME_BROWSER_PUSH_MESSAGING_PUSH_MESSAGING_NOTIFICATION_MANAGER_H_ | 6 #define CHROME_BROWSER_PUSH_MESSAGING_PUSH_MESSAGING_NOTIFICATION_MANAGER_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/callback_forward.h" | 11 #include "base/callback_forward.h" |
| 12 #include "base/gtest_prod_util.h" |
12 #include "base/macros.h" | 13 #include "base/macros.h" |
13 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
14 | 15 |
15 class GURL; | 16 class GURL; |
16 class Profile; | 17 class Profile; |
17 | 18 |
18 namespace content { | 19 namespace content { |
19 struct NotificationDatabaseData; | 20 struct NotificationDatabaseData; |
20 struct PlatformNotificationData; | 21 struct PlatformNotificationData; |
| 22 class WebContents; |
21 } | 23 } |
22 | 24 |
23 // Developers may be required to display a Web Notification in response to an | 25 // Developers may be required to display a Web Notification in response to an |
24 // incoming push message in order to clarify to the user that something has | 26 // incoming push message in order to clarify to the user that something has |
25 // happened in the background. When they forget to do so, a default notification | 27 // happened in the background. When they forget to do so, a default notification |
26 // has to be displayed on their behalf. | 28 // has to be displayed on their behalf. |
27 // | 29 // |
28 // This class implements the heuristics for determining whether the default | 30 // This class implements the heuristics for determining whether the default |
29 // notification is necessary, as well as the functionality of displaying the | 31 // notification is necessary, as well as the functionality of displaying the |
30 // default notification when it is. | 32 // default notification when it is. |
31 // | 33 // |
32 // See the following document and bug for more context: | 34 // See the following document and bug for more context: |
33 // https://docs.google.com/document/d/13VxFdLJbMwxHrvnpDm8RXnU41W2ZlcP0mdWWe9zXQ
T8/edit | 35 // https://docs.google.com/document/d/13VxFdLJbMwxHrvnpDm8RXnU41W2ZlcP0mdWWe9zXQ
T8/edit |
34 // https://crbug.com/437277 | 36 // https://crbug.com/437277 |
35 class PushMessagingNotificationManager { | 37 class PushMessagingNotificationManager { |
36 public: | 38 public: |
37 explicit PushMessagingNotificationManager(Profile* profile); | 39 explicit PushMessagingNotificationManager(Profile* profile); |
38 ~PushMessagingNotificationManager(); | 40 ~PushMessagingNotificationManager(); |
39 | 41 |
40 // Enforces the requirements implied for push subscriptions which must display | 42 // Enforces the requirements implied for push subscriptions which must display |
41 // a Web Notification in response to an incoming message. | 43 // a Web Notification in response to an incoming message. |
42 void EnforceUserVisibleOnlyRequirements( | 44 void EnforceUserVisibleOnlyRequirements( |
43 const GURL& origin, | 45 const GURL& origin, |
44 int64_t service_worker_registration_id, | 46 int64_t service_worker_registration_id, |
45 const base::Closure& message_handled_closure); | 47 const base::Closure& message_handled_closure); |
46 | 48 |
47 private: | 49 private: |
| 50 FRIEND_TEST_ALL_PREFIXES(PushMessagingNotificationManagerTest, IsTabVisible); |
| 51 |
48 static void DidGetNotificationsFromDatabaseIOProxy( | 52 static void DidGetNotificationsFromDatabaseIOProxy( |
49 const base::WeakPtr<PushMessagingNotificationManager>& ui_weak_ptr, | 53 const base::WeakPtr<PushMessagingNotificationManager>& ui_weak_ptr, |
50 const GURL& origin, | 54 const GURL& origin, |
51 int64_t service_worker_registration_id, | 55 int64_t service_worker_registration_id, |
52 const base::Closure& message_handled_closure, | 56 const base::Closure& message_handled_closure, |
53 bool success, | 57 bool success, |
54 const std::vector<content::NotificationDatabaseData>& data); | 58 const std::vector<content::NotificationDatabaseData>& data); |
55 | 59 |
56 void DidGetNotificationsFromDatabase( | 60 void DidGetNotificationsFromDatabase( |
57 const GURL& origin, | 61 const GURL& origin, |
58 int64_t service_worker_registration_id, | 62 int64_t service_worker_registration_id, |
59 const base::Closure& message_handled_closure, | 63 const base::Closure& message_handled_closure, |
60 bool success, | 64 bool success, |
61 const std::vector<content::NotificationDatabaseData>& data); | 65 const std::vector<content::NotificationDatabaseData>& data); |
62 | 66 |
| 67 // Checks whether |profile| is the one owning this instance, |
| 68 // |active_web_contents| exists and its main frame is visible, and the URL |
| 69 // currently visible to the user is for |origin|. |
| 70 bool IsTabVisible(Profile* profile, |
| 71 content::WebContents* active_web_contents, |
| 72 const GURL& origin); |
| 73 |
63 void DidGetNotificationsShownAndNeeded( | 74 void DidGetNotificationsShownAndNeeded( |
64 const GURL& origin, | 75 const GURL& origin, |
65 int64_t service_worker_registration_id, | 76 int64_t service_worker_registration_id, |
66 bool notification_shown, | 77 bool notification_shown, |
67 bool notification_needed, | 78 bool notification_needed, |
68 const base::Closure& message_handled_closure, | 79 const base::Closure& message_handled_closure, |
69 const std::string& data, | 80 const std::string& data, |
70 bool success, | 81 bool success, |
71 bool not_found); | 82 bool not_found); |
72 | 83 |
(...skipping 14 matching lines...) Expand all Loading... |
87 | 98 |
88 // Weak. This manager is owned by a keyed service on this profile. | 99 // Weak. This manager is owned by a keyed service on this profile. |
89 Profile* profile_; | 100 Profile* profile_; |
90 | 101 |
91 base::WeakPtrFactory<PushMessagingNotificationManager> weak_factory_; | 102 base::WeakPtrFactory<PushMessagingNotificationManager> weak_factory_; |
92 | 103 |
93 DISALLOW_COPY_AND_ASSIGN(PushMessagingNotificationManager); | 104 DISALLOW_COPY_AND_ASSIGN(PushMessagingNotificationManager); |
94 }; | 105 }; |
95 | 106 |
96 #endif // CHROME_BROWSER_PUSH_MESSAGING_PUSH_MESSAGING_NOTIFICATION_MANAGER_H_ | 107 #endif // CHROME_BROWSER_PUSH_MESSAGING_PUSH_MESSAGING_NOTIFICATION_MANAGER_H_ |
OLD | NEW |