Home | History | Annotate | Download | only in website_settings
      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_GTK_WEBSITE_SETTINGS_PERMISSION_SELECTOR_H_
      6 #define CHROME_BROWSER_UI_GTK_WEBSITE_SETTINGS_PERMISSION_SELECTOR_H_
      7 
      8 #include <gtk/gtk.h>
      9 
     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"
     19 
     20 class MenuGtk;
     21 class GtkThemeService;
     22 
     23 // The class |PermissionSelector| allows to change the permission |setting| of a
     24 // given permission |type|.
     25 class PermissionSelector : public PermissionMenuModel::Delegate {
     26  public:
     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,
     33                      const GURL& url,
     34                      ContentSettingsType type,
     35                      ContentSetting setting,
     36                      ContentSetting default_setting,
     37                      content_settings::SettingSource source);
     38   virtual ~PermissionSelector();
     39 
     40   // Returns the container widget that contains all |PermissionSelector| UI
     41   // widgets.
     42   GtkWidget* widget() { return widget_; }
     43 
     44   // Adds an |observer|.
     45   void AddObserver(PermissionSelectorObserver* observer);
     46 
     47   // Returns the current permission setting.
     48   ContentSetting GetSetting() const;
     49 
     50   // Returns the permissions type.
     51   ContentSettingsType GetType() const;
     52 
     53  private:
     54   // Gtk callback to intercept mouse clicks to the menu buttons.
     55   CHROMEGTK_CALLBACK_1(PermissionSelector, gboolean, OnMenuButtonPressEvent,
     56                        GdkEventButton*);
     57 
     58   // PermissionMenuModel::Delegate implementation.
     59   virtual void ExecuteCommand(int command_id) OVERRIDE;
     60   virtual bool IsCommandIdChecked(int command_id) OVERRIDE;
     61 
     62   // The container widget that contains the PermissionSelecter UI widgets.
     63   GtkWidget* widget_;  // Owned by the widget hierarchy.
     64 
     65   // The button that toggles the permission |menu_|.
     66   GtkWidget* menu_button_;  // Owned by the widget hierarchy.
     67 
     68   // The menu that provides the permission settings.
     69   scoped_ptr<MenuGtk> menu_;
     70 
     71   // The model for the permission |menu_|.
     72   scoped_ptr<PermissionMenuModel> menu_model_;
     73 
     74   // The permission type icon. The icon is changed depending on the selected
     75   // setting.
     76   // Owned by the widget hierarchy created by the CreateUI method.
     77   GtkWidget* icon_;
     78 
     79   // The site permission (the |ContentSettingsType|) for which the menu model
     80   // provides settings.
     81   ContentSettingsType type_;
     82 
     83   // The global default setting for the permission |type_|.
     84   ContentSetting default_setting_;
     85 
     86   // The currently active setting for the permission |type_|.
     87   ContentSetting setting_;
     88 
     89   ObserverList<PermissionSelectorObserver, false> observer_list_;
     90 
     91   DISALLOW_COPY_AND_ASSIGN(PermissionSelector);
     92 };
     93 
     94 #endif  // CHROME_BROWSER_UI_GTK_WEBSITE_SETTINGS_PERMISSION_SELECTOR_H_
     95