1 // Copyright 2013 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_USAGES_STATE_H_ 6 #define CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_USAGES_STATE_H_ 7 8 #include <map> 9 #include <set> 10 11 #include "chrome/common/content_settings.h" 12 #include "chrome/common/content_settings_types.h" 13 #include "url/gurl.h" 14 15 class Profile; 16 17 namespace content { 18 struct LoadCommittedDetails; 19 } 20 21 // This class manages a content setting state per tab for a given 22 // |ContentSettingsType|, and provides information and presentation data about 23 // the content setting usage. 24 class ContentSettingsUsagesState { 25 public: 26 ContentSettingsUsagesState(Profile* profile, ContentSettingsType type); 27 virtual ~ContentSettingsUsagesState(); 28 29 typedef std::map<GURL, ContentSetting> StateMap; 30 const StateMap& state_map() const { 31 return state_map_; 32 } 33 34 // Sets the state for |requesting_origin|. 35 void OnPermissionSet(const GURL& requesting_origin, bool allowed); 36 37 // Delegated by WebContents to indicate a navigation has happened and we 38 // may need to clear our settings. 39 void DidNavigate(const content::LoadCommittedDetails& details); 40 41 void ClearStateMap(); 42 43 enum TabState { 44 TABSTATE_NONE = 0, 45 // There's at least one entry with non-default setting. 46 TABSTATE_HAS_EXCEPTION = 1 << 1, 47 // There's at least one entry with a non-ASK setting. 48 TABSTATE_HAS_ANY_ICON = 1 << 2, 49 // There's at least one entry with ALLOWED setting. 50 TABSTATE_HAS_ANY_ALLOWED = 1 << 3, 51 // There's at least one entry that doesn't match the saved setting. 52 TABSTATE_HAS_CHANGED = 1 << 4, 53 }; 54 55 // Maps ContentSetting to a set of hosts formatted for presentation. 56 typedef std::map<ContentSetting, std::set<std::string> > 57 FormattedHostsPerState; 58 59 // Returns an (optional) |formatted_hosts_per_state| and a mask of TabState. 60 void GetDetailedInfo(FormattedHostsPerState* formatted_hosts_per_state, 61 unsigned int* tab_state_flags) const; 62 63 private: 64 std::string GURLToFormattedHost(const GURL& url) const; 65 66 Profile* profile_; 67 ContentSettingsType type_; 68 StateMap state_map_; 69 GURL embedder_url_; 70 71 DISALLOW_COPY_AND_ASSIGN(ContentSettingsUsagesState); 72 }; 73 74 #endif // CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_USAGES_STATE_H_ 75