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

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: Rebase 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 #include "url/gurl.h" 64 #include "url/gurl.h"
65 65
66 namespace { 66 namespace {
67 67
68 // NOTE(jdonnelly): This use of this process-wide variable assumes that there's 68 // NOTE(jdonnelly): This use of this process-wide variable assumes that there's
69 // never more than one website settings popup shown and that it's associated 69 // never more than one website settings popup shown and that it's associated
70 // with the current window. If this assumption fails in the future, we'll need 70 // with the current window. If this assumption fails in the future, we'll need
71 // to return a weak pointer from ShowPopup so callers can associate it with the 71 // to return a weak pointer from ShowPopup so callers can associate it with the
72 // current window (or other context) and check if the popup they care about is 72 // current window (or other context) and check if the popup they care about is
73 // showing. 73 // showing.
74 bool is_popup_showing = false; 74 WebsiteSettingsPopupView::PopupType g_shown_popup_type =
75 WebsiteSettingsPopupView::POPUP_NONE;
75 76
76 // General constants ----------------------------------------------------------- 77 // General constants -----------------------------------------------------------
77 78
78 // Popup width constraints. 79 // Popup width constraints.
79 const int kMinPopupWidth = 320; 80 const int kMinPopupWidth = 320;
80 const int kMaxPopupWidth = 1000; 81 const int kMaxPopupWidth = 1000;
81 82
82 // Margin and padding values shared by all sections. 83 // Margin and padding values shared by all sections.
83 const int kSectionPaddingHorizontal = 16; 84 const int kSectionPaddingHorizontal = 16;
84 85
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 328
328 //////////////////////////////////////////////////////////////////////////////// 329 ////////////////////////////////////////////////////////////////////////////////
329 // InternalPageInfoPopupView 330 // InternalPageInfoPopupView
330 //////////////////////////////////////////////////////////////////////////////// 331 ////////////////////////////////////////////////////////////////////////////////
331 332
332 InternalPageInfoPopupView::InternalPageInfoPopupView( 333 InternalPageInfoPopupView::InternalPageInfoPopupView(
333 views::View* anchor_view, 334 views::View* anchor_view,
334 gfx::NativeView parent_window, 335 gfx::NativeView parent_window,
335 const GURL& url) 336 const GURL& url)
336 : BubbleDialogDelegateView(anchor_view, views::BubbleBorder::TOP_LEFT) { 337 : BubbleDialogDelegateView(anchor_view, views::BubbleBorder::TOP_LEFT) {
338 g_shown_popup_type = WebsiteSettingsPopupView::POPUP_INTERNAL_PAGE;
337 set_parent_window(parent_window); 339 set_parent_window(parent_window);
338 340
339 int text = IDS_PAGE_INFO_INTERNAL_PAGE; 341 int text = IDS_PAGE_INFO_INTERNAL_PAGE;
340 int icon = IDR_PRODUCT_LOGO_16; 342 int icon = IDR_PRODUCT_LOGO_16;
341 if (url.SchemeIs(extensions::kExtensionScheme)) { 343 if (url.SchemeIs(extensions::kExtensionScheme)) {
342 text = IDS_PAGE_INFO_EXTENSION_PAGE; 344 text = IDS_PAGE_INFO_EXTENSION_PAGE;
343 icon = IDR_PLUGINS_FAVICON; 345 icon = IDR_PLUGINS_FAVICON;
344 } else if (url.SchemeIs(content::kViewSourceScheme)) { 346 } else if (url.SchemeIs(content::kViewSourceScheme)) {
345 text = IDS_PAGE_INFO_VIEW_SOURCE_PAGE; 347 text = IDS_PAGE_INFO_VIEW_SOURCE_PAGE;
346 // view-source scheme uses the same icon as chrome:// pages. 348 // view-source scheme uses the same icon as chrome:// pages.
347 icon = IDR_PRODUCT_LOGO_16; 349 icon = IDR_PRODUCT_LOGO_16;
348 } else if (!url.SchemeIs(content::kChromeUIScheme)) { 350 } else if (!url.SchemeIs(content::kChromeUIScheme) &&
351 !url.SchemeIs(content::kChromeDevToolsScheme)) {
349 NOTREACHED(); 352 NOTREACHED();
350 } 353 }
351 354
352 // Compensate for built-in vertical padding in the anchor view's image. 355 // Compensate for built-in vertical padding in the anchor view's image.
353 set_anchor_view_insets(gfx::Insets( 356 set_anchor_view_insets(gfx::Insets(
354 GetLayoutConstant(LOCATION_BAR_BUBBLE_ANCHOR_VERTICAL_INSET), 0)); 357 GetLayoutConstant(LOCATION_BAR_BUBBLE_ANCHOR_VERTICAL_INSET), 0));
355 358
356 const int kSpacing = 16; 359 const int kSpacing = 16;
357 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, kSpacing, 360 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, kSpacing,
358 kSpacing, kSpacing)); 361 kSpacing, kSpacing));
(...skipping 19 matching lines...) Expand all
378 views::Widget* widget) { 381 views::Widget* widget) {
379 views::BubbleFrameView* frame = static_cast<views::BubbleFrameView*>( 382 views::BubbleFrameView* frame = static_cast<views::BubbleFrameView*>(
380 BubbleDialogDelegateView::CreateNonClientFrameView(widget)); 383 BubbleDialogDelegateView::CreateNonClientFrameView(widget));
381 // 16px padding + half of icon width comes out to 24px. 384 // 16px padding + half of icon width comes out to 24px.
382 frame->bubble_border()->set_arrow_offset( 385 frame->bubble_border()->set_arrow_offset(
383 24 + frame->bubble_border()->GetBorderThickness()); 386 24 + frame->bubble_border()->GetBorderThickness());
384 return frame; 387 return frame;
385 } 388 }
386 389
387 void InternalPageInfoPopupView::OnWidgetDestroying(views::Widget* widget) { 390 void InternalPageInfoPopupView::OnWidgetDestroying(views::Widget* widget) {
388 is_popup_showing = false; 391 g_shown_popup_type = WebsiteSettingsPopupView::POPUP_NONE;
389 } 392 }
390 393
391 int InternalPageInfoPopupView::GetDialogButtons() const { 394 int InternalPageInfoPopupView::GetDialogButtons() const {
392 return ui::DIALOG_BUTTON_NONE; 395 return ui::DIALOG_BUTTON_NONE;
393 } 396 }
394 397
395 //////////////////////////////////////////////////////////////////////////////// 398 ////////////////////////////////////////////////////////////////////////////////
396 // WebsiteSettingsPopupView 399 // WebsiteSettingsPopupView
397 //////////////////////////////////////////////////////////////////////////////// 400 ////////////////////////////////////////////////////////////////////////////////
398 401
399 WebsiteSettingsPopupView::~WebsiteSettingsPopupView() { 402 WebsiteSettingsPopupView::~WebsiteSettingsPopupView() {
400 } 403 }
401 404
402 // static 405 // static
403 void WebsiteSettingsPopupView::ShowPopup( 406 void WebsiteSettingsPopupView::ShowPopup(
404 views::View* anchor_view, 407 views::View* anchor_view,
405 const gfx::Rect& anchor_rect, 408 const gfx::Rect& anchor_rect,
406 Profile* profile, 409 Profile* profile,
407 content::WebContents* web_contents, 410 content::WebContents* web_contents,
408 const GURL& url, 411 const GURL& url,
409 const security_state::SecurityStateModel::SecurityInfo& security_info) { 412 const security_state::SecurityStateModel::SecurityInfo& security_info) {
410 is_popup_showing = true;
411 gfx::NativeView parent_window = 413 gfx::NativeView parent_window =
412 anchor_view ? nullptr : web_contents->GetNativeView(); 414 anchor_view ? nullptr : web_contents->GetNativeView();
413 if (url.SchemeIs(content::kChromeUIScheme) || 415 if (url.SchemeIs(content::kChromeUIScheme) ||
416 url.SchemeIs(content::kChromeDevToolsScheme) ||
414 url.SchemeIs(extensions::kExtensionScheme) || 417 url.SchemeIs(extensions::kExtensionScheme) ||
415 url.SchemeIs(content::kViewSourceScheme)) { 418 url.SchemeIs(content::kViewSourceScheme)) {
416 // Use the concrete type so that |SetAnchorRect| can be called as a friend. 419 // Use the concrete type so that |SetAnchorRect| can be called as a friend.
417 InternalPageInfoPopupView* popup = 420 InternalPageInfoPopupView* popup =
418 new InternalPageInfoPopupView(anchor_view, parent_window, url); 421 new InternalPageInfoPopupView(anchor_view, parent_window, url);
419 if (!anchor_view) 422 if (!anchor_view)
420 popup->SetAnchorRect(anchor_rect); 423 popup->SetAnchorRect(anchor_rect);
421 popup->GetWidget()->Show(); 424 popup->GetWidget()->Show();
422 return; 425 return;
423 } 426 }
424 WebsiteSettingsPopupView* popup = new WebsiteSettingsPopupView( 427 WebsiteSettingsPopupView* popup = new WebsiteSettingsPopupView(
425 anchor_view, parent_window, profile, web_contents, url, security_info); 428 anchor_view, parent_window, profile, web_contents, url, security_info);
426 if (!anchor_view) 429 if (!anchor_view)
427 popup->SetAnchorRect(anchor_rect); 430 popup->SetAnchorRect(anchor_rect);
428 popup->GetWidget()->Show(); 431 popup->GetWidget()->Show();
429 } 432 }
430 433
431 // static 434 // static
432 bool WebsiteSettingsPopupView::IsPopupShowing() { 435 WebsiteSettingsPopupView::PopupType
433 return is_popup_showing; 436 WebsiteSettingsPopupView::GetShownPopupType() {
437 return g_shown_popup_type;
434 } 438 }
435 439
436 WebsiteSettingsPopupView::WebsiteSettingsPopupView( 440 WebsiteSettingsPopupView::WebsiteSettingsPopupView(
437 views::View* anchor_view, 441 views::View* anchor_view,
438 gfx::NativeView parent_window, 442 gfx::NativeView parent_window,
439 Profile* profile, 443 Profile* profile,
440 content::WebContents* web_contents, 444 content::WebContents* web_contents,
441 const GURL& url, 445 const GURL& url,
442 const security_state::SecurityStateModel::SecurityInfo& security_info) 446 const security_state::SecurityStateModel::SecurityInfo& security_info)
443 : content::WebContentsObserver(web_contents), 447 : content::WebContentsObserver(web_contents),
444 BubbleDialogDelegateView(anchor_view, views::BubbleBorder::TOP_LEFT), 448 BubbleDialogDelegateView(anchor_view, views::BubbleBorder::TOP_LEFT),
445 profile_(profile), 449 profile_(profile),
446 header_(nullptr), 450 header_(nullptr),
447 separator_(nullptr), 451 separator_(nullptr),
448 site_settings_view_(nullptr), 452 site_settings_view_(nullptr),
449 cookies_view_(nullptr), 453 cookies_view_(nullptr),
450 cookie_dialog_link_(nullptr), 454 cookie_dialog_link_(nullptr),
451 permissions_view_(nullptr), 455 permissions_view_(nullptr),
452 weak_factory_(this) { 456 weak_factory_(this) {
457 g_shown_popup_type = POPUP_WEBSITE_SETTINGS;
453 set_parent_window(parent_window); 458 set_parent_window(parent_window);
454
455 is_devtools_disabled_ = 459 is_devtools_disabled_ =
456 profile->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled); 460 profile->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled);
457 461
458 // Compensate for built-in vertical padding in the anchor view's image. 462 // Compensate for built-in vertical padding in the anchor view's image.
459 set_anchor_view_insets(gfx::Insets( 463 set_anchor_view_insets(gfx::Insets(
460 GetLayoutConstant(LOCATION_BAR_BUBBLE_ANCHOR_VERTICAL_INSET), 0)); 464 GetLayoutConstant(LOCATION_BAR_BUBBLE_ANCHOR_VERTICAL_INSET), 0));
461 465
462 views::GridLayout* layout = new views::GridLayout(this); 466 views::GridLayout* layout = new views::GridLayout(this);
463 SetLayoutManager(layout); 467 SetLayoutManager(layout);
464 const int content_column = 0; 468 const int content_column = 0;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 // need to size the whole bubble. 515 // need to size the whole bubble.
512 SizeToContents(); 516 SizeToContents();
513 } 517 }
514 518
515 void WebsiteSettingsPopupView::OnChosenObjectDeleted( 519 void WebsiteSettingsPopupView::OnChosenObjectDeleted(
516 const WebsiteSettingsUI::ChosenObjectInfo& info) { 520 const WebsiteSettingsUI::ChosenObjectInfo& info) {
517 presenter_->OnSiteChosenObjectDeleted(info.ui_info, *info.object); 521 presenter_->OnSiteChosenObjectDeleted(info.ui_info, *info.object);
518 } 522 }
519 523
520 void WebsiteSettingsPopupView::OnWidgetDestroying(views::Widget* widget) { 524 void WebsiteSettingsPopupView::OnWidgetDestroying(views::Widget* widget) {
521 is_popup_showing = false; 525 g_shown_popup_type = POPUP_NONE;
522 presenter_->OnUIClosing(); 526 presenter_->OnUIClosing();
523 } 527 }
524 528
525 int WebsiteSettingsPopupView::GetDialogButtons() const { 529 int WebsiteSettingsPopupView::GetDialogButtons() const {
526 return ui::DIALOG_BUTTON_NONE; 530 return ui::DIALOG_BUTTON_NONE;
527 } 531 }
528 532
529 void WebsiteSettingsPopupView::ButtonPressed(views::Button* button, 533 void WebsiteSettingsPopupView::ButtonPressed(views::Button* button,
530 const ui::Event& event) { 534 const ui::Event& event) {
531 switch (button->id()) { 535 switch (button->id()) {
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 gfx::NativeWindow parent = 784 gfx::NativeWindow parent =
781 anchor_widget() ? anchor_widget()->GetNativeWindow() : nullptr; 785 anchor_widget() ? anchor_widget()->GetNativeWindow() : nullptr;
782 presenter_->RecordWebsiteSettingsAction( 786 presenter_->RecordWebsiteSettingsAction(
783 WebsiteSettings::WEBSITE_SETTINGS_CERTIFICATE_DIALOG_OPENED); 787 WebsiteSettings::WEBSITE_SETTINGS_CERTIFICATE_DIALOG_OPENED);
784 ShowCertificateViewer(web_contents(), parent, certificate_.get()); 788 ShowCertificateViewer(web_contents(), parent, certificate_.get());
785 } else { 789 } else {
786 DevToolsWindow::OpenDevToolsWindow( 790 DevToolsWindow::OpenDevToolsWindow(
787 web_contents(), DevToolsToggleAction::ShowSecurityPanel()); 791 web_contents(), DevToolsToggleAction::ShowSecurityPanel());
788 } 792 }
789 } 793 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698