summaryrefslogtreecommitdiffstats
path: root/chrome/browser/push_messaging/push_messaging_permission_context.h
blob: 94d1a281f58c967e26dd4d45b8c3a5169ca3d993 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_PUSH_MESSAGING_PUSH_MESSAGING_PERMISSION_CONTEXT_H_
#define CHROME_BROWSER_PUSH_MESSAGING_PUSH_MESSAGING_PERMISSION_CONTEXT_H_

#include "chrome/browser/permissions/permission_context_base.h"

#include "components/content_settings/core/common/content_settings_types.h"

class PermissionRequestID;
class Profile;

// Permission context for push messages.
class PushMessagingPermissionContext : public PermissionContextBase {
 public:
  explicit PushMessagingPermissionContext(Profile* profile);
  ~PushMessagingPermissionContext() override;

  // PermissionContextBase:
  ContentSetting GetPermissionStatus(
      const GURL& requesting_origin,
      const GURL& embedding_origin) const override;

  void CancelPermissionRequest(content::WebContents* web_contents,
                               const PermissionRequestID& id) override;

 protected:
  // PermissionContextBase:
  void DecidePermission(content::WebContents* web_contents,
                        const PermissionRequestID& id,
                        const GURL& requesting_origin,
                        const GURL& embedding_origin,
                        bool user_gesture,
                        const BrowserPermissionCallback& callback) override;
  bool IsRestrictedToSecureOrigins() const override;

 private:
  FRIEND_TEST_ALL_PREFIXES(PushMessagingPermissionContextTest,
                           DecidePushPermission);

  // Used to decide the permission for push, once the permission for
  // Notification has been granted/denied.
  void DecidePushPermission(const PermissionRequestID& id,
                            const GURL& requesting_origin,
                            const GURL& embedding_origin,
                            const BrowserPermissionCallback& callback,
                            ContentSetting notifications_content_setting);

  Profile* profile_;

  // Must be the last member, to ensure that it will be
  // destroyed first, which will invalidate weak pointers
  base::WeakPtrFactory<PushMessagingPermissionContext> weak_factory_ui_thread_;

  DISALLOW_COPY_AND_ASSIGN(PushMessagingPermissionContext);
};

#endif  // CHROME_BROWSER_PUSH_MESSAGING_PUSH_MESSAGING_PERMISSION_CONTEXT_H_