• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2011 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.
4 
5 #ifndef CHROME_BROWSER_UI_BROWSER_WINDOW_H_
6 #define CHROME_BROWSER_UI_BROWSER_WINDOW_H_
7 #pragma once
8 
9 #include "chrome/common/content_settings_types.h"
10 #include "content/browser/tab_contents/navigation_entry.h"
11 #include "ui/gfx/native_widget_types.h"
12 
13 class Browser;
14 class BrowserWindowTesting;
15 class DownloadShelf;
16 class FindBar;
17 class GURL;
18 class HtmlDialogUIDelegate;
19 class LocationBar;
20 class Panel;
21 class Profile;
22 class StatusBubble;
23 class TabContents;
24 class TabContentsWrapper;
25 class TemplateURL;
26 class TemplateURLModel;
27 #if !defined(OS_MACOSX)
28 class ToolbarView;
29 #endif
30 struct NativeWebKeyboardEvent;
31 
32 namespace gfx {
33 class Rect;
34 }
35 
36 namespace views {
37 class Window;
38 }
39 
40 class Extension;
41 
42 ////////////////////////////////////////////////////////////////////////////////
43 // BrowserWindow interface
44 //  An interface implemented by the "view" of the Browser window.
45 //
46 // NOTE: All getters may return NULL.
47 class BrowserWindow {
48  public:
~BrowserWindow()49   virtual ~BrowserWindow() {}
50 
51   // Show the window, or activates it if it's already visible.
52   virtual void Show() = 0;
53 
54   // Show the window, but do not activate it. Does nothing if window
55   // is already visible.
56   virtual void ShowInactive() = 0;
57 
58   // Sets the window's size and position to the specified values.
59   virtual void SetBounds(const gfx::Rect& bounds) = 0;
60 
61   // Closes the frame as soon as possible.  If the frame is not in a drag
62   // session, it will close immediately; otherwise, it will move offscreen (so
63   // events are still fired) until the drag ends, then close. This assumes
64   // that the Browser is not immediately destroyed, but will be eventually
65   // destroyed by other means (eg, the tab strip going to zero elements).
66   // Bad things happen if the Browser dtor is called directly as a result of
67   // invoking this method.
68   virtual void Close() = 0;
69 
70   // Activates (brings to front) the window. Restores the window from minimized
71   // state if necessary.
72   virtual void Activate() = 0;
73 
74   // Deactivates the window, making the next window in the Z order the active
75   // window.
76   virtual void Deactivate() = 0;
77 
78   // Returns true if the window is currently the active/focused window.
79   virtual bool IsActive() const = 0;
80 
81   // Flashes the taskbar item associated with this frame.
82   virtual void FlashFrame() = 0;
83 
84   // Return a platform dependent identifier for this frame. On Windows, this
85   // returns an HWND.
86   virtual gfx::NativeWindow GetNativeHandle() = 0;
87 
88   // Returns a pointer to the testing interface to the Browser window, or NULL
89   // if there is none.
90   virtual BrowserWindowTesting* GetBrowserWindowTesting() = 0;
91 
92   // Return the status bubble associated with the frame
93   virtual StatusBubble* GetStatusBubble() = 0;
94 
95   // Inform the receiving frame that an animation has progressed in the
96   // selected tab.
97   // TODO(beng): Remove. Infobars/Boomarks bars should talk directly to
98   //             BrowserView.
99   virtual void ToolbarSizeChanged(bool is_animating) = 0;
100 
101   // Inform the frame that the selected tab favicon or title has changed. Some
102   // frames may need to refresh their title bar.
103   virtual void UpdateTitleBar() = 0;
104 
105   // Invoked when the visibility of the bookmark bar.
106   // NOTE: this is NOT sent when the user toggles the visibility of this,
107   // but rather when the user transitions from a page that forces
108   // it to be visibile to one that doesn't have it visible (or
109   // vice-versa).
110   // TODO(sky): see about routing visibility pref changing through here too.
111   virtual void ShelfVisibilityChanged() = 0;
112 
113   // Inform the frame that the dev tools window for the selected tab has
114   // changed.
115   virtual void UpdateDevTools() = 0;
116 
117   // Update any loading animations running in the window. |should_animate| is
118   // true if there are tabs loading and the animations should continue, false
119   // if there are no active loads and the animations should end.
120   virtual void UpdateLoadingAnimations(bool should_animate) = 0;
121 
122   // Sets the starred state for the current tab.
123   virtual void SetStarredState(bool is_starred) = 0;
124 
125   // Returns the nonmaximized bounds of the frame (even if the frame is
126   // currently maximized or minimized) in terms of the screen coordinates.
127   virtual gfx::Rect GetRestoredBounds() const = 0;
128 
129   // Retrieves the window's current bounds, including its frame.
130   // This will only differ from GetRestoredBounds() for maximized
131   // and minimized windows.
132   virtual gfx::Rect GetBounds() const = 0;
133 
134   // TODO(beng): REMOVE?
135   // Returns true if the frame is maximized (aka zoomed).
136   virtual bool IsMaximized() const = 0;
137 
138   // Accessors for fullscreen mode state.
139   virtual void SetFullscreen(bool fullscreen) = 0;
140   virtual bool IsFullscreen() const = 0;
141 
142   // Returns true if the fullscreen bubble is visible.
143   virtual bool IsFullscreenBubbleVisible() const = 0;
144 
145   // Returns the location bar.
146   virtual LocationBar* GetLocationBar() const = 0;
147 
148   // Tries to focus the location bar.  Clears the window focus (to avoid
149   // inconsistent state) if this fails.
150   virtual void SetFocusToLocationBar(bool select_all) = 0;
151 
152   // Informs the view whether or not a load is in progress for the current tab.
153   // The view can use this notification to update the reload/stop button.
154   virtual void UpdateReloadStopState(bool is_loading, bool force) = 0;
155 
156   // Updates the toolbar with the state for the specified |contents|.
157   virtual void UpdateToolbar(TabContentsWrapper* contents,
158                              bool should_restore_state) = 0;
159 
160   // Focuses the toolbar (for accessibility).
161   virtual void FocusToolbar() = 0;
162 
163   // Focuses the app menu like it was a menu bar.
164   //
165   // Not used on the Mac, which has a "normal" menu bar.
166   virtual void FocusAppMenu() = 0;
167 
168   // Focuses the bookmarks toolbar (for accessibility).
169   virtual void FocusBookmarksToolbar() = 0;
170 
171   // Focuses the Chrome OS status view (for accessibility).
172   virtual void FocusChromeOSStatus() = 0;
173 
174   // Moves keyboard focus to the next pane.
175   virtual void RotatePaneFocus(bool forwards) = 0;
176 
177   // Returns whether the bookmark bar is visible or not.
178   virtual bool IsBookmarkBarVisible() const = 0;
179 
180   // Returns whether the bookmark bar is animating or not.
181   virtual bool IsBookmarkBarAnimating() const = 0;
182 
183   // Returns whether the tab strip is editable (for extensions).
184   virtual bool IsTabStripEditable() const = 0;
185 
186   // Returns whether the tool bar is visible or not.
187   virtual bool IsToolbarVisible() const = 0;
188 
189   // Tells the frame not to render as inactive until the next activation change.
190   // This is required on Windows when dropdown selects are shown to prevent the
191   // select from deactivating the browser frame. A stub implementation is
192   // provided here since the functionality is Windows-specific.
DisableInactiveFrame()193   virtual void DisableInactiveFrame() {}
194 
195   // Shows a confirmation dialog box for setting the default search engine
196   // described by |template_url|. Takes ownership of |template_url|.
ConfirmSetDefaultSearchProvider(TabContents * tab_contents,TemplateURL * template_url,TemplateURLModel * template_url_model)197   virtual void ConfirmSetDefaultSearchProvider(
198       TabContents* tab_contents,
199       TemplateURL* template_url,
200       TemplateURLModel* template_url_model) {
201     // TODO(levin): Implement this for non-Windows platforms and make it pure.
202     // http://crbug.com/38475
203   }
204 
205   // Shows a confirmation dialog box for adding a search engine described by
206   // |template_url|. Takes ownership of |template_url|.
207   virtual void ConfirmAddSearchProvider(const TemplateURL* template_url,
208                                         Profile* profile) = 0;
209 
210   // Shows or hides the bookmark bar depending on its current visibility.
211   virtual void ToggleBookmarkBar() = 0;
212 
213   // Shows the About Chrome dialog box.
214   virtual void ShowAboutChromeDialog() = 0;
215 
216   // Shows the Update Recommended dialog box.
217   virtual void ShowUpdateChromeDialog() = 0;
218 
219   // Shows the Task manager.
220   virtual void ShowTaskManager() = 0;
221 
222   // Shows task information related to background pages.
223   virtual void ShowBackgroundPages() = 0;
224 
225   // Shows the Bookmark bubble. |url| is the URL being bookmarked,
226   // |already_bookmarked| is true if the url is already bookmarked.
227   virtual void ShowBookmarkBubble(const GURL& url, bool already_bookmarked) = 0;
228 
229   // Whether or not the shelf view is visible.
230   virtual bool IsDownloadShelfVisible() const = 0;
231 
232   // Returns the DownloadShelf.
233   virtual DownloadShelf* GetDownloadShelf() = 0;
234 
235   // Shows the repost form confirmation dialog box.
236   virtual void ShowRepostFormWarningDialog(TabContents* tab_contents) = 0;
237 
238   // Shows the collected cookies dialog box.
239   virtual void ShowCollectedCookiesDialog(TabContents* tab_contents) = 0;
240 
241   // Show the bubble that indicates to the user that a theme is being installed.
242   virtual void ShowThemeInstallBubble() = 0;
243 
244   // Shows the confirmation dialog box warning that the browser is closing with
245   // in-progress downloads.
246   // This method should call Browser::InProgressDownloadResponse once the user
247   // has confirmed.
248   virtual void ConfirmBrowserCloseWithPendingDownloads() = 0;
249 
250   // Shows a dialog box with HTML content. |parent_window| is the window the
251   // dialog should be opened modal to and is a native window handle.
252   virtual void ShowHTMLDialog(HtmlDialogUIDelegate* delegate,
253                               gfx::NativeWindow parent_window) = 0;
254 
255   // ThemeService calls this when a user has changed his or her theme,
256   // indicating that it's time to redraw everything.
257   virtual void UserChangedTheme() = 0;
258 
259   // Get extra vertical height that the render view should add to its requests
260   // to webkit. This can help prevent sending extraneous layout/repaint requests
261   // when the delegate is in the process of resizing the tab contents view (e.g.
262   // during infobar animations).
263   virtual int GetExtraRenderViewHeight() const = 0;
264 
265   // Notification that |tab_contents| got the focus through user action (click
266   // on the page).
267   virtual void TabContentsFocused(TabContents* tab_contents) = 0;
268 
269   // Shows the page info using the specified information.
270   // |url| is the url of the page/frame the info applies to, |ssl| is the SSL
271   // information for that page/frame.  If |show_history| is true, a section
272   // showing how many times that URL has been visited is added to the page info.
273   virtual void ShowPageInfo(Profile* profile,
274                             const GURL& url,
275                             const NavigationEntry::SSLStatus& ssl,
276                             bool show_history) = 0;
277 
278   // Shows the app menu (for accessibility).
279   virtual void ShowAppMenu() = 0;
280 
281   // Allows the BrowserWindow object to handle the specified keyboard event
282   // before sending it to the renderer.
283   // Returns true if the |event| was handled. Otherwise, if the |event| would
284   // be handled in HandleKeyboardEvent() method as a normal keyboard shortcut,
285   // |*is_keyboard_shortcut| should be set to true.
286   virtual bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
287                                       bool* is_keyboard_shortcut) = 0;
288 
289   // Allows the BrowserWindow object to handle the specified keyboard event,
290   // if the renderer did not process it.
291   virtual void HandleKeyboardEvent(const NativeWebKeyboardEvent& event) = 0;
292 
293   // Shows the create web app shortcut dialog box.
294   virtual void ShowCreateWebAppShortcutsDialog(
295       TabContentsWrapper* tab_contents) = 0;
296 
297   // Shows the create chrome app shortcut dialog box.
298   virtual void ShowCreateChromeAppShortcutsDialog(Profile* profile,
299                                                   const Extension* app) = 0;
300 
301   // Clipboard commands applied to the whole browser window.
302   virtual void Cut() = 0;
303   virtual void Copy() = 0;
304   virtual void Paste() = 0;
305 
306   // Switches between available tabstrip display modes.
307   virtual void ToggleTabStripMode() = 0;
308 
309 #if defined(OS_MACOSX)
310   // Opens the tabpose view.
311   virtual void OpenTabpose() = 0;
312 #endif
313 
314   // See InstantDelegate for details.
315   virtual void PrepareForInstant() = 0;
316 
317   // Invoked when instant's tab contents should be shown.
318   virtual void ShowInstant(TabContentsWrapper* preview) = 0;
319 
320   // Invoked when the instant's tab contents should be hidden.
321   // |instant_is_active| indicates if instant is still active.
322   virtual void HideInstant(bool instant_is_active) = 0;
323 
324   // Returns the desired bounds for instant in screen coordinates. Note that if
325   // instant isn't currently visible this returns the bounds instant would be
326   // placed at.
327   virtual gfx::Rect GetInstantBounds() = 0;
328 
329 #if defined(OS_CHROMEOS)
330   // Shows the keyboard overlay dialog box.
331   virtual void ShowKeyboardOverlay(gfx::NativeWindow owning_window) = 0;
332 #endif
333 
334   // Construct a BrowserWindow implementation for the specified |browser|.
335   static BrowserWindow* CreateBrowserWindow(Browser* browser);
336 
337   // Construct a FindBar implementation for the specified |browser|.
338   static FindBar* CreateFindBar(Browser* browser_window);
339 
340  protected:
341   friend class BrowserList;
342   friend class BrowserView;
343   virtual void DestroyBrowser() = 0;
344 };
345 
346 #if defined(OS_WIN) || defined(TOOLKIT_VIEWS)
347 class BookmarkBarView;
348 class LocationBarView;
349 
350 namespace views {
351 class View;
352 }
353 #endif  // defined(OS_WIN)
354 
355 // A BrowserWindow utility interface used for accessing elements of the browser
356 // UI used only by UI test automation.
357 class BrowserWindowTesting {
358  public:
359 #if defined(OS_WIN) || defined(TOOLKIT_VIEWS)
360   // Returns the BookmarkBarView.
361   virtual BookmarkBarView* GetBookmarkBarView() const = 0;
362 
363   // Returns the LocationBarView.
364   virtual LocationBarView* GetLocationBarView() const = 0;
365 
366   // Returns the TabContentsContainer.
367   virtual views::View* GetTabContentsContainerView() const = 0;
368 
369   // Returns the TabContentsContainer.
370   virtual views::View* GetSidebarContainerView() const = 0;
371 
372   // Returns the ToolbarView.
373   virtual ToolbarView* GetToolbarView() const = 0;
374 #endif
375 
376  protected:
~BrowserWindowTesting()377   virtual ~BrowserWindowTesting() {}
378 };
379 
380 #endif  // CHROME_BROWSER_UI_BROWSER_WINDOW_H_
381