1// Copyright (c) 2011 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#pragma once
8
9#include "chrome/browser/plugin_data_remover_helper.h"
10#include "chrome/browser/prefs/pref_change_registrar.h"
11#include "chrome/browser/ui/webui/options/options_ui.h"
12#include "chrome/common/content_settings_types.h"
13#include "content/common/notification_observer.h"
14#include "content/common/notification_registrar.h"
15
16class HostContentSettingsMap;
17
18class ContentSettingsHandler : public OptionsPageUIHandler {
19 public:
20  ContentSettingsHandler();
21  virtual ~ContentSettingsHandler();
22
23  // OptionsPageUIHandler implementation.
24  virtual void GetLocalizedValues(DictionaryValue* localized_strings);
25
26  virtual void Initialize();
27
28  virtual void RegisterMessages();
29
30  // NotificationObserver implementation.
31  virtual void Observe(NotificationType type,
32                       const NotificationSource& source,
33                       const NotificationDetails& details);
34
35  // Gets a string identifier for the group name, for use in HTML.
36  static std::string ContentSettingsTypeToGroupName(ContentSettingsType type);
37
38 private:
39  // Functions that call into the page -----------------------------------------
40
41  // Updates the page with the default settings (allow, ask, block, etc.)
42  void UpdateSettingDefaultFromModel(ContentSettingsType type);
43
44  // Clobbers and rebuilds the specific content setting type exceptions table.
45  void UpdateExceptionsViewFromModel(ContentSettingsType type);
46  // Clobbers and rebuilds the specific content setting type exceptions
47  // OTR table.
48  void UpdateOTRExceptionsViewFromModel(ContentSettingsType type);
49  // Clobbers and rebuilds all the exceptions tables in the page (both normal
50  // and OTR tables).
51  void UpdateAllExceptionsViewsFromModel();
52  // As above, but only OTR tables.
53  void UpdateAllOTRExceptionsViewsFromModel();
54  // Clobbers and rebuilds just the geolocation exception table.
55  void UpdateGeolocationExceptionsView();
56  // Clobbers and rebuilds just the desktop notification exception table.
57  void UpdateNotificationExceptionsView();
58  // Clobbers and rebuilds an exception table that's managed by the host content
59  // settings map.
60  void UpdateExceptionsViewFromHostContentSettingsMap(ContentSettingsType type);
61  // As above, but acts on the OTR table for the content setting type.
62  void UpdateExceptionsViewFromOTRHostContentSettingsMap(
63      ContentSettingsType type);
64
65  // Callbacks used by the page ------------------------------------------------
66
67  // Sets the default value for a specific content type. |args| includes the
68  // content type and a string describing the new default the user has
69  // chosen.
70  void SetContentFilter(const ListValue* args);
71
72  // Removes the given row from the table. The first entry in |args| is the
73  // content type, and the rest of the arguments depend on the content type
74  // to be removed.
75  void RemoveException(const ListValue* args);
76
77  // Changes the value of an exception. Called after the user is done editing an
78  // exception.
79  void SetException(const ListValue* args);
80
81  // Called to decide whether a given pattern is valid, or if it should be
82  // rejected. Called while the user is editing an exception pattern.
83  void CheckExceptionPatternValidity(const ListValue* args);
84
85  // Sets the global 3rd party cookies pref.
86  void SetAllowThirdPartyCookies(const ListValue* args);
87
88  // Utility functions ---------------------------------------------------------
89
90  // Gets the HostContentSettingsMap for the normal profile.
91  HostContentSettingsMap* GetContentSettingsMap();
92
93  // Gets the HostContentSettingsMap for the incognito profile, or NULL if there
94  // is no active incognito session.
95  HostContentSettingsMap* GetOTRContentSettingsMap();
96
97  // Gets the default setting in string form.
98  std::string GetSettingDefaultFromModel(ContentSettingsType type);
99
100  // Returns true if the default setting for the given content settings type
101  // |type| is managed.
102  bool GetDefaultSettingManagedFromModel(ContentSettingsType type);
103
104  // Member variables ---------------------------------------------------------
105
106  NotificationRegistrar notification_registrar_;
107  PrefChangeRegistrar pref_change_registrar_;
108
109  DISALLOW_COPY_AND_ASSIGN(ContentSettingsHandler);
110};
111
112#endif  // CHROME_BROWSER_UI_WEBUI_OPTIONS_CONTENT_SETTINGS_HANDLER_H_
113