Commit 4dd87d54 authored by Elly Fong-Jones's avatar Elly Fong-Jones Committed by Commit Bot

polychrome: wire SessionCrashedBubbleView

This change:
1) Allows SessionCrashedBubbleView to anchor to a rect instead of a view;
2) Has it use a rect when a Cocoa browser window is in use;
3) Has SessionCrashedBubbleViewTest use a rect when a Cocoa browser window is
   in use too

Bug: 653966, 817408
Change-Id: I89d6327cc4df09e870891ace0b9cca151235051a
Reviewed-on: https://chromium-review.googlesource.com/961501
Commit-Queue: Elly Fong-Jones <ellyjones@chromium.org>
Reviewed-by: default avatarTrent Apted <tapted@chromium.org>
Cr-Commit-Position: refs/heads/master@{#543690}
parent aaa47c0d
......@@ -507,7 +507,6 @@ split_static_library("ui") {
"cocoa/screen_capture_notification_ui_cocoa.mm",
"cocoa/separate_fullscreen_window.h",
"cocoa/separate_fullscreen_window.mm",
"cocoa/session_crashed_bubble.mm",
"cocoa/simple_message_box_bridge_views.mm",
"cocoa/simple_message_box_cocoa.h",
"cocoa/simple_message_box_cocoa.mm",
......@@ -2521,7 +2520,6 @@ split_static_library("ui") {
"cocoa/password_reuse_warning_view_controller.h",
"cocoa/password_reuse_warning_view_controller.mm",
"cocoa/passwords/password_prompt_views_mac.mm",
"cocoa/session_crashed_bubble.mm",
"cocoa/simple_message_box_bridge_views.mm",
"cocoa/simple_message_box_cocoa.h",
"cocoa/simple_message_box_cocoa.mm",
......@@ -2926,6 +2924,8 @@ split_static_library("ui") {
"views/permission_bubble/permission_prompt_impl.h",
"views/safe_browsing/password_reuse_modal_warning_dialog.cc",
"views/safe_browsing/password_reuse_modal_warning_dialog.h",
"views/session_crashed_bubble_view.cc",
"views/session_crashed_bubble_view.h",
"views/simple_message_box_views.cc",
"views/simple_message_box_views.h",
"views/subtle_notification_view.cc",
......@@ -3163,8 +3163,6 @@ split_static_library("ui") {
"views/proximity_auth/proximity_auth_error_bubble_view.h",
"views/sad_tab_view.cc",
"views/sad_tab_view.h",
"views/session_crashed_bubble_view.cc",
"views/session_crashed_bubble_view.h",
"views/ssl_client_certificate_selector.cc",
"views/ssl_client_certificate_selector.h",
"views/status_bubble_views.cc",
......
......@@ -47,6 +47,10 @@ gfx::Rect GetPageInfoAnchorRectCocoa(Browser* browser);
gfx::Point GetExtensionInstalledAnchorPointCocoa(
gfx::NativeWindow window,
const ExtensionInstalledBubble* bubble);
// Returns the app menu anchor rect for |browser|, which is assumed to have a
// Cocoa browser window.
gfx::Rect GetAppMenuAnchorRectCocoa(Browser* browser);
#endif
} // namespace bubble_anchor_util
......
......@@ -6,13 +6,16 @@
#import <Cocoa/Cocoa.h>
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h"
#import "chrome/browser/ui/cocoa/browser_window_controller.h"
#include "chrome/browser/ui/cocoa/browser_window_views_mac.h"
#import "chrome/browser/ui/cocoa/bubble_anchor_helper.h"
#import "chrome/browser/ui/cocoa/extensions/browser_actions_controller.h"
#import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h"
#import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h"
#include "chrome/browser/ui/extensions/extension_installed_bubble.h"
#include "ui/base/cocoa/cocoa_base_utils.h"
#import "ui/base/cocoa/cocoa_base_utils.h"
#include "ui/base/ui_features.h"
#include "ui/gfx/geometry/rect.h"
#import "ui/gfx/mac/coordinate_conversion.h"
......@@ -64,6 +67,15 @@ gfx::Point GetExtensionInstalledAnchorPointCocoa(
return gfx::ScreenPointFromNSPoint(arrow_point);
}
gfx::Rect GetAppMenuAnchorRectCocoa(Browser* browser) {
NSWindow* window = browser->window()->GetNativeWindow();
BrowserWindowController* bwc = BrowserWindowControllerForWindow(window);
NSPoint point = [[bwc toolbarController] appMenuBubblePoint];
return gfx::Rect(gfx::ScreenPointFromNSPoint(
ui::ConvertPointFromWindowToScreen(window, point)),
gfx::Size());
}
#if !BUILDFLAG(MAC_VIEWS_BROWSER)
gfx::Rect GetPageInfoAnchorRect(Browser* browser) {
return GetPageInfoAnchorRectCocoa(browser);
......
// Copyright 2015 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/session_crashed_bubble.h"
bool SessionCrashedBubble::Show(Browser* /* browser */) {
return false;
}
......@@ -21,6 +21,7 @@
#include "chrome/browser/ui/browser_dialogs.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_list_observer.h"
#include "chrome/browser/ui/bubble_anchor_util.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/frame/browser_view_button_provider.h"
......@@ -36,6 +37,7 @@
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/ui_features.h"
#include "ui/views/controls/button/checkbox.h"
#include "ui/views/controls/button/menu_button.h"
#include "ui/views/controls/label.h"
......@@ -45,6 +47,11 @@
#include "ui/views/layout/grid_layout.h"
#include "ui/views/widget/widget.h"
#if defined(OS_MACOSX)
#include "chrome/browser/platform_util.h"
#include "chrome/browser/ui/cocoa/browser_dialogs_views_mac.h"
#endif
using views::GridLayout;
namespace {
......@@ -75,6 +82,35 @@ bool DoesSupportConsentCheck() {
#endif
}
#if !defined(OS_MACOSX) || BUILDFLAG(MAC_VIEWS_BROWSER)
// Returns the app menu view, except when the browser window is Cocoa; Cocoa
// browser windows always have a null anchor view and use GetBubbleAnchorRect()
// instead.
views::View* GetBubbleAnchorView(Browser* browser) {
#if BUILDFLAG(MAC_VIEWS_BROWSER)
if (views_mode_controller::IsViewsBrowserCocoa())
return nullptr;
#endif
return BrowserView::GetBrowserViewForBrowser(browser)
->button_provider()
->GetAppMenuButton();
}
#else // OS_MACOSX && !MAC_VIEWS_BROWSER
views::View* GetBubbleAnchorView(Browser* browser) {
return nullptr;
}
#endif
gfx::Rect GetBubbleAnchorRect(Browser* browser) {
#if BUILDFLAG(MAC_VIEWS_BROWSER)
if (views_mode_controller::IsViewsBrowserCocoa())
return bubble_anchor_util::GetAppMenuAnchorRectCocoa(browser);
#elif defined(OS_MACOSX)
return bubble_anchor_util::GetAppMenuAnchorRectCocoa(browser);
#endif
return gfx::Rect();
}
} // namespace
// A helper class that listens to browser removal event.
......@@ -104,6 +140,11 @@ class SessionCrashedBubbleView::BrowserRemovalObserver
// static
bool SessionCrashedBubble::Show(Browser* browser) {
#if defined(OS_MACOSX)
if (!chrome::ShowAllDialogsWithViewsToolkit())
return false;
#endif
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
if (browser->profile()->IsOffTheRecord())
return true;
......@@ -120,14 +161,6 @@ bool SessionCrashedBubble::Show(Browser* browser) {
base::Bind(&SessionCrashedBubbleView::ShowForReal,
base::Passed(&browser_observer)));
} else {
#if defined(OS_MACOSX)
// SessionCrashedBubbleView doesn't support being hosted by a Cocoa browser
// window, so return false here so StartupBrowserCreator will fall back to
// the infobar.
// TODO(ellyjones): Make SessionCrashedBubbleView support a Cocoa host.
if (views_mode_controller::IsViewsBrowserCocoa())
return false;
#endif
SessionCrashedBubbleView::ShowForReal(std::move(browser_observer), false);
}
return true;
......@@ -152,11 +185,9 @@ void SessionCrashedBubbleView::ShowForReal(
return;
}
views::View* anchor_view = BrowserView::GetBrowserViewForBrowser(browser)
->button_provider()
->GetAppMenuButton();
SessionCrashedBubbleView* crash_bubble =
new SessionCrashedBubbleView(anchor_view, browser, offer_uma_optin);
SessionCrashedBubbleView* crash_bubble = new SessionCrashedBubbleView(
GetBubbleAnchorView(browser), GetBubbleAnchorRect(browser), browser,
offer_uma_optin);
views::BubbleDialogDelegateView::CreateBubble(crash_bubble)->Show();
RecordBubbleHistogramValue(SESSION_CRASHED_BUBBLE_SHOWN);
......@@ -165,6 +196,7 @@ void SessionCrashedBubbleView::ShowForReal(
}
SessionCrashedBubbleView::SessionCrashedBubbleView(views::View* anchor_view,
const gfx::Rect& anchor_rect,
Browser* browser,
bool offer_uma_optin)
: BubbleDialogDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT),
......@@ -174,6 +206,12 @@ SessionCrashedBubbleView::SessionCrashedBubbleView(views::View* anchor_view,
ignored_(true) {
set_close_on_deactivate(false);
chrome::RecordDialogCreation(chrome::DialogIdentifier::SESSION_CRASHED);
if (!anchor_view) {
SetAnchorRect(anchor_rect);
set_parent_window(
platform_util::GetViewForWindow(browser->window()->GetNativeWindow()));
}
}
SessionCrashedBubbleView::~SessionCrashedBubbleView() {
......
......@@ -40,6 +40,7 @@ class SessionCrashedBubbleView : public SessionCrashedBubble,
friend class SessionCrashedBubbleViewTest;
SessionCrashedBubbleView(views::View* anchor_view,
const gfx::Rect& anchor_rect,
Browser* browser,
bool offer_uma_optin);
~SessionCrashedBubbleView() override;
......
......@@ -6,11 +6,15 @@
#include <string>
#include "build/buildflag.h"
#include "chrome/browser/ui/bubble_anchor_util.h"
#include "chrome/browser/ui/test/test_browser_dialog.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/toolbar/app_menu_button.h"
#include "chrome/browser/ui/views/toolbar/toolbar_view.h"
#include "chrome/browser/ui/views_mode_controller.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "ui/base/ui_features.h"
#include "ui/views/view.h"
class SessionCrashedBubbleViewTest : public DialogBrowserTest {
......@@ -19,11 +23,20 @@ class SessionCrashedBubbleViewTest : public DialogBrowserTest {
~SessionCrashedBubbleViewTest() override {}
void ShowUi(const std::string& name) override {
views::View* anchor_view = BrowserView::GetBrowserViewForBrowser(browser())
->toolbar()
->app_menu_button();
SessionCrashedBubbleView* crash_bubble = new SessionCrashedBubbleView(
anchor_view, browser(), name == "SessionCrashedBubbleOfferUma");
gfx::Rect anchor_rect = gfx::Rect();
views::View* anchor_view = nullptr;
#if BUILDFLAG(MAC_VIEWS_BROWSER)
if (views_mode_controller::IsViewsBrowserCocoa())
anchor_rect = bubble_anchor_util::GetAppMenuAnchorRectCocoa(browser());
#endif
if (anchor_rect == gfx::Rect()) {
anchor_view = BrowserView::GetBrowserViewForBrowser(browser())
->toolbar()
->app_menu_button();
}
SessionCrashedBubbleView* crash_bubble =
new SessionCrashedBubbleView(anchor_view, anchor_rect, browser(),
name == "SessionCrashedBubbleOfferUma");
views::BubbleDialogDelegateView::CreateBubble(crash_bubble)->Show();
}
......
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