| 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 CHROME_BROWSER_PERMISSIONS_PERMISSION_CONTEXT_BASE_H_ | 5 #ifndef CHROME_BROWSER_PERMISSIONS_PERMISSION_CONTEXT_BASE_H_ |
| 6 #define CHROME_BROWSER_PERMISSIONS_PERMISSION_CONTEXT_BASE_H_ | 6 #define CHROME_BROWSER_PERMISSIONS_PERMISSION_CONTEXT_BASE_H_ |
| 7 | 7 |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/containers/scoped_ptr_hash_map.h" | 9 #include "base/containers/scoped_ptr_hash_map.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
| 13 #include "chrome/browser/ui/website_settings/permission_bubble_request.h" | 13 #include "chrome/browser/ui/website_settings/permission_bubble_request.h" |
| 14 #include "components/content_settings/core/common/content_settings.h" | 14 #include "components/content_settings/core/common/content_settings.h" |
| 15 #include "components/content_settings/core/common/content_settings_types.h" | 15 #include "components/content_settings/core/common/content_settings_types.h" |
| 16 #include "components/keyed_service/core/keyed_service.h" | 16 #include "components/keyed_service/core/keyed_service.h" |
| 17 #include "content/public/browser/permission_type.h" | 17 #include "content/public/browser/permission_type.h" |
| 18 #include "url/gurl.h" | 18 #include "url/origin.h" |
| 19 | 19 |
| 20 #if defined(OS_ANDROID) | 20 #if defined(OS_ANDROID) |
| 21 class PermissionQueueController; | 21 class PermissionQueueController; |
| 22 #endif | 22 #endif |
| 23 class PermissionRequestID; | 23 class PermissionRequestID; |
| 24 class Profile; | 24 class Profile; |
| 25 | 25 |
| 26 namespace content { | 26 namespace content { |
| 27 class WebContents; | 27 class WebContents; |
| 28 } | 28 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 | 67 |
| 68 // The field trial param to enable the global permissions kill switch. | 68 // The field trial param to enable the global permissions kill switch. |
| 69 // This is public for testing purposes. | 69 // This is public for testing purposes. |
| 70 static const char kPermissionsKillSwitchBlockedValue[]; | 70 static const char kPermissionsKillSwitchBlockedValue[]; |
| 71 | 71 |
| 72 // The renderer is requesting permission to push messages. | 72 // The renderer is requesting permission to push messages. |
| 73 // When the answer to a permission request has been determined, |callback| | 73 // When the answer to a permission request has been determined, |callback| |
| 74 // should be called with the result. | 74 // should be called with the result. |
| 75 virtual void RequestPermission(content::WebContents* web_contents, | 75 virtual void RequestPermission(content::WebContents* web_contents, |
| 76 const PermissionRequestID& id, | 76 const PermissionRequestID& id, |
| 77 const GURL& requesting_frame, | 77 const url::Origin& requesting_origin, |
| 78 const BrowserPermissionCallback& callback); | 78 const BrowserPermissionCallback& callback); |
| 79 | 79 |
| 80 // Returns whether the permission has been granted, denied... | 80 // Returns whether the permission has been granted, denied... |
| 81 virtual ContentSetting GetPermissionStatus( | 81 virtual ContentSetting GetPermissionStatus( |
| 82 const GURL& requesting_origin, | 82 const url::Origin& requesting_origin, |
| 83 const GURL& embedding_origin) const; | 83 const url::Origin& embedding_origin) const; |
| 84 | 84 |
| 85 // Resets the permission to its default value. | 85 // Resets the permission to its default value. |
| 86 virtual void ResetPermission(const GURL& requesting_origin, | 86 virtual void ResetPermission(const url::Origin& requesting_origin, |
| 87 const GURL& embedding_origin); | 87 const url::Origin& embedding_origin); |
| 88 | 88 |
| 89 // Withdraw an existing permission request, no op if the permission request | 89 // Withdraw an existing permission request, no op if the permission request |
| 90 // was already cancelled by some other means. | 90 // was already cancelled by some other means. |
| 91 virtual void CancelPermissionRequest(content::WebContents* web_contents, | 91 virtual void CancelPermissionRequest(content::WebContents* web_contents, |
| 92 const PermissionRequestID& id); | 92 const PermissionRequestID& id); |
| 93 | 93 |
| 94 // Whether the kill switch has been enabled for this permission. | 94 // Whether the kill switch has been enabled for this permission. |
| 95 // public for permissions that do not use RequestPermission, like | 95 // public for permissions that do not use RequestPermission, like |
| 96 // camera and microphone, and for testing. | 96 // camera and microphone, and for testing. |
| 97 bool IsPermissionKillSwitchOn() const; | 97 bool IsPermissionKillSwitchOn() const; |
| 98 | 98 |
| 99 protected: | 99 protected: |
| 100 // Decide whether the permission should be granted. | 100 // Decide whether the permission should be granted. |
| 101 // Calls PermissionDecided if permission can be decided non-interactively, | 101 // Calls PermissionDecided if permission can be decided non-interactively, |
| 102 // or NotifyPermissionSet if permission decided by presenting an infobar. | 102 // or NotifyPermissionSet if permission decided by presenting an infobar. |
| 103 virtual void DecidePermission(content::WebContents* web_contents, | 103 virtual void DecidePermission(content::WebContents* web_contents, |
| 104 const PermissionRequestID& id, | 104 const PermissionRequestID& id, |
| 105 const GURL& requesting_origin, | 105 const url::Origin& requesting_origin, |
| 106 const GURL& embedding_origin, | 106 const url::Origin& embedding_origin, |
| 107 const BrowserPermissionCallback& callback); | 107 const BrowserPermissionCallback& callback); |
| 108 | 108 |
| 109 // Called when permission is granted without interactively asking the user. | 109 // Called when permission is granted without interactively asking the user. |
| 110 void PermissionDecided(const PermissionRequestID& id, | 110 void PermissionDecided(const PermissionRequestID& id, |
| 111 const GURL& requesting_origin, | 111 const url::Origin& requesting_origin, |
| 112 const GURL& embedding_origin, | 112 const url::Origin& embedding_origin, |
| 113 const BrowserPermissionCallback& callback, | 113 const BrowserPermissionCallback& callback, |
| 114 bool persist, | 114 bool persist, |
| 115 ContentSetting content_setting); | 115 ContentSetting content_setting); |
| 116 | 116 |
| 117 virtual void NotifyPermissionSet(const PermissionRequestID& id, | 117 virtual void NotifyPermissionSet(const PermissionRequestID& id, |
| 118 const GURL& requesting_origin, | 118 const url::Origin& requesting_origin, |
| 119 const GURL& embedding_origin, | 119 const url::Origin& embedding_origin, |
| 120 const BrowserPermissionCallback& callback, | 120 const BrowserPermissionCallback& callback, |
| 121 bool persist, | 121 bool persist, |
| 122 ContentSetting content_setting); | 122 ContentSetting content_setting); |
| 123 | 123 |
| 124 // Implementors can override this method to update the icons on the | 124 // Implementors can override this method to update the icons on the |
| 125 // url bar with the result of the new permission. | 125 // url bar with the result of the new permission. |
| 126 virtual void UpdateTabContext(const PermissionRequestID& id, | 126 virtual void UpdateTabContext(const PermissionRequestID& id, |
| 127 const GURL& requesting_origin, | 127 const url::Origin& requesting_origin, |
| 128 bool allowed) {} | 128 bool allowed) {} |
| 129 | 129 |
| 130 #if defined(OS_ANDROID) | 130 #if defined(OS_ANDROID) |
| 131 // Return an instance of the infobar queue controller, creating it if needed. | 131 // Return an instance of the infobar queue controller, creating it if needed. |
| 132 PermissionQueueController* GetQueueController(); | 132 PermissionQueueController* GetQueueController(); |
| 133 #endif | 133 #endif |
| 134 | 134 |
| 135 // Returns the profile associated with this permission context. | 135 // Returns the profile associated with this permission context. |
| 136 Profile* profile() const; | 136 Profile* profile() const; |
| 137 | 137 |
| 138 // Store the decided permission as a content setting. | 138 // Store the decided permission as a content setting. |
| 139 // virtual since the permission might be stored with different restrictions | 139 // virtual since the permission might be stored with different restrictions |
| 140 // (for example for desktop notifications). | 140 // (for example for desktop notifications). |
| 141 virtual void UpdateContentSetting(const GURL& requesting_origin, | 141 virtual void UpdateContentSetting(const url::Origin& requesting_origin, |
| 142 const GURL& embedding_origin, | 142 const url::Origin& embedding_origin, |
| 143 ContentSetting content_setting); | 143 ContentSetting content_setting); |
| 144 | 144 |
| 145 // Whether the permission should be restricted to secure origins. | 145 // Whether the permission should be restricted to secure origins. |
| 146 virtual bool IsRestrictedToSecureOrigins() const = 0; | 146 virtual bool IsRestrictedToSecureOrigins() const = 0; |
| 147 | 147 |
| 148 content::PermissionType permission_type() const { return permission_type_; } | 148 content::PermissionType permission_type() const { return permission_type_; } |
| 149 ContentSettingsType content_settings_type() const { | 149 ContentSettingsType content_settings_type() const { |
| 150 return content_settings_type_; | 150 return content_settings_type_; |
| 151 } | 151 } |
| 152 | 152 |
| 153 private: | 153 private: |
| 154 // Called when a bubble is no longer used so it can be cleaned up. | 154 // Called when a bubble is no longer used so it can be cleaned up. |
| 155 void CleanUpBubble(const PermissionRequestID& id); | 155 void CleanUpBubble(const PermissionRequestID& id); |
| 156 | 156 |
| 157 Profile* profile_; | 157 Profile* profile_; |
| 158 const content::PermissionType permission_type_; | 158 const content::PermissionType permission_type_; |
| 159 const ContentSettingsType content_settings_type_; | 159 const ContentSettingsType content_settings_type_; |
| 160 #if defined(OS_ANDROID) | 160 #if defined(OS_ANDROID) |
| 161 scoped_ptr<PermissionQueueController> permission_queue_controller_; | 161 scoped_ptr<PermissionQueueController> permission_queue_controller_; |
| 162 #endif | 162 #endif |
| 163 base::ScopedPtrHashMap<std::string, scoped_ptr<PermissionBubbleRequest>> | 163 base::ScopedPtrHashMap<std::string, scoped_ptr<PermissionBubbleRequest>> |
| 164 pending_bubbles_; | 164 pending_bubbles_; |
| 165 | 165 |
| 166 // Must be the last member, to ensure that it will be | 166 // Must be the last member, to ensure that it will be |
| 167 // destroyed first, which will invalidate weak pointers | 167 // destroyed first, which will invalidate weak pointers |
| 168 base::WeakPtrFactory<PermissionContextBase> weak_factory_; | 168 base::WeakPtrFactory<PermissionContextBase> weak_factory_; |
| 169 }; | 169 }; |
| 170 | 170 |
| 171 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_CONTEXT_BASE_H_ | 171 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_CONTEXT_BASE_H_ |
| OLD | NEW |