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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_COCOA_BROWSER_WINDOW_COCOA_H_
6 #define CHROME_BROWSER_UI_COCOA_BROWSER_WINDOW_COCOA_H_
8 #include "base/mac/scoped_nsobject.h"
9 #include "base/memory/weak_ptr.h"
10 #include "chrome/browser/extensions/extension_keybinding_registry.h"
11 #include "chrome/browser/signin/chrome_signin_helper.h"
12 #include "chrome/browser/ssl/security_state_model.h"
13 #include "chrome/browser/ui/browser_window.h"
14 #include "chrome/browser/ui/exclusive_access/exclusive_access_context.h"
15 #include "chrome/browser/ui/search/search_model_observer.h"
16 #include "components/bookmarks/browser/bookmark_model.h"
17 #include "ui/base/ui_base_types.h"
20 @
class BrowserWindowController
;
21 @
class FindBarCocoaController
;
26 namespace extensions
{
27 class ActiveTabPermissionGranter
;
32 // An implementation of BrowserWindow for Cocoa. Bridges between C++ and
33 // the Cocoa NSWindow. Cross-platform code will interact with this object when
34 // it needs to manipulate the window.
36 class BrowserWindowCocoa
37 : public BrowserWindow
,
38 public ExclusiveAccessContext
,
39 public extensions::ExtensionKeybindingRegistry::Delegate
,
40 public SearchModelObserver
{
42 BrowserWindowCocoa(Browser
* browser
,
43 BrowserWindowController
* controller
);
44 ~BrowserWindowCocoa() override
;
46 // Overridden from BrowserWindow
48 void ShowInactive() override
;
50 void SetBounds(const gfx::Rect
& bounds
) override
;
51 void Close() override
;
52 void Activate() override
;
53 void Deactivate() override
;
54 bool IsActive() const override
;
55 void FlashFrame(bool flash
) override
;
56 bool IsAlwaysOnTop() const override
;
57 void SetAlwaysOnTop(bool always_on_top
) override
;
58 gfx::NativeWindow
GetNativeWindow() const override
;
59 StatusBubble
* GetStatusBubble() override
;
60 void UpdateTitleBar() override
;
61 void BookmarkBarStateChanged(
62 BookmarkBar::AnimateChangeType change_type
) override
;
63 void UpdateDevTools() override
;
64 void UpdateLoadingAnimations(bool should_animate
) override
;
65 void SetStarredState(bool is_starred
) override
;
66 void SetTranslateIconToggled(bool is_lit
) override
;
67 void OnActiveTabChanged(content::WebContents
* old_contents
,
68 content::WebContents
* new_contents
,
71 void ZoomChangedForActiveTab(bool can_show_bubble
) override
;
72 gfx::Rect
GetRestoredBounds() const override
;
73 ui::WindowShowState
GetRestoredState() const override
;
74 gfx::Rect
GetBounds() const override
;
75 bool IsMaximized() const override
;
76 bool IsMinimized() const override
;
77 void Maximize() override
;
78 void Minimize() override
;
79 void Restore() override
;
80 void EnterFullscreen(const GURL
& url
,
81 ExclusiveAccessBubbleType type
,
82 bool with_toolbar
) override
;
83 void ExitFullscreen() override
;
84 void UpdateExclusiveAccessExitBubbleContent(
86 ExclusiveAccessBubbleType bubble_type
) override
;
87 bool ShouldHideUIForFullscreen() const override
;
88 bool IsFullscreen() const override
;
89 bool IsFullscreenBubbleVisible() const override
;
90 bool SupportsFullscreenWithToolbar() const override
;
91 void UpdateFullscreenWithToolbar(bool with_toolbar
) override
;
92 bool IsFullscreenWithToolbar() const override
;
93 LocationBar
* GetLocationBar() const override
;
94 void SetFocusToLocationBar(bool select_all
) override
;
95 void UpdateReloadStopState(bool is_loading
, bool force
) override
;
96 void UpdateToolbar(content::WebContents
* contents
) override
;
97 void ResetToolbarTabState(content::WebContents
* contents
) override
;
98 void FocusToolbar() override
;
99 ToolbarActionsBar
* GetToolbarActionsBar() override
;
100 void ToolbarSizeChanged(bool is_animating
) override
;
101 void FocusAppMenu() override
;
102 void FocusBookmarksToolbar() override
;
103 void FocusInfobars() override
;
104 void RotatePaneFocus(bool forwards
) override
;
105 bool IsBookmarkBarVisible() const override
;
106 bool IsBookmarkBarAnimating() const override
;
107 bool IsTabStripEditable() const override
;
108 bool IsToolbarVisible() const override
;
109 gfx::Rect
GetRootWindowResizerRect() const override
;
110 void ConfirmAddSearchProvider(TemplateURL
* template_url
,
111 Profile
* profile
) override
;
112 void ShowUpdateChromeDialog() override
;
113 void ShowBookmarkBubble(const GURL
& url
, bool already_bookmarked
) override
;
114 void ShowBookmarkAppBubble(
115 const WebApplicationInfo
& web_app_info
,
116 const ShowBookmarkAppBubbleCallback
& callback
) override
;
117 void ShowTranslateBubble(content::WebContents
* contents
,
118 translate::TranslateStep step
,
119 translate::TranslateErrors::Type error_type
,
120 bool is_user_gesture
) override
;
121 bool ShowSessionCrashedBubble() override
;
122 bool IsProfileResetBubbleSupported() const override
;
123 GlobalErrorBubbleViewBase
* ShowProfileResetBubble(
124 const base::WeakPtr
<ProfileResetGlobalError
>& global_error
) override
;
125 #if defined(ENABLE_ONE_CLICK_SIGNIN)
126 void ShowOneClickSigninBubble(
127 OneClickSigninBubbleType type
,
128 const base::string16
& email
,
129 const base::string16
& error_message
,
130 const StartSyncCallback
& start_sync_callback
) override
;
132 bool IsDownloadShelfVisible() const override
;
133 DownloadShelf
* GetDownloadShelf() override
;
134 void ConfirmBrowserCloseWithPendingDownloads(
136 Browser::DownloadClosePreventionType dialog_type
,
138 const base::Callback
<void(bool)>& callback
) override
;
139 void UserChangedTheme() override
;
140 void ShowWebsiteSettings(
142 content::WebContents
* web_contents
,
144 const SecurityStateModel::SecurityInfo
& security_info
) override
;
145 void ShowAppMenu() override
;
146 bool PreHandleKeyboardEvent(const content::NativeWebKeyboardEvent
& event
,
147 bool* is_keyboard_shortcut
) override
;
148 void HandleKeyboardEvent(
149 const content::NativeWebKeyboardEvent
& event
) override
;
150 void CutCopyPaste(int command_id
) override
;
151 WindowOpenDisposition
GetDispositionForPopupBounds(
152 const gfx::Rect
& bounds
) override
;
153 FindBar
* CreateFindBar() override
;
154 web_modal::WebContentsModalDialogHost
* GetWebContentsModalDialogHost()
156 void ShowAvatarBubbleFromAvatarButton(
157 AvatarBubbleMode mode
,
158 const signin::ManageAccountsParams
& manage_accounts_params
) override
;
159 int GetRenderViewHeightInsetWithDetachedBookmarkBar() override
;
160 void ExecuteExtensionCommand(const extensions::Extension
* extension
,
161 const extensions::Command
& command
) override
;
162 ExclusiveAccessContext
* GetExclusiveAccessContext() override
;
164 // ExclusiveAccessContext interface
165 Profile
* GetProfile() override
;
166 content::WebContents
* GetActiveWebContents() override
;
167 void UnhideDownloadShelf() override
;
168 void HideDownloadShelf() override
;
170 // Overridden from ExtensionKeybindingRegistry::Delegate:
171 extensions::ActiveTabPermissionGranter
* GetActiveTabPermissionGranter()
174 // Overridden from SearchModelObserver:
175 void ModelChanged(const SearchModel::State
& old_state
,
176 const SearchModel::State
& new_state
) override
;
178 // Adds the given FindBar cocoa controller to this browser window.
179 void AddFindBar(FindBarCocoaController
* find_bar_cocoa_controller
);
181 // Returns the cocoa-world BrowserWindowController
182 BrowserWindowController
* cocoa_controller() { return controller_
; }
185 void DestroyBrowser() override
;
188 NSWindow
* window() const; // Accessor for the (current) |NSWindow|.
190 Browser
* browser_
; // weak, owned by controller
191 BrowserWindowController
* controller_
; // weak, owns us
192 base::scoped_nsobject
<NSString
> pending_window_title_
;
193 ui::WindowShowState initial_show_state_
;
194 NSInteger attention_request_id_
; // identifier from requestUserAttention
197 #endif // CHROME_BROWSER_UI_COCOA_BROWSER_WINDOW_COCOA_H_