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

Unified Diff: chrome/browser/ui/cocoa/browser_window_controller.mm

Issue 2196203002: [Mac] The infobar's top arrow should be hidden while the omnibox popup is shown (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/cocoa/browser_window_controller.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/cocoa/browser_window_controller.mm
diff --git a/chrome/browser/ui/cocoa/browser_window_controller.mm b/chrome/browser/ui/cocoa/browser_window_controller.mm
index 2fd4f20fa2362cd5b3c99df981d23eb4abb640b3..214d8ce454b6ccb944ff4c8e059b0a4f7c0a2e68 100644
--- a/chrome/browser/ui/cocoa/browser_window_controller.mm
+++ b/chrome/browser/ui/cocoa/browser_window_controller.mm
@@ -13,6 +13,8 @@
#import "base/mac/foundation_util.h"
#include "base/mac/mac_util.h"
#import "base/mac/sdk_forward_declarations.h"
+#include "base/memory/ptr_util.h"
+#include "base/scoped_observer.h"
#include "base/strings/sys_string_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/app/chrome_command_ids.h" // IDC_*
@@ -64,6 +66,7 @@
#import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h"
#include "chrome/browser/ui/cocoa/l10n_util.h"
#import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.h"
+#import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h"
#include "chrome/browser/ui/cocoa/permission_bubble/permission_bubble_cocoa.h"
#import "chrome/browser/ui/cocoa/profiles/avatar_base_controller.h"
#import "chrome/browser/ui/cocoa/profiles/avatar_button_controller.h"
@@ -87,6 +90,9 @@
#include "chrome/common/pref_names.h"
#include "components/bookmarks/browser/bookmark_model.h"
#include "components/bookmarks/managed/managed_bookmark_service.h"
+#include "components/omnibox/browser/omnibox_edit_model.h"
+#include "components/omnibox/browser/omnibox_popup_model.h"
+#include "components/omnibox/browser/omnibox_popup_model_observer.h"
#include "components/signin/core/common/profile_management_switches.h"
#include "components/translate/core/browser/translate_manager.h"
#include "components/translate/core/browser/translate_ui_delegate.h"
@@ -185,6 +191,43 @@
namespace {
+// This class shows or hides the top arrow of the infobar in accordance with the
+// visibility of the omnibox popup. It hides the top arrow when the omnibox
+// popup is shown, and vice versa.
+class OmniboxPopupModelObserverBridge final : public OmniboxPopupModelObserver {
+ public:
+ explicit OmniboxPopupModelObserverBridge(BrowserWindowController* controller)
+ : controller_(controller),
+ omnibox_popup_model_([controller_ locationBarBridge]
+ ->GetOmniboxView()
+ ->model()
+ ->popup_model()),
+ omnibox_popup_model_observer_(this) {
+ DCHECK(omnibox_popup_model_);
+ omnibox_popup_model_observer_.Add(omnibox_popup_model_);
+ }
+
+ void OnOmniboxPopupShownOrHidden() override {
+ int max_top_arrow_height = 0;
+ if (!omnibox_popup_model_->IsOpen()) {
+ base::scoped_nsobject<BrowserWindowLayout> layout(
+ [[BrowserWindowLayout alloc] init]);
+ [controller_ updateLayoutParameters:layout];
+ max_top_arrow_height = [layout computeLayout].infoBarMaxTopArrowHeight;
+ }
+ [[controller_ infoBarContainerController]
+ setMaxTopArrowHeight:max_top_arrow_height];
+ }
+
+ private:
+ BrowserWindowController* controller_;
+ OmniboxPopupModel* omnibox_popup_model_;
+ ScopedObserver<OmniboxPopupModel, OmniboxPopupModelObserver>
+ omnibox_popup_model_observer_;
+
+ DISALLOW_COPY_AND_ASSIGN(OmniboxPopupModelObserverBridge);
+};
+
void SetUpBrowserWindowCommandHandler(NSWindow* window) {
// Make the window handle browser window commands.
[base::mac::ObjCCastStrict<ChromeEventProcessingWindow>(window)
@@ -389,6 +432,9 @@ new ExtensionKeybindingRegistryCocoa(browser_->profile(),
extensions::ExtensionKeybindingRegistry::ALL_EXTENSIONS,
windowShim_.get()));
+ omniboxPopupModelObserverBridge_ =
+ base::MakeUnique<OmniboxPopupModelObserverBridge>(self);
+
blockLayoutSubviews_ = NO;
// We are done initializing now.
@@ -418,6 +464,10 @@ - (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
+ // Explicitly release |omniboxPopupModelObserverBridge_| before sending
+ // |browserWillBeDestroyed| to prevent it from UAFing OmniboxPopupModel.
+ omniboxPopupModelObserverBridge_.reset();
+
// Inform reference counted objects that the Browser will be destroyed. This
// ensures they invalidate their weak Browser* to prevent use-after-free.
// These may outlive the Browser if they are retained by something else. For
« no previous file with comments | « chrome/browser/ui/cocoa/browser_window_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698