Commit 6ed69ac8 authored by Patricia Lor's avatar Patricia Lor Committed by Commit Bot

Desktop Page Info/Mac: Dismiss internal page info bubble on tab switches.

Follow up to r475019, which dismisses the (non-internal) page info bubble when
using global browser hotkeys. This fixes the same issue, but for the internal
page info bubble.

Bug: 786361
Change-Id: If0a04f057e023871ff2b665d98941b836920625a
Reviewed-on: https://chromium-review.googlesource.com/799651
Commit-Queue: Patti <patricialor@chromium.org>
Reviewed-by: default avatarTrent Apted <tapted@chromium.org>
Cr-Commit-Position: refs/heads/master@{#521641}
parent 8b7386c0
......@@ -2772,6 +2772,8 @@ split_static_library("ui") {
"views/page_info/non_accessible_image_view.h",
"views/page_info/page_info_bubble_view.cc",
"views/page_info/page_info_bubble_view.h",
"views/page_info/page_info_bubble_view_base.cc",
"views/page_info/page_info_bubble_view_base.h",
"views/page_info/permission_selector_row.cc",
"views/page_info/permission_selector_row.h",
"views/page_info/permission_selector_row_observer.h",
......
......@@ -5,7 +5,9 @@
#import "chrome/browser/ui/cocoa/page_info/page_info_bubble_controller.h"
#include "base/command_line.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/exclusive_access/exclusive_access_manager.h"
#include "chrome/browser/ui/exclusive_access/fullscreen_controller.h"
#include "chrome/browser/ui/page_info/page_info_dialog.h"
......@@ -14,6 +16,7 @@
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "ui/base/material_design/material_design_controller.h"
#include "ui/base/page_transition_types.h"
#import "ui/base/test/scoped_fake_nswindow_fullscreen.h"
#include "ui/base/ui_base_switches.h"
#include "ui/views/bubble/bubble_dialog_delegate.h"
......@@ -27,15 +30,33 @@
namespace {
using PageInfoBubbleViewsMacTest = InProcessBrowserTest;
struct GURLBubbleTypePair {
const char* const url;
const PageInfoBubbleView::BubbleType bubble_type;
};
constexpr GURLBubbleTypePair kGurlBubbleTypePairs[] = {
{url::kAboutBlankURL, PageInfoBubbleView::BUBBLE_PAGE_INFO},
{"chrome://settings", PageInfoBubbleView::BUBBLE_INTERNAL_PAGE},
};
class PageInfoBubbleViewsMacTest
: public InProcessBrowserTest,
public testing::WithParamInterface<GURLBubbleTypePair> {
protected:
PageInfoBubbleViewsMacTest() {}
private:
DISALLOW_COPY_AND_ASSIGN(PageInfoBubbleViewsMacTest);
};
} // namespace
// Test the Page Info bubble doesn't crash upon entering full screen mode while
// it is open. This may occur when the bubble is trying to reanchor itself.
IN_PROC_BROWSER_TEST_F(PageInfoBubbleViewsMacTest, NoCrashOnFullScreenToggle) {
IN_PROC_BROWSER_TEST_P(PageInfoBubbleViewsMacTest, NoCrashOnFullScreenToggle) {
ui::test::ScopedFakeNSWindowFullscreen fake_fullscreen;
ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL));
ui_test_utils::NavigateToURL(browser(), GURL(GetParam().url));
ShowPageInfoDialog(browser()->tab_strip_model()->GetWebContentsAt(0));
ExclusiveAccessManager* access_manager =
browser()->exclusive_access_manager();
......@@ -49,8 +70,7 @@ IN_PROC_BROWSER_TEST_F(PageInfoBubbleViewsMacTest, NoCrashOnFullScreenToggle) {
EXPECT_TRUE(page_info);
views::Widget* page_info_bubble = page_info->GetWidget();
EXPECT_TRUE(page_info_bubble);
EXPECT_EQ(PageInfoBubbleView::BUBBLE_PAGE_INFO,
PageInfoBubbleView::GetShownBubbleType());
EXPECT_EQ(GetParam().bubble_type, PageInfoBubbleView::GetShownBubbleType());
EXPECT_TRUE(page_info_bubble->IsVisible());
} else {
EXPECT_TRUE([PageInfoBubbleController getPageInfoBubbleForTest]);
......@@ -62,3 +82,42 @@ IN_PROC_BROWSER_TEST_F(PageInfoBubbleViewsMacTest, NoCrashOnFullScreenToggle) {
// transitioning into full screen.
fake_fullscreen.FinishTransition();
}
// Test |PageInfoBubbleView| or |InternalPageInfoBubbleView| is hidden on tab
// switches via keyboard shortcuts.
IN_PROC_BROWSER_TEST_P(PageInfoBubbleViewsMacTest,
BubbleClosesOnKeyboardTabSwitch) {
ui_test_utils::NavigateToURL(browser(), GURL(GetParam().url));
// Add a second tab, but make sure the first is selected.
AddTabAtIndex(1, GURL("https://test_url.com"),
ui::PageTransition::PAGE_TRANSITION_LINK);
browser()->tab_strip_model()->ActivateTabAt(0, true);
EXPECT_EQ(0, browser()->tab_strip_model()->active_index());
// Show the (internal or external) Page Info bubble and check it's visible.
ShowPageInfoDialog(browser()->tab_strip_model()->GetWebContentsAt(0));
EXPECT_EQ(GetParam().bubble_type, PageInfoBubbleView::GetShownBubbleType());
views::BubbleDialogDelegateView* page_info =
PageInfoBubbleView::GetPageInfoBubble();
EXPECT_TRUE(page_info);
EXPECT_TRUE(page_info->GetWidget()->IsVisible());
// Switch to the second tab without clicking (which would normally dismiss the
// bubble).
chrome::SelectNextTab(browser());
EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
page_info = PageInfoBubbleView::GetPageInfoBubble();
// Check the bubble is no longer visible. BubbleDialogDelegateView's Widget is
// destroyed when the native widget is destroyed, so it should still be alive.
EXPECT_TRUE(page_info);
EXPECT_TRUE(page_info->GetWidget());
EXPECT_FALSE(page_info->GetWidget()->IsVisible());
base::RunLoop().RunUntilIdle();
EXPECT_FALSE(PageInfoBubbleView::GetPageInfoBubble());
}
INSTANTIATE_TEST_CASE_P(,
PageInfoBubbleViewsMacTest,
testing::ValuesIn(kGurlBubbleTypePairs));
......@@ -22,7 +22,6 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/layout_constants.h"
#include "chrome/browser/ui/page_info/page_info.h"
#include "chrome/browser/ui/page_info/page_info_dialog.h"
#include "chrome/browser/ui/view_ids.h"
......@@ -37,6 +36,7 @@
#include "chrome/common/url_constants.h"
#include "chrome/grit/theme_resources.h"
#include "components/content_settings/core/common/content_settings_types.h"
#include "components/security_state/core/security_state.h"
#include "components/strings/grit/components_chromium_strings.h"
#include "components/strings/grit/components_strings.h"
#include "content/public/browser/browser_thread.h"
......@@ -80,15 +80,6 @@ using views::GridLayout;
namespace {
// NOTE(jdonnelly): The following two process-wide variables assume that there's
// never more than one page info bubble shown and that it's associated with the
// current window. If this assumption fails in the future, we'll need to return
// a weak pointer from ShowBubble so callers can associate it with the current
// window (or other context) and check if the bubble they care about is showing.
PageInfoBubbleView::BubbleType g_shown_bubble_type =
PageInfoBubbleView::BUBBLE_NONE;
views::BubbleDialogDelegateView* g_page_info_bubble = nullptr;
// General constants -----------------------------------------------------------
// Bubble width constraints.
......@@ -283,26 +274,23 @@ class BubbleHeaderView : public views::View {
// The regular PageInfoBubbleView is not supported for internal Chrome pages and
// extension pages. Instead of the |PageInfoBubbleView|, the
// |InternalPageInfoBubbleView| is displayed.
class InternalPageInfoBubbleView : public views::BubbleDialogDelegateView {
class InternalPageInfoBubbleView : public PageInfoBubbleViewBase {
public:
// If |anchor_view| is nullptr, or has no Widget, |parent_window| may be
// provided to ensure this bubble is closed when the parent closes.
InternalPageInfoBubbleView(views::View* anchor_view,
const gfx::Rect& anchor_rect,
gfx::NativeView parent_window,
content::WebContents* web_contents,
const GURL& url);
~InternalPageInfoBubbleView() override;
// views::BubbleDialogDelegateView:
int GetDialogButtons() const override;
base::string16 GetWindowTitle() const override;
// PageInfoBubbleViewBase:
bool ShouldShowCloseButton() const override;
gfx::ImageSkia GetWindowIcon() override;
bool ShouldShowWindowIcon() const override;
void OnWidgetDestroying(views::Widget* widget) override;
private:
base::string16 title_text_;
gfx::ImageSkia* bubble_icon_;
DISALLOW_COPY_AND_ASSIGN(InternalPageInfoBubbleView);
......@@ -459,14 +447,13 @@ InternalPageInfoBubbleView::InternalPageInfoBubbleView(
views::View* anchor_view,
const gfx::Rect& anchor_rect,
gfx::NativeView parent_window,
content::WebContents* web_contents,
const GURL& url)
: BubbleDialogDelegateView(anchor_view, views::BubbleBorder::TOP_LEFT) {
g_shown_bubble_type = PageInfoBubbleView::BUBBLE_INTERNAL_PAGE;
g_page_info_bubble = this;
set_parent_window(parent_window);
if (!anchor_view)
SetAnchorRect(anchor_rect);
: PageInfoBubbleViewBase(anchor_view,
anchor_rect,
parent_window,
PageInfoBubbleViewBase::BUBBLE_INTERNAL_PAGE,
web_contents) {
int text = IDS_PAGE_INFO_INTERNAL_PAGE;
int icon = IDR_PRODUCT_LOGO_16;
if (url.SchemeIs(extensions::kExtensionScheme)) {
......@@ -481,10 +468,6 @@ InternalPageInfoBubbleView::InternalPageInfoBubbleView(
NOTREACHED();
}
// Compensate for built-in vertical padding in the anchor view's image.
set_anchor_view_insets(gfx::Insets(
GetLayoutConstant(LOCATION_BAR_BUBBLE_ANCHOR_VERTICAL_INSET), 0));
// Title insets assume there is content (and thus have no bottom padding). Use
// dialog insets to get the bottom margin back.
set_title_margins(
......@@ -493,7 +476,7 @@ InternalPageInfoBubbleView::InternalPageInfoBubbleView(
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
bubble_icon_ = rb.GetImageSkiaNamed(icon);
title_text_ = l10n_util::GetStringUTF16(text);
set_window_title(l10n_util::GetStringUTF16(text));
views::BubbleDialogDelegateView::CreateBubble(this);
......@@ -509,14 +492,6 @@ InternalPageInfoBubbleView::InternalPageInfoBubbleView(
InternalPageInfoBubbleView::~InternalPageInfoBubbleView() {}
int InternalPageInfoBubbleView::GetDialogButtons() const {
return ui::DIALOG_BUTTON_NONE;
}
base::string16 InternalPageInfoBubbleView::GetWindowTitle() const {
return title_text_;
}
bool InternalPageInfoBubbleView::ShouldShowCloseButton() const {
// TODO(patricialor): When Harmony is default, also remove |bubble_icon_| and
// supporting code.
......@@ -531,11 +506,6 @@ bool InternalPageInfoBubbleView::ShouldShowWindowIcon() const {
return ChromeLayoutProvider::Get()->ShouldShowWindowIcon();
}
void InternalPageInfoBubbleView::OnWidgetDestroying(views::Widget* widget) {
g_shown_bubble_type = PageInfoBubbleView::BUBBLE_NONE;
g_page_info_bubble = nullptr;
}
////////////////////////////////////////////////////////////////////////////////
// PageInfoBubbleView
////////////////////////////////////////////////////////////////////////////////
......@@ -559,7 +529,7 @@ views::BubbleDialogDelegateView* PageInfoBubbleView::CreatePageInfoBubble(
url.SchemeIs(extensions::kExtensionScheme) ||
url.SchemeIs(content::kViewSourceScheme)) {
return new InternalPageInfoBubbleView(anchor_view, anchor_rect,
parent_window, url);
parent_window, web_contents, url);
}
return new PageInfoBubbleView(anchor_view, anchor_rect, parent_window,
......@@ -567,16 +537,6 @@ views::BubbleDialogDelegateView* PageInfoBubbleView::CreatePageInfoBubble(
security_info);
}
// static
PageInfoBubbleView::BubbleType PageInfoBubbleView::GetShownBubbleType() {
return g_shown_bubble_type;
}
// static
views::BubbleDialogDelegateView* PageInfoBubbleView::GetPageInfoBubble() {
return g_page_info_bubble;
}
PageInfoBubbleView::PageInfoBubbleView(
views::View* anchor_view,
const gfx::Rect& anchor_rect,
......@@ -585,24 +545,17 @@ PageInfoBubbleView::PageInfoBubbleView(
content::WebContents* web_contents,
const GURL& url,
const security_state::SecurityInfo& security_info)
: content::WebContentsObserver(web_contents),
BubbleDialogDelegateView(anchor_view, views::BubbleBorder::TOP_LEFT),
: PageInfoBubbleViewBase(anchor_view,
anchor_rect,
parent_window,
PageInfoBubbleViewBase::BUBBLE_PAGE_INFO,
web_contents),
profile_(profile),
header_(nullptr),
site_settings_view_(nullptr),
cookie_link_legacy_(nullptr),
cookie_button_(nullptr),
weak_factory_(this) {
g_shown_bubble_type = BUBBLE_PAGE_INFO;
g_page_info_bubble = this;
set_parent_window(parent_window);
if (!anchor_view)
SetAnchorRect(anchor_rect);
// Compensate for built-in vertical padding in the anchor view's image.
set_anchor_view_insets(gfx::Insets(
GetLayoutConstant(LOCATION_BAR_BUBBLE_ANCHOR_VERTICAL_INSET), 0));
// Capture the default bubble margin, and move it to the Layout classes. This
// is necessary so that the views::Separator can extend the full width of the
// bubble.
......@@ -659,25 +612,10 @@ PageInfoBubbleView::PageInfoBubbleView(
web_contents, url, security_info));
}
void PageInfoBubbleView::RenderFrameDeleted(
content::RenderFrameHost* render_frame_host) {
if (render_frame_host == web_contents()->GetMainFrame()) {
GetWidget()->Close();
}
}
void PageInfoBubbleView::WebContentsDestroyed() {
weak_factory_.InvalidateWeakPtrs();
}
void PageInfoBubbleView::WasHidden() {
GetWidget()->Close();
}
void PageInfoBubbleView::DidStartNavigation(content::NavigationHandle* handle) {
GetWidget()->Close();
}
void PageInfoBubbleView::OnPermissionChanged(
const PageInfoUI::PermissionInfo& permission) {
presenter_->OnSitePermissionChanged(permission.type, permission.setting);
......@@ -692,24 +630,11 @@ void PageInfoBubbleView::OnChosenObjectDeleted(
presenter_->OnSiteChosenObjectDeleted(info.ui_info, *info.object);
}
base::string16 PageInfoBubbleView::GetWindowTitle() const {
return summary_text_;
}
bool PageInfoBubbleView::ShouldShowCloseButton() const {
return true;
}
void PageInfoBubbleView::OnWidgetDestroying(views::Widget* widget) {
g_shown_bubble_type = BUBBLE_NONE;
g_page_info_bubble = nullptr;
PageInfoBubbleViewBase::OnWidgetDestroying(widget);
presenter_->OnUIClosing();
}
int PageInfoBubbleView::GetDialogButtons() const {
return ui::DIALOG_BUTTON_NONE;
}
void PageInfoBubbleView::ButtonPressed(views::Button* button,
const ui::Event& event) {
switch (button->id()) {
......@@ -936,7 +861,7 @@ void PageInfoBubbleView::SetIdentityInfo(const IdentityInfo& identity_info) {
identity_info.GetSecurityDescription();
// Set the bubble title, update the title label text, then apply color.
summary_text_ = security_description->summary;
set_window_title(security_description->summary);
GetBubbleFrameView()->UpdateWindowTitle();
if (ui::MaterialDesignController::IsSecondaryUiMaterial()) {
int text_style = views::style::STYLE_PRIMARY;
......
......@@ -13,28 +13,27 @@
#include "base/memory/weak_ptr.h"
#include "chrome/browser/ui/page_info/page_info_ui.h"
#include "chrome/browser/ui/views/page_info/chosen_object_view_observer.h"
#include "chrome/browser/ui/views/page_info/page_info_bubble_view_base.h"
#include "chrome/browser/ui/views/page_info/permission_selector_row.h"
#include "chrome/browser/ui/views/page_info/permission_selector_row_observer.h"
#include "content/public/browser/web_contents_observer.h"
#include "ui/views/bubble/bubble_dialog_delegate.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/controls/link_listener.h"
#include "ui/views/controls/separator.h"
#include "ui/views/controls/styled_label_listener.h"
class GURL;
class Browser;
class BubbleHeaderView;
class GURL;
class HoverButton;
class Profile;
namespace content {
class WebContents;
}
} // namespace content
namespace net {
class X509Certificate;
}
} // namespace net
namespace security_state {
struct SecurityInfo;
......@@ -42,7 +41,7 @@ struct SecurityInfo;
namespace test {
class PageInfoBubbleViewTestApi;
}
} // namespace test
namespace views {
class Link;
......@@ -50,10 +49,9 @@ class Widget;
} // namespace views
// The views implementation of the page info UI.
class PageInfoBubbleView : public content::WebContentsObserver,
class PageInfoBubbleView : public PageInfoBubbleViewBase,
public PermissionSelectorRowObserver,
public ChosenObjectViewObserver,
public views::BubbleDialogDelegateView,
public views::ButtonListener,
public views::LinkListener,
public views::StyledLabelListener,
......@@ -66,15 +64,6 @@ class PageInfoBubbleView : public content::WebContentsObserver,
~PageInfoBubbleView() override;
// Type of the bubble being displayed.
enum BubbleType {
BUBBLE_NONE,
// Usual page info bubble for websites.
BUBBLE_PAGE_INFO,
// Custom bubble for internal pages like chrome:// and chrome-extensions://.
BUBBLE_INTERNAL_PAGE
};
enum PageInfoBubbleViewID {
VIEW_ID_NONE = 0,
VIEW_ID_PAGE_INFO_BUTTON_CLOSE,
......@@ -94,12 +83,6 @@ class PageInfoBubbleView : public content::WebContentsObserver,
const GURL& url,
const security_state::SecurityInfo& security_info);
// Returns the type of the bubble being shown.
static BubbleType GetShownBubbleType();
// Returns a weak reference to the page info bubble being shown.
static views::BubbleDialogDelegateView* GetPageInfoBubble();
private:
friend class PageInfoBubbleViewBrowserTest;
friend class test::PageInfoBubbleViewTestApi;
......@@ -112,40 +95,30 @@ class PageInfoBubbleView : public content::WebContentsObserver,
const GURL& url,
const security_state::SecurityInfo& security_info);
// WebContentsObserver implementation.
void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override;
// PageInfoBubbleViewBase:
gfx::Size CalculatePreferredSize() const override;
void OnWidgetDestroying(views::Widget* widget) override;
void WebContentsDestroyed() override;
void WasHidden() override;
void DidStartNavigation(content::NavigationHandle* handle) override;
// PermissionSelectorRowObserver implementation.
// PermissionSelectorRowObserver:
void OnPermissionChanged(
const PageInfoUI::PermissionInfo& permission) override;
// ChosenObjectViewObserver implementation.
// ChosenObjectViewObserver:
void OnChosenObjectDeleted(const PageInfoUI::ChosenObjectInfo& info) override;
// views::BubbleDialogDelegateView implementation.
base::string16 GetWindowTitle() const override;
bool ShouldShowCloseButton() const override;
void OnWidgetDestroying(views::Widget* widget) override;
int GetDialogButtons() const override;
// views::ButtonListener implementation.
// views::ButtonListener:
void ButtonPressed(views::Button* button, const ui::Event& event) override;
// views::LinkListener implementation.
// views::LinkListener:
void LinkClicked(views::Link* source, int event_flags) override;
// views::StyledLabelListener implementation.
// views::StyledLabelListener:
void StyledLabelLinkClicked(views::StyledLabel* label,
const gfx::Range& range,
int event_flags) override;
// views::View implementation.
gfx::Size CalculatePreferredSize() const override;
// PageInfoUI implementations.
// PageInfoUI:
void SetCookieInfo(const CookieInfoList& cookie_info_list) override;
void SetPermissionInfo(const PermissionInfoList& permission_info_list,
ChosenObjectInfoList chosen_object_info_list) override;
......@@ -171,9 +144,6 @@ class PageInfoBubbleView : public content::WebContentsObserver,
// The header section (containing security-related information).
BubbleHeaderView* header_;
// The security summary for the current page.
base::string16 summary_text_;
// The view that contains the certificate, cookie, and permissions sections.
views::View* site_settings_view_;
......
// Copyright 2017 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/page_info/page_info_bubble_view_base.h"
#include "base/strings/string16.h"
#include "chrome/browser/ui/layout_constants.h"
#include "chrome/browser/ui/page_info/page_info_dialog.h"
#include "content/public/browser/web_contents.h"
#include "ui/base/ui_features.h"
#include "ui/views/view.h"
#include "ui/views/widget/widget.h"
namespace {
// NOTE(jdonnelly): The following two process-wide variables assume that there's
// never more than one page info bubble shown and that it's associated with the
// current window. If this assumption fails in the future, we'll need to return
// a weak pointer from ShowBubble so callers can associate it with the current
// window (or other context) and check if the bubble they care about is showing.
PageInfoBubbleViewBase::BubbleType g_shown_bubble_type =
PageInfoBubbleViewBase::BUBBLE_NONE;
PageInfoBubbleViewBase* g_page_info_bubble = nullptr;
} // namespace
// static
PageInfoBubbleViewBase::BubbleType
PageInfoBubbleViewBase::GetShownBubbleType() {
return g_shown_bubble_type;
}
// static
views::BubbleDialogDelegateView* PageInfoBubbleViewBase::GetPageInfoBubble() {
return g_page_info_bubble;
}
PageInfoBubbleViewBase::PageInfoBubbleViewBase(
views::View* anchor_view,
const gfx::Rect& anchor_rect,
gfx::NativeView parent_window,
PageInfoBubbleViewBase::BubbleType type,
content::WebContents* web_contents)
: BubbleDialogDelegateView(anchor_view, views::BubbleBorder::TOP_LEFT),
content::WebContentsObserver(web_contents) {
g_shown_bubble_type = type;
g_page_info_bubble = this;
set_parent_window(parent_window);
if (!anchor_view)
SetAnchorRect(anchor_rect);
// Compensate for built-in vertical padding in the anchor view's image.
set_anchor_view_insets(gfx::Insets(
GetLayoutConstant(LOCATION_BAR_BUBBLE_ANCHOR_VERTICAL_INSET), 0));
}
int PageInfoBubbleViewBase::GetDialogButtons() const {
return ui::DIALOG_BUTTON_NONE;
}
base::string16 PageInfoBubbleViewBase::GetWindowTitle() const {
return window_title_;
}
bool PageInfoBubbleViewBase::ShouldShowCloseButton() const {
return true;
}
void PageInfoBubbleViewBase::OnWidgetDestroying(views::Widget* widget) {
BubbleDialogDelegateView::OnWidgetDestroying(widget);
g_shown_bubble_type = BUBBLE_NONE;
g_page_info_bubble = nullptr;
}
void PageInfoBubbleViewBase::RenderFrameDeleted(
content::RenderFrameHost* render_frame_host) {
if (render_frame_host == web_contents()->GetMainFrame()) {
GetWidget()->Close();
}
}
void PageInfoBubbleViewBase::WasHidden() {
GetWidget()->Close();
}
void PageInfoBubbleViewBase::DidStartNavigation(
content::NavigationHandle* handle) {
GetWidget()->Close();
}
// Copyright 2017 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.
#ifndef CHROME_BROWSER_UI_VIEWS_PAGE_INFO_PAGE_INFO_BUBBLE_VIEW_BASE_H_
#define CHROME_BROWSER_UI_VIEWS_PAGE_INFO_PAGE_INFO_BUBBLE_VIEW_BASE_H_
#include "content/public/browser/web_contents_observer.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/views/bubble/bubble_dialog_delegate.h"
namespace content {
class WebContents;
} // namespace content
namespace gfx {
class Rect;
} // namespace gfx
namespace views {
class View;
class Widget;
} // namespace views
// Common class to |PageInfoBubbleView| and |InternalPageInfoBubbleView|.
class PageInfoBubbleViewBase : public views::BubbleDialogDelegateView,
public content::WebContentsObserver {
public:
// Type of the bubble being displayed.
enum BubbleType {
BUBBLE_NONE,
// Usual page info bubble for websites.
BUBBLE_PAGE_INFO,
// Custom bubble for internal pages like chrome:// and chrome-extensions://.
BUBBLE_INTERNAL_PAGE
};
// Returns the type of the bubble being shown. For testing only.
static BubbleType GetShownBubbleType();
// Returns a weak reference to the page info bubble being shown. For testing
// only.
static views::BubbleDialogDelegateView* GetPageInfoBubble();
protected:
PageInfoBubbleViewBase(views::View* anchor_view,
const gfx::Rect& anchor_rect,
gfx::NativeView parent_window,
BubbleType type,
content::WebContents* web_contents);
// views::BubbleDialogDelegateView:
int GetDialogButtons() const override;
base::string16 GetWindowTitle() const override;
bool ShouldShowCloseButton() const override;
void OnWidgetDestroying(views::Widget* widget) override;
void set_window_title(const base::string16& title) { window_title_ = title; }
private:
// WebContentsObserver:
void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override;
void WasHidden() override;
void DidStartNavigation(content::NavigationHandle* handle) override;
base::string16 window_title_;
DISALLOW_COPY_AND_ASSIGN(PageInfoBubbleViewBase);
};
#endif // CHROME_BROWSER_UI_VIEWS_PAGE_INFO_PAGE_INFO_BUBBLE_VIEW_BASE_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment