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