summaryrefslogtreecommitdiffstats
path: root/chrome/browser/views/options/passwords_exceptions_window_view.cc
blob: 9bf44b411a39d21ce143264d42b407bec568b64a (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
// 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.

#include "chrome/browser/views/options/passwords_exceptions_window_view.h"

#include "chrome/browser/views/options/passwords_page_view.h"
#include "chrome/browser/views/options/exceptions_page_view.h"
#include "chrome/common/l10n_util.h"
#include "grit/generated_resources.h"

// static
PasswordsExceptionsWindowView* PasswordsExceptionsWindowView::instance_ = NULL;

static const int kDefaultWindowWidth = 530;
static const int kDefaultWindowHeight = 240;
static const int kDialogPadding = 7;

///////////////////////////////////////////////////////////////////////////////
// PasswordsExceptionsWindowView, public

PasswordsExceptionsWindowView::PasswordsExceptionsWindowView(Profile* profile)
    : tabs_(NULL),
      passwords_page_view_(NULL),
      exceptions_page_view_(NULL),
      profile_(profile) {
}

// static
void PasswordsExceptionsWindowView::Show(Profile* profile) {
  DCHECK(profile);
  if (!instance_) {
    instance_ = new PasswordsExceptionsWindowView(profile);

    // instances_ will get deleted once Close() is called.
    views::Window::CreateChromeWindow(NULL, gfx::Rect(), instance_);
  }
  if (!instance_->window()->IsVisible()) {
    instance_->window()->Show();
  } else {
    instance_->window()->Activate();
  }
}

/////////////////////////////////////////////////////////////////////////////
// PasswordsExceptionsWindowView, views::View implementations

void PasswordsExceptionsWindowView::Layout() {
  tabs_->SetBounds(kDialogPadding, kDialogPadding,
                   width() - (2 * kDialogPadding),
                   height() - (2 * kDialogPadding));
}

gfx::Size PasswordsExceptionsWindowView::GetPreferredSize() {
  return gfx::Size(kDefaultWindowWidth, kDefaultWindowHeight);
}

void PasswordsExceptionsWindowView::ViewHierarchyChanged(
    bool is_add, views::View* parent, views::View* child) {
  if (is_add && child == this)
    Init();
}

/////////////////////////////////////////////////////////////////////////////
// PasswordsExceptionsWindowView, views::DisloagDelegate implementations

int PasswordsExceptionsWindowView::GetDialogButtons() const {
  return DIALOGBUTTON_CANCEL;
}

std::wstring PasswordsExceptionsWindowView::GetWindowTitle() const {
  return l10n_util::GetString(IDS_PASSWORDS_EXCEPTIONS_WINDOW_TITLE);
}

void PasswordsExceptionsWindowView::WindowClosing() {
  // |instnace_| is deleted once the window is closed, so we just have to set
  // it to NULL.
  instance_ = NULL;
}

views::View* PasswordsExceptionsWindowView::GetContentsView() {
  return this;
}

/////////////////////////////////////////////////////////////////////////////
// PasswordsExceptionsWindowView, private

void PasswordsExceptionsWindowView::Init() {
  tabs_ = new views::TabbedPane();
  AddChildView(tabs_);

  passwords_page_view_ = new PasswordsPageView(profile_);
  tabs_->AddTab(l10n_util::GetString(
      IDS_PASSWORDS_SHOW_PASSWORDS_TAB_TITLE), passwords_page_view_);

  exceptions_page_view_ = new ExceptionsPageView(profile_);
  tabs_->AddTab(l10n_util::GetString(
      IDS_PASSWORDS_EXCEPTIONS_TAB_TITLE), exceptions_page_view_);
}