OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/views/page_info/page_info_popup_view.h" | 5 #include "chrome/browser/ui/views/page_info/page_info_bubble_view.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/i18n/rtl.h" | 12 #include "base/i18n/rtl.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
15 #include "base/strings/string16.h" | 15 #include "base/strings/string16.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 #include "ui/views/layout/box_layout.h" | 56 #include "ui/views/layout/box_layout.h" |
57 #include "ui/views/layout/grid_layout.h" | 57 #include "ui/views/layout/grid_layout.h" |
58 #include "ui/views/layout/layout_manager.h" | 58 #include "ui/views/layout/layout_manager.h" |
59 #include "ui/views/view.h" | 59 #include "ui/views/view.h" |
60 #include "ui/views/widget/widget.h" | 60 #include "ui/views/widget/widget.h" |
61 #include "url/gurl.h" | 61 #include "url/gurl.h" |
62 | 62 |
63 namespace { | 63 namespace { |
64 | 64 |
65 // NOTE(jdonnelly): This use of this process-wide variable assumes that there's | 65 // NOTE(jdonnelly): This use of this process-wide variable assumes that there's |
66 // never more than one page info popup shown and that it's associated | 66 // never more than one page info bubble shown and that it's associated |
67 // with the current window. If this assumption fails in the future, we'll need | 67 // with the current window. If this assumption fails in the future, we'll need |
68 // to return a weak pointer from ShowPopup so callers can associate it with the | 68 // to return a weak pointer from ShowBubble so callers can associate it with the |
69 // current window (or other context) and check if the popup they care about is | 69 // current window (or other context) and check if the bubble they care about is |
70 // showing. | 70 // showing. |
71 PageInfoPopupView::PopupType g_shown_popup_type = PageInfoPopupView::POPUP_NONE; | 71 PageInfoBubbleView::BubbleType g_shown_bubble_type = |
| 72 PageInfoBubbleView::BUBBLE_NONE; |
72 | 73 |
73 // General constants ----------------------------------------------------------- | 74 // General constants ----------------------------------------------------------- |
74 | 75 |
75 // Popup width constraints. | 76 // Bubble width constraints. |
76 const int kMinPopupWidth = 320; | 77 const int kMinBubbleWidth = 320; |
77 const int kMaxPopupWidth = 1000; | 78 const int kMaxBubbleWidth = 1000; |
78 | 79 |
79 // Security Section (PopupHeaderView) ------------------------------------------ | 80 // Security Section (BubbleHeaderView) |
| 81 // ------------------------------------------ |
80 | 82 |
81 // Margin and padding values for the |PopupHeaderView|. | 83 // Margin and padding values for the |BubbleHeaderView|. |
82 const int kHeaderMarginBottom = 10; | 84 const int kHeaderMarginBottom = 10; |
83 const int kHeaderPaddingBottom = 13; | 85 const int kHeaderPaddingBottom = 13; |
84 | 86 |
85 // Spacing between labels in the header. | 87 // Spacing between labels in the header. |
86 const int kHeaderLabelSpacing = 4; | 88 const int kHeaderLabelSpacing = 4; |
87 | 89 |
88 // Site Settings Section ------------------------------------------------------- | 90 // Site Settings Section ------------------------------------------------------- |
89 | 91 |
90 // Spacing above and below the cookies view. | 92 // Spacing above and below the cookies view. |
91 const int kCookiesViewVerticalPadding = 6; | 93 const int kCookiesViewVerticalPadding = 6; |
(...skipping 23 matching lines...) Expand all Loading... |
115 void AddColumnWithSideMargin(views::GridLayout* layout, int margin, int id) { | 117 void AddColumnWithSideMargin(views::GridLayout* layout, int margin, int id) { |
116 views::ColumnSet* column_set = layout->AddColumnSet(id); | 118 views::ColumnSet* column_set = layout->AddColumnSet(id); |
117 column_set->AddPaddingColumn(0, margin); | 119 column_set->AddPaddingColumn(0, margin); |
118 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, | 120 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, |
119 views::GridLayout::USE_PREF, 0, 0); | 121 views::GridLayout::USE_PREF, 0, 0); |
120 column_set->AddPaddingColumn(0, margin); | 122 column_set->AddPaddingColumn(0, margin); |
121 } | 123 } |
122 | 124 |
123 } // namespace | 125 } // namespace |
124 | 126 |
125 // |PopupHeaderView| is the UI element (view) that represents the header of the | 127 // |BubbleHeaderView| is the UI element (view) that represents the header of the |
126 // |PageInfoPopupView|. The header shows the status of the site's | 128 // |PageInfoBubbleView|. The header shows the status of the site's |
127 // identity check and the name of the site's identity. | 129 // identity check and the name of the site's identity. |
128 class PopupHeaderView : public views::View { | 130 class BubbleHeaderView : public views::View { |
129 public: | 131 public: |
130 PopupHeaderView(views::ButtonListener* button_listener, | 132 BubbleHeaderView(views::ButtonListener* button_listener, |
131 views::StyledLabelListener* styled_label_listener, | 133 views::StyledLabelListener* styled_label_listener, |
132 int side_margin); | 134 int side_margin); |
133 ~PopupHeaderView() override; | 135 ~BubbleHeaderView() override; |
134 | 136 |
135 // Sets the security summary for the current page. | 137 // Sets the security summary for the current page. |
136 void SetSummary(const base::string16& summary_text); | 138 void SetSummary(const base::string16& summary_text); |
137 | 139 |
138 // Sets the security details for the current page. | 140 // Sets the security details for the current page. |
139 void SetDetails(const base::string16& details_text); | 141 void SetDetails(const base::string16& details_text); |
140 | 142 |
141 void AddResetDecisionsLabel(); | 143 void AddResetDecisionsLabel(); |
142 | 144 |
143 private: | 145 private: |
144 // The listener for the styled labels in this view. | 146 // The listener for the styled labels in this view. |
145 views::StyledLabelListener* styled_label_listener_; | 147 views::StyledLabelListener* styled_label_listener_; |
146 | 148 |
147 // The label that displays the status of the identity check for this site. | 149 // The label that displays the status of the identity check for this site. |
148 // Includes a link to open the Chrome Help Center article about connection | 150 // Includes a link to open the Chrome Help Center article about connection |
149 // security. | 151 // security. |
150 views::StyledLabel* details_label_; | 152 views::StyledLabel* details_label_; |
151 | 153 |
152 // A container for the styled label with a link for resetting cert decisions. | 154 // A container for the styled label with a link for resetting cert decisions. |
153 // This is only shown sometimes, so we use a container to keep track of | 155 // This is only shown sometimes, so we use a container to keep track of |
154 // where to place it (if needed). | 156 // where to place it (if needed). |
155 views::View* reset_decisions_label_container_; | 157 views::View* reset_decisions_label_container_; |
156 views::StyledLabel* reset_decisions_label_; | 158 views::StyledLabel* reset_decisions_label_; |
157 | 159 |
158 DISALLOW_COPY_AND_ASSIGN(PopupHeaderView); | 160 DISALLOW_COPY_AND_ASSIGN(BubbleHeaderView); |
159 }; | 161 }; |
160 | 162 |
161 // The regular PageInfoPopupView is not supported for internal Chrome pages and | 163 // The regular PageInfoBubbleView is not supported for internal Chrome pages and |
162 // extension pages. Instead of the |PageInfoPopupView|, the | 164 // extension pages. Instead of the |PageInfoBubbleView|, the |
163 // |InternalPageInfoPopupView| is displayed. | 165 // |InternalPageInfoBubbleView| is displayed. |
164 class InternalPageInfoPopupView : public views::BubbleDialogDelegateView { | 166 class InternalPageInfoBubbleView : public views::BubbleDialogDelegateView { |
165 public: | 167 public: |
166 // If |anchor_view| is nullptr, or has no Widget, |parent_window| may be | 168 // If |anchor_view| is nullptr, or has no Widget, |parent_window| may be |
167 // provided to ensure this bubble is closed when the parent closes. | 169 // provided to ensure this bubble is closed when the parent closes. |
168 InternalPageInfoPopupView(views::View* anchor_view, | 170 InternalPageInfoBubbleView(views::View* anchor_view, |
169 gfx::NativeView parent_window, | 171 gfx::NativeView parent_window, |
170 const GURL& url); | 172 const GURL& url); |
171 ~InternalPageInfoPopupView() override; | 173 ~InternalPageInfoBubbleView() override; |
172 | 174 |
173 // views::BubbleDialogDelegateView: | 175 // views::BubbleDialogDelegateView: |
174 void OnWidgetDestroying(views::Widget* widget) override; | 176 void OnWidgetDestroying(views::Widget* widget) override; |
175 int GetDialogButtons() const override; | 177 int GetDialogButtons() const override; |
176 | 178 |
177 private: | 179 private: |
178 friend class PageInfoPopupView; | 180 friend class PageInfoBubbleView; |
179 | 181 |
180 // Used around icon and inside bubble border. | 182 // Used around icon and inside bubble border. |
181 static constexpr int kSpacing = 12; | 183 static constexpr int kSpacing = 12; |
182 | 184 |
183 DISALLOW_COPY_AND_ASSIGN(InternalPageInfoPopupView); | 185 DISALLOW_COPY_AND_ASSIGN(InternalPageInfoBubbleView); |
184 }; | 186 }; |
185 | 187 |
186 //////////////////////////////////////////////////////////////////////////////// | 188 //////////////////////////////////////////////////////////////////////////////// |
187 // Popup Header | 189 // Bubble Header |
188 //////////////////////////////////////////////////////////////////////////////// | 190 //////////////////////////////////////////////////////////////////////////////// |
189 | 191 |
190 PopupHeaderView::PopupHeaderView( | 192 BubbleHeaderView::BubbleHeaderView( |
191 views::ButtonListener* button_listener, | 193 views::ButtonListener* button_listener, |
192 views::StyledLabelListener* styled_label_listener, | 194 views::StyledLabelListener* styled_label_listener, |
193 int side_margin) | 195 int side_margin) |
194 : styled_label_listener_(styled_label_listener), | 196 : styled_label_listener_(styled_label_listener), |
195 details_label_(nullptr), | 197 details_label_(nullptr), |
196 reset_decisions_label_container_(nullptr), | 198 reset_decisions_label_container_(nullptr), |
197 reset_decisions_label_(nullptr) { | 199 reset_decisions_label_(nullptr) { |
198 views::GridLayout* layout = new views::GridLayout(this); | 200 views::GridLayout* layout = new views::GridLayout(this); |
199 SetLayoutManager(layout); | 201 SetLayoutManager(layout); |
200 | 202 |
(...skipping 11 matching lines...) Expand all Loading... |
212 layout->StartRow(0, label_column_status); | 214 layout->StartRow(0, label_column_status); |
213 reset_decisions_label_container_ = new views::View(); | 215 reset_decisions_label_container_ = new views::View(); |
214 reset_decisions_label_container_->SetLayoutManager( | 216 reset_decisions_label_container_->SetLayoutManager( |
215 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); | 217 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); |
216 layout->AddView(reset_decisions_label_container_, 1, 1, | 218 layout->AddView(reset_decisions_label_container_, 1, 1, |
217 views::GridLayout::FILL, views::GridLayout::LEADING); | 219 views::GridLayout::FILL, views::GridLayout::LEADING); |
218 | 220 |
219 layout->AddPaddingRow(1, kHeaderPaddingBottom); | 221 layout->AddPaddingRow(1, kHeaderPaddingBottom); |
220 } | 222 } |
221 | 223 |
222 PopupHeaderView::~PopupHeaderView() {} | 224 BubbleHeaderView::~BubbleHeaderView() {} |
223 | 225 |
224 void PopupHeaderView::SetDetails(const base::string16& details_text) { | 226 void BubbleHeaderView::SetDetails(const base::string16& details_text) { |
225 std::vector<base::string16> subst; | 227 std::vector<base::string16> subst; |
226 subst.push_back(details_text); | 228 subst.push_back(details_text); |
227 subst.push_back(l10n_util::GetStringUTF16(IDS_LEARN_MORE)); | 229 subst.push_back(l10n_util::GetStringUTF16(IDS_LEARN_MORE)); |
228 | 230 |
229 std::vector<size_t> offsets; | 231 std::vector<size_t> offsets; |
230 | 232 |
231 base::string16 text = base::ReplaceStringPlaceholders( | 233 base::string16 text = base::ReplaceStringPlaceholders( |
232 base::ASCIIToUTF16("$1 $2"), subst, &offsets); | 234 base::ASCIIToUTF16("$1 $2"), subst, &offsets); |
233 details_label_->SetText(text); | 235 details_label_->SetText(text); |
234 gfx::Range details_range(offsets[1], text.length()); | 236 gfx::Range details_range(offsets[1], text.length()); |
235 | 237 |
236 views::StyledLabel::RangeStyleInfo link_style = | 238 views::StyledLabel::RangeStyleInfo link_style = |
237 views::StyledLabel::RangeStyleInfo::CreateForLink(); | 239 views::StyledLabel::RangeStyleInfo::CreateForLink(); |
238 if (!ui::MaterialDesignController::IsSecondaryUiMaterial()) | 240 if (!ui::MaterialDesignController::IsSecondaryUiMaterial()) |
239 link_style.font_style |= gfx::Font::FontStyle::UNDERLINE; | 241 link_style.font_style |= gfx::Font::FontStyle::UNDERLINE; |
240 link_style.disable_line_wrapping = false; | 242 link_style.disable_line_wrapping = false; |
241 | 243 |
242 details_label_->AddStyleRange(details_range, link_style); | 244 details_label_->AddStyleRange(details_range, link_style); |
243 } | 245 } |
244 | 246 |
245 void PopupHeaderView::AddResetDecisionsLabel() { | 247 void BubbleHeaderView::AddResetDecisionsLabel() { |
246 std::vector<base::string16> subst; | 248 std::vector<base::string16> subst; |
247 subst.push_back( | 249 subst.push_back( |
248 l10n_util::GetStringUTF16(IDS_PAGEINFO_INVALID_CERTIFICATE_DESCRIPTION)); | 250 l10n_util::GetStringUTF16(IDS_PAGEINFO_INVALID_CERTIFICATE_DESCRIPTION)); |
249 subst.push_back(l10n_util::GetStringUTF16( | 251 subst.push_back(l10n_util::GetStringUTF16( |
250 IDS_PAGEINFO_RESET_INVALID_CERTIFICATE_DECISIONS_BUTTON)); | 252 IDS_PAGEINFO_RESET_INVALID_CERTIFICATE_DECISIONS_BUTTON)); |
251 | 253 |
252 std::vector<size_t> offsets; | 254 std::vector<size_t> offsets; |
253 | 255 |
254 base::string16 text = base::ReplaceStringPlaceholders( | 256 base::string16 text = base::ReplaceStringPlaceholders( |
255 base::ASCIIToUTF16("$1 $2"), subst, &offsets); | 257 base::ASCIIToUTF16("$1 $2"), subst, &offsets); |
(...skipping 13 matching lines...) Expand all Loading... |
269 reset_decisions_label_container_->AddChildView(reset_decisions_label_); | 271 reset_decisions_label_container_->AddChildView(reset_decisions_label_); |
270 | 272 |
271 // Now that it contains a label, the container needs padding at the top. | 273 // Now that it contains a label, the container needs padding at the top. |
272 reset_decisions_label_container_->SetBorder( | 274 reset_decisions_label_container_->SetBorder( |
273 views::CreateEmptyBorder(8, 0, 0, 0)); | 275 views::CreateEmptyBorder(8, 0, 0, 0)); |
274 | 276 |
275 InvalidateLayout(); | 277 InvalidateLayout(); |
276 } | 278 } |
277 | 279 |
278 //////////////////////////////////////////////////////////////////////////////// | 280 //////////////////////////////////////////////////////////////////////////////// |
279 // InternalPageInfoPopupView | 281 // InternalPageInfoBubbleView |
280 //////////////////////////////////////////////////////////////////////////////// | 282 //////////////////////////////////////////////////////////////////////////////// |
281 | 283 |
282 InternalPageInfoPopupView::InternalPageInfoPopupView( | 284 InternalPageInfoBubbleView::InternalPageInfoBubbleView( |
283 views::View* anchor_view, | 285 views::View* anchor_view, |
284 gfx::NativeView parent_window, | 286 gfx::NativeView parent_window, |
285 const GURL& url) | 287 const GURL& url) |
286 : BubbleDialogDelegateView(anchor_view, views::BubbleBorder::TOP_LEFT) { | 288 : BubbleDialogDelegateView(anchor_view, views::BubbleBorder::TOP_LEFT) { |
287 g_shown_popup_type = PageInfoPopupView::POPUP_INTERNAL_PAGE; | 289 g_shown_bubble_type = PageInfoBubbleView::BUBBLE_INTERNAL_PAGE; |
288 set_parent_window(parent_window); | 290 set_parent_window(parent_window); |
289 | 291 |
290 int text = IDS_PAGE_INFO_INTERNAL_PAGE; | 292 int text = IDS_PAGE_INFO_INTERNAL_PAGE; |
291 int icon = IDR_PRODUCT_LOGO_16; | 293 int icon = IDR_PRODUCT_LOGO_16; |
292 if (url.SchemeIs(extensions::kExtensionScheme)) { | 294 if (url.SchemeIs(extensions::kExtensionScheme)) { |
293 text = IDS_PAGE_INFO_EXTENSION_PAGE; | 295 text = IDS_PAGE_INFO_EXTENSION_PAGE; |
294 icon = IDR_PLUGINS_FAVICON; | 296 icon = IDR_PLUGINS_FAVICON; |
295 } else if (url.SchemeIs(content::kViewSourceScheme)) { | 297 } else if (url.SchemeIs(content::kViewSourceScheme)) { |
296 text = IDS_PAGE_INFO_VIEW_SOURCE_PAGE; | 298 text = IDS_PAGE_INFO_VIEW_SOURCE_PAGE; |
297 // view-source scheme uses the same icon as chrome:// pages. | 299 // view-source scheme uses the same icon as chrome:// pages. |
(...skipping 19 matching lines...) Expand all Loading... |
317 | 319 |
318 views::Label* label = new views::Label(l10n_util::GetStringUTF16(text)); | 320 views::Label* label = new views::Label(l10n_util::GetStringUTF16(text)); |
319 label->SetMultiLine(true); | 321 label->SetMultiLine(true); |
320 label->SetAllowCharacterBreak(true); | 322 label->SetAllowCharacterBreak(true); |
321 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 323 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
322 AddChildView(label); | 324 AddChildView(label); |
323 | 325 |
324 views::BubbleDialogDelegateView::CreateBubble(this); | 326 views::BubbleDialogDelegateView::CreateBubble(this); |
325 } | 327 } |
326 | 328 |
327 InternalPageInfoPopupView::~InternalPageInfoPopupView() {} | 329 InternalPageInfoBubbleView::~InternalPageInfoBubbleView() {} |
328 | 330 |
329 void InternalPageInfoPopupView::OnWidgetDestroying(views::Widget* widget) { | 331 void InternalPageInfoBubbleView::OnWidgetDestroying(views::Widget* widget) { |
330 g_shown_popup_type = PageInfoPopupView::POPUP_NONE; | 332 g_shown_bubble_type = PageInfoBubbleView::BUBBLE_NONE; |
331 } | 333 } |
332 | 334 |
333 int InternalPageInfoPopupView::GetDialogButtons() const { | 335 int InternalPageInfoBubbleView::GetDialogButtons() const { |
334 return ui::DIALOG_BUTTON_NONE; | 336 return ui::DIALOG_BUTTON_NONE; |
335 } | 337 } |
336 | 338 |
337 //////////////////////////////////////////////////////////////////////////////// | 339 //////////////////////////////////////////////////////////////////////////////// |
338 // PageInfoPopupView | 340 // PageInfoBubbleView |
339 //////////////////////////////////////////////////////////////////////////////// | 341 //////////////////////////////////////////////////////////////////////////////// |
340 | 342 |
341 PageInfoPopupView::~PageInfoPopupView() {} | 343 PageInfoBubbleView::~PageInfoBubbleView() {} |
342 | 344 |
343 // static | 345 // static |
344 void PageInfoPopupView::ShowPopup( | 346 void PageInfoBubbleView::ShowBubble( |
345 views::View* anchor_view, | 347 views::View* anchor_view, |
346 const gfx::Rect& anchor_rect, | 348 const gfx::Rect& anchor_rect, |
347 Profile* profile, | 349 Profile* profile, |
348 content::WebContents* web_contents, | 350 content::WebContents* web_contents, |
349 const GURL& url, | 351 const GURL& url, |
350 const security_state::SecurityInfo& security_info) { | 352 const security_state::SecurityInfo& security_info) { |
351 gfx::NativeView parent_window = | 353 gfx::NativeView parent_window = |
352 anchor_view ? nullptr : web_contents->GetNativeView(); | 354 anchor_view ? nullptr : web_contents->GetNativeView(); |
353 if (url.SchemeIs(content::kChromeUIScheme) || | 355 if (url.SchemeIs(content::kChromeUIScheme) || |
354 url.SchemeIs(content::kChromeDevToolsScheme) || | 356 url.SchemeIs(content::kChromeDevToolsScheme) || |
355 url.SchemeIs(extensions::kExtensionScheme) || | 357 url.SchemeIs(extensions::kExtensionScheme) || |
356 url.SchemeIs(content::kViewSourceScheme)) { | 358 url.SchemeIs(content::kViewSourceScheme)) { |
357 // Use the concrete type so that |SetAnchorRect| can be called as a friend. | 359 // Use the concrete type so that |SetAnchorRect| can be called as a friend. |
358 InternalPageInfoPopupView* popup = | 360 InternalPageInfoBubbleView* bubble = |
359 new InternalPageInfoPopupView(anchor_view, parent_window, url); | 361 new InternalPageInfoBubbleView(anchor_view, parent_window, url); |
360 if (!anchor_view) | 362 if (!anchor_view) |
361 popup->SetAnchorRect(anchor_rect); | 363 bubble->SetAnchorRect(anchor_rect); |
362 popup->GetWidget()->Show(); | 364 bubble->GetWidget()->Show(); |
363 return; | 365 return; |
364 } | 366 } |
365 PageInfoPopupView* popup = new PageInfoPopupView( | 367 PageInfoBubbleView* bubble = new PageInfoBubbleView( |
366 anchor_view, parent_window, profile, web_contents, url, security_info); | 368 anchor_view, parent_window, profile, web_contents, url, security_info); |
367 if (!anchor_view) | 369 if (!anchor_view) |
368 popup->SetAnchorRect(anchor_rect); | 370 bubble->SetAnchorRect(anchor_rect); |
369 popup->GetWidget()->Show(); | 371 bubble->GetWidget()->Show(); |
370 } | 372 } |
371 | 373 |
372 // static | 374 // static |
373 PageInfoPopupView::PopupType PageInfoPopupView::GetShownPopupType() { | 375 PageInfoBubbleView::BubbleType PageInfoBubbleView::GetShownBubbleType() { |
374 return g_shown_popup_type; | 376 return g_shown_bubble_type; |
375 } | 377 } |
376 | 378 |
377 PageInfoPopupView::PageInfoPopupView( | 379 PageInfoBubbleView::PageInfoBubbleView( |
378 views::View* anchor_view, | 380 views::View* anchor_view, |
379 gfx::NativeView parent_window, | 381 gfx::NativeView parent_window, |
380 Profile* profile, | 382 Profile* profile, |
381 content::WebContents* web_contents, | 383 content::WebContents* web_contents, |
382 const GURL& url, | 384 const GURL& url, |
383 const security_state::SecurityInfo& security_info) | 385 const security_state::SecurityInfo& security_info) |
384 : content::WebContentsObserver(web_contents), | 386 : content::WebContentsObserver(web_contents), |
385 BubbleDialogDelegateView(anchor_view, views::BubbleBorder::TOP_LEFT), | 387 BubbleDialogDelegateView(anchor_view, views::BubbleBorder::TOP_LEFT), |
386 profile_(profile), | 388 profile_(profile), |
387 header_(nullptr), | 389 header_(nullptr), |
388 separator_(nullptr), | 390 separator_(nullptr), |
389 site_settings_view_(nullptr), | 391 site_settings_view_(nullptr), |
390 cookies_view_(nullptr), | 392 cookies_view_(nullptr), |
391 cookie_dialog_link_(nullptr), | 393 cookie_dialog_link_(nullptr), |
392 permissions_view_(nullptr), | 394 permissions_view_(nullptr), |
393 weak_factory_(this) { | 395 weak_factory_(this) { |
394 g_shown_popup_type = POPUP_PAGE_INFO; | 396 g_shown_bubble_type = BUBBLE_PAGE_INFO; |
395 set_parent_window(parent_window); | 397 set_parent_window(parent_window); |
396 | 398 |
397 // Compensate for built-in vertical padding in the anchor view's image. | 399 // Compensate for built-in vertical padding in the anchor view's image. |
398 set_anchor_view_insets(gfx::Insets( | 400 set_anchor_view_insets(gfx::Insets( |
399 GetLayoutConstant(LOCATION_BAR_BUBBLE_ANCHOR_VERTICAL_INSET), 0)); | 401 GetLayoutConstant(LOCATION_BAR_BUBBLE_ANCHOR_VERTICAL_INSET), 0)); |
400 | 402 |
401 // Capture the default bubble margin, and move it to the Layout classes. This | 403 // Capture the default bubble margin, and move it to the Layout classes. This |
402 // is necessary so that the views::Separator can extend the full width of the | 404 // is necessary so that the views::Separator can extend the full width of the |
403 // bubble. | 405 // bubble. |
404 const int side_margin = margins().left(); | 406 const int side_margin = margins().left(); |
405 DCHECK_EQ(margins().left(), margins().right()); | 407 DCHECK_EQ(margins().left(), margins().right()); |
406 | 408 |
407 // Also remove the top margin from the client area so there is less space | 409 // Also remove the top margin from the client area so there is less space |
408 // below the dialog title. | 410 // below the dialog title. |
409 set_margins(gfx::Insets(0, 0, margins().bottom(), 0)); | 411 set_margins(gfx::Insets(0, 0, margins().bottom(), 0)); |
410 | 412 |
411 views::GridLayout* layout = new views::GridLayout(this); | 413 views::GridLayout* layout = new views::GridLayout(this); |
412 SetLayoutManager(layout); | 414 SetLayoutManager(layout); |
413 | 415 |
414 // Use a single ColumnSet here. Otherwise the preferred width doesn't properly | 416 // Use a single ColumnSet here. Otherwise the preferred width doesn't properly |
415 // propagate up to the dialog width. | 417 // propagate up to the dialog width. |
416 const int content_column = 0; | 418 const int content_column = 0; |
417 views::ColumnSet* column_set = layout->AddColumnSet(content_column); | 419 views::ColumnSet* column_set = layout->AddColumnSet(content_column); |
418 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, | 420 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, |
419 views::GridLayout::USE_PREF, 0, 0); | 421 views::GridLayout::USE_PREF, 0, 0); |
420 | 422 |
421 header_ = new PopupHeaderView(this, this, side_margin); | 423 header_ = new BubbleHeaderView(this, this, side_margin); |
422 layout->StartRow(1, content_column); | 424 layout->StartRow(1, content_column); |
423 layout->AddView(header_); | 425 layout->AddView(header_); |
424 | 426 |
425 layout->StartRow(0, content_column); | 427 layout->StartRow(0, content_column); |
426 separator_ = new views::Separator(); | 428 separator_ = new views::Separator(); |
427 layout->AddView(separator_); | 429 layout->AddView(separator_); |
428 | 430 |
429 layout->AddPaddingRow(1, kHeaderMarginBottom); | 431 layout->AddPaddingRow(1, kHeaderMarginBottom); |
430 layout->StartRow(1, content_column); | 432 layout->StartRow(1, content_column); |
431 | 433 |
432 site_settings_view_ = CreateSiteSettingsView(side_margin); | 434 site_settings_view_ = CreateSiteSettingsView(side_margin); |
433 layout->AddView(site_settings_view_); | 435 layout->AddView(site_settings_view_); |
434 | 436 |
435 if (!ui::MaterialDesignController::IsSecondaryUiMaterial()) { | 437 if (!ui::MaterialDesignController::IsSecondaryUiMaterial()) { |
436 // In non-material, titles are inset from the dialog margin. Ensure the | 438 // In non-material, titles are inset from the dialog margin. Ensure the |
437 // horizontal insets match. | 439 // horizontal insets match. |
438 set_title_margins( | 440 set_title_margins( |
439 gfx::Insets(LayoutDelegate::Get()->GetMetric( | 441 gfx::Insets(LayoutDelegate::Get()->GetMetric( |
440 LayoutDelegate::Metric::PANEL_CONTENT_MARGIN), | 442 LayoutDelegate::Metric::PANEL_CONTENT_MARGIN), |
441 side_margin, 0, side_margin)); | 443 side_margin, 0, side_margin)); |
442 } | 444 } |
443 views::BubbleDialogDelegateView::CreateBubble(this); | 445 views::BubbleDialogDelegateView::CreateBubble(this); |
444 | 446 |
445 presenter_.reset(new PageInfo( | 447 presenter_.reset(new PageInfo( |
446 this, profile, TabSpecificContentSettings::FromWebContents(web_contents), | 448 this, profile, TabSpecificContentSettings::FromWebContents(web_contents), |
447 web_contents, url, security_info)); | 449 web_contents, url, security_info)); |
448 } | 450 } |
449 | 451 |
450 void PageInfoPopupView::RenderFrameDeleted( | 452 void PageInfoBubbleView::RenderFrameDeleted( |
451 content::RenderFrameHost* render_frame_host) { | 453 content::RenderFrameHost* render_frame_host) { |
452 if (render_frame_host == web_contents()->GetMainFrame()) | 454 if (render_frame_host == web_contents()->GetMainFrame()) |
453 GetWidget()->Close(); | 455 GetWidget()->Close(); |
454 } | 456 } |
455 | 457 |
456 void PageInfoPopupView::WebContentsDestroyed() { | 458 void PageInfoBubbleView::WebContentsDestroyed() { |
457 weak_factory_.InvalidateWeakPtrs(); | 459 weak_factory_.InvalidateWeakPtrs(); |
458 } | 460 } |
459 | 461 |
460 void PageInfoPopupView::OnPermissionChanged( | 462 void PageInfoBubbleView::OnPermissionChanged( |
461 const PageInfoUI::PermissionInfo& permission) { | 463 const PageInfoUI::PermissionInfo& permission) { |
462 presenter_->OnSitePermissionChanged(permission.type, permission.setting); | 464 presenter_->OnSitePermissionChanged(permission.type, permission.setting); |
463 // The menu buttons for the permissions might have longer strings now, so we | 465 // The menu buttons for the permissions might have longer strings now, so we |
464 // need to layout and size the whole bubble. | 466 // need to layout and size the whole bubble. |
465 Layout(); | 467 Layout(); |
466 SizeToContents(); | 468 SizeToContents(); |
467 } | 469 } |
468 | 470 |
469 void PageInfoPopupView::OnChosenObjectDeleted( | 471 void PageInfoBubbleView::OnChosenObjectDeleted( |
470 const PageInfoUI::ChosenObjectInfo& info) { | 472 const PageInfoUI::ChosenObjectInfo& info) { |
471 presenter_->OnSiteChosenObjectDeleted(info.ui_info, *info.object); | 473 presenter_->OnSiteChosenObjectDeleted(info.ui_info, *info.object); |
472 } | 474 } |
473 | 475 |
474 base::string16 PageInfoPopupView::GetWindowTitle() const { | 476 base::string16 PageInfoBubbleView::GetWindowTitle() const { |
475 return summary_text_; | 477 return summary_text_; |
476 } | 478 } |
477 | 479 |
478 bool PageInfoPopupView::ShouldShowCloseButton() const { | 480 bool PageInfoBubbleView::ShouldShowCloseButton() const { |
479 return true; | 481 return true; |
480 } | 482 } |
481 | 483 |
482 void PageInfoPopupView::OnWidgetDestroying(views::Widget* widget) { | 484 void PageInfoBubbleView::OnWidgetDestroying(views::Widget* widget) { |
483 g_shown_popup_type = POPUP_NONE; | 485 g_shown_bubble_type = BUBBLE_NONE; |
484 presenter_->OnUIClosing(); | 486 presenter_->OnUIClosing(); |
485 } | 487 } |
486 | 488 |
487 int PageInfoPopupView::GetDialogButtons() const { | 489 int PageInfoBubbleView::GetDialogButtons() const { |
488 return ui::DIALOG_BUTTON_NONE; | 490 return ui::DIALOG_BUTTON_NONE; |
489 } | 491 } |
490 | 492 |
491 const gfx::FontList& PageInfoPopupView::GetTitleFontList() const { | 493 const gfx::FontList& PageInfoBubbleView::GetTitleFontList() const { |
492 return ui::ResourceBundle::GetSharedInstance().GetFontListWithDelta( | 494 return ui::ResourceBundle::GetSharedInstance().GetFontListWithDelta( |
493 kSummaryFontSizeDelta); | 495 kSummaryFontSizeDelta); |
494 } | 496 } |
495 | 497 |
496 void PageInfoPopupView::ButtonPressed(views::Button* button, | 498 void PageInfoBubbleView::ButtonPressed(views::Button* button, |
497 const ui::Event& event) { | 499 const ui::Event& event) { |
498 DCHECK_EQ(BUTTON_CLOSE, button->id()); | 500 DCHECK_EQ(BUTTON_CLOSE, button->id()); |
499 GetWidget()->Close(); | 501 GetWidget()->Close(); |
500 } | 502 } |
501 | 503 |
502 void PageInfoPopupView::LinkClicked(views::Link* source, int event_flags) { | 504 void PageInfoBubbleView::LinkClicked(views::Link* source, int event_flags) { |
503 // The popup closes automatically when the collected cookies dialog or the | 505 // The bubble closes automatically when the collected cookies dialog or the |
504 // certificate viewer opens. So delay handling of the link clicked to avoid | 506 // certificate viewer opens. So delay handling of the link clicked to avoid |
505 // a crash in the base class which needs to complete the mouse event handling. | 507 // a crash in the base class which needs to complete the mouse event handling. |
506 content::BrowserThread::PostTask( | 508 content::BrowserThread::PostTask( |
507 content::BrowserThread::UI, FROM_HERE, | 509 content::BrowserThread::UI, FROM_HERE, |
508 base::Bind(&PageInfoPopupView::HandleLinkClickedAsync, | 510 base::Bind(&PageInfoBubbleView::HandleLinkClickedAsync, |
509 weak_factory_.GetWeakPtr(), source)); | 511 weak_factory_.GetWeakPtr(), source)); |
510 } | 512 } |
511 | 513 |
512 gfx::Size PageInfoPopupView::GetPreferredSize() const { | 514 gfx::Size PageInfoBubbleView::GetPreferredSize() const { |
513 if (header_ == nullptr && site_settings_view_ == nullptr) | 515 if (header_ == nullptr && site_settings_view_ == nullptr) |
514 return views::View::GetPreferredSize(); | 516 return views::View::GetPreferredSize(); |
515 | 517 |
516 int height = 0; | 518 int height = 0; |
517 if (header_) | 519 if (header_) |
518 height += header_->GetPreferredSize().height() + kHeaderMarginBottom; | 520 height += header_->GetPreferredSize().height() + kHeaderMarginBottom; |
519 if (separator_) | 521 if (separator_) |
520 height += separator_->GetPreferredSize().height(); | 522 height += separator_->GetPreferredSize().height(); |
521 | 523 |
522 if (site_settings_view_) | 524 if (site_settings_view_) |
523 height += site_settings_view_->GetPreferredSize().height(); | 525 height += site_settings_view_->GetPreferredSize().height(); |
524 | 526 |
525 int width = kMinPopupWidth; | 527 int width = kMinBubbleWidth; |
526 if (site_settings_view_) | 528 if (site_settings_view_) |
527 width = std::max(width, site_settings_view_->GetPreferredSize().width()); | 529 width = std::max(width, site_settings_view_->GetPreferredSize().width()); |
528 width = std::min(width, kMaxPopupWidth); | 530 width = std::min(width, kMaxBubbleWidth); |
529 return gfx::Size(width, height); | 531 return gfx::Size(width, height); |
530 } | 532 } |
531 | 533 |
532 void PageInfoPopupView::SetCookieInfo(const CookieInfoList& cookie_info_list) { | 534 void PageInfoBubbleView::SetCookieInfo(const CookieInfoList& cookie_info_list) { |
533 // |cookie_info_list| should only ever have 2 items: first- and third-party | 535 // |cookie_info_list| should only ever have 2 items: first- and third-party |
534 // cookies. | 536 // cookies. |
535 DCHECK_EQ(cookie_info_list.size(), 2u); | 537 DCHECK_EQ(cookie_info_list.size(), 2u); |
536 int total_allowed = 0; | 538 int total_allowed = 0; |
537 for (const auto& i : cookie_info_list) | 539 for (const auto& i : cookie_info_list) |
538 total_allowed += i.allowed; | 540 total_allowed += i.allowed; |
539 base::string16 label_text = l10n_util::GetPluralStringFUTF16( | 541 base::string16 label_text = l10n_util::GetPluralStringFUTF16( |
540 IDS_PAGE_INFO_NUM_COOKIES, total_allowed); | 542 IDS_PAGE_INFO_NUM_COOKIES, total_allowed); |
541 | 543 |
542 if (!cookie_dialog_link_) { | 544 if (!cookie_dialog_link_) { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
589 | 591 |
590 layout->AddView(cookie_dialog_link_); | 592 layout->AddView(cookie_dialog_link_); |
591 | 593 |
592 layout->AddPaddingRow(0, kCookiesViewVerticalPadding); | 594 layout->AddPaddingRow(0, kCookiesViewVerticalPadding); |
593 } | 595 } |
594 | 596 |
595 layout->Layout(cookies_view_); | 597 layout->Layout(cookies_view_); |
596 SizeToContents(); | 598 SizeToContents(); |
597 } | 599 } |
598 | 600 |
599 void PageInfoPopupView::SetPermissionInfo( | 601 void PageInfoBubbleView::SetPermissionInfo( |
600 const PermissionInfoList& permission_info_list, | 602 const PermissionInfoList& permission_info_list, |
601 ChosenObjectInfoList chosen_object_info_list) { | 603 ChosenObjectInfoList chosen_object_info_list) { |
602 // When a permission is changed, PageInfo::OnSitePermissionChanged() | 604 // When a permission is changed, PageInfo::OnSitePermissionChanged() |
603 // calls this method with updated permissions. However, PermissionSelectorRow | 605 // calls this method with updated permissions. However, PermissionSelectorRow |
604 // will have already updated its state, so it's already reflected in the UI. | 606 // will have already updated its state, so it's already reflected in the UI. |
605 // In addition, if a permission is set to the default setting, PageInfo | 607 // In addition, if a permission is set to the default setting, PageInfo |
606 // removes it from |permission_info_list|, but the button should remain. | 608 // removes it from |permission_info_list|, but the button should remain. |
607 if (permissions_view_) | 609 if (permissions_view_) |
608 return; | 610 return; |
609 | 611 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
662 views::View* link_section = new views::View(); | 664 views::View* link_section = new views::View(); |
663 const int kLinkMarginTop = 4; | 665 const int kLinkMarginTop = 4; |
664 link_section->SetLayoutManager(new views::BoxLayout( | 666 link_section->SetLayoutManager(new views::BoxLayout( |
665 views::BoxLayout::kHorizontal, 0, kLinkMarginTop, 0)); | 667 views::BoxLayout::kHorizontal, 0, kLinkMarginTop, 0)); |
666 link_section->AddChildView(site_settings_link); | 668 link_section->AddChildView(site_settings_link); |
667 site_settings_view_->AddChildView(link_section); | 669 site_settings_view_->AddChildView(link_section); |
668 | 670 |
669 SizeToContents(); | 671 SizeToContents(); |
670 } | 672 } |
671 | 673 |
672 void PageInfoPopupView::SetIdentityInfo(const IdentityInfo& identity_info) { | 674 void PageInfoBubbleView::SetIdentityInfo(const IdentityInfo& identity_info) { |
673 std::unique_ptr<PageInfoUI::SecurityDescription> security_description = | 675 std::unique_ptr<PageInfoUI::SecurityDescription> security_description = |
674 identity_info.GetSecurityDescription(); | 676 identity_info.GetSecurityDescription(); |
675 | 677 |
676 summary_text_ = security_description->summary; | 678 summary_text_ = security_description->summary; |
677 GetWidget()->UpdateWindowTitle(); | 679 GetWidget()->UpdateWindowTitle(); |
678 | 680 |
679 if (identity_info.certificate) { | 681 if (identity_info.certificate) { |
680 certificate_ = identity_info.certificate; | 682 certificate_ = identity_info.certificate; |
681 | 683 |
682 if (identity_info.show_ssl_decision_revoke_button) | 684 if (identity_info.show_ssl_decision_revoke_button) |
683 header_->AddResetDecisionsLabel(); | 685 header_->AddResetDecisionsLabel(); |
684 } | 686 } |
685 | 687 |
686 header_->SetDetails(security_description->details); | 688 header_->SetDetails(security_description->details); |
687 | 689 |
688 Layout(); | 690 Layout(); |
689 SizeToContents(); | 691 SizeToContents(); |
690 } | 692 } |
691 | 693 |
692 views::View* PageInfoPopupView::CreateSiteSettingsView(int side_margin) { | 694 views::View* PageInfoBubbleView::CreateSiteSettingsView(int side_margin) { |
693 views::View* site_settings_view = new views::View(); | 695 views::View* site_settings_view = new views::View(); |
694 views::BoxLayout* box_layout = | 696 views::BoxLayout* box_layout = |
695 new views::BoxLayout(views::BoxLayout::kVertical, side_margin, 0, 0); | 697 new views::BoxLayout(views::BoxLayout::kVertical, side_margin, 0, 0); |
696 site_settings_view->SetLayoutManager(box_layout); | 698 site_settings_view->SetLayoutManager(box_layout); |
697 box_layout->set_cross_axis_alignment( | 699 box_layout->set_cross_axis_alignment( |
698 views::BoxLayout::CROSS_AXIS_ALIGNMENT_STRETCH); | 700 views::BoxLayout::CROSS_AXIS_ALIGNMENT_STRETCH); |
699 | 701 |
700 // Add cookies view. | 702 // Add cookies view. |
701 cookies_view_ = new views::View(); | 703 cookies_view_ = new views::View(); |
702 site_settings_view->AddChildView(cookies_view_); | 704 site_settings_view->AddChildView(cookies_view_); |
703 | 705 |
704 return site_settings_view; | 706 return site_settings_view; |
705 } | 707 } |
706 | 708 |
707 void PageInfoPopupView::HandleLinkClickedAsync(views::Link* source) { | 709 void PageInfoBubbleView::HandleLinkClickedAsync(views::Link* source) { |
708 // Both switch cases require accessing web_contents(), so we check it here. | 710 // Both switch cases require accessing web_contents(), so we check it here. |
709 if (web_contents() == nullptr || web_contents()->IsBeingDestroyed()) | 711 if (web_contents() == nullptr || web_contents()->IsBeingDestroyed()) |
710 return; | 712 return; |
711 switch (source->id()) { | 713 switch (source->id()) { |
712 case LINK_SITE_SETTINGS: | 714 case LINK_SITE_SETTINGS: |
713 // TODO(crbug.com/655876): This opens the general Content Settings pane, | 715 // TODO(crbug.com/655876): This opens the general Content Settings pane, |
714 // which is OK for now. But on Android, it opens a page specific to a | 716 // which is OK for now. But on Android, it opens a page specific to a |
715 // given origin that shows all of the settings for that origin. If/when | 717 // given origin that shows all of the settings for that origin. If/when |
716 // that's available on desktop we should link to that here, too. | 718 // that's available on desktop we should link to that here, too. |
717 web_contents()->OpenURL(content::OpenURLParams( | 719 web_contents()->OpenURL(content::OpenURLParams( |
718 GURL(chrome::kChromeUIContentSettingsURL), content::Referrer(), | 720 GURL(chrome::kChromeUIContentSettingsURL), content::Referrer(), |
719 WindowOpenDisposition::NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_LINK, | 721 WindowOpenDisposition::NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_LINK, |
720 false)); | 722 false)); |
721 presenter_->RecordPageInfoAction( | 723 presenter_->RecordPageInfoAction( |
722 PageInfo::PAGE_INFO_SITE_SETTINGS_OPENED); | 724 PageInfo::PAGE_INFO_SITE_SETTINGS_OPENED); |
723 break; | 725 break; |
724 case LINK_COOKIE_DIALOG: | 726 case LINK_COOKIE_DIALOG: |
725 // Count how often the Collected Cookies dialog is opened. | 727 // Count how often the Collected Cookies dialog is opened. |
726 presenter_->RecordPageInfoAction( | 728 presenter_->RecordPageInfoAction( |
727 PageInfo::PAGE_INFO_COOKIES_DIALOG_OPENED); | 729 PageInfo::PAGE_INFO_COOKIES_DIALOG_OPENED); |
728 new CollectedCookiesViews(web_contents()); | 730 new CollectedCookiesViews(web_contents()); |
729 break; | 731 break; |
730 default: | 732 default: |
731 NOTREACHED(); | 733 NOTREACHED(); |
732 } | 734 } |
733 } | 735 } |
734 | 736 |
735 void PageInfoPopupView::StyledLabelLinkClicked(views::StyledLabel* label, | 737 void PageInfoBubbleView::StyledLabelLinkClicked(views::StyledLabel* label, |
736 const gfx::Range& range, | 738 const gfx::Range& range, |
737 int event_flags) { | 739 int event_flags) { |
738 switch (label->id()) { | 740 switch (label->id()) { |
739 case STYLED_LABEL_SECURITY_DETAILS: | 741 case STYLED_LABEL_SECURITY_DETAILS: |
740 web_contents()->OpenURL(content::OpenURLParams( | 742 web_contents()->OpenURL(content::OpenURLParams( |
741 GURL(chrome::kPageInfoHelpCenterURL), content::Referrer(), | 743 GURL(chrome::kPageInfoHelpCenterURL), content::Referrer(), |
742 WindowOpenDisposition::NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_LINK, | 744 WindowOpenDisposition::NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_LINK, |
743 false)); | 745 false)); |
744 presenter_->RecordPageInfoAction( | 746 presenter_->RecordPageInfoAction( |
745 PageInfo::PAGE_INFO_CONNECTION_HELP_OPENED); | 747 PageInfo::PAGE_INFO_CONNECTION_HELP_OPENED); |
746 break; | 748 break; |
747 case STYLED_LABEL_RESET_CERTIFICATE_DECISIONS: | 749 case STYLED_LABEL_RESET_CERTIFICATE_DECISIONS: |
748 presenter_->OnRevokeSSLErrorBypassButtonPressed(); | 750 presenter_->OnRevokeSSLErrorBypassButtonPressed(); |
749 GetWidget()->Close(); | 751 GetWidget()->Close(); |
750 break; | 752 break; |
751 default: | 753 default: |
752 NOTREACHED(); | 754 NOTREACHED(); |
753 } | 755 } |
754 } | 756 } |
OLD | NEW |