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.
5 #ifndef CHROME_BROWSER_UI_GTK_WEBSITE_SETTINGS_PERMISSION_SELECTOR_H_
6 #define CHROME_BROWSER_UI_GTK_WEBSITE_SETTINGS_PERMISSION_SELECTOR_H_
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/observer_list.h"
14 #include "chrome/browser/ui/website_settings/permission_menu_model.h"
15 #include "chrome/browser/ui/gtk/website_settings/permission_selector_observer.h"
16 #include "chrome/common/content_settings.h"
17 #include "chrome/common/content_settings_types.h"
18 #include "ui/base/gtk/gtk_signal.h"
21 class GtkThemeService
;
23 // The class |PermissionSelector| allows to change the permission |setting| of a
24 // given permission |type|.
25 class PermissionSelector
: public PermissionMenuModel::Delegate
{
27 // Creates a |PermissionSelector| for the given permission |type|. |setting|
28 // is the current permissions setting. It is possible to pass
29 // |CONTENT_SETTING_DEFAULT| as value for |setting|. |default_setting| is the
30 // effective default setting for the given permission |type|. It is not
31 // allowed to pass |CONTENT_SETTING_DEFAULT| as value for |default_setting|.
32 PermissionSelector(GtkThemeService
* theme_service
,
34 ContentSettingsType type
,
35 ContentSetting setting
,
36 ContentSetting default_setting
,
37 content_settings::SettingSource source
);
38 virtual ~PermissionSelector();
40 // Returns the container widget that contains all |PermissionSelector| UI
42 GtkWidget
* widget() { return widget_
; }
44 // Adds an |observer|.
45 void AddObserver(PermissionSelectorObserver
* observer
);
47 // Returns the current permission setting.
48 ContentSetting
GetSetting() const;
50 // Returns the permissions type.
51 ContentSettingsType
GetType() const;
54 // Gtk callback to intercept mouse clicks to the menu buttons.
55 CHROMEGTK_CALLBACK_1(PermissionSelector
, gboolean
, OnMenuButtonPressEvent
,
58 // PermissionMenuModel::Delegate implementation.
59 virtual void ExecuteCommand(int command_id
) OVERRIDE
;
60 virtual bool IsCommandIdChecked(int command_id
) OVERRIDE
;
62 // The container widget that contains the PermissionSelecter UI widgets.
63 GtkWidget
* widget_
; // Owned by the widget hierarchy.
65 // The button that toggles the permission |menu_|.
66 GtkWidget
* menu_button_
; // Owned by the widget hierarchy.
68 // The menu that provides the permission settings.
69 scoped_ptr
<MenuGtk
> menu_
;
71 // The model for the permission |menu_|.
72 scoped_ptr
<PermissionMenuModel
> menu_model_
;
74 // The permission type icon. The icon is changed depending on the selected
76 // Owned by the widget hierarchy created by the CreateUI method.
79 // The site permission (the |ContentSettingsType|) for which the menu model
81 ContentSettingsType type_
;
83 // The global default setting for the permission |type_|.
84 ContentSetting default_setting_
;
86 // The currently active setting for the permission |type_|.
87 ContentSetting setting_
;
89 ObserverList
<PermissionSelectorObserver
, false> observer_list_
;
91 DISALLOW_COPY_AND_ASSIGN(PermissionSelector
);
94 #endif // CHROME_BROWSER_UI_GTK_WEBSITE_SETTINGS_PERMISSION_SELECTOR_H_