1 // Copyright (c) 2011 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_CONTENT_SETTINGS_CONTENT_SETTINGS_NOTIFICATION_PROVIDER_H_ 6 #define CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_NOTIFICATION_PROVIDER_H_ 7 8 #include <string> 9 #include <vector> 10 11 #include "base/basictypes.h" 12 #include "base/memory/ref_counted.h" 13 #include "chrome/browser/content_settings/content_settings_provider.h" 14 #include "chrome/browser/prefs/pref_change_registrar.h" 15 #include "content/common/notification_observer.h" 16 #include "content/common/notification_registrar.h" 17 18 class GURL; 19 class PrefService; 20 class Profile; 21 22 namespace content_settings { 23 24 class NotificationProvider : public ProviderInterface, 25 public NotificationObserver { 26 public: 27 static void RegisterUserPrefs(PrefService* user_prefs); 28 29 static ContentSettingsPattern ToContentSettingsPattern(const GURL& origin); 30 31 static GURL ToGURL(const ContentSettingsPattern& pattern); 32 33 explicit NotificationProvider(Profile* profile); 34 35 virtual ~NotificationProvider(); 36 37 // ProviderInterface implementation 38 virtual bool ContentSettingsTypeIsManaged( 39 ContentSettingsType content_type); 40 41 virtual ContentSetting GetContentSetting( 42 const GURL& requesting_url, 43 const GURL& embedding_url, 44 ContentSettingsType content_type, 45 const ResourceIdentifier& resource_identifier) const; 46 47 virtual void SetContentSetting( 48 const ContentSettingsPattern& requesting_url_pattern, 49 const ContentSettingsPattern& embedding_url_pattern, 50 ContentSettingsType content_type, 51 const ResourceIdentifier& resource_identifier, 52 ContentSetting content_setting); 53 54 virtual void GetAllContentSettingsRules( 55 ContentSettingsType content_type, 56 const ResourceIdentifier& resource_identifier, 57 Rules* content_setting_rules) const; 58 59 virtual void ClearAllContentSettingsRules( 60 ContentSettingsType content_type); 61 62 virtual void ResetToDefaults(); 63 64 // NotificationObserver implementation. 65 virtual void Observe(NotificationType type, 66 const NotificationSource& source, 67 const NotificationDetails& details); 68 private: 69 void StartObserving(); 70 void StopObserving(); 71 72 void OnPrefsChanged(const std::string& pref_name); 73 74 // Notifies the observers when permissions settings change. 75 void NotifySettingsChange(); 76 77 // Returns all origins that explicitly have been allowed. 78 std::vector<GURL> GetAllowedOrigins() const; 79 80 // Returns all origins that explicitly have been denied. 81 std::vector<GURL> GetBlockedOrigins() const; 82 83 // Methods to setup and modify permission preferences. 84 void GrantPermission(const GURL& origin); 85 void DenyPermission(const GURL& origin); 86 87 void PersistPermissionChange(const GURL& origin, bool is_allowed); 88 89 ContentSetting GetContentSetting(const GURL& origin) const; 90 91 // Removes an origin from the "explicitly allowed" set. 92 void ResetAllowedOrigin(const GURL& origin); 93 94 // Removes an origin from the "explicitly denied" set. 95 void ResetBlockedOrigin(const GURL& origin); 96 97 // Clears the sets of explicitly allowed and denied origins. 98 void ResetAllOrigins(); 99 100 Profile* profile_; 101 102 PrefChangeRegistrar prefs_registrar_; 103 NotificationRegistrar notification_registrar_; 104 105 DISALLOW_COPY_AND_ASSIGN(NotificationProvider); 106 }; 107 108 } // namespace content_settings 109 110 #endif // CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_NOTIFICATION_PROVIDER_H_ 111