Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(296)

Side by Side Diff: chrome/browser/ui/views/extensions/suspicious_extension_bubble_view.cc

Issue 119303002: Deleting redundant files after refactoring. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/views/extensions/suspicious_extension_bubble_view.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/views/extensions/suspicious_extension_bubble_view.h"
6
7 #include "base/strings/string_number_conversions.h"
8 #include "base/strings/string_util.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/extensions/extension_prefs.h"
11 #include "chrome/browser/extensions/extension_service.h"
12 #include "chrome/browser/extensions/extension_system.h"
13 #include "chrome/browser/extensions/suspicious_extension_bubble_controller.h"
14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/ui/browser.h"
16 #include "grit/locale_settings.h"
17 #include "ui/base/accessibility/accessible_view_state.h"
18 #include "ui/base/resource/resource_bundle.h"
19 #include "ui/views/controls/button/label_button.h"
20 #include "ui/views/controls/label.h"
21 #include "ui/views/controls/link.h"
22 #include "ui/views/layout/grid_layout.h"
23 #include "ui/views/widget/widget.h"
24
25 namespace {
26
27 // Layout constants.
28 const int kExtensionListPadding = 10;
29 const int kInsetBottomRight = 13;
30 const int kInsetLeft = 14;
31 const int kInsetTop = 9;
32 const int kHeadlineMessagePadding = 4;
33 const int kHeadlineRowPadding = 10;
34 const int kMessageBubblePadding = 11;
35
36 // How many extensions to show in the bubble (max).
37 const size_t kMaxExtensionsToShow = 7;
38
39 // How long to wait until showing the bubble (in seconds).
40 const int kBubbleAppearanceWaitTime = 5;
41
42 } // namespace
43
44 ////////////////////////////////////////////////////////////////////////////////
45 // SuspiciousExtensionBubbleView
46
47 namespace extensions {
48
49 SuspiciousExtensionBubbleView::SuspiciousExtensionBubbleView(
50 views::View* anchor_view,
51 SuspiciousExtensionBubbleController* controller)
52 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT),
53 weak_factory_(this),
54 controller_(controller),
55 headline_(NULL),
56 learn_more_(NULL),
57 dismiss_button_(NULL),
58 link_clicked_(false) {
59 DCHECK(anchor_view->GetWidget());
60 set_close_on_deactivate(false);
61 set_move_with_anchor(true);
62 set_close_on_esc(true);
63
64 // Compensate for built-in vertical padding in the anchor view's image.
65 set_anchor_view_insets(gfx::Insets(5, 0, 5, 0));
66 }
67
68 // static
69 void SuspiciousExtensionBubbleView::MaybeShow(
70 Browser* browser,
71 views::View* anchor_view) {
72 SuspiciousExtensionBubbleController* controller =
73 extensions::SuspiciousExtensionBubbleController::Get(
74 browser->profile());
75 if (controller->HasSuspiciousExtensions()) {
76 SuspiciousExtensionBubbleView* bubble_delegate =
77 new SuspiciousExtensionBubbleView(anchor_view, controller);
78 views::BubbleDelegateView::CreateBubble(bubble_delegate);
79 controller->Show(bubble_delegate);
80 }
81 }
82
83 void SuspiciousExtensionBubbleView::OnButtonClicked(
84 const base::Closure& callback) {
85 button_callback_ = callback;
86 }
87
88 void SuspiciousExtensionBubbleView::OnLinkClicked(
89 const base::Closure& callback) {
90 link_callback_ = callback;
91 }
92
93 void SuspiciousExtensionBubbleView::Show() {
94 // Not showing the bubble right away (during startup) has a few benefits:
95 // We don't have to worry about focus being lost due to the Omnibox (or to
96 // other things that want focus at startup). This allows Esc to work to close
97 // the bubble and also solves the keyboard accessibility problem that comes
98 // with focus being lost (we don't have a good generic mechanism of injecting
99 // bubbles into the focus cycle). Another benefit of delaying the show is
100 // that fade-in works (the fade-in isn't apparent if the the bubble appears at
101 // startup).
102 base::MessageLoop::current()->PostDelayedTask(
103 FROM_HERE,
104 base::Bind(&SuspiciousExtensionBubbleView::ShowBubble,
105 weak_factory_.GetWeakPtr()),
106 base::TimeDelta::FromSeconds(kBubbleAppearanceWaitTime));
107 }
108
109 void SuspiciousExtensionBubbleView::OnWidgetDestroying(views::Widget* widget) {
110 // To catch Esc, we monitor destroy message. Unless the link has been clicked,
111 // we assume Dismiss was the action taken.
112 if (!link_clicked_)
113 button_callback_.Run();
114 }
115
116 ////////////////////////////////////////////////////////////////////////////////
117 // SuspiciousExtensionBubbleView - private.
118
119 SuspiciousExtensionBubbleView::~SuspiciousExtensionBubbleView() {
120 }
121
122 void SuspiciousExtensionBubbleView::ShowBubble() {
123 StartFade(true);
124 }
125
126 void SuspiciousExtensionBubbleView::Init() {
127 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
128
129 views::GridLayout* layout = views::GridLayout::CreatePanel(this);
130 layout->SetInsets(kInsetTop, kInsetLeft,
131 kInsetBottomRight, kInsetBottomRight);
132 SetLayoutManager(layout);
133
134 const int headline_column_set_id = 0;
135 views::ColumnSet* top_columns = layout->AddColumnSet(headline_column_set_id);
136 top_columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER,
137 0, views::GridLayout::USE_PREF, 0, 0);
138 top_columns->AddPaddingColumn(1, 0);
139 layout->StartRow(0, headline_column_set_id);
140
141 headline_ = new views::Label();
142 headline_->SetFont(rb.GetFont(ui::ResourceBundle::MediumFont));
143 headline_->SetText(controller_->GetTitle());
144 layout->AddView(headline_);
145
146 layout->AddPaddingRow(0, kHeadlineRowPadding);
147
148 const int text_column_set_id = 1;
149 views::ColumnSet* upper_columns = layout->AddColumnSet(text_column_set_id);
150 upper_columns->AddColumn(
151 views::GridLayout::LEADING, views::GridLayout::LEADING,
152 0, views::GridLayout::USE_PREF, 0, 0);
153 layout->StartRow(0, text_column_set_id);
154
155 views::Label* message = new views::Label();
156 message->SetMultiLine(true);
157 message->SetHorizontalAlignment(gfx::ALIGN_LEFT);
158 message->SetText(controller_->GetMessageBody());
159 message->SizeToFit(views::Widget::GetLocalizedContentsWidth(
160 IDS_EXTENSION_WIPEOUT_BUBBLE_WIDTH_CHARS));
161 layout->AddView(message);
162
163 const int extension_list_column_set_id = 2;
164 views::ColumnSet* middle_columns =
165 layout->AddColumnSet(extension_list_column_set_id);
166 middle_columns->AddPaddingColumn(0, kExtensionListPadding);
167 middle_columns->AddColumn(
168 views::GridLayout::LEADING, views::GridLayout::CENTER,
169 0, views::GridLayout::USE_PREF, 0, 0);
170
171 layout->StartRowWithPadding(0, extension_list_column_set_id,
172 0, kHeadlineMessagePadding);
173 views::Label* extensions = new views::Label();
174 extensions->SetMultiLine(true);
175 extensions->SetHorizontalAlignment(gfx::ALIGN_LEFT);
176
177 std::vector<base::string16> extension_list;
178 char16 bullet_point = 0x2022;
179
180 std::vector<base::string16> suspicious =
181 controller_->GetSuspiciousExtensionNames();
182 size_t i = 0;
183 for (; i < suspicious.size() && i < kMaxExtensionsToShow; ++i) {
184 // Add each extension with bullet point.
185 extension_list.push_back(bullet_point + ASCIIToUTF16(" ") + suspicious[i]);
186 }
187
188 if (i > kMaxExtensionsToShow) {
189 base::string16 difference = base::IntToString16(i - kMaxExtensionsToShow);
190 extension_list.push_back(bullet_point + ASCIIToUTF16(" ") +
191 controller_->GetOverflowText(difference));
192 }
193
194 extensions->SetText(JoinString(extension_list, ASCIIToUTF16("\n")));
195 extensions->SizeToFit(views::Widget::GetLocalizedContentsWidth(
196 IDS_EXTENSION_WIPEOUT_BUBBLE_WIDTH_CHARS));
197 layout->AddView(extensions);
198
199 const int action_row_column_set_id = 3;
200 views::ColumnSet* bottom_columns =
201 layout->AddColumnSet(action_row_column_set_id);
202 bottom_columns->AddColumn(views::GridLayout::LEADING,
203 views::GridLayout::CENTER, 0, views::GridLayout::USE_PREF, 0, 0);
204 bottom_columns->AddPaddingColumn(1, 0);
205 bottom_columns->AddColumn(views::GridLayout::TRAILING,
206 views::GridLayout::CENTER, 0, views::GridLayout::USE_PREF, 0, 0);
207 layout->StartRowWithPadding(0, action_row_column_set_id,
208 0, kMessageBubblePadding);
209
210 learn_more_ = new views::Link(controller_->GetLearnMoreLabel());
211 learn_more_->set_listener(this);
212 layout->AddView(learn_more_);
213
214 dismiss_button_ = new views::LabelButton(this,
215 controller_->GetDismissButtonLabel());
216 dismiss_button_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON);
217 layout->AddView(dismiss_button_);
218 }
219
220 void SuspiciousExtensionBubbleView::ButtonPressed(views::Button* sender,
221 const ui::Event& event) {
222 DCHECK_EQ(dismiss_button_, sender);
223 GetWidget()->Close();
224 }
225
226 void SuspiciousExtensionBubbleView::LinkClicked(views::Link* source,
227 int event_flags) {
228 DCHECK_EQ(learn_more_, source);
229 link_clicked_ = true;
230 link_callback_.Run();
231 GetWidget()->Close();
232 }
233
234 void SuspiciousExtensionBubbleView::GetAccessibleState(
235 ui::AccessibleViewState* state) {
236 state->role = ui::AccessibilityTypes::ROLE_ALERT;
237 }
238
239 void SuspiciousExtensionBubbleView::ViewHierarchyChanged(
240 const ViewHierarchyChangedDetails& details) {
241 if (details.is_add && details.child == this)
242 NotifyAccessibilityEvent(ui::AccessibilityTypes::EVENT_ALERT, true);
243 }
244
245 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/extensions/suspicious_extension_bubble_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698