OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_SERVICES_GCM_PERMISSION_CONTEXT_BASE_H_ |
| 6 #define CHROME_BROWSER_SERVICES_GCM_PERMISSION_CONTEXT_BASE_H_ |
| 7 |
| 8 #include "base/callback.h" |
| 9 #include "base/memory/ref_counted.h" |
| 10 #include "chrome/common/content_settings_types.h" |
| 11 #include "components/keyed_service/core/keyed_service.h" |
| 12 |
| 13 class GURL; |
| 14 class PermissionQueueController; |
| 15 class PermissionRequestID; |
| 16 class Profile; |
| 17 |
| 18 namespace content { |
| 19 class WebContents; |
| 20 } |
| 21 |
| 22 typedef base::Callback<void(bool)> BrowserPermissionCallback; |
| 23 |
| 24 // TODO(miguelg) Move this out of gcm into a generic place and make |
| 25 // Midi permissions and others use it. |
| 26 namespace gcm { |
| 27 |
| 28 // This base class contains common operations for grating permissions. |
| 29 // It is spit out of Midi and Push and will be moved to a common place |
| 30 // so it can be used by both classes (and eventually others) in a separate |
| 31 // patch. |
| 32 class PermissionContextBase : public KeyedService { |
| 33 public: |
| 34 PermissionContextBase(Profile* profile, |
| 35 const ContentSettingsType permission_type); |
| 36 virtual ~PermissionContextBase(); |
| 37 |
| 38 // The renderer is requesting permission to push messages. |
| 39 // When the answer to a permission request has been determined, |callback| |
| 40 // should be called with the result. |
| 41 virtual void RequestPermission(content::WebContents* web_contents, |
| 42 const PermissionRequestID& id, |
| 43 const GURL& requesting_frame, |
| 44 bool user_gesture, |
| 45 const BrowserPermissionCallback& callback); |
| 46 |
| 47 protected: |
| 48 // Decide whether the permission should be granted. |
| 49 // Calls PermissionDecided if permission can be decided non-interactively, |
| 50 // or NotifyPermissionSet if permission decided by presenting an infobar. |
| 51 void DecidePermission(content::WebContents* web_contents, |
| 52 const PermissionRequestID& id, |
| 53 const GURL& requesting_frame, |
| 54 const GURL& embedder, |
| 55 bool user_gesture, |
| 56 const BrowserPermissionCallback& callback); |
| 57 |
| 58 // Called when permission is granted without interactively asking the user. |
| 59 void PermissionDecided(const PermissionRequestID& id, |
| 60 const GURL& requesting_frame, |
| 61 const GURL& embedder, |
| 62 const BrowserPermissionCallback& callback, |
| 63 bool allowed); |
| 64 |
| 65 void NotifyPermissionSet(const PermissionRequestID& id, |
| 66 const GURL& requesting_frame, |
| 67 const BrowserPermissionCallback& callback, |
| 68 bool allowed); |
| 69 |
| 70 // Implementors can override this method to update the icons on the |
| 71 // url bar with the result of the new permission. |
| 72 virtual void UpdateTabContext(const PermissionRequestID& id, |
| 73 const GURL& requesting_frame, |
| 74 bool allowed) {} |
| 75 |
| 76 // Return an instance of the infobar queue controller, creating it if needed. |
| 77 PermissionQueueController* GetQueueController(); |
| 78 |
| 79 private: |
| 80 Profile* profile_; |
| 81 const ContentSettingsType permission_type_; |
| 82 scoped_ptr<PermissionQueueController> permission_queue_controller_; |
| 83 }; |
| 84 } // namespace gcm |
| 85 |
| 86 #endif // CHROME_BROWSER_SERVICES_GCM_PERMISSION_CONTEXT_BASE_H_ |
OLD | NEW |