| 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/containers/scoped_ptr_hash_map.h" | |
| 10 #include "base/memory/ref_counted.h" | |
| 11 #include "base/memory/weak_ptr.h" | |
| 12 #include "chrome/browser/ui/website_settings/permission_bubble_request.h" | |
| 13 #include "chrome/common/content_settings_types.h" | |
| 14 #include "components/keyed_service/core/keyed_service.h" | |
| 15 #include "url/gurl.h" | |
| 16 | |
| 17 class PermissionQueueController; | |
| 18 class PermissionRequestID; | |
| 19 class Profile; | |
| 20 | |
| 21 namespace content { | |
| 22 class WebContents; | |
| 23 } | |
| 24 | |
| 25 typedef base::Callback<void(bool)> BrowserPermissionCallback; | |
| 26 | |
| 27 // TODO(miguelg): Move this out of gcm into a generic place and make | |
| 28 // Midi permissions and others use it. | |
| 29 namespace gcm { | |
| 30 | |
| 31 // This base class contains common operations for granting permissions. | |
| 32 // It is spit out of Midi and Push and will be moved to a common place | |
| 33 // so it can be used by both classes (and eventually others) in a separate | |
| 34 // patch. | |
| 35 // It supports both infobars and bubbles, but it handles them differently. | |
| 36 // For bubbles, it manages the life cycle of permission request and persists the | |
| 37 // permission choices when stated by the user. | |
| 38 // For infobars however all that logic is managed by the internal | |
| 39 // PermissionQueueController object. | |
| 40 class PermissionContextBase : public KeyedService { | |
| 41 public: | |
| 42 PermissionContextBase(Profile* profile, | |
| 43 const ContentSettingsType permission_type); | |
| 44 virtual ~PermissionContextBase(); | |
| 45 | |
| 46 // The renderer is requesting permission to push messages. | |
| 47 // When the answer to a permission request has been determined, |callback| | |
| 48 // should be called with the result. | |
| 49 virtual void RequestPermission(content::WebContents* web_contents, | |
| 50 const PermissionRequestID& id, | |
| 51 const GURL& requesting_frame, | |
| 52 bool user_gesture, | |
| 53 const BrowserPermissionCallback& callback); | |
| 54 | |
| 55 protected: | |
| 56 // Decide whether the permission should be granted. | |
| 57 // Calls PermissionDecided if permission can be decided non-interactively, | |
| 58 // or NotifyPermissionSet if permission decided by presenting an infobar. | |
| 59 void DecidePermission(content::WebContents* web_contents, | |
| 60 const PermissionRequestID& id, | |
| 61 const GURL& requesting_frame, | |
| 62 const GURL& embedder, | |
| 63 bool user_gesture, | |
| 64 const BrowserPermissionCallback& callback); | |
| 65 | |
| 66 // Called when permission is granted without interactively asking the user. | |
| 67 void PermissionDecided(const PermissionRequestID& id, | |
| 68 const GURL& requesting_frame, | |
| 69 const GURL& embedder, | |
| 70 const BrowserPermissionCallback& callback, | |
| 71 bool allowed); | |
| 72 | |
| 73 void NotifyPermissionSet(const PermissionRequestID& id, | |
| 74 const GURL& requesting_frame, | |
| 75 const GURL& embedder, | |
| 76 const BrowserPermissionCallback& callback, | |
| 77 bool persist, | |
| 78 bool allowed); | |
| 79 | |
| 80 // Implementors can override this method to update the icons on the | |
| 81 // url bar with the result of the new permission. | |
| 82 virtual void UpdateTabContext(const PermissionRequestID& id, | |
| 83 const GURL& requesting_frame, | |
| 84 bool allowed) {} | |
| 85 | |
| 86 // Return an instance of the infobar queue controller, creating it if needed. | |
| 87 PermissionQueueController* GetQueueController(); | |
| 88 | |
| 89 private: | |
| 90 void UpdateContentSetting( | |
| 91 const GURL& requesting_frame, | |
| 92 const GURL& embedder, | |
| 93 bool allowed); | |
| 94 | |
| 95 // Called when a bubble is no longer used so it can be cleaned up. | |
| 96 void CleanUpBubble(const PermissionRequestID& id); | |
| 97 | |
| 98 Profile* profile_; | |
| 99 const ContentSettingsType permission_type_; | |
| 100 base::WeakPtrFactory<PermissionContextBase> weak_factory_; | |
| 101 scoped_ptr<PermissionQueueController> permission_queue_controller_; | |
| 102 base::ScopedPtrHashMap<std::string, PermissionBubbleRequest> | |
| 103 pending_bubbles_; | |
| 104 }; | |
| 105 | |
| 106 } // namespace gcm | |
| 107 | |
| 108 #endif // CHROME_BROWSER_SERVICES_GCM_PERMISSION_CONTEXT_BASE_H_ | |
| OLD | NEW |