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