blob: 8b18627eda86bdc43e219cdf802eb3e65c6b3d7b [file] [log] [blame]
[email protected]e41982a72012-11-20 07:16:511// Copyright 2012 The Chromium Authors. All rights reserved.
[email protected]69b04b92010-11-08 22:12:182// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CHROME_BROWSER_UI_BROWSER_WINDOW_H_
6#define CHROME_BROWSER_UI_BROWSER_WINDOW_H_
[email protected]69b04b92010-11-08 22:12:187
[email protected]fe54b4a2012-03-28 16:11:048#include "base/callback_forward.h"
[email protected]2e6389f2012-05-18 19:41:259#include "chrome/browser/lifetime/application_lifetime.h"
[email protected]41d9faf2012-02-28 23:46:0210#include "chrome/browser/ui/base_window.h"
[email protected]09b29342011-06-24 19:18:4811#include "chrome/browser/ui/bookmarks/bookmark_bar.h"
[email protected]9d5c059a82012-06-29 20:13:0712#include "chrome/browser/ui/fullscreen/fullscreen_exit_bubble_type.h"
[email protected]e4b66bf2012-05-29 20:39:5113#include "chrome/browser/ui/sync/one_click_signin_sync_starter.h"
[email protected]69b04b92010-11-08 22:12:1814#include "chrome/common/content_settings_types.h"
[email protected]08397d52011-02-05 01:53:3815#include "ui/gfx/native_widget_types.h"
[email protected]588300d2011-04-28 21:06:3516#include "webkit/glue/window_open_disposition.h"
[email protected]69b04b92010-11-08 22:12:1817
18class Browser;
19class BrowserWindowTesting;
20class DownloadShelf;
21class FindBar;
22class GURL;
[email protected]69b04b92010-11-08 22:12:1823class LocationBar;
24class Profile;
25class StatusBubble;
[email protected]69b04b92010-11-08 22:12:1826class TemplateURL;
[email protected]69b04b92010-11-08 22:12:1827#if !defined(OS_MACOSX)
28class ToolbarView;
29#endif
[email protected]69b04b92010-11-08 22:12:1830
[email protected]e0f90fc2012-06-06 19:30:1031namespace autofill {
32class PasswordGenerator;
33}
[email protected]ea049a02011-12-25 21:37:0934namespace content {
35class WebContents;
[email protected]b87ee522012-05-18 15:16:5436struct NativeWebKeyboardEvent;
[email protected]1ecbe862012-10-05 01:29:1437struct PasswordForm;
[email protected]d583e3f22011-12-27 21:38:1738struct SSLStatus;
[email protected]ea049a02011-12-25 21:37:0939}
40
[email protected]1c321ee2012-05-21 03:02:3441namespace extensions {
42class Extension;
43}
44
[email protected]69b04b92010-11-08 22:12:1845namespace gfx {
46class Rect;
[email protected]0548c5352011-09-07 00:33:3347class Size;
[email protected]69b04b92010-11-08 22:12:1848}
49
[email protected]69b04b92010-11-08 22:12:1850////////////////////////////////////////////////////////////////////////////////
51// BrowserWindow interface
52// An interface implemented by the "view" of the Browser window.
[email protected]41d9faf2012-02-28 23:46:0253// This interface includes BaseWindow methods as well as Browser window
54// specific methods.
[email protected]69b04b92010-11-08 22:12:1855//
56// NOTE: All getters may return NULL.
[email protected]41d9faf2012-02-28 23:46:0257//
58class BrowserWindow : public BaseWindow {
[email protected]69b04b92010-11-08 22:12:1859 public:
[email protected]ed2f27132011-04-04 17:19:5760 virtual ~BrowserWindow() {}
61
[email protected]41d9faf2012-02-28 23:46:0262 //////////////////////////////////////////////////////////////////////////////
63 // BaseWindow interface notes:
[email protected]69b04b92010-11-08 22:12:1864
[email protected]41d9faf2012-02-28 23:46:0265 // Closes the window as soon as possible. If the window is not in a drag
[email protected]69b04b92010-11-08 22:12:1866 // session, it will close immediately; otherwise, it will move offscreen (so
67 // events are still fired) until the drag ends, then close. This assumes
68 // that the Browser is not immediately destroyed, but will be eventually
69 // destroyed by other means (eg, the tab strip going to zero elements).
70 // Bad things happen if the Browser dtor is called directly as a result of
71 // invoking this method.
[email protected]41d9faf2012-02-28 23:46:0272 // virtual void Close() = 0;
[email protected]69b04b92010-11-08 22:12:1873
[email protected]41d9faf2012-02-28 23:46:0274 // Browser::OnWindowDidShow should be called after showing the window.
75 // virtual void Show() = 0;
[email protected]69b04b92010-11-08 22:12:1876
[email protected]41d9faf2012-02-28 23:46:0277 //////////////////////////////////////////////////////////////////////////////
78 // Browser specific methods:
[email protected]69b04b92010-11-08 22:12:1879
[email protected]69b04b92010-11-08 22:12:1880 // Returns a pointer to the testing interface to the Browser window, or NULL
81 // if there is none.
82 virtual BrowserWindowTesting* GetBrowserWindowTesting() = 0;
83
84 // Return the status bubble associated with the frame
85 virtual StatusBubble* GetStatusBubble() = 0;
86
[email protected]69b04b92010-11-08 22:12:1887 // Inform the frame that the selected tab favicon or title has changed. Some
88 // frames may need to refresh their title bar.
89 virtual void UpdateTitleBar() = 0;
90
[email protected]09b29342011-06-24 19:18:4891 // Invoked when the state of the bookmark bar changes. This is only invoked if
92 // the state changes for the current tab, it is not sent when switching tabs.
93 virtual void BookmarkBarStateChanged(
94 BookmarkBar::AnimateChangeType change_type) = 0;
[email protected]69b04b92010-11-08 22:12:1895
96 // Inform the frame that the dev tools window for the selected tab has
97 // changed.
98 virtual void UpdateDevTools() = 0;
99
100 // Update any loading animations running in the window. |should_animate| is
101 // true if there are tabs loading and the animations should continue, false
102 // if there are no active loads and the animations should end.
103 virtual void UpdateLoadingAnimations(bool should_animate) = 0;
104
105 // Sets the starred state for the current tab.
106 virtual void SetStarredState(bool is_starred) = 0;
107
[email protected]5423c372012-08-22 05:50:16108 // Called to force the zoom state to for the active tab to be recalculated.
109 // |can_show_bubble| is true when a user presses the zoom up or down keyboard
110 // shortcuts and will be false in other cases (e.g. switching tabs, "clicking"
111 // + or - in the wrench menu to change zoom).
112 virtual void ZoomChangedForActiveTab(bool can_show_bubble) = 0;
[email protected]6f80e932012-06-04 19:00:07113
[email protected]69b04b92010-11-08 22:12:18114 // Accessors for fullscreen mode state.
[email protected]8d944b32011-10-17 06:11:53115 virtual void EnterFullscreen(const GURL& url,
116 FullscreenExitBubbleType bubble_type) = 0;
[email protected]55c87fa2011-10-15 07:28:28117 virtual void ExitFullscreen() = 0;
[email protected]8d944b32011-10-17 06:11:53118 virtual void UpdateFullscreenExitBubbleContent(
119 const GURL& url,
120 FullscreenExitBubbleType bubble_type) = 0;
[email protected]69b04b92010-11-08 22:12:18121
122 // Returns true if the fullscreen bubble is visible.
123 virtual bool IsFullscreenBubbleVisible() const = 0;
124
[email protected]77cbe50e2012-06-14 02:44:38125#if defined(OS_WIN)
126 // Sets state for entering or exiting Win8 Metro snap mode.
127 virtual void SetMetroSnapMode(bool enable) = 0;
128
129 // Returns whether the window is currently in Win8 Metro snap mode.
130 virtual bool IsInMetroSnapMode() const = 0;
131#endif
132
[email protected]69b04b92010-11-08 22:12:18133 // Returns the location bar.
134 virtual LocationBar* GetLocationBar() const = 0;
135
136 // Tries to focus the location bar. Clears the window focus (to avoid
137 // inconsistent state) if this fails.
138 virtual void SetFocusToLocationBar(bool select_all) = 0;
139
140 // Informs the view whether or not a load is in progress for the current tab.
141 // The view can use this notification to update the reload/stop button.
142 virtual void UpdateReloadStopState(bool is_loading, bool force) = 0;
143
144 // Updates the toolbar with the state for the specified |contents|.
[email protected]36ad4aa82012-11-21 19:20:48145 virtual void UpdateToolbar(content::WebContents* contents,
[email protected]69b04b92010-11-08 22:12:18146 bool should_restore_state) = 0;
147
148 // Focuses the toolbar (for accessibility).
149 virtual void FocusToolbar() = 0;
150
151 // Focuses the app menu like it was a menu bar.
152 //
153 // Not used on the Mac, which has a "normal" menu bar.
154 virtual void FocusAppMenu() = 0;
155
156 // Focuses the bookmarks toolbar (for accessibility).
157 virtual void FocusBookmarksToolbar() = 0;
158
[email protected]69b04b92010-11-08 22:12:18159 // Moves keyboard focus to the next pane.
160 virtual void RotatePaneFocus(bool forwards) = 0;
161
162 // Returns whether the bookmark bar is visible or not.
163 virtual bool IsBookmarkBarVisible() const = 0;
164
165 // Returns whether the bookmark bar is animating or not.
166 virtual bool IsBookmarkBarAnimating() const = 0;
167
[email protected]95bf8a5b2010-12-22 16:04:07168 // Returns whether the tab strip is editable (for extensions).
169 virtual bool IsTabStripEditable() const = 0;
170
[email protected]69b04b92010-11-08 22:12:18171 // Returns whether the tool bar is visible or not.
172 virtual bool IsToolbarVisible() const = 0;
173
[email protected]b7a756d42012-01-23 18:08:17174 // Returns the rect where the resize corner should be drawn by the render
175 // widget host view (on top of what the renderer returns). We return an empty
176 // rect to identify that there shouldn't be a resize corner (in the cases
177 // where we take care of it ourselves at the browser level).
178 virtual gfx::Rect GetRootWindowResizerRect() const = 0;
179
[email protected]5f58c2af2012-01-11 17:55:29180 // Returns whether the window is a panel. This is not always synonomous
181 // with the associated browser having type panel since some environments
182 // may draw popups in panel windows.
183 virtual bool IsPanel() const = 0;
184
[email protected]69b04b92010-11-08 22:12:18185 // Tells the frame not to render as inactive until the next activation change.
186 // This is required on Windows when dropdown selects are shown to prevent the
187 // select from deactivating the browser frame. A stub implementation is
188 // provided here since the functionality is Windows-specific.
189 virtual void DisableInactiveFrame() {}
190
[email protected]69b04b92010-11-08 22:12:18191 // Shows a confirmation dialog box for adding a search engine described by
192 // |template_url|. Takes ownership of |template_url|.
[email protected]3613347d2012-04-27 20:27:37193 virtual void ConfirmAddSearchProvider(TemplateURL* template_url,
[email protected]69b04b92010-11-08 22:12:18194 Profile* profile) = 0;
195
196 // Shows or hides the bookmark bar depending on its current visibility.
197 virtual void ToggleBookmarkBar() = 0;
198
[email protected]69b04b92010-11-08 22:12:18199 // Shows the Update Recommended dialog box.
200 virtual void ShowUpdateChromeDialog() = 0;
201
202 // Shows the Task manager.
203 virtual void ShowTaskManager() = 0;
204
[email protected]adb6a84d2011-02-07 16:58:40205 // Shows task information related to background pages.
206 virtual void ShowBackgroundPages() = 0;
207
[email protected]69b04b92010-11-08 22:12:18208 // Shows the Bookmark bubble. |url| is the URL being bookmarked,
209 // |already_bookmarked| is true if the url is already bookmarked.
210 virtual void ShowBookmarkBubble(const GURL& url, bool already_bookmarked) = 0;
211
[email protected]195c99c2012-10-31 06:24:51212 // Shows the bookmark prompt.
213 // TODO(yosin): Make ShowBookmarkPrompt pure virtual.
214 virtual void ShowBookmarkPrompt() {}
215
[email protected]b106ca52012-03-13 06:08:46216 // Shows the Chrome To Mobile bubble.
217 virtual void ShowChromeToMobileBubble() = 0;
218
[email protected]235a0562012-03-26 22:22:35219#if defined(ENABLE_ONE_CLICK_SIGNIN)
[email protected]e4b66bf2012-05-29 20:39:51220 // Callback type used with the ShowOneClickSigninBubble() method. If the
221 // user chooses to accept the sign in, the callback is called to start the
222 // sync process.
223 typedef base::Callback<void(OneClickSigninSyncStarter::StartSyncMode)>
224 StartSyncCallback;
225
226 // Shows the one-click sign in bubble.
[email protected]fe54b4a2012-03-28 16:11:04227 virtual void ShowOneClickSigninBubble(
[email protected]e4b66bf2012-05-29 20:39:51228 const StartSyncCallback& start_sync_callback) = 0;
[email protected]235a0562012-03-26 22:22:35229#endif
230
[email protected]69b04b92010-11-08 22:12:18231 // Whether or not the shelf view is visible.
232 virtual bool IsDownloadShelfVisible() const = 0;
233
234 // Returns the DownloadShelf.
235 virtual DownloadShelf* GetDownloadShelf() = 0;
236
[email protected]69b04b92010-11-08 22:12:18237 // Shows the confirmation dialog box warning that the browser is closing with
238 // in-progress downloads.
239 // This method should call Browser::InProgressDownloadResponse once the user
240 // has confirmed.
241 virtual void ConfirmBrowserCloseWithPendingDownloads() = 0;
242
[email protected]a0ea76c2011-03-23 17:36:42243 // ThemeService calls this when a user has changed his or her theme,
[email protected]69b04b92010-11-08 22:12:18244 // indicating that it's time to redraw everything.
245 virtual void UserChangedTheme() = 0;
246
247 // Get extra vertical height that the render view should add to its requests
248 // to webkit. This can help prevent sending extraneous layout/repaint requests
249 // when the delegate is in the process of resizing the tab contents view (e.g.
250 // during infobar animations).
251 virtual int GetExtraRenderViewHeight() const = 0;
252
[email protected]2a6bc3e2011-12-28 23:51:33253 // Notification that |contents| got the focus through user action (click
[email protected]69b04b92010-11-08 22:12:18254 // on the page).
[email protected]2a6bc3e2011-12-28 23:51:33255 virtual void WebContentsFocused(content::WebContents* contents) = 0;
[email protected]69b04b92010-11-08 22:12:18256
257 // Shows the page info using the specified information.
258 // |url| is the url of the page/frame the info applies to, |ssl| is the SSL
259 // information for that page/frame. If |show_history| is true, a section
260 // showing how many times that URL has been visited is added to the page info.
[email protected]4eb4ec02012-06-19 15:54:21261 virtual void ShowPageInfo(content::WebContents* web_contents,
[email protected]69b04b92010-11-08 22:12:18262 const GURL& url,
[email protected]d583e3f22011-12-27 21:38:17263 const content::SSLStatus& ssl,
[email protected]69b04b92010-11-08 22:12:18264 bool show_history) = 0;
265
[email protected]b8e681e82012-02-20 10:18:47266 // Shows the website settings using the specified information. |url| is the
267 // url of the page/frame the info applies to, |ssl| is the SSL information for
268 // that page/frame. If |show_history| is true, a section showing how many
269 // times that URL has been visited is added to the page info.
270 virtual void ShowWebsiteSettings(Profile* profile,
[email protected]36ad4aa82012-11-21 19:20:48271 content::WebContents* web_contents,
[email protected]b8e681e82012-02-20 10:18:47272 const GURL& url,
273 const content::SSLStatus& ssl,
274 bool show_history) = 0;
275
[email protected]69b04b92010-11-08 22:12:18276 // Shows the app menu (for accessibility).
277 virtual void ShowAppMenu() = 0;
278
279 // Allows the BrowserWindow object to handle the specified keyboard event
280 // before sending it to the renderer.
281 // Returns true if the |event| was handled. Otherwise, if the |event| would
282 // be handled in HandleKeyboardEvent() method as a normal keyboard shortcut,
283 // |*is_keyboard_shortcut| should be set to true.
[email protected]b87ee522012-05-18 15:16:54284 virtual bool PreHandleKeyboardEvent(
285 const content::NativeWebKeyboardEvent& event,
286 bool* is_keyboard_shortcut) = 0;
[email protected]69b04b92010-11-08 22:12:18287
288 // Allows the BrowserWindow object to handle the specified keyboard event,
289 // if the renderer did not process it.
[email protected]b87ee522012-05-18 15:16:54290 virtual void HandleKeyboardEvent(
291 const content::NativeWebKeyboardEvent& event) = 0;
[email protected]69b04b92010-11-08 22:12:18292
[email protected]a3b734b2010-11-30 03:17:11293 // Shows the create chrome app shortcut dialog box.
294 virtual void ShowCreateChromeAppShortcutsDialog(Profile* profile,
[email protected]1c321ee2012-05-21 03:02:34295 const extensions::Extension* app) = 0;
296
[email protected]69b04b92010-11-08 22:12:18297 // Clipboard commands applied to the whole browser window.
298 virtual void Cut() = 0;
299 virtual void Copy() = 0;
300 virtual void Paste() = 0;
301
[email protected]69b04b92010-11-08 22:12:18302#if defined(OS_MACOSX)
303 // Opens the tabpose view.
304 virtual void OpenTabpose() = 0;
[email protected]d3766932011-08-04 22:18:23305
306 // Sets the presentation mode for the window. If the window is not already in
307 // fullscreen, also enters fullscreen mode.
[email protected]8d944b32011-10-17 06:11:53308 virtual void EnterPresentationMode(
309 const GURL& url,
310 FullscreenExitBubbleType bubble_type) = 0;
311 virtual void ExitPresentationMode() = 0;
[email protected]d3766932011-08-04 22:18:23312 virtual bool InPresentationMode() = 0;
[email protected]69b04b92010-11-08 22:12:18313#endif
314
[email protected]e41982a72012-11-20 07:16:51315 // Returns the desired bounds for Instant in screen coordinates. Note that if
316 // Instant isn't currently visible this returns the bounds Instant would be
[email protected]69b04b92010-11-08 22:12:18317 // placed at.
318 virtual gfx::Rect GetInstantBounds() = 0;
319
[email protected]e41982a72012-11-20 07:16:51320 // Checks if an Instant's tab contents is being shown.
[email protected]85fd03e2012-09-04 22:50:14321 virtual bool IsInstantTabShowing() = 0;
322
[email protected]588300d2011-04-28 21:06:35323 // Return the correct disposition for a popup window based on |bounds|.
324 virtual WindowOpenDisposition GetDispositionForPopupBounds(
325 const gfx::Rect& bounds) = 0;
326
[email protected]632983f2011-08-08 22:51:24327 // Construct a FindBar implementation for the |browser|.
328 virtual FindBar* CreateFindBar() = 0;
329
[email protected]d3afce92012-10-07 05:47:36330 // Updates the |top_y| where the top of the constrained window should be
[email protected]4cb7d3fc2012-10-09 17:32:10331 // positioned. When implemented, the method returns true and the value of
332 // |top_y| is non-negative. When not implemented, the method returns false and
333 // the value of |top_y| is not defined.
[email protected]d3afce92012-10-07 05:47:36334 virtual bool GetConstrainedWindowTopY(int* top_y) = 0;
[email protected]6a151762012-10-03 22:33:19335
[email protected]0548c5352011-09-07 00:33:33336 // Invoked when the preferred size of the contents in current tab has been
337 // changed. We might choose to update the window size to accomodate this
338 // change.
339 // Note that this won't be fired if we change tabs.
[email protected]2a6bc3e2011-12-28 23:51:33340 virtual void UpdatePreferredSize(content::WebContents* web_contents,
[email protected]0548c5352011-09-07 00:33:33341 const gfx::Size& pref_size) {}
342
[email protected]61e2b3cc2012-03-02 16:13:34343 // Invoked when the contents auto-resized and the container should match it.
344 virtual void ResizeDueToAutoResize(content::WebContents* web_contents,
345 const gfx::Size& new_size) {}
346
[email protected]69b04b92010-11-08 22:12:18347 // Construct a BrowserWindow implementation for the specified |browser|.
348 static BrowserWindow* CreateBrowserWindow(Browser* browser);
349
[email protected]0ec4898e2011-12-30 21:09:24350 // Shows the avatar bubble inside |web_contents|. The bubble is positioned
351 // relative to |rect|. |rect| should be in the |web_contents| coordinate
[email protected]2f733a02011-10-06 15:17:34352 // system.
[email protected]0ec4898e2011-12-30 21:09:24353 virtual void ShowAvatarBubble(content::WebContents* web_contents,
[email protected]2f733a02011-10-06 15:17:34354 const gfx::Rect& rect) = 0;
355
[email protected]7d2d08152011-10-25 22:58:47356 // Shows the avatar bubble on the window frame off of the avatar button.
357 virtual void ShowAvatarBubbleFromAvatarButton() = 0;
358
[email protected]e0f90fc2012-06-06 19:30:10359 // Show bubble for password generation positioned relative to |rect|. The
360 // subclasses implementing this interface do not own the |password_generator|
361 // object which is passed to generate the password. |form| is the form that
362 // contains the password field that the bubble will be associated with. A
363 // stub implementation is provided since this feature is currently not
364 // available on mac.
[email protected]4d5ef8692012-05-31 02:28:57365 virtual void ShowPasswordGenerationBubble(
366 const gfx::Rect& rect,
[email protected]1ecbe862012-10-05 01:29:14367 const content::PasswordForm& form,
[email protected]cc5419d2012-08-30 02:29:46368 autofill::PasswordGenerator* password_generator) {}
[email protected]90ee09232012-03-21 02:01:01369
[email protected]69b04b92010-11-08 22:12:18370 protected:
[email protected]2e6389f2012-05-18 19:41:25371 friend void browser::CloseAllBrowsers();
[email protected]69b04b92010-11-08 22:12:18372 friend class BrowserView;
373 virtual void DestroyBrowser() = 0;
[email protected]69b04b92010-11-08 22:12:18374};
375
376#if defined(OS_WIN) || defined(TOOLKIT_VIEWS)
377class BookmarkBarView;
378class LocationBarView;
379
380namespace views {
381class View;
382}
383#endif // defined(OS_WIN)
384
385// A BrowserWindow utility interface used for accessing elements of the browser
386// UI used only by UI test automation.
387class BrowserWindowTesting {
388 public:
389#if defined(OS_WIN) || defined(TOOLKIT_VIEWS)
390 // Returns the BookmarkBarView.
391 virtual BookmarkBarView* GetBookmarkBarView() const = 0;
392
393 // Returns the LocationBarView.
394 virtual LocationBarView* GetLocationBarView() const = 0;
395
396 // Returns the TabContentsContainer.
397 virtual views::View* GetTabContentsContainerView() const = 0;
398
[email protected]69b04b92010-11-08 22:12:18399 // Returns the ToolbarView.
400 virtual ToolbarView* GetToolbarView() const = 0;
401#endif
402
403 protected:
404 virtual ~BrowserWindowTesting() {}
405};
406
407#endif // CHROME_BROWSER_UI_BROWSER_WINDOW_H_