summaryrefslogtreecommitdiffstats
path: root/chrome/browser/gtk/options/exceptions_page_gtk.h
blob: 67ae0a7e2a9aab51c5d5228fca5978cc9e525d6d (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
// Copyright (c) 2009 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_EXCEPTIONS_PAGE_GTK_H_
#define CHROME_BROWSER_GTK_OPTIONS_EXCEPTIONS_PAGE_GTK_H_

#include <gtk/gtk.h>

#include <vector>

#include "chrome/browser/password_manager/password_store.h"
#include "chrome/browser/profile.h"

class ExceptionsPageGtk {
 public:
  explicit ExceptionsPageGtk(Profile* profile);
  ~ExceptionsPageGtk();

  GtkWidget* get_page_widget() const {
    return page_;
  }

 private:
  // Initialize the exception tree widget, setting the member variables.
  void InitExceptionTree();

  // The password store associated with the currently active profile.
  PasswordStore* GetPasswordStore();

  // Sets the exception list contents to the given data.
  void SetExceptionList(const std::vector<webkit_glue::PasswordForm*>& result);

  // Callback for the remove button.
  static void OnRemoveButtonClicked(GtkButton* widget, ExceptionsPageGtk* page);

  // Callback for the remove all button.
  static void OnRemoveAllButtonClicked(GtkButton* widget,
                                       ExceptionsPageGtk* page);

  // Callback for selection changed events.
  static void OnExceptionSelectionChanged(GtkTreeSelection* selection,
                                          ExceptionsPageGtk* page);

  // Sorting function.
  static gint CompareSite(GtkTreeModel* model,
                          GtkTreeIter* a, GtkTreeIter* b,
                          gpointer window);

  // A short class to mediate requests to the password store.
  class ExceptionListPopulater : public PasswordStoreConsumer {
   public:
    explicit ExceptionListPopulater(ExceptionsPageGtk* page)
        : page_(page),
          pending_login_query_(0) {
    }

    // Send a query to the password store to populate an ExceptionsPageGtk.
    void populate();

    // Send the password store's reply back to the ExceptionsPageGtk.
    virtual void OnPasswordStoreRequestDone(
        int handle, const std::vector<webkit_glue::PasswordForm*>& result);

   private:
    ExceptionsPageGtk* page_;
    int pending_login_query_;
  };

  // Password store consumer for populating the exception list.
  ExceptionListPopulater populater;

  // Widgets for the buttons.
  GtkWidget* remove_button_;
  GtkWidget* remove_all_button_;

  // Widgets for the exception table.
  GtkWidget* exception_tree_;
  GtkListStore* exception_list_store_;
  GtkTreeModel* exception_list_sort_;
  GtkTreeSelection* exception_selection_;

  // The parent GtkHBox widget.
  GtkWidget* page_;

  Profile* profile_;
  std::vector<webkit_glue::PasswordForm> exception_list_;

  DISALLOW_COPY_AND_ASSIGN(ExceptionsPageGtk);
};

#endif  // CHROME_BROWSER_GTK_OPTIONS_EXCEPTIONS_PAGE_GTK_H_