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