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

Side by Side Diff: chrome/browser/ui/views/website_settings/website_settings_popup_view.cc

Issue 2397273002: Show a custom page info bubble for chrome-devtools:// URLs (Closed)
Patch Set: Fix test Created 4 years, 2 months 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
OLDNEW
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/website_settings/website_settings_popup_view.h " 5 #include "chrome/browser/ui/views/website_settings/website_settings_popup_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>
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 #include "url/gurl.h" 63 #include "url/gurl.h"
64 64
65 namespace { 65 namespace {
66 66
67 // NOTE(jdonnelly): This use of this process-wide variable assumes that there's 67 // NOTE(jdonnelly): This use of this process-wide variable assumes that there's
68 // never more than one website settings popup shown and that it's associated 68 // never more than one website settings popup shown and that it's associated
69 // with the current window. If this assumption fails in the future, we'll need 69 // with the current window. If this assumption fails in the future, we'll need
70 // to return a weak pointer from ShowPopup so callers can associate it with the 70 // to return a weak pointer from ShowPopup so callers can associate it with the
71 // current window (or other context) and check if the popup they care about is 71 // current window (or other context) and check if the popup they care about is
72 // showing. 72 // showing.
73 bool is_popup_showing = false; 73 WebsiteSettingsPopupView::PopupType shown_popup_type =
raymes 2016/10/12 02:43:12 nit: I think globals tend to be prefixed with g_ (
meacer 2016/10/12 17:48:39 Renamed, and sad global is sad :)
74 WebsiteSettingsPopupView::POPUP_NONE;
74 75
75 // Left icon margin. 76 // Left icon margin.
76 const int kIconMarginLeft = 6; 77 const int kIconMarginLeft = 6;
77 78
78 // Margin and padding values for the |PopupHeaderView|. 79 // Margin and padding values for the |PopupHeaderView|.
79 const int kHeaderMarginBottom = 10; 80 const int kHeaderMarginBottom = 10;
80 const int kHeaderPaddingBottom = 16; 81 const int kHeaderPaddingBottom = 16;
81 const int kHeaderPaddingLeft = 18; 82 const int kHeaderPaddingLeft = 18;
82 const int kHeaderPaddingRightForText = kHeaderPaddingLeft; 83 const int kHeaderPaddingRightForText = kHeaderPaddingLeft;
83 const int kHeaderPaddingTop = 16; 84 const int kHeaderPaddingTop = 16;
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 337
337 //////////////////////////////////////////////////////////////////////////////// 338 ////////////////////////////////////////////////////////////////////////////////
338 // InternalPageInfoPopupView 339 // InternalPageInfoPopupView
339 //////////////////////////////////////////////////////////////////////////////// 340 ////////////////////////////////////////////////////////////////////////////////
340 341
341 InternalPageInfoPopupView::InternalPageInfoPopupView( 342 InternalPageInfoPopupView::InternalPageInfoPopupView(
342 views::View* anchor_view, 343 views::View* anchor_view,
343 gfx::NativeView parent_window, 344 gfx::NativeView parent_window,
344 const GURL& url) 345 const GURL& url)
345 : BubbleDialogDelegateView(anchor_view, views::BubbleBorder::TOP_LEFT) { 346 : BubbleDialogDelegateView(anchor_view, views::BubbleBorder::TOP_LEFT) {
347 shown_popup_type = WebsiteSettingsPopupView::POPUP_INTERNAL_PAGE;
346 set_parent_window(parent_window); 348 set_parent_window(parent_window);
347 349
348 int text = IDS_PAGE_INFO_INTERNAL_PAGE; 350 int text = IDS_PAGE_INFO_INTERNAL_PAGE;
349 int icon = IDR_PRODUCT_LOGO_16; 351 int icon = IDR_PRODUCT_LOGO_16;
350 if (url.SchemeIs(extensions::kExtensionScheme)) { 352 if (url.SchemeIs(extensions::kExtensionScheme)) {
351 text = IDS_PAGE_INFO_EXTENSION_PAGE; 353 text = IDS_PAGE_INFO_EXTENSION_PAGE;
352 icon = IDR_PLUGINS_FAVICON; 354 icon = IDR_PLUGINS_FAVICON;
353 } else if (url.SchemeIs(content::kViewSourceScheme)) { 355 } else if (url.SchemeIs(content::kViewSourceScheme)) {
354 text = IDS_PAGE_INFO_VIEW_SOURCE_PAGE; 356 text = IDS_PAGE_INFO_VIEW_SOURCE_PAGE;
355 // view-source scheme uses the same icon as chrome:// pages. 357 // view-source scheme uses the same icon as chrome:// pages.
356 icon = IDR_PRODUCT_LOGO_16; 358 icon = IDR_PRODUCT_LOGO_16;
357 } else if (!url.SchemeIs(content::kChromeUIScheme)) { 359 } else if (!url.SchemeIs(content::kChromeUIScheme) &&
360 !url.SchemeIs(content::kChromeDevToolsScheme)) {
358 NOTREACHED(); 361 NOTREACHED();
359 } 362 }
360 363
361 // Compensate for built-in vertical padding in the anchor view's image. 364 // Compensate for built-in vertical padding in the anchor view's image.
362 set_anchor_view_insets(gfx::Insets( 365 set_anchor_view_insets(gfx::Insets(
363 GetLayoutConstant(LOCATION_BAR_BUBBLE_ANCHOR_VERTICAL_INSET), 0)); 366 GetLayoutConstant(LOCATION_BAR_BUBBLE_ANCHOR_VERTICAL_INSET), 0));
364 367
365 const int kSpacing = 16; 368 const int kSpacing = 16;
366 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, kSpacing, 369 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, kSpacing,
367 kSpacing, kSpacing)); 370 kSpacing, kSpacing));
(...skipping 19 matching lines...) Expand all
387 views::Widget* widget) { 390 views::Widget* widget) {
388 views::BubbleFrameView* frame = static_cast<views::BubbleFrameView*>( 391 views::BubbleFrameView* frame = static_cast<views::BubbleFrameView*>(
389 BubbleDialogDelegateView::CreateNonClientFrameView(widget)); 392 BubbleDialogDelegateView::CreateNonClientFrameView(widget));
390 // 16px padding + half of icon width comes out to 24px. 393 // 16px padding + half of icon width comes out to 24px.
391 frame->bubble_border()->set_arrow_offset( 394 frame->bubble_border()->set_arrow_offset(
392 24 + frame->bubble_border()->GetBorderThickness()); 395 24 + frame->bubble_border()->GetBorderThickness());
393 return frame; 396 return frame;
394 } 397 }
395 398
396 void InternalPageInfoPopupView::OnWidgetDestroying(views::Widget* widget) { 399 void InternalPageInfoPopupView::OnWidgetDestroying(views::Widget* widget) {
397 is_popup_showing = false; 400 shown_popup_type = WebsiteSettingsPopupView::POPUP_NONE;
398 } 401 }
399 402
400 int InternalPageInfoPopupView::GetDialogButtons() const { 403 int InternalPageInfoPopupView::GetDialogButtons() const {
401 return ui::DIALOG_BUTTON_NONE; 404 return ui::DIALOG_BUTTON_NONE;
402 } 405 }
403 406
404 //////////////////////////////////////////////////////////////////////////////// 407 ////////////////////////////////////////////////////////////////////////////////
405 // WebsiteSettingsPopupView 408 // WebsiteSettingsPopupView
406 //////////////////////////////////////////////////////////////////////////////// 409 ////////////////////////////////////////////////////////////////////////////////
407 410
408 WebsiteSettingsPopupView::~WebsiteSettingsPopupView() { 411 WebsiteSettingsPopupView::~WebsiteSettingsPopupView() {
409 } 412 }
410 413
411 // static 414 // static
412 void WebsiteSettingsPopupView::ShowPopup( 415 void WebsiteSettingsPopupView::ShowPopup(
413 views::View* anchor_view, 416 views::View* anchor_view,
414 const gfx::Rect& anchor_rect, 417 const gfx::Rect& anchor_rect,
415 Profile* profile, 418 Profile* profile,
416 content::WebContents* web_contents, 419 content::WebContents* web_contents,
417 const GURL& url, 420 const GURL& url,
418 const security_state::SecurityStateModel::SecurityInfo& security_info) { 421 const security_state::SecurityStateModel::SecurityInfo& security_info) {
419 is_popup_showing = true;
420 gfx::NativeView parent_window = 422 gfx::NativeView parent_window =
421 anchor_view ? nullptr : web_contents->GetNativeView(); 423 anchor_view ? nullptr : web_contents->GetNativeView();
422 if (url.SchemeIs(content::kChromeUIScheme) || 424 if (url.SchemeIs(content::kChromeUIScheme) ||
425 url.SchemeIs(content::kChromeDevToolsScheme) ||
423 url.SchemeIs(extensions::kExtensionScheme) || 426 url.SchemeIs(extensions::kExtensionScheme) ||
424 url.SchemeIs(content::kViewSourceScheme)) { 427 url.SchemeIs(content::kViewSourceScheme)) {
425 // Use the concrete type so that |SetAnchorRect| can be called as a friend. 428 // Use the concrete type so that |SetAnchorRect| can be called as a friend.
426 InternalPageInfoPopupView* popup = 429 InternalPageInfoPopupView* popup =
427 new InternalPageInfoPopupView(anchor_view, parent_window, url); 430 new InternalPageInfoPopupView(anchor_view, parent_window, url);
428 if (!anchor_view) 431 if (!anchor_view)
429 popup->SetAnchorRect(anchor_rect); 432 popup->SetAnchorRect(anchor_rect);
430 popup->GetWidget()->Show(); 433 popup->GetWidget()->Show();
431 return; 434 return;
432 } 435 }
433 WebsiteSettingsPopupView* popup = new WebsiteSettingsPopupView( 436 WebsiteSettingsPopupView* popup = new WebsiteSettingsPopupView(
434 anchor_view, parent_window, profile, web_contents, url, security_info); 437 anchor_view, parent_window, profile, web_contents, url, security_info);
435 if (!anchor_view) 438 if (!anchor_view)
436 popup->SetAnchorRect(anchor_rect); 439 popup->SetAnchorRect(anchor_rect);
437 popup->GetWidget()->Show(); 440 popup->GetWidget()->Show();
438 } 441 }
439 442
440 // static 443 // static
441 bool WebsiteSettingsPopupView::IsPopupShowing() { 444 WebsiteSettingsPopupView::PopupType
442 return is_popup_showing; 445 WebsiteSettingsPopupView::GetShownPopupType() {
446 return shown_popup_type;
443 } 447 }
444 448
445 WebsiteSettingsPopupView::WebsiteSettingsPopupView( 449 WebsiteSettingsPopupView::WebsiteSettingsPopupView(
446 views::View* anchor_view, 450 views::View* anchor_view,
447 gfx::NativeView parent_window, 451 gfx::NativeView parent_window,
448 Profile* profile, 452 Profile* profile,
449 content::WebContents* web_contents, 453 content::WebContents* web_contents,
450 const GURL& url, 454 const GURL& url,
451 const security_state::SecurityStateModel::SecurityInfo& security_info) 455 const security_state::SecurityStateModel::SecurityInfo& security_info)
452 : content::WebContentsObserver(web_contents), 456 : content::WebContentsObserver(web_contents),
453 BubbleDialogDelegateView(anchor_view, views::BubbleBorder::TOP_LEFT), 457 BubbleDialogDelegateView(anchor_view, views::BubbleBorder::TOP_LEFT),
454 header_(nullptr), 458 header_(nullptr),
455 separator_(nullptr), 459 separator_(nullptr),
456 site_settings_view_(nullptr), 460 site_settings_view_(nullptr),
457 site_data_content_(nullptr), 461 site_data_content_(nullptr),
458 cookie_dialog_link_(nullptr), 462 cookie_dialog_link_(nullptr),
459 permissions_content_(nullptr), 463 permissions_content_(nullptr),
460 site_settings_link_(nullptr), 464 site_settings_link_(nullptr),
461 weak_factory_(this) { 465 weak_factory_(this) {
466 shown_popup_type = POPUP_WEBSITE_SETTINGS;
462 set_parent_window(parent_window); 467 set_parent_window(parent_window);
463
464 is_devtools_disabled_ = 468 is_devtools_disabled_ =
465 profile->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled); 469 profile->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled);
466 470
467 // Compensate for built-in vertical padding in the anchor view's image. 471 // Compensate for built-in vertical padding in the anchor view's image.
468 set_anchor_view_insets(gfx::Insets( 472 set_anchor_view_insets(gfx::Insets(
469 GetLayoutConstant(LOCATION_BAR_BUBBLE_ANCHOR_VERTICAL_INSET), 0)); 473 GetLayoutConstant(LOCATION_BAR_BUBBLE_ANCHOR_VERTICAL_INSET), 0));
470 474
471 views::GridLayout* layout = new views::GridLayout(this); 475 views::GridLayout* layout = new views::GridLayout(this);
472 SetLayoutManager(layout); 476 SetLayoutManager(layout);
473 const int content_column = 0; 477 const int content_column = 0;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 const WebsiteSettingsUI::PermissionInfo& permission) { 521 const WebsiteSettingsUI::PermissionInfo& permission) {
518 presenter_->OnSitePermissionChanged(permission.type, permission.setting); 522 presenter_->OnSitePermissionChanged(permission.type, permission.setting);
519 } 523 }
520 524
521 void WebsiteSettingsPopupView::OnChosenObjectDeleted( 525 void WebsiteSettingsPopupView::OnChosenObjectDeleted(
522 const WebsiteSettingsUI::ChosenObjectInfo& info) { 526 const WebsiteSettingsUI::ChosenObjectInfo& info) {
523 presenter_->OnSiteChosenObjectDeleted(info.ui_info, *info.object); 527 presenter_->OnSiteChosenObjectDeleted(info.ui_info, *info.object);
524 } 528 }
525 529
526 void WebsiteSettingsPopupView::OnWidgetDestroying(views::Widget* widget) { 530 void WebsiteSettingsPopupView::OnWidgetDestroying(views::Widget* widget) {
527 is_popup_showing = false; 531 shown_popup_type = POPUP_NONE;
528 presenter_->OnUIClosing(); 532 presenter_->OnUIClosing();
529 } 533 }
530 534
531 int WebsiteSettingsPopupView::GetDialogButtons() const { 535 int WebsiteSettingsPopupView::GetDialogButtons() const {
532 return ui::DIALOG_BUTTON_NONE; 536 return ui::DIALOG_BUTTON_NONE;
533 } 537 }
534 538
535 void WebsiteSettingsPopupView::ButtonPressed(views::Button* button, 539 void WebsiteSettingsPopupView::ButtonPressed(views::Button* button,
536 const ui::Event& event) { 540 const ui::Event& event) {
537 if (button->id() == BUTTON_RESET_CERTIFICATE_DECISIONS) 541 if (button->id() == BUTTON_RESET_CERTIFICATE_DECISIONS)
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
846 gfx::NativeWindow parent = 850 gfx::NativeWindow parent =
847 anchor_widget() ? anchor_widget()->GetNativeWindow() : nullptr; 851 anchor_widget() ? anchor_widget()->GetNativeWindow() : nullptr;
848 presenter_->RecordWebsiteSettingsAction( 852 presenter_->RecordWebsiteSettingsAction(
849 WebsiteSettings::WEBSITE_SETTINGS_CERTIFICATE_DIALOG_OPENED); 853 WebsiteSettings::WEBSITE_SETTINGS_CERTIFICATE_DIALOG_OPENED);
850 ShowCertificateViewer(web_contents(), parent, certificate_.get()); 854 ShowCertificateViewer(web_contents(), parent, certificate_.get());
851 } else { 855 } else {
852 DevToolsWindow::OpenDevToolsWindow( 856 DevToolsWindow::OpenDevToolsWindow(
853 web_contents(), DevToolsToggleAction::ShowSecurityPanel()); 857 web_contents(), DevToolsToggleAction::ShowSecurityPanel());
854 } 858 }
855 } 859 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698