summaryrefslogtreecommitdiffstats
path: root/chrome/browser/gtk/options/content_exceptions_window_gtk.h
blob: 0f70c9017380b7ae1a3b616c4a3f6fe43f8b8c71 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_GTK_OPTIONS_CONTENT_EXCEPTIONS_WINDOW_GTK_H_
#define CHROME_BROWSER_GTK_OPTIONS_CONTENT_EXCEPTIONS_WINDOW_GTK_H_
#pragma once

#include <gtk/gtk.h>

#include <string>

#include "app/gtk_signal.h"
#include "base/scoped_ptr.h"
#include "chrome/browser/content_exceptions_table_model.h"
#include "chrome/browser/gtk/gtk_tree.h"
#include "chrome/browser/gtk/options/content_exception_editor.h"
#include "chrome/common/content_settings.h"
#include "chrome/common/content_settings_types.h"

class HostContentSettingsMap;

// Dialog that lists each of the exceptions to the current content policy, and
// has options for adding/editing/removing entries. Modal to parrent.
class ContentExceptionsWindowGtk : public gtk_tree::TableAdapter::Delegate,
                                   public ContentExceptionEditor::Delegate {
 public:
  static void ShowExceptionsWindow(GtkWindow* window,
                                   HostContentSettingsMap* map,
                                   HostContentSettingsMap* off_the_record_map,
                                   ContentSettingsType content_type);

  ~ContentExceptionsWindowGtk();

  // gtk_tree::TableAdapter::Delegate implementation:
  virtual void SetColumnValues(int row, GtkTreeIter* iter);

  // ContentExceptionEditor::Delegate implementation:
  virtual void AcceptExceptionEdit(
      const ContentSettingsPattern& pattern,
      ContentSetting setting,
      bool is_off_the_record,
      int index,
      bool is_new);

 private:
  // Column ids for |list_store_|.
  enum {
    COL_PATTERN,
    COL_ACTION,
    COL_OTR,
    COL_COUNT
  };

  ContentExceptionsWindowGtk(GtkWindow* parent,
                             HostContentSettingsMap* map,
                             HostContentSettingsMap* off_the_record_map,
                             ContentSettingsType type);

  // Updates which buttons are enabled.
  void UpdateButtonState();

  // Callbacks for the buttons.
  CHROMEGTK_CALLBACK_0(ContentExceptionsWindowGtk, void, Add);
  CHROMEGTK_CALLBACK_0(ContentExceptionsWindowGtk, void, Edit);
  CHROMEGTK_CALLBACK_0(ContentExceptionsWindowGtk, void, Remove);
  CHROMEGTK_CALLBACK_0(ContentExceptionsWindowGtk, void, RemoveAll);

  // Returns the title of the window (changes based on what ContentSettingsType
  // was set to in the constructor).
  std::string GetWindowTitle() const;

  // Gets the selected indicies in the two list stores. Indicies are returned
  // in <list_store_, sort_list_store_> order.
  void GetSelectedModelIndices(std::set<std::pair<int, int> >* indices);

  // GTK Callbacks
  CHROMEGTK_CALLBACK_2(ContentExceptionsWindowGtk, void,
                       OnTreeViewRowActivate, GtkTreePath*, GtkTreeViewColumn*);
  CHROMEGTK_CALLBACK_0(ContentExceptionsWindowGtk, void, OnWindowDestroy);
  CHROMEGTK_CALLBACK_0(ContentExceptionsWindowGtk, void,
                       OnTreeSelectionChanged);

  // The list presented in |treeview_|. Separate from |list_store_|, the list
  // that backs |sort_model_|. This separation comes so the user can sort the
  // data on screen without changing the underlying |list_store_|.
  GtkTreeModel* sort_list_store_;

  // The backing to |sort_list_store_|. Doesn't change when sorted.
  GtkListStore* list_store_;

  // The C++, views-ish, cross-platform model class that actually contains the
  // gold standard data.
  scoped_ptr<ContentExceptionsTableModel> model_;

  // True if we also show exceptions from an OTR profile.
  bool allow_off_the_record_;

  // The adapter that ferries data back and forth between |model_| and
  // |list_store_| whenever either of them change.
  scoped_ptr<gtk_tree::TableAdapter> model_adapter_;

  // The exception window.
  GtkWidget* dialog_;

  // The treeview that presents the site/action pairs.
  GtkWidget* treeview_;

  // The current user selection from |treeview_|.
  GtkTreeSelection* treeview_selection_;

  // Buttons.
  GtkWidget* edit_button_;
  GtkWidget* remove_button_;
  GtkWidget* remove_all_button_;

  friend class ContentExceptionsWindowGtkUnittest;
};

#endif  // CHROME_BROWSER_GTK_OPTIONS_CONTENT_EXCEPTIONS_WINDOW_GTK_H_