| 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_CONTENT_SETTINGS_PERMISSION_CONTEXT_BASE_H_ | 5 #ifndef CHROME_BROWSER_CONTENT_SETTINGS_PERMISSION_CONTEXT_BASE_H_ |
| 6 #define CHROME_BROWSER_CONTENT_SETTINGS_PERMISSION_CONTEXT_BASE_H_ | 6 #define CHROME_BROWSER_CONTENT_SETTINGS_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 "chrome/browser/ui/website_settings/permission_bubble_request.h" | 12 #include "chrome/browser/ui/website_settings/permission_bubble_request.h" |
| 13 #include "components/content_settings/core/common/content_settings.h" | 13 #include "components/content_settings/core/common/content_settings.h" |
| 14 #include "components/content_settings/core/common/content_settings_types.h" | 14 #include "components/content_settings/core/common/content_settings_types.h" |
| 15 #include "components/keyed_service/core/keyed_service.h" | 15 #include "components/keyed_service/core/keyed_service.h" |
| 16 #include "url/gurl.h" | 16 #include "url/gurl.h" |
| 17 | 17 |
| 18 class PermissionQueueController; | 18 class PermissionQueueController; |
| 19 class PermissionRequestID; | 19 class PermissionRequestID; |
| 20 class Profile; | 20 class Profile; |
| 21 | 21 |
| 22 namespace content { | 22 namespace content { |
| 23 class WebContents; | 23 class WebContents; |
| 24 } | 24 } |
| 25 | 25 |
| 26 typedef base::Callback<void(bool)> BrowserPermissionCallback; | 26 using BrowserPermissionCallback = base::Callback<void(ContentSetting)>; |
| 27 | 27 |
| 28 // This base class contains common operations for granting permissions. | 28 // This base class contains common operations for granting permissions. |
| 29 // It offers the following functionality: | 29 // It offers the following functionality: |
| 30 // - Creates a bubble or infobar when a permission is needed | 30 // - Creates a bubble or infobar when a permission is needed |
| 31 // - If accepted/denied the permission is saved in content settings for | 31 // - If accepted/denied the permission is saved in content settings for |
| 32 // future uses (for the domain that requested it). | 32 // future uses (for the domain that requested it). |
| 33 // - If dismissed the permission is not saved but it's considered denied for | 33 // - If dismissed the permission is not saved but it's considered denied for |
| 34 // this one request | 34 // this one request |
| 35 // - In any case the BrowserPermissionCallback is executed once a decision | 35 // - In any case the BrowserPermissionCallback is executed once a decision |
| 36 // about the permission is made by the user. | 36 // about the permission is made by the user. |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 const GURL& embedding_origin, | 88 const GURL& embedding_origin, |
| 89 bool user_gesture, | 89 bool user_gesture, |
| 90 const BrowserPermissionCallback& callback); | 90 const BrowserPermissionCallback& callback); |
| 91 | 91 |
| 92 // Called when permission is granted without interactively asking the user. | 92 // Called when permission is granted without interactively asking the user. |
| 93 void PermissionDecided(const PermissionRequestID& id, | 93 void PermissionDecided(const PermissionRequestID& id, |
| 94 const GURL& requesting_origin, | 94 const GURL& requesting_origin, |
| 95 const GURL& embedding_origin, | 95 const GURL& embedding_origin, |
| 96 const BrowserPermissionCallback& callback, | 96 const BrowserPermissionCallback& callback, |
| 97 bool persist, | 97 bool persist, |
| 98 bool allowed); | 98 ContentSetting content_setting); |
| 99 | 99 |
| 100 virtual void NotifyPermissionSet(const PermissionRequestID& id, | 100 virtual void NotifyPermissionSet(const PermissionRequestID& id, |
| 101 const GURL& requesting_origin, | 101 const GURL& requesting_origin, |
| 102 const GURL& embedding_origin, | 102 const GURL& embedding_origin, |
| 103 const BrowserPermissionCallback& callback, | 103 const BrowserPermissionCallback& callback, |
| 104 bool persist, | 104 bool persist, |
| 105 bool allowed); | 105 ContentSetting content_setting); |
| 106 | 106 |
| 107 // Implementors can override this method to update the icons on the | 107 // Implementors can override this method to update the icons on the |
| 108 // url bar with the result of the new permission. | 108 // url bar with the result of the new permission. |
| 109 virtual void UpdateTabContext(const PermissionRequestID& id, | 109 virtual void UpdateTabContext(const PermissionRequestID& id, |
| 110 const GURL& requesting_origin, | 110 const GURL& requesting_origin, |
| 111 bool allowed) {} | 111 bool allowed) {} |
| 112 | 112 |
| 113 // Return an instance of the infobar queue controller, creating it if needed. | 113 // Return an instance of the infobar queue controller, creating it if needed. |
| 114 PermissionQueueController* GetQueueController(); | 114 PermissionQueueController* GetQueueController(); |
| 115 | 115 |
| 116 // Returns the profile associated with this permission context. | 116 // Returns the profile associated with this permission context. |
| 117 Profile* profile() const; | 117 Profile* profile() const; |
| 118 | 118 |
| 119 // Store the decided permission as a content setting. | 119 // Store the decided permission as a content setting. |
| 120 // virtual since the permission might be stored with different restrictions | 120 // virtual since the permission might be stored with different restrictions |
| 121 // (for example for desktop notifications). | 121 // (for example for desktop notifications). |
| 122 virtual void UpdateContentSetting(const GURL& requesting_origin, | 122 virtual void UpdateContentSetting(const GURL& requesting_origin, |
| 123 const GURL& embedding_origin, | 123 const GURL& embedding_origin, |
| 124 bool allowed); | 124 ContentSetting content_setting); |
| 125 | 125 |
| 126 private: | 126 private: |
| 127 // Called when a bubble is no longer used so it can be cleaned up. | 127 // Called when a bubble is no longer used so it can be cleaned up. |
| 128 void CleanUpBubble(const PermissionRequestID& id); | 128 void CleanUpBubble(const PermissionRequestID& id); |
| 129 | 129 |
| 130 Profile* profile_; | 130 Profile* profile_; |
| 131 const ContentSettingsType permission_type_; | 131 const ContentSettingsType permission_type_; |
| 132 scoped_ptr<PermissionQueueController> permission_queue_controller_; | 132 scoped_ptr<PermissionQueueController> permission_queue_controller_; |
| 133 base::ScopedPtrHashMap<std::string, PermissionBubbleRequest> | 133 base::ScopedPtrHashMap<std::string, PermissionBubbleRequest> |
| 134 pending_bubbles_; | 134 pending_bubbles_; |
| 135 | 135 |
| 136 // Must be the last member, to ensure that it will be | 136 // Must be the last member, to ensure that it will be |
| 137 // destroyed first, which will invalidate weak pointers | 137 // destroyed first, which will invalidate weak pointers |
| 138 base::WeakPtrFactory<PermissionContextBase> weak_factory_; | 138 base::WeakPtrFactory<PermissionContextBase> weak_factory_; |
| 139 }; | 139 }; |
| 140 | 140 |
| 141 #endif // CHROME_BROWSER_CONTENT_SETTINGS_PERMISSION_CONTEXT_BASE_H_ | 141 #endif // CHROME_BROWSER_CONTENT_SETTINGS_PERMISSION_CONTEXT_BASE_H_ |
| OLD | NEW |