• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 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.
4 
5 #ifndef CHROME_BROWSER_UI_BROWSER_WINDOW_H_
6 #define CHROME_BROWSER_UI_BROWSER_WINDOW_H_
7 
8 #include "base/callback_forward.h"
9 #include "chrome/browser/lifetime/browser_close_manager.h"
10 #include "chrome/browser/signin/signin_header_helper.h"
11 #include "chrome/browser/translate/chrome_translate_client.h"
12 #include "chrome/browser/ui/bookmarks/bookmark_bar.h"
13 #include "chrome/browser/ui/browser.h"
14 #include "chrome/browser/ui/fullscreen/fullscreen_exit_bubble_type.h"
15 #include "chrome/browser/ui/host_desktop.h"
16 #include "chrome/browser/ui/sync/one_click_signin_sync_starter.h"
17 #include "chrome/common/content_settings_types.h"
18 #include "components/translate/core/common/translate_errors.h"
19 #include "ui/base/base_window.h"
20 #include "ui/base/window_open_disposition.h"
21 #include "ui/gfx/native_widget_types.h"
22 
23 class Browser;
24 class BrowserWindowTesting;
25 class DownloadShelf;
26 class FindBar;
27 class GURL;
28 class LocationBar;
29 class Profile;
30 class StatusBubble;
31 class TemplateURL;
32 #if !defined(OS_MACOSX)
33 class ToolbarView;
34 #endif
35 
36 struct WebApplicationInfo;
37 
38 namespace autofill {
39 class PasswordGenerator;
40 struct PasswordForm;
41 }
42 namespace content {
43 class WebContents;
44 struct NativeWebKeyboardEvent;
45 struct SSLStatus;
46 }
47 
48 namespace extensions {
49 class Command;
50 class Extension;
51 }
52 
53 namespace gfx {
54 class Rect;
55 class Size;
56 }
57 
58 namespace web_modal {
59 class WebContentsModalDialogHost;
60 }
61 
62 ////////////////////////////////////////////////////////////////////////////////
63 // BrowserWindow interface
64 //  An interface implemented by the "view" of the Browser window.
65 //  This interface includes ui::BaseWindow methods as well as Browser window
66 //  specific methods.
67 //
68 // NOTE: All getters may return NULL.
69 //
70 class BrowserWindow : public ui::BaseWindow {
71  public:
~BrowserWindow()72   virtual ~BrowserWindow() {}
73 
74   //////////////////////////////////////////////////////////////////////////////
75   // ui::BaseWindow interface notes:
76 
77   // Closes the window as soon as possible. If the window is not in a drag
78   // session, it will close immediately; otherwise, it will move offscreen (so
79   // events are still fired) until the drag ends, then close. This assumes
80   // that the Browser is not immediately destroyed, but will be eventually
81   // destroyed by other means (eg, the tab strip going to zero elements).
82   // Bad things happen if the Browser dtor is called directly as a result of
83   // invoking this method.
84   // virtual void Close() = 0;
85 
86   // Browser::OnWindowDidShow should be called after showing the window.
87   // virtual void Show() = 0;
88 
89   //////////////////////////////////////////////////////////////////////////////
90   // Browser specific methods:
91 
92   // Returns a pointer to the testing interface to the Browser window, or NULL
93   // if there is none.
94   virtual BrowserWindowTesting* GetBrowserWindowTesting() = 0;
95 
96   // Return the status bubble associated with the frame
97   virtual StatusBubble* GetStatusBubble() = 0;
98 
99   // Inform the frame that the selected tab favicon or title has changed. Some
100   // frames may need to refresh their title bar.
101   virtual void UpdateTitleBar() = 0;
102 
103   // Invoked when the state of the bookmark bar changes. This is only invoked if
104   // the state changes for the current tab, it is not sent when switching tabs.
105   virtual void BookmarkBarStateChanged(
106       BookmarkBar::AnimateChangeType change_type) = 0;
107 
108   // Inform the frame that the dev tools window for the selected tab has
109   // changed.
110   virtual void UpdateDevTools() = 0;
111 
112   // Update any loading animations running in the window. |should_animate| is
113   // true if there are tabs loading and the animations should continue, false
114   // if there are no active loads and the animations should end.
115   virtual void UpdateLoadingAnimations(bool should_animate) = 0;
116 
117   // Sets the starred state for the current tab.
118   virtual void SetStarredState(bool is_starred) = 0;
119 
120   // Sets whether the translate icon is lit for the current tab.
121   virtual void SetTranslateIconToggled(bool is_lit) = 0;
122 
123   // Called when the active tab changes.  Subclasses which implement
124   // TabStripModelObserver should implement this instead of ActiveTabChanged();
125   // the Browser will call this method while processing that one.
126   virtual void OnActiveTabChanged(content::WebContents* old_contents,
127                                   content::WebContents* new_contents,
128                                   int index,
129                                   int reason) = 0;
130 
131   // Called to force the zoom state to for the active tab to be recalculated.
132   // |can_show_bubble| is true when a user presses the zoom up or down keyboard
133   // shortcuts and will be false in other cases (e.g. switching tabs, "clicking"
134   // + or - in the wrench menu to change zoom).
135   virtual void ZoomChangedForActiveTab(bool can_show_bubble) = 0;
136 
137   // Accessors for fullscreen mode state.
138   virtual void EnterFullscreen(const GURL& url,
139                                FullscreenExitBubbleType bubble_type) = 0;
140   virtual void ExitFullscreen() = 0;
141   virtual void UpdateFullscreenExitBubbleContent(
142       const GURL& url,
143       FullscreenExitBubbleType bubble_type) = 0;
144 
145   // Windows and GTK remove the top controls in fullscreen, but Mac and Ash
146   // keep the controls in a slide-down panel.
147   virtual bool ShouldHideUIForFullscreen() const = 0;
148 
149   // Returns true if the fullscreen bubble is visible.
150   virtual bool IsFullscreenBubbleVisible() const = 0;
151 
152 #if defined(OS_WIN)
153   // Sets state for entering or exiting Win8 Metro snap mode.
154   virtual void SetMetroSnapMode(bool enable) = 0;
155 
156   // Returns whether the window is currently in Win8 Metro snap mode.
157   virtual bool IsInMetroSnapMode() const = 0;
158 #endif
159 
160   // Returns the location bar.
161   virtual LocationBar* GetLocationBar() const = 0;
162 
163   // Tries to focus the location bar.  Clears the window focus (to avoid
164   // inconsistent state) if this fails.
165   virtual void SetFocusToLocationBar(bool select_all) = 0;
166 
167   // Informs the view whether or not a load is in progress for the current tab.
168   // The view can use this notification to update the reload/stop button.
169   virtual void UpdateReloadStopState(bool is_loading, bool force) = 0;
170 
171   // Updates the toolbar with the state for the specified |contents|.
172   virtual void UpdateToolbar(content::WebContents* contents) = 0;
173 
174   // Focuses the toolbar (for accessibility).
175   virtual void FocusToolbar() = 0;
176 
177   // Focuses the app menu like it was a menu bar.
178   //
179   // Not used on the Mac, which has a "normal" menu bar.
180   virtual void FocusAppMenu() = 0;
181 
182   // Focuses the bookmarks toolbar (for accessibility).
183   virtual void FocusBookmarksToolbar() = 0;
184 
185   // Focuses an infobar, if shown (for accessibility).
186   virtual void FocusInfobars() = 0;
187 
188   // Moves keyboard focus to the next pane.
189   virtual void RotatePaneFocus(bool forwards) = 0;
190 
191   // Returns whether the bookmark bar is visible or not.
192   virtual bool IsBookmarkBarVisible() const = 0;
193 
194   // Returns whether the bookmark bar is animating or not.
195   virtual bool IsBookmarkBarAnimating() const = 0;
196 
197   // Returns whether the tab strip is editable (for extensions).
198   virtual bool IsTabStripEditable() const = 0;
199 
200   // Returns whether the tool bar is visible or not.
201   virtual bool IsToolbarVisible() const = 0;
202 
203   // Returns the rect where the resize corner should be drawn by the render
204   // widget host view (on top of what the renderer returns). We return an empty
205   // rect to identify that there shouldn't be a resize corner (in the cases
206   // where we take care of it ourselves at the browser level).
207   virtual gfx::Rect GetRootWindowResizerRect() const = 0;
208 
209   // Shows a confirmation dialog box for adding a search engine described by
210   // |template_url|. Takes ownership of |template_url|.
211   virtual void ConfirmAddSearchProvider(TemplateURL* template_url,
212                                         Profile* profile) = 0;
213 
214   // Shows the Update Recommended dialog box.
215   virtual void ShowUpdateChromeDialog() = 0;
216 
217   // Shows the Bookmark bubble. |url| is the URL being bookmarked,
218   // |already_bookmarked| is true if the url is already bookmarked.
219   virtual void ShowBookmarkBubble(const GURL& url, bool already_bookmarked) = 0;
220 
221   // Shows the Bookmark App bubble.
222   // See Extension::InitFromValueFlags::FROM_BOOKMARK for a description of
223   // bookmark apps.
224   //
225   // |web_app_info| is the WebApplicationInfo being converted into an app.
226   // |extension_id| is the id of the bookmark app.
227   virtual void ShowBookmarkAppBubble(const WebApplicationInfo& web_app_info,
228                                      const std::string& extension_id) = 0;
229 
230   // Shows the translate bubble.
231   virtual void ShowTranslateBubble(content::WebContents* contents,
232                                    translate::TranslateStep step,
233                                    TranslateErrors::Type error_type) = 0;
234 
235 #if defined(ENABLE_ONE_CLICK_SIGNIN)
236   enum OneClickSigninBubbleType {
237     ONE_CLICK_SIGNIN_BUBBLE_TYPE_BUBBLE,
238     ONE_CLICK_SIGNIN_BUBBLE_TYPE_MODAL_DIALOG,
239     ONE_CLICK_SIGNIN_BUBBLE_TYPE_SAML_MODAL_DIALOG
240   };
241 
242   // Callback type used with the ShowOneClickSigninBubble() method.  If the
243   // user chooses to accept the sign in, the callback is called to start the
244   // sync process.
245   typedef base::Callback<void(OneClickSigninSyncStarter::StartSyncMode)>
246       StartSyncCallback;
247 
248   // Shows the one-click sign in bubble.  |email| holds the full email address
249   // of the account that has signed in.
250   virtual void ShowOneClickSigninBubble(
251       OneClickSigninBubbleType type,
252       const base::string16& email,
253       const base::string16& error_message,
254       const StartSyncCallback& start_sync_callback) = 0;
255 #endif
256 
257   // Whether or not the shelf view is visible.
258   virtual bool IsDownloadShelfVisible() const = 0;
259 
260   // Returns the DownloadShelf.
261   virtual DownloadShelf* GetDownloadShelf() = 0;
262 
263   // Shows the confirmation dialog box warning that the browser is closing with
264   // in-progress downloads.
265   // This method should call |callback| with the user's response.
266   virtual void ConfirmBrowserCloseWithPendingDownloads(
267       int download_count,
268       Browser::DownloadClosePreventionType dialog_type,
269       bool app_modal,
270       const base::Callback<void(bool)>& callback) = 0;
271 
272   // ThemeService calls this when a user has changed his or her theme,
273   // indicating that it's time to redraw everything.
274   virtual void UserChangedTheme() = 0;
275 
276   // Get extra vertical height that the render view should add to its requests
277   // to webkit. This can help prevent sending extraneous layout/repaint requests
278   // when the delegate is in the process of resizing the tab contents view (e.g.
279   // during infobar animations).
280   virtual int GetExtraRenderViewHeight() const = 0;
281 
282   // Notification that |contents| got the focus through user action (click
283   // on the page).
284   virtual void WebContentsFocused(content::WebContents* contents) = 0;
285 
286   // Shows the website settings using the specified information. |url| is the
287   // url of the page/frame the info applies to, |ssl| is the SSL information for
288   // that page/frame.  If |show_history| is true, a section showing how many
289   // times that URL has been visited is added to the page info.
290   virtual void ShowWebsiteSettings(Profile* profile,
291                                    content::WebContents* web_contents,
292                                    const GURL& url,
293                                    const content::SSLStatus& ssl) = 0;
294 
295   // Shows the app menu (for accessibility).
296   virtual void ShowAppMenu() = 0;
297 
298   // Allows the BrowserWindow object to handle the specified keyboard event
299   // before sending it to the renderer.
300   // Returns true if the |event| was handled. Otherwise, if the |event| would
301   // be handled in HandleKeyboardEvent() method as a normal keyboard shortcut,
302   // |*is_keyboard_shortcut| should be set to true.
303   virtual bool PreHandleKeyboardEvent(
304       const content::NativeWebKeyboardEvent& event,
305       bool* is_keyboard_shortcut) = 0;
306 
307   // Allows the BrowserWindow object to handle the specified keyboard event,
308   // if the renderer did not process it.
309   virtual void HandleKeyboardEvent(
310       const content::NativeWebKeyboardEvent& event) = 0;
311 
312   // Clipboard commands applied to the whole browser window.
313   virtual void Cut() = 0;
314   virtual void Copy() = 0;
315   virtual void Paste() = 0;
316 
317 #if defined(OS_MACOSX)
318   // Enters Mac specific fullscreen mode with chrome displayed (e.g. omnibox)
319   // on OSX 10.7+, a.k.a. Lion Fullscreen mode.
320   // Invalid to call on OSX earlier than 10.7.
321   // Enters either from non fullscreen, or from fullscreen without chrome.
322   // Exit to normal fullscreen with EnterFullscreen().
323   virtual void EnterFullscreenWithChrome() = 0;
324   virtual bool IsFullscreenWithChrome() = 0;
325   virtual bool IsFullscreenWithoutChrome() = 0;
326 #endif
327 
328   // Return the correct disposition for a popup window based on |bounds|.
329   virtual WindowOpenDisposition GetDispositionForPopupBounds(
330       const gfx::Rect& bounds) = 0;
331 
332   // Construct a FindBar implementation for the |browser|.
333   virtual FindBar* CreateFindBar() = 0;
334 
335   // Return the WebContentsModalDialogHost for use in positioning web contents
336   // modal dialogs within the browser window. This can sometimes be NULL (for
337   // instance during tab drag on Views/Win32).
338   virtual web_modal::WebContentsModalDialogHost*
339       GetWebContentsModalDialogHost() = 0;
340 
341   // Invoked when the preferred size of the contents in current tab has been
342   // changed. We might choose to update the window size to accomodate this
343   // change.
344   // Note that this won't be fired if we change tabs.
UpdatePreferredSize(content::WebContents * web_contents,const gfx::Size & pref_size)345   virtual void UpdatePreferredSize(content::WebContents* web_contents,
346                                    const gfx::Size& pref_size) {}
347 
348   // Invoked when the contents auto-resized and the container should match it.
ResizeDueToAutoResize(content::WebContents * web_contents,const gfx::Size & new_size)349   virtual void ResizeDueToAutoResize(content::WebContents* web_contents,
350                                      const gfx::Size& new_size) {}
351 
352   // Construct a BrowserWindow implementation for the specified |browser|.
353   static BrowserWindow* CreateBrowserWindow(Browser* browser);
354 
355   // Returns a HostDesktopType that is compatible with the current Chrome window
356   // configuration. On Windows with Ash, this is always HOST_DESKTOP_TYPE_ASH
357   // while Chrome is running in Metro mode. Otherwise returns |desktop_type|.
358   static chrome::HostDesktopType AdjustHostDesktopType(
359       chrome::HostDesktopType desktop_type);
360 
361   // Shows the avatar bubble inside |web_contents|. The bubble is positioned
362   // relative to |rect|. |rect| should be in the |web_contents| coordinate
363   // system.
364   virtual void ShowAvatarBubble(content::WebContents* web_contents,
365                                 const gfx::Rect& rect) = 0;
366 
367   // Shows the avatar bubble on the window frame off of the avatar button with
368   // the given mode. The Service Type specified by GAIA is provided as well.
369   enum AvatarBubbleMode {
370     AVATAR_BUBBLE_MODE_DEFAULT,
371     AVATAR_BUBBLE_MODE_ACCOUNT_MANAGEMENT,
372     AVATAR_BUBBLE_MODE_SIGNIN,
373     AVATAR_BUBBLE_MODE_REAUTH,
374   };
375   virtual void ShowAvatarBubbleFromAvatarButton(AvatarBubbleMode mode,
376       const signin::ManageAccountsParams& manage_accounts_params) = 0;
377 
378   // Show bubble for password generation positioned relative to |rect|. The
379   // subclasses implementing this interface do not own the |password_generator|
380   // object which is passed to generate the password. |form| is the form that
381   // contains the password field that the bubble will be associated with.
382   virtual void ShowPasswordGenerationBubble(
383       const gfx::Rect& rect,
384       const autofill::PasswordForm& form,
385       autofill::PasswordGenerator* password_generator) = 0;
386 
387   // Invoked when the amount of vertical overscroll changes. |delta_y| is the
388   // amount of overscroll that has occured in the y-direction.
OverscrollUpdate(int delta_y)389   virtual void OverscrollUpdate(int delta_y) {}
390 
391   // Returns the height inset for RenderView when detached bookmark bar is
392   // shown.  Invoked when a new RenderHostView is created for a non-NTP
393   // navigation entry and the bookmark bar is detached.
394   virtual int GetRenderViewHeightInsetWithDetachedBookmarkBar() = 0;
395 
396   // Executes |command| registered by |extension|.
397   virtual void ExecuteExtensionCommand(const extensions::Extension* extension,
398                                        const extensions::Command& command) = 0;
399 
400   // Shows the page action for the extension.
401   virtual void ShowPageActionPopup(const extensions::Extension* extension) = 0;
402 
403   // Shows the browser action for the extension. NOTE(wittman): This function
404   // grants tab permissions to the browser action popup, so it should only be
405   // invoked due to user action, not due to invocation from an extensions API.
406   virtual void ShowBrowserActionPopup(
407       const extensions::Extension* extension) = 0;
408 
409  protected:
410   friend class BrowserCloseManager;
411   friend class BrowserView;
412   virtual void DestroyBrowser() = 0;
413 };
414 
415 #if defined(OS_WIN) || defined(TOOLKIT_VIEWS)
416 class BookmarkBarView;
417 class LocationBarView;
418 
419 namespace views {
420 class View;
421 }
422 #endif  // defined(OS_WIN)
423 
424 // A BrowserWindow utility interface used for accessing elements of the browser
425 // UI used only by UI test automation.
426 class BrowserWindowTesting {
427  public:
428 #if defined(OS_WIN) || defined(TOOLKIT_VIEWS)
429   // Returns the BookmarkBarView.
430   virtual BookmarkBarView* GetBookmarkBarView() const = 0;
431 
432   // Returns the LocationBarView.
433   virtual LocationBarView* GetLocationBarView() const = 0;
434 
435   // Returns the TabContentsContainer.
436   virtual views::View* GetTabContentsContainerView() const = 0;
437 
438   // Returns the ToolbarView.
439   virtual ToolbarView* GetToolbarView() const = 0;
440 #endif
441 
442  protected:
~BrowserWindowTesting()443   virtual ~BrowserWindowTesting() {}
444 };
445 
446 #endif  // CHROME_BROWSER_UI_BROWSER_WINDOW_H_
447