Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / webui / options / content_settings_handler.h
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_UI_WEBUI_OPTIONS_CONTENT_SETTINGS_HANDLER_H_
6 #define CHROME_BROWSER_UI_WEBUI_OPTIONS_CONTENT_SETTINGS_HANDLER_H_
7
8 #include <string>
9
10 #include "base/memory/scoped_ptr.h"
11 #include "base/prefs/pref_change_registrar.h"
12 #include "base/scoped_observer.h"
13 #include "chrome/browser/pepper_flash_settings_manager.h"
14 #include "chrome/browser/ui/webui/options/options_ui.h"
15 #include "chrome/browser/ui/webui/options/pepper_flash_content_settings_utils.h"
16 #include "components/content_settings/core/browser/content_settings_observer.h"
17 #include "components/content_settings/core/common/content_settings.h"
18 #include "components/content_settings/core/common/content_settings_types.h"
19 #include "content/public/browser/host_zoom_map.h"
20 #include "content/public/browser/notification_observer.h"
21 #include "content/public/browser/notification_registrar.h"
22
23 class HostContentSettingsMap;
24 class ProtocolHandlerRegistry;
25
26 namespace options {
27
28 class ContentSettingsHandler : public OptionsPageUIHandler,
29                                public content_settings::Observer,
30                                public content::NotificationObserver,
31                                public PepperFlashSettingsManager::Client {
32  public:
33   ContentSettingsHandler();
34   ~ContentSettingsHandler() override;
35
36   // OptionsPageUIHandler implementation.
37   void GetLocalizedValues(base::DictionaryValue* localized_strings) override;
38   void InitializeHandler() override;
39   void InitializePage() override;
40   void RegisterMessages() override;
41
42   // content_settings::Observer implementation.
43   void OnContentSettingChanged(const ContentSettingsPattern& primary_pattern,
44                                const ContentSettingsPattern& secondary_pattern,
45                                ContentSettingsType content_type,
46                                std::string resource_identifier) override;
47
48   // content::NotificationObserver implementation.
49   void Observe(int type,
50                const content::NotificationSource& source,
51                const content::NotificationDetails& details) override;
52
53   // PepperFlashSettingsManager::Client implementation.
54   void OnGetPermissionSettingsCompleted(
55       uint32 request_id,
56       bool success,
57       PP_Flash_BrowserOperations_Permission default_permission,
58       const ppapi::FlashSiteSettings& sites) override;
59
60   // Gets a string identifier for the group name, for use in HTML.
61   static std::string ContentSettingsTypeToGroupName(ContentSettingsType type);
62
63  private:
64   // Used to determine whether we should show links to Flash camera and
65   // microphone settings.
66   struct MediaSettingsInfo {
67     MediaSettingsInfo();
68     ~MediaSettingsInfo();
69
70     // Cached Pepper Flash settings.
71     ContentSetting flash_default_setting;
72     MediaExceptions flash_exceptions;
73     bool flash_settings_initialized;
74     uint32_t last_flash_refresh_request_id;
75
76     // Whether the links to Flash settings pages are showed.
77     bool show_flash_default_link;
78     bool show_flash_exceptions_link;
79
80     // Cached Chrome media settings.
81     ContentSetting default_setting;
82     bool policy_disable_audio;
83     bool policy_disable_video;
84     bool default_setting_initialized;
85     MediaExceptions exceptions;
86     bool exceptions_initialized;
87   };
88
89   // Used by ShowFlashMediaLink() to specify which link to show/hide.
90   enum LinkType {
91     DEFAULT_SETTING = 0,
92     EXCEPTIONS,
93   };
94
95   // Functions that call into the page -----------------------------------------
96
97   // Updates the page with the default settings (allow, ask, block, etc.)
98   void UpdateSettingDefaultFromModel(ContentSettingsType type);
99
100   // Updates the media radio buttons according to the enabled split prefs.
101   void UpdateMediaSettingsView();
102
103   // Clobbers and rebuilds the specific content setting type exceptions table.
104   void UpdateExceptionsViewFromModel(ContentSettingsType type);
105
106   // Clobbers and rebuilds the specific content setting type exceptions
107   // OTR table.
108   void UpdateOTRExceptionsViewFromModel(ContentSettingsType type);
109
110   // Clobbers and rebuilds all the exceptions tables in the page (both normal
111   // and OTR tables).
112   void UpdateAllExceptionsViewsFromModel();
113
114   // As above, but only OTR tables.
115   void UpdateAllOTRExceptionsViewsFromModel();
116
117   // Clobbers and rebuilds just the geolocation exception table.
118   void UpdateGeolocationExceptionsView();
119
120   // Clobbers and rebuilds just the desktop notification exception table.
121   void UpdateNotificationExceptionsView();
122
123   // Clobbers and rebuilds just the Media device exception table.
124   void UpdateMediaExceptionsView();
125
126   // Clobbers and rebuilds just the MIDI SysEx exception table.
127   void UpdateMIDISysExExceptionsView();
128
129   // Clobbers and rebuilds just the zoom levels exception table.
130   void UpdateZoomLevelsExceptionsView();
131
132   // Clobbers and rebuilds an exception table that's managed by the host content
133   // settings map.
134   void UpdateExceptionsViewFromHostContentSettingsMap(ContentSettingsType type);
135
136   // As above, but acts on the OTR table for the content setting type.
137   void UpdateExceptionsViewFromOTRHostContentSettingsMap(
138       ContentSettingsType type);
139
140   // Updates the radio buttons for enabling / disabling handlers.
141   void UpdateHandlersEnabledRadios();
142
143   // Removes one geolocation exception. |args| contains the parameters passed to
144   // RemoveException().
145   void RemoveGeolocationException(const base::ListValue* args);
146
147   // Removes one notification exception. |args| contains the parameters passed
148   // to RemoveException().
149   void RemoveNotificationException(const base::ListValue* args);
150
151   // Removes one media camera and microphone exception. |args| contains the
152   // parameters passed to RemoveException().
153   void RemoveMediaException(const base::ListValue* args);
154
155   // Removes one exception of |type| from the host content settings map. |args|
156   // contains the parameters passed to RemoveException().
157   void RemoveExceptionFromHostContentSettingsMap(
158       const base::ListValue* args,
159       ContentSettingsType type);
160
161   // Removes one zoom level exception. |args| contains the parameters passed to
162   // RemoveException().
163   void RemoveZoomLevelException(const base::ListValue* args);
164
165   // Callbacks used by the page ------------------------------------------------
166
167   // Sets the default value for a specific content type. |args| includes the
168   // content type and a string describing the new default the user has
169   // chosen.
170   void SetContentFilter(const base::ListValue* args);
171
172   // Removes the given row from the table. The first entry in |args| is the
173   // content type, and the rest of the arguments depend on the content type
174   // to be removed.
175   void RemoveException(const base::ListValue* args);
176
177   // Changes the value of an exception. Called after the user is done editing an
178   // exception.
179   void SetException(const base::ListValue* args);
180
181   // Called to decide whether a given pattern is valid, or if it should be
182   // rejected. Called while the user is editing an exception pattern.
183   void CheckExceptionPatternValidity(const base::ListValue* args);
184
185   // Utility functions ---------------------------------------------------------
186
187   // Applies content settings whitelists to reduce breakage / user confusion.
188   void ApplyWhitelist(ContentSettingsType content_type,
189                       ContentSetting default_setting);
190
191   // Gets the HostContentSettingsMap for the normal profile.
192   HostContentSettingsMap* GetContentSettingsMap();
193
194   // Gets the HostContentSettingsMap for the incognito profile, or NULL if there
195   // is no active incognito session.
196   HostContentSettingsMap* GetOTRContentSettingsMap();
197
198   // Gets the default setting in string form. If |provider_id| is not NULL, the
199   // id of the provider which provided the default setting is assigned to it.
200   std::string GetSettingDefaultFromModel(ContentSettingsType type,
201                                          std::string* provider_id);
202
203   // Gets the ProtocolHandlerRegistry for the normal profile.
204   ProtocolHandlerRegistry* GetProtocolHandlerRegistry();
205
206   void RefreshFlashMediaSettings();
207
208   // Fills in |exceptions| with Values for the given |type| from |map|.
209   void GetExceptionsFromHostContentSettingsMap(
210       const HostContentSettingsMap* map,
211       ContentSettingsType type,
212       base::ListValue* exceptions);
213
214   void OnPepperFlashPrefChanged();
215
216   // content::HostZoomMap subscription.
217   void OnZoomLevelChanged(const content::HostZoomMap::ZoomLevelChange& change);
218
219   void ShowFlashMediaLink(LinkType link_type, bool show);
220
221   void UpdateFlashMediaLinksVisibility();
222
223   void UpdateProtectedContentExceptionsButton();
224
225   // Member variables ---------------------------------------------------------
226
227   content::NotificationRegistrar notification_registrar_;
228   PrefChangeRegistrar pref_change_registrar_;
229   scoped_ptr<PepperFlashSettingsManager> flash_settings_manager_;
230   MediaSettingsInfo media_settings_;
231   scoped_ptr<content::HostZoomMap::Subscription> host_zoom_map_subscription_;
232   ScopedObserver<HostContentSettingsMap, content_settings::Observer> observer_;
233
234   DISALLOW_COPY_AND_ASSIGN(ContentSettingsHandler);
235 };
236
237 }  // namespace options
238
239 #endif  // CHROME_BROWSER_UI_WEBUI_OPTIONS_CONTENT_SETTINGS_HANDLER_H_