| 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 <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/containers/scoped_ptr_hash_map.h" | 11 #include "base/containers/scoped_ptr_hash_map.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
| 15 #include "chrome/browser/permissions/permission_request.h" | 15 #include "chrome/browser/permissions/permission_request.h" |
| 16 #include "components/content_settings/core/common/content_settings.h" | 16 #include "components/content_settings/core/common/content_settings.h" |
| 17 #include "components/content_settings/core/common/content_settings_types.h" | 17 #include "components/content_settings/core/common/content_settings_types.h" |
| 18 #include "components/keyed_service/core/keyed_service.h" | 18 #include "components/keyed_service/core/keyed_service.h" |
| 19 #include "content/public/browser/permission_type.h" | 19 #include "content/public/browser/permission_type.h" |
| 20 #include "url/gurl.h" | 20 #include "url/gurl.h" |
| 21 | 21 |
| 22 #if defined(OS_ANDROID) | 22 // #if defined(OS_ANDROID) |
| 23 class PermissionQueueController; | 23 // class PermissionQueueController; |
| 24 #endif | 24 // #endif |
| 25 class PermissionRequestID; | 25 class PermissionRequestID; |
| 26 class Profile; | 26 class Profile; |
| 27 | 27 |
| 28 namespace content { | 28 namespace content { |
| 29 class WebContents; | 29 class WebContents; |
| 30 } | 30 } |
| 31 | 31 |
| 32 using BrowserPermissionCallback = base::Callback<void(ContentSetting)>; | 32 using BrowserPermissionCallback = base::Callback<void(ContentSetting)>; |
| 33 | 33 |
| 34 // This base class contains common operations for granting permissions. | 34 // This base class contains common operations for granting permissions. |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 const BrowserPermissionCallback& callback, | 123 const BrowserPermissionCallback& callback, |
| 124 bool persist, | 124 bool persist, |
| 125 ContentSetting content_setting); | 125 ContentSetting content_setting); |
| 126 | 126 |
| 127 // Implementors can override this method to update the icons on the | 127 // Implementors can override this method to update the icons on the |
| 128 // url bar with the result of the new permission. | 128 // url bar with the result of the new permission. |
| 129 virtual void UpdateTabContext(const PermissionRequestID& id, | 129 virtual void UpdateTabContext(const PermissionRequestID& id, |
| 130 const GURL& requesting_origin, | 130 const GURL& requesting_origin, |
| 131 bool allowed) {} | 131 bool allowed) {} |
| 132 | 132 |
| 133 #if defined(OS_ANDROID) | 133 // #if defined(OS_ANDROID) |
| 134 // Return an instance of the infobar queue controller, creating it if needed. | 134 // // Return an instance of the infobar queue controller, creating it if neede
d. |
| 135 PermissionQueueController* GetQueueController(); | 135 // PermissionQueueController* GetQueueController(); |
| 136 #endif | 136 // #endif |
| 137 | 137 |
| 138 // Returns the profile associated with this permission context. | 138 // Returns the profile associated with this permission context. |
| 139 Profile* profile() const; | 139 Profile* profile() const; |
| 140 | 140 |
| 141 // Store the decided permission as a content setting. | 141 // Store the decided permission as a content setting. |
| 142 // virtual since the permission might be stored with different restrictions | 142 // virtual since the permission might be stored with different restrictions |
| 143 // (for example for desktop notifications). | 143 // (for example for desktop notifications). |
| 144 virtual void UpdateContentSetting(const GURL& requesting_origin, | 144 virtual void UpdateContentSetting(const GURL& requesting_origin, |
| 145 const GURL& embedding_origin, | 145 const GURL& embedding_origin, |
| 146 ContentSetting content_setting); | 146 ContentSetting content_setting); |
| 147 | 147 |
| 148 // Whether the permission should be restricted to secure origins. | 148 // Whether the permission should be restricted to secure origins. |
| 149 virtual bool IsRestrictedToSecureOrigins() const = 0; | 149 virtual bool IsRestrictedToSecureOrigins() const = 0; |
| 150 | 150 |
| 151 content::PermissionType permission_type() const { return permission_type_; } | 151 content::PermissionType permission_type() const { return permission_type_; } |
| 152 ContentSettingsType content_settings_type() const { | 152 ContentSettingsType content_settings_type() const { |
| 153 return content_settings_type_; | 153 return content_settings_type_; |
| 154 } | 154 } |
| 155 | 155 |
| 156 private: | 156 private: |
| 157 // Called when a request is no longer used so it can be cleaned up. | 157 // Called when a request is no longer used so it can be cleaned up. |
| 158 void CleanUpRequest(const PermissionRequestID& id); | 158 void CleanUpRequest(const PermissionRequestID& id); |
| 159 | 159 |
| 160 Profile* profile_; | 160 Profile* profile_; |
| 161 const content::PermissionType permission_type_; | 161 const content::PermissionType permission_type_; |
| 162 const ContentSettingsType content_settings_type_; | 162 const ContentSettingsType content_settings_type_; |
| 163 #if defined(OS_ANDROID) | 163 //#if defined(OS_ANDROID) |
| 164 std::unique_ptr<PermissionQueueController> permission_queue_controller_; | 164 // std::unique_ptr<PermissionQueueController> permission_queue_controller_; |
| 165 #endif | 165 //#endif |
| 166 base::ScopedPtrHashMap<std::string, std::unique_ptr<PermissionRequest>> | 166 base::ScopedPtrHashMap<std::string, std::unique_ptr<PermissionRequest>> |
| 167 pending_requests_; | 167 pending_requests_; |
| 168 | 168 |
| 169 // Must be the last member, to ensure that it will be | 169 // Must be the last member, to ensure that it will be |
| 170 // destroyed first, which will invalidate weak pointers | 170 // destroyed first, which will invalidate weak pointers |
| 171 base::WeakPtrFactory<PermissionContextBase> weak_factory_; | 171 base::WeakPtrFactory<PermissionContextBase> weak_factory_; |
| 172 }; | 172 }; |
| 173 | 173 |
| 174 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_CONTEXT_BASE_H_ | 174 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_CONTEXT_BASE_H_ |
| OLD | NEW |