summaryrefslogtreecommitdiffstats
path: root/chrome/browser/gtk/options/content_exception_editor.h
blob: a40b4d2a56fc181b44370d445a8146ff75fa0f39 (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
// 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_EXCEPTION_EDITOR_H_
#define CHROME_BROWSER_GTK_OPTIONS_CONTENT_EXCEPTION_EDITOR_H_

#include <gtk/gtk.h>

#include <string>

#include "chrome/browser/content_exceptions_table_model.h"
#include "chrome/common/content_settings.h"
#include "chrome/common/content_settings_types.h"

// An editor which lets the user create or edit an individual exception to the
// current content setting policy. (i.e. let www.google.com always show
// images). Modal to parent.
class ContentExceptionEditor {
 public:
  class Delegate {
   public:
    // Invoked when the user accepts the edit.
    virtual void AcceptExceptionEdit(const std::string& host,
                                     ContentSetting setting,
                                     int index,
                                     bool is_new) = 0;

   protected:
    virtual ~Delegate() {}
  };

  ContentExceptionEditor(GtkWindow* parent,
                         Delegate* delegate,
                         ContentExceptionsTableModel* model,
                         int index,
                         const std::string& host,
                         ContentSetting setting);

 private:
  // Returns true if we're adding a new item.
  bool is_new() const { return index_ == -1; }

  // Returns the number of items in the |action_combo_|.
  int GetItemCount();

  // Returns the string representation for an item in |action_combo_|.
  std::string GetTitleFor(int index);

  // Changes an index from |action_combo_| into a ContentSetting and vice versa.
  ContentSetting SettingForIndex(int index);
  int IndexForSetting(ContentSetting setting);

  bool IsHostValid(const std::string& host) const;

  void UpdateImage(GtkWidget* image, bool is_valid);

  // GTK callbacks
  static void OnEntryChanged(GtkEditable* entry,
                             ContentExceptionEditor* window);
  static void OnResponse(GtkWidget* sender,
                         int response_id,
                         ContentExceptionEditor* window);
  static void OnWindowDestroy(GtkWidget* widget,
                              ContentExceptionEditor* editor);

  Delegate* delegate_;
  ContentExceptionsTableModel* model_;
  bool show_ask_;

  // Index of the item being edited. If -1, indicates this is a new entry.
  const int index_;
  const std::string host_;
  const ContentSetting setting_;

  // UI widgets.
  GtkWidget* dialog_;
  GtkWidget* entry_;
  GtkWidget* host_image_;
  GtkWidget* action_combo_;

  DISALLOW_COPY_AND_ASSIGN(ContentExceptionEditor);
};

#endif  // CHROME_BROWSER_GTK_OPTIONS_CONTENT_EXCEPTION_EDITOR_H_