summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/views/clear_data_view.cc
blob: 681ac6e8a081ba17cb924c617f6f7af757785e87 (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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
// Copyright (c) 2011 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/ui/views/clear_data_view.h"

#include "app/l10n_util.h"
#include "base/string16.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/browser_window.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search_engines/template_url_model.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/views/clear_browsing_data.h"
#include "chrome/browser/ui/views/clear_server_data.h"
#include "chrome/common/pref_names.h"
#include "gfx/insets.h"
#include "grit/generated_resources.h"
#include "grit/locale_settings.h"
#include "net/url_request/url_request_context.h"
#include "views/background.h"
#include "views/controls/button/checkbox.h"
#include "views/controls/label.h"
#include "views/controls/separator.h"
#include "views/controls/throbber.h"
#include "views/grid_layout.h"
#include "views/standard_layout.h"
#include "views/widget/widget.h"
#include "views/window/dialog_client_view.h"
#include "views/window/window.h"

using views::GridLayout;

// The combo box is vertically aligned to the 'time-period' label, which makes
// the combo box look a little too close to the check box above it when we use
// standard layout to separate them. We therefore add a little extra margin to
// the label, giving it a little breathing space.
static const int kExtraMarginForTimePeriodLabel = 3;

////////////////////////////////////////////////////////////////////////////////
// ClearDataView, public:

ClearDataView::ClearDataView(Profile* profile)
    : profile_(profile),
      clear_server_data_tab_(NULL),
      clear_browsing_data_tab_(NULL),
      clearing_data_(false) {
  DCHECK(profile);
  Init();
}

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

  tabs_->SetAccessibleName(
      UTF16ToWide(l10n_util::GetStringFUTF16(IDS_OPTIONS_DIALOG_TITLE,
          l10n_util::GetStringUTF16(IDS_OPTIONS_DIALOG_TITLE))));
  AddChildView(tabs_);

  int tab_index = 0;
  clear_browsing_data_tab_ = new ClearBrowsingDataView2(profile_, this);
  tabs_->AddTabAtIndex(
      tab_index++,
      UTF16ToWide(l10n_util::GetStringUTF16(IDS_CLEAR_CHROME_DATA_TAB_LABEL)),
      clear_browsing_data_tab_, false);
  clear_server_data_tab_ = new ClearServerDataView(profile_, this);
  tabs_->AddTabAtIndex(
      tab_index++,
      UTF16ToWide(l10n_util::GetStringUTF16(IDS_CLEAR_OTHER_DATA_TAB_LABEL)),
      clear_server_data_tab_, false);

  tabs_->SelectTabAt(static_cast<int>(0));
}

void ClearDataView::StartClearingBrowsingData() {
  // Only one clear can happen at a time
  clear_server_data_tab_->SetAllowClear(false);
  clearing_data_ = true;
  window()->EnableClose(false);
  GetDialogClientView()->UpdateDialogButtons();
}

void ClearDataView::StopClearingBrowsingData() {
  window()->Close();
}

void ClearDataView::StartClearingServerData() {
  // Only one clear can happen at a time
  clear_browsing_data_tab_->SetAllowClear(false);
  clearing_data_ = true;
  window()->EnableClose(false);
  GetDialogClientView()->UpdateDialogButtons();
}

void ClearDataView::SucceededClearingServerData() {
  window()->Close();
}

void ClearDataView::FailedClearingServerData() {
  clear_browsing_data_tab_->SetAllowClear(true);
  clearing_data_ = false;
  window()->EnableClose(false);
  GetDialogClientView()->UpdateDialogButtons();
}

////////////////////////////////////////////////////////////////////////////////
// ClearDataView, views::View implementation:

gfx::Size ClearDataView::GetPreferredSize() {
  gfx::Size size(tabs_->GetPreferredSize());
  size.Enlarge(2 * kDialogPadding, 2 * kDialogPadding);
  return size;
}

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

////////////////////////////////////////////////////////////////////////////////
// ClearDataView, views::DialogDelegate implementation:

int ClearDataView::GetDefaultDialogButton() const {
  return MessageBoxFlags::DIALOGBUTTON_NONE;
}

std::wstring ClearDataView::GetDialogButtonLabel(
    MessageBoxFlags::DialogButton button) const {
  DCHECK(button == MessageBoxFlags::DIALOGBUTTON_CANCEL);
  return UTF16ToWide(l10n_util::GetStringUTF16(IDS_CANCEL));
}

int ClearDataView::GetDialogButtons() const {
  return MessageBoxFlags::DIALOGBUTTON_CANCEL;
}


bool ClearDataView::IsDialogButtonEnabled(
    MessageBoxFlags::DialogButton button) const {

  return !clearing_data_;
}

bool ClearDataView::CanResize() const {
  return false;
}

bool ClearDataView::CanMaximize() const {
  return false;
}

bool ClearDataView::IsAlwaysOnTop() const {
  return false;
}

bool ClearDataView::HasAlwaysOnTopMenu() const {
  return false;
}

bool ClearDataView::IsModal() const {
  return true;
}

std::wstring ClearDataView::GetWindowTitle() const {
  return UTF16ToWide(l10n_util::GetStringUTF16(IDS_CLEAR_BROWSING_DATA_TITLE));
}

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

views::View* ClearDataView::GetInitiallyFocusedView() {
  return GetDialogClientView()->cancel_button();
}