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