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.
5 #ifndef CHROME_BROWSER_UI_WEBUI_OPTIONS_WEBSITE_SETTINGS_HANDLER_H_
6 #define CHROME_BROWSER_UI_WEBUI_OPTIONS_WEBSITE_SETTINGS_HANDLER_H_
10 #include "base/basictypes.h"
11 #include "base/macros.h"
12 #include "base/scoped_observer.h"
13 #include "chrome/browser/browsing_data/browsing_data_local_storage_helper.h"
14 #include "chrome/browser/content_settings/host_content_settings_map.h"
15 #include "chrome/browser/content_settings/local_shared_objects_container.h"
16 #include "chrome/browser/ui/webui/options/options_ui.h"
17 #include "components/content_settings/core/browser/content_settings_observer.h"
18 #include "components/power/origin_power_map.h"
22 class WebsiteSettingsHandler : public content_settings::Observer,
23 public OptionsPageUIHandler {
25 WebsiteSettingsHandler();
26 virtual ~WebsiteSettingsHandler();
28 typedef std::list<BrowsingDataLocalStorageHelper::LocalStorageInfo>
31 // OptionsPageUIHandler implementation.
32 virtual void GetLocalizedValues(
33 base::DictionaryValue* localized_strings) OVERRIDE;
34 virtual void InitializeHandler() OVERRIDE;
35 virtual void RegisterMessages() OVERRIDE;
37 // content_settings::Observer implementation.
38 virtual void OnContentSettingChanged(
39 const ContentSettingsPattern& primary_pattern,
40 const ContentSettingsPattern& secondary_pattern,
41 ContentSettingsType content_type,
42 std::string resource_identifier) OVERRIDE;
43 virtual void OnContentSettingUsed(
44 const ContentSettingsPattern& primary_pattern,
45 const ContentSettingsPattern& secondary_pattern,
46 ContentSettingsType content_type) OVERRIDE;
49 // Update the page with all origins for a given content setting.
50 // |args| is the string name of the content setting.
51 void HandleUpdateOrigins(const base::ListValue* args);
53 // Update the page with all origins given a filter string.
54 // |args| is the filter string.
55 void HandleUpdateSearchResults(const base::ListValue* args);
57 // Update the single site edit view with the permission values for a given
58 // url, if the url is valid.
60 void HandleGetOriginInfo(const base::ListValue* args);
62 // Sets the content setting permissions for a given setting type for the last
64 // |args| is the name of the setting and the new value.
65 void HandleSetOriginPermission(const base::ListValue* args);
67 // Update the page with all origins that are using local storage.
68 void HandleUpdateLocalStorage(const base::ListValue* args);
70 // Show the single site edit view if the given URL is valid.
72 void HandleMaybeShowEditPage(const base::ListValue* args);
74 // Get all origins that have used power, filter them by |last_filter_|, and
76 void HandleUpdateBatteryUsage(const base::ListValue* args);
78 // Deletes the local storage and repopulates the page.
79 void HandleDeleteLocalStorage(const base::ListValue* args);
81 // Populates the default setting drop down on the single site edit page.
82 void HandleUpdateDefaultSetting(const base::ListValue* args);
84 // Sets the default setting for the last used content setting to |args|.
85 void HandleSetDefaultSetting(const base::ListValue* args);
87 // Sets if a certain content setting enabled to |args|.
88 void HandleSetGlobalToggle(const base::ListValue* args);
90 // Closes all tabs and app windows which have the same origin as the selected
92 void HandleStopOrigin(const base::ListValue* args);
94 // Callback method to be invoked when fetching the data is complete.
95 void OnLocalStorageFetched(const LocalStorageList& storage);
97 // Get all origins with Content Settings for the last given content setting,
98 // filter them by |last_filter_|, and update the page.
101 // Get all origins with local storage usage, filter them by |last_filter_|,
102 // and update the page.
103 void UpdateLocalStorage();
105 // Get all origins with power consumption, filter them by |last_filter_|,
106 // and update the page.
107 void UpdateBatteryUsage();
109 // Kill all tabs and app windows which have the same origin as |site_url|.
110 void StopOrigin(const GURL& site_url);
112 // Delete all of the local storage for the |site_url|.
113 void DeleteLocalStorage(const GURL& site_url);
115 // Populates the single site edit view with the permissions and local storage
116 // usage for a given |site_url|. If |show_page| is true, it raises a new
117 // single site edit view.
118 void GetInfoForOrigin(const GURL& site_url, bool show_page);
120 // Updates the page with the last settings used.
123 // Gets the default setting in string form. If |provider_id| is not NULL, the
124 // id of the provider which provided the default setting is assigned to it.
125 std::string GetSettingDefaultFromModel(ContentSettingsType type,
126 std::string* provider_id);
128 // Returns the base URL for websites, or the app name for Chrome App URLs.
129 const std::string& GetReadableName(const GURL& site_url);
131 Profile* GetProfile();
133 std::string last_setting_;
134 std::string last_filter_;
136 scoped_refptr<BrowsingDataLocalStorageHelper> local_storage_;
137 LocalStorageList local_storage_list_;
139 // Observer to watch for content settings changes.
140 ScopedObserver<HostContentSettingsMap, content_settings::Observer> observer_;
142 // Subscription to watch for power consumption updates.
143 scoped_ptr<power::OriginPowerMap::Subscription> subscription_;
145 base::WeakPtrFactory<WebsiteSettingsHandler> weak_ptr_factory_;
147 DISALLOW_COPY_AND_ASSIGN(WebsiteSettingsHandler);
150 } // namespace options
152 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_WEBSITE_SETTINGS_HANDLER_H_