OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef CHROME_BROWSER_UI_WEBUI_OPTIONS_WEBSITE_SETTINGS_HANDLER_H_ | |
6 #define CHROME_BROWSER_UI_WEBUI_OPTIONS_WEBSITE_SETTINGS_HANDLER_H_ | |
7 | |
8 #include <string> | |
9 | |
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/ui/webui/options/options_ui.h" | |
15 #include "components/content_settings/core/browser/content_settings_observer.h" | |
16 #include "components/content_settings/core/browser/host_content_settings_map.h" | |
17 #include "components/power/origin_power_map.h" | |
18 | |
19 namespace options { | |
20 | |
21 class WebsiteSettingsHandler : public content_settings::Observer, | |
22 public OptionsPageUIHandler { | |
23 public: | |
24 WebsiteSettingsHandler(); | |
25 ~WebsiteSettingsHandler() override; | |
26 | |
27 typedef std::list<BrowsingDataLocalStorageHelper::LocalStorageInfo> | |
28 LocalStorageList; | |
29 | |
30 // OptionsPageUIHandler implementation. | |
31 void GetLocalizedValues(base::DictionaryValue* localized_strings) override; | |
32 void InitializeHandler() override; | |
33 void RegisterMessages() override; | |
34 | |
35 // content_settings::Observer implementation. | |
36 void OnContentSettingChanged(const ContentSettingsPattern& primary_pattern, | |
37 const ContentSettingsPattern& secondary_pattern, | |
38 ContentSettingsType content_type, | |
39 std::string resource_identifier) override; | |
40 void OnContentSettingUsed(const ContentSettingsPattern& primary_pattern, | |
41 const ContentSettingsPattern& secondary_pattern, | |
42 ContentSettingsType content_type) override; | |
43 | |
44 private: | |
45 // Update the page with all origins for a given content setting. | |
46 // |args| is the string name of the content setting. | |
47 void HandleUpdateOrigins(const base::ListValue* args); | |
48 | |
49 // Update the page with all origins given a filter string. | |
50 // |args| is the filter string. | |
51 void HandleUpdateSearchResults(const base::ListValue* args); | |
52 | |
53 // Update the single site edit view with the permission values for a given | |
54 // url, if the url is valid. | |
55 // |args| is the URL. | |
56 void HandleGetOriginInfo(const base::ListValue* args); | |
57 | |
58 // Sets the content setting permissions for a given setting type for the last | |
59 // used origin. | |
60 // |args| is the name of the setting and the new value. | |
61 void HandleSetOriginPermission(const base::ListValue* args); | |
62 | |
63 // Update the page with all origins that are using local storage. | |
64 void HandleUpdateLocalStorage(const base::ListValue* args); | |
65 | |
66 // Show the single site edit view if the given URL is valid. | |
67 // |args| is the URL. | |
68 void HandleMaybeShowEditPage(const base::ListValue* args); | |
69 | |
70 // Get all origins that have used power, filter them by |last_filter_|, and | |
71 // update the page. | |
72 void HandleUpdateBatteryUsage(const base::ListValue* args); | |
73 | |
74 // Deletes the local storage and repopulates the page. | |
75 void HandleDeleteLocalStorage(const base::ListValue* args); | |
76 | |
77 // Populates the default setting drop down on the single site edit page. | |
78 void HandleUpdateDefaultSetting(const base::ListValue* args); | |
79 | |
80 // Sets the default setting for the last used content setting to |args|. | |
81 void HandleSetDefaultSetting(const base::ListValue* args); | |
82 | |
83 // Sets if a certain content setting enabled to |args|. | |
84 void HandleSetGlobalToggle(const base::ListValue* args); | |
85 | |
86 // Closes all tabs and app windows which have the same origin as the selected | |
87 // page. | |
88 void HandleStopOrigin(const base::ListValue* args); | |
89 | |
90 // Callback method to be invoked when fetching the data is complete. | |
91 void OnLocalStorageFetched(const LocalStorageList& storage); | |
92 | |
93 // Get all origins with Content Settings for the last given content setting, | |
94 // filter them by |last_filter_|, and update the page. | |
95 void UpdateOrigins(); | |
96 | |
97 // Get all origins with local storage usage, filter them by |last_filter_|, | |
98 // and update the page. | |
99 void UpdateLocalStorage(); | |
100 | |
101 // Get all origins with power consumption, filter them by |last_filter_|, | |
102 // and update the page. | |
103 void UpdateBatteryUsage(); | |
104 | |
105 // Kill all tabs and app windows which have the same origin as |site_url|. | |
106 void StopOrigin(const GURL& site_url); | |
107 | |
108 // Delete all of the local storage for the |site_url|. | |
109 void DeleteLocalStorage(const GURL& site_url); | |
110 | |
111 // Populates the single site edit view with the permissions and local storage | |
112 // usage for a given |site_url|. If |show_page| is true, it raises a new | |
113 // single site edit view. | |
114 void GetInfoForOrigin(const GURL& site_url, bool show_page); | |
115 | |
116 // Updates the page with the last settings used. | |
117 void Update(); | |
118 | |
119 // Returns the base URL for websites, or the app name for Chrome App URLs. | |
120 const std::string& GetReadableName(const GURL& site_url); | |
121 | |
122 Profile* GetProfile(); | |
123 | |
124 std::string last_setting_; | |
125 std::string last_filter_; | |
126 GURL last_site_; | |
127 scoped_refptr<BrowsingDataLocalStorageHelper> local_storage_; | |
128 LocalStorageList local_storage_list_; | |
129 | |
130 // Observer to watch for content settings changes. | |
131 ScopedObserver<HostContentSettingsMap, content_settings::Observer> observer_; | |
132 | |
133 // Subscription to watch for power consumption updates. | |
134 scoped_ptr<power::OriginPowerMap::Subscription> subscription_; | |
135 | |
136 base::WeakPtrFactory<WebsiteSettingsHandler> weak_ptr_factory_; | |
137 | |
138 DISALLOW_COPY_AND_ASSIGN(WebsiteSettingsHandler); | |
139 }; | |
140 | |
141 } // namespace options | |
142 | |
143 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_WEBSITE_SETTINGS_HANDLER_H_ | |
OLD | NEW |