Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_MANAGED_MODE_MANAGED_MODE_H_ | 5 #ifndef CHROME_BROWSER_MANAGED_MODE_MANAGED_MODE_H_ |
| 6 #define CHROME_BROWSER_MANAGED_MODE_MANAGED_MODE_H_ | 6 #define CHROME_BROWSER_MANAGED_MODE_MANAGED_MODE_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/gtest_prod_util.h" | |
| 14 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/memory/singleton.h" | 16 #include "base/memory/singleton.h" |
| 16 #include "chrome/browser/extensions/management_policy.h" | |
| 17 #include "chrome/browser/ui/browser_list_observer.h" | 17 #include "chrome/browser/ui/browser_list_observer.h" |
| 18 #include "content/public/browser/notification_observer.h" | 18 #include "content/public/browser/notification_observer.h" |
| 19 #include "content/public/browser/notification_registrar.h" | 19 #include "content/public/browser/notification_registrar.h" |
| 20 | 20 |
| 21 class Browser; | 21 class Browser; |
| 22 template<typename T> | 22 template<typename T> |
| 23 struct DefaultSingletonTraits; | 23 struct DefaultSingletonTraits; |
| 24 class ManagedModeSiteList; | 24 class ManagedModeSiteList; |
| 25 class ManagedModeURLFilter; | 25 class ManagedModeURLFilter; |
| 26 class PrefChangeRegistrar; | 26 class PrefChangeRegistrar; |
| 27 class PrefServiceSimple; | 27 class PrefServiceSimple; |
| 28 class PrefServiceSyncable; | 28 class PrefServiceSyncable; |
| 29 class Profile; | 29 class Profile; |
| 30 | 30 |
| 31 namespace policy{ | 31 namespace policy { |
| 32 class URLBlacklist; | 32 class URLBlacklist; |
| 33 } | 33 } |
| 34 | 34 |
| 35 // Managed mode allows one person to manage the Chrome experience for another | 35 // Managed mode allows one person to manage the Chrome experience for another |
| 36 // person by pre-configuring and then locking a managed User profile. | 36 // person by pre-configuring and then locking a managed User profile. |
| 37 // The ManagedMode class provides methods to check whether the browser is in | 37 // The ManagedMode class provides methods to check whether the browser is in |
|
Pam (message me for reviews)
2013/01/14 14:12:42
Reword this to match the new world.
Would it be w
Bernhard Bauer
2013/01/15 14:24:44
Reworded it a bit. For now though, there still is
Pam (message me for reviews)
2013/01/15 14:47:53
+1
| |
| 38 // managed mode, and to attempt to enter or leave managed mode. | 38 // managed mode, and to attempt to enter or leave managed mode. |
| 39 // Except where otherwise noted, this class should be used on the UI thread. | 39 // Except where otherwise noted, this class should be used on the UI thread. |
| 40 class ManagedMode : public chrome::BrowserListObserver, | 40 class ManagedMode : public chrome::BrowserListObserver, |
| 41 public extensions::ManagementPolicy::Provider, | |
| 42 public content::NotificationObserver { | 41 public content::NotificationObserver { |
| 43 public: | 42 public: |
| 44 typedef base::Callback<void(bool)> EnterCallback; | 43 typedef base::Callback<void(bool)> EnterCallback; |
| 45 | 44 |
| 46 static void RegisterPrefs(PrefServiceSimple* prefs); | 45 static void RegisterPrefs(PrefServiceSimple* prefs); |
| 47 static void RegisterUserPrefs(PrefServiceSyncable* prefs); | |
| 48 | 46 |
| 49 // Initializes the singleton, setting the managed_profile_. Must be called | 47 // Initializes the singleton, setting the managed_profile_. Must be called |
| 50 // after g_browser_process and the LocalState have been created. | 48 // after g_browser_process and the LocalState have been created. |
| 51 static void Init(Profile* profile); | 49 static void Init(Profile* profile); |
| 52 static bool IsInManagedMode(); | 50 static bool IsInManagedMode(); |
| 53 | 51 |
| 54 // Calls |callback| with the argument true iff managed mode was entered | 52 // Calls |callback| with the argument true iff managed mode was entered |
| 55 // sucessfully. | 53 // sucessfully. |
| 56 static void EnterManagedMode(Profile* profile, const EnterCallback& callback); | 54 static void EnterManagedMode(Profile* profile, const EnterCallback& callback); |
| 57 static void LeaveManagedMode(); | 55 static void LeaveManagedMode(); |
| 58 | 56 |
| 59 // Returns the URL filter for the IO thread, for filtering network requests | |
| 60 // (in ChromeNetworkDelegate). | |
| 61 // This method should only be called on the IO thread. | |
| 62 static const ManagedModeURLFilter* GetURLFilterForIOThread(); | |
| 63 | |
| 64 // Returns the URL filter for the UI thread, for filtering navigations and | |
| 65 // classifying sites in the history view. | |
| 66 // This method should only be called on the UI thread. | |
| 67 static const ManagedModeURLFilter* GetURLFilterForUIThread(); | |
| 68 | |
| 69 // The functions that handle manual whitelists use |url_pattern| or lists | |
| 70 // of "url patterns". An "url pattern" is a pattern in the format used by the | |
| 71 // policy::URLBlacklist filter. A description of the format used can be found | |
| 72 // here: http://dev.chromium.org/administrators/url-blacklist-filter-format. | |
| 73 // They all receive the |is_whitelist| parameter which dictates whether they | |
| 74 // act on the whitelist (for |is_whitelist| == true) or on the blacklist (for | |
| 75 // |is_whitelist| == false). | |
| 76 | |
| 77 // Checks if the |url_pattern| is in the manual whitelist. | |
| 78 static bool IsInManualList(const bool is_whitelist, | |
| 79 const std::string& url_pattern); | |
| 80 | |
| 81 // Appends |list| to the manual white/black list (according to |is_whitelist|) | |
| 82 // both in URL filter and in preferences. | |
| 83 static void AddToManualList(const bool is_whitelist, | |
| 84 const base::ListValue& list); | |
| 85 | |
| 86 // Removes |list| from the manual white/black list (according to | |
| 87 // |is_whitelist|) both in URL filter and in preferences. | |
| 88 static void RemoveFromManualList(const bool is_whitelist, | |
| 89 const base::ListValue& list); | |
| 90 | |
| 91 // Updates the whitelist and the blacklist from the prefs. | |
| 92 static void UpdateManualLists(); | |
| 93 | |
| 94 // Returns the profile blacklist. | |
| 95 static scoped_ptr<base::ListValue> GetBlacklist(); | |
| 96 | |
| 97 // ExtensionManagementPolicy::Provider implementation: | |
| 98 virtual std::string GetDebugPolicyProviderName() const OVERRIDE; | |
| 99 virtual bool UserMayLoad(const extensions::Extension* extension, | |
| 100 string16* error) const OVERRIDE; | |
| 101 virtual bool UserMayModifySettings(const extensions::Extension* extension, | |
| 102 string16* error) const OVERRIDE; | |
| 103 | |
| 104 // chrome::BrowserListObserver implementation: | 57 // chrome::BrowserListObserver implementation: |
| 105 virtual void OnBrowserAdded(Browser* browser) OVERRIDE; | 58 virtual void OnBrowserAdded(Browser* browser) OVERRIDE; |
| 106 virtual void OnBrowserRemoved(Browser* browser) OVERRIDE; | 59 virtual void OnBrowserRemoved(Browser* browser) OVERRIDE; |
| 107 | 60 |
| 108 // content::NotificationObserver implementation: | 61 // content::NotificationObserver implementation: |
| 109 virtual void Observe(int type, | 62 virtual void Observe(int type, |
| 110 const content::NotificationSource& source, | 63 const content::NotificationSource& source, |
| 111 const content::NotificationDetails& details) OVERRIDE; | 64 const content::NotificationDetails& details) OVERRIDE; |
| 112 | 65 |
| 113 protected: | 66 protected: |
| 114 ManagedMode(); | 67 ManagedMode(); |
| 115 virtual ~ManagedMode(); | 68 virtual ~ManagedMode(); |
| 116 void EnterManagedModeImpl(Profile* profile, const EnterCallback& callback); | 69 void EnterManagedModeImpl(Profile* profile, const EnterCallback& callback); |
| 117 | 70 |
| 118 // The managed profile. This is NULL iff we are not in managed mode. | 71 // The managed profile. This is NULL iff we are not in managed mode. |
| 119 Profile* managed_profile_; | 72 Profile* managed_profile_; |
| 120 | 73 |
| 121 private: | 74 private: |
| 122 class URLFilterContext; | |
| 123 | |
| 124 friend class Singleton<ManagedMode, LeakySingletonTraits<ManagedMode> >; | 75 friend class Singleton<ManagedMode, LeakySingletonTraits<ManagedMode> >; |
| 125 friend struct DefaultSingletonTraits<ManagedMode>; | 76 friend struct DefaultSingletonTraits<ManagedMode>; |
| 126 FRIEND_TEST_ALL_PREFIXES(ExtensionApiTest, ManagedModeOnChange); | 77 FRIEND_TEST_ALL_PREFIXES(ExtensionApiTest, ManagedModeOnChange); |
| 127 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, | 78 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, |
| 128 ManagedModeProhibitsModification); | 79 ManagedModeProhibitsModification); |
| 129 | 80 |
| 130 static ManagedMode* GetInstance(); | 81 static ManagedMode* GetInstance(); |
| 131 | 82 |
| 132 virtual void InitImpl(Profile* profile); | 83 virtual void InitImpl(Profile* profile); |
| 133 | 84 |
| 134 // Internal implementation for ExtensionManagementPolicy::Delegate methods. | |
| 135 // If |error| is not NULL, it will be filled with an error message if the | |
| 136 // requested extension action (install, modify status, etc.) is not permitted. | |
| 137 bool ExtensionManagementPolicyImpl(string16* error) const; | |
| 138 | |
| 139 void LeaveManagedModeImpl(); | 85 void LeaveManagedModeImpl(); |
| 140 | 86 |
| 141 const ManagedModeURLFilter* GetURLFilterForIOThreadImpl(); | |
| 142 const ManagedModeURLFilter* GetURLFilterForUIThreadImpl(); | |
| 143 | |
| 144 void FinalizeEnter(bool result); | 87 void FinalizeEnter(bool result); |
| 145 | 88 |
| 146 // Platform-specific methods that confirm whether we can enter or leave | 89 // Platform-specific methods that confirm whether we can enter or leave |
| 147 // managed mode. | 90 // managed mode. |
| 148 virtual bool PlatformConfirmEnter(); | 91 virtual bool PlatformConfirmEnter(); |
| 149 virtual bool PlatformConfirmLeave(); | 92 virtual bool PlatformConfirmLeave(); |
| 150 | 93 |
| 151 virtual bool IsInManagedModeImpl() const; | 94 virtual bool IsInManagedModeImpl() const; |
| 152 | 95 |
| 153 // Enables or disables managed mode and registers or unregisters it with the | 96 // Enables or disables managed mode and registers or unregisters it with the |
| 154 // ManagementPolicy. If |newly_managed_profile| is NULL, managed mode will | 97 // ManagementPolicy. If |newly_managed_profile| is NULL, managed mode will |
| 155 // be disabled. Otherwise, managed mode will be enabled for that profile | 98 // be disabled. Otherwise, managed mode will be enabled for that profile |
| 156 // (typically |managed_profile_|, but other values are possible during | 99 // (typically |managed_profile_|, but other values are possible during |
| 157 // testing). | 100 // testing). |
| 158 virtual void SetInManagedMode(Profile* newly_managed_profile); | 101 virtual void SetInManagedMode(Profile* newly_managed_profile); |
| 159 | 102 |
| 160 // Returns a list of all installed and enabled site lists in the current | |
| 161 // managed profile. | |
| 162 // This method should only be called if managed mode is active. | |
| 163 ScopedVector<ManagedModeSiteList> GetActiveSiteLists(); | |
| 164 | |
| 165 void OnDefaultFilteringBehaviorChanged(); | |
| 166 | |
| 167 void UpdateManualListsImpl(); | |
| 168 | |
| 169 // Returns a copy of the manual whitelist which is stored in each profile. | |
| 170 scoped_ptr<base::ListValue> GetWhitelist(); | |
| 171 | |
| 172 // The following functions use |is_whitelist| to select between the whitelist | |
| 173 // and the blacklist as the target of the function. If |is_whitelist| is true | |
| 174 // |url_pattern| is added to the whitelist, otherwise it is added to the | |
| 175 // blacklist. | |
| 176 | |
| 177 void RemoveFromManualListImpl(const bool is_whitelist, | |
| 178 const base::ListValue& whitelist); | |
| 179 | |
| 180 // Adds the |url_pattern| to the manual lists in the URL filter. This is used | |
| 181 // by AddToManualListImpl(). | |
| 182 void AddURLPatternToManualList(const bool is_whitelist, | |
| 183 const std::string& url_pattern); | |
| 184 | |
| 185 void AddToManualListImpl(const bool is_whitelist, | |
| 186 const base::ListValue& whitelist); | |
| 187 | |
| 188 bool IsInManualListImpl(const bool is_whitelist, | |
| 189 const std::string& url_pattern); | |
| 190 | |
| 191 content::NotificationRegistrar registrar_; | 103 content::NotificationRegistrar registrar_; |
| 192 scoped_ptr<PrefChangeRegistrar> pref_change_registrar_; | |
| 193 | |
| 194 scoped_ptr<URLFilterContext> io_url_filter_context_; | |
| 195 scoped_ptr<URLFilterContext> ui_url_filter_context_; | |
| 196 | |
| 197 std::set<Browser*> browsers_to_close_; | 104 std::set<Browser*> browsers_to_close_; |
| 198 std::vector<EnterCallback> callbacks_; | 105 std::vector<EnterCallback> callbacks_; |
| 199 | 106 |
| 200 DISALLOW_COPY_AND_ASSIGN(ManagedMode); | 107 DISALLOW_COPY_AND_ASSIGN(ManagedMode); |
| 201 }; | 108 }; |
| 202 | 109 |
| 203 #endif // CHROME_BROWSER_MANAGED_MODE_MANAGED_MODE_H_ | 110 #endif // CHROME_BROWSER_MANAGED_MODE_MANAGED_MODE_H_ |
| OLD | NEW |