Fix link in German terms of service.
[chromium-blink-merge.git] / content / shell / browser / shell.h
blobde193c042bd1c334676ad34c583c049ab8b4f1d6
1 // Copyright 2013 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 #ifndef CONTENT_SHELL_BROWSER_SHELL_H_
5 #define CONTENT_SHELL_BROWSER_SHELL_H_
8 #include <vector>
10 #include "base/basictypes.h"
11 #include "base/callback_forward.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/strings/string_piece.h"
14 #include "build/build_config.h"
15 #include "content/public/browser/web_contents_delegate.h"
16 #include "content/public/browser/web_contents_observer.h"
17 #include "ipc/ipc_channel.h"
18 #include "ui/gfx/geometry/size.h"
19 #include "ui/gfx/native_widget_types.h"
21 #if defined(OS_ANDROID)
22 #include "base/android/scoped_java_ref.h"
23 #elif defined(USE_AURA)
24 #if defined(OS_CHROMEOS)
25 namespace gfx {
26 class Screen;
28 namespace wm {
29 class WMTestHelper;
31 #endif // defined(OS_CHROMEOS)
32 namespace views {
33 class Widget;
34 class ViewsDelegate;
36 #endif // defined(USE_AURA)
38 class GURL;
39 namespace content {
41 #if defined(USE_AURA)
42 class ShellPlatformDataAura;
43 #endif
45 class BrowserContext;
46 class ShellDevToolsFrontend;
47 class ShellJavaScriptDialogManager;
48 class SiteInstance;
49 class WebContents;
51 // This represents one window of the Content Shell, i.e. all the UI including
52 // buttons and url bar, as well as the web content area.
53 class Shell : public WebContentsDelegate,
54 public WebContentsObserver {
55 public:
56 ~Shell() override;
58 void LoadURL(const GURL& url);
59 void LoadURLForFrame(const GURL& url, const std::string& frame_name);
60 void LoadDataWithBaseURL(const GURL& url,
61 const std::string& data,
62 const GURL& base_url);
63 void GoBackOrForward(int offset);
64 void Reload();
65 void Stop();
66 void UpdateNavigationControls(bool to_different_document);
67 void Close();
68 void ShowDevTools();
69 void ShowDevToolsForElementAt(int x, int y);
70 void CloseDevTools();
71 #if defined(OS_MACOSX)
72 // Resizes the web content view to the given dimensions.
73 void SizeTo(const gfx::Size& content_size);
74 #endif
76 // Do one time initialization at application startup.
77 static void Initialize();
79 static Shell* CreateNewWindow(BrowserContext* browser_context,
80 const GURL& url,
81 SiteInstance* site_instance,
82 const gfx::Size& initial_size);
84 // Returns the Shell object corresponding to the given RenderViewHost.
85 static Shell* FromRenderViewHost(RenderViewHost* rvh);
87 // Returns the currently open windows.
88 static std::vector<Shell*>& windows() { return windows_; }
90 // Closes all windows and returns. This runs a message loop.
91 static void CloseAllWindows();
93 // Used for content_browsertests. Called once.
94 static void SetShellCreatedCallback(
95 base::Callback<void(Shell*)> shell_created_callback);
97 WebContents* web_contents() const { return web_contents_.get(); }
98 gfx::NativeWindow window() { return window_; }
100 #if defined(OS_MACOSX)
101 // Public to be called by an ObjC bridge object.
102 void ActionPerformed(int control);
103 void URLEntered(std::string url_string);
104 #elif defined(OS_ANDROID)
105 // Registers the Android Java to native methods.
106 static bool Register(JNIEnv* env);
107 #endif
109 // WebContentsDelegate
110 WebContents* OpenURLFromTab(WebContents* source,
111 const OpenURLParams& params) override;
112 void AddNewContents(WebContents* source,
113 WebContents* new_contents,
114 WindowOpenDisposition disposition,
115 const gfx::Rect& initial_rect,
116 bool user_gesture,
117 bool* was_blocked) override;
118 void LoadingStateChanged(WebContents* source,
119 bool to_different_document) override;
120 #if defined(OS_ANDROID)
121 void LoadProgressChanged(WebContents* source, double progress) override;
122 #endif
123 void EnterFullscreenModeForTab(WebContents* web_contents,
124 const GURL& origin) override;
125 void ExitFullscreenModeForTab(WebContents* web_contents) override;
126 bool IsFullscreenForTabOrPending(
127 const WebContents* web_contents) const override;
128 blink::WebDisplayMode GetDisplayMode(
129 const WebContents* web_contents) const override;
130 void RequestToLockMouse(WebContents* web_contents,
131 bool user_gesture,
132 bool last_unlocked_by_target) override;
133 void CloseContents(WebContents* source) override;
134 bool CanOverscrollContent() const override;
135 void DidNavigateMainFramePostCommit(WebContents* web_contents) override;
136 JavaScriptDialogManager* GetJavaScriptDialogManager(
137 WebContents* source) override;
138 #if defined(OS_MACOSX)
139 void HandleKeyboardEvent(WebContents* source,
140 const NativeWebKeyboardEvent& event) override;
141 #endif
142 bool AddMessageToConsole(WebContents* source,
143 int32 level,
144 const base::string16& message,
145 int32 line_no,
146 const base::string16& source_id) override;
147 void RendererUnresponsive(WebContents* source) override;
148 void ActivateContents(WebContents* contents) override;
149 void DeactivateContents(WebContents* contents) override;
150 void WorkerCrashed(WebContents* source) override;
151 bool HandleContextMenu(const content::ContextMenuParams& params) override;
153 static gfx::Size GetShellDefaultSize();
155 private:
156 enum UIControl {
157 BACK_BUTTON,
158 FORWARD_BUTTON,
159 STOP_BUTTON
162 class DevToolsWebContentsObserver;
164 explicit Shell(WebContents* web_contents);
166 // Helper to create a new Shell given a newly created WebContents.
167 static Shell* CreateShell(WebContents* web_contents,
168 const gfx::Size& initial_size);
170 // Helper for one time initialization of application
171 static void PlatformInitialize(const gfx::Size& default_window_size);
172 // Helper for one time deinitialization of platform specific state.
173 static void PlatformExit();
175 // Adjust the size when Blink sends 0 for width and/or height.
176 // This happens when Blink requests a default-sized window.
177 static gfx::Size AdjustWindowSize(const gfx::Size& initial_size);
179 // All the methods that begin with Platform need to be implemented by the
180 // platform specific Shell implementation.
181 // Called from the destructor to let each platform do any necessary cleanup.
182 void PlatformCleanUp();
183 // Creates the main window GUI.
184 void PlatformCreateWindow(int width, int height);
185 // Links the WebContents into the newly created window.
186 void PlatformSetContents();
187 // Resize the content area and GUI.
188 void PlatformResizeSubViews();
189 // Enable/disable a button.
190 void PlatformEnableUIControl(UIControl control, bool is_enabled);
191 // Updates the url in the url bar.
192 void PlatformSetAddressBarURL(const GURL& url);
193 // Sets whether the spinner is spinning.
194 void PlatformSetIsLoading(bool loading);
195 // Set the title of shell window
196 void PlatformSetTitle(const base::string16& title);
197 // User right-clicked on the web view
198 bool PlatformHandleContextMenu(const content::ContextMenuParams& params);
199 #if defined(OS_ANDROID)
200 void PlatformToggleFullscreenModeForTab(WebContents* web_contents,
201 bool enter_fullscreen);
202 bool PlatformIsFullscreenForTabOrPending(
203 const WebContents* web_contents) const;
204 #endif
206 gfx::NativeView GetContentView();
208 void ToggleFullscreenModeForTab(WebContents* web_contents,
209 bool enter_fullscreen);
210 // WebContentsObserver
211 void TitleWasSet(NavigationEntry* entry, bool explicit_set) override;
213 void InnerShowDevTools();
214 void OnDevToolsWebContentsDestroyed();
216 scoped_ptr<ShellJavaScriptDialogManager> dialog_manager_;
218 scoped_ptr<WebContents> web_contents_;
220 scoped_ptr<DevToolsWebContentsObserver> devtools_observer_;
221 ShellDevToolsFrontend* devtools_frontend_;
223 bool is_fullscreen_;
225 gfx::NativeWindow window_;
226 gfx::NativeEditView url_edit_view_;
228 gfx::Size content_size_;
230 #if defined(OS_ANDROID)
231 base::android::ScopedJavaGlobalRef<jobject> java_object_;
232 #elif defined(USE_AURA)
233 #if defined(OS_CHROMEOS)
234 static wm::WMTestHelper* wm_test_helper_;
235 static gfx::Screen* test_screen_;
236 #endif
237 #if defined(TOOLKIT_VIEWS)
238 static views::ViewsDelegate* views_delegate_;
240 views::Widget* window_widget_;
241 #endif // defined(TOOLKIT_VIEWS)
242 static ShellPlatformDataAura* platform_;
243 #endif // defined(USE_AURA)
245 bool headless_;
247 // A container of all the open windows. We use a vector so we can keep track
248 // of ordering.
249 static std::vector<Shell*> windows_;
251 static base::Callback<void(Shell*)> shell_created_callback_;
253 // True if the destructur of Shell should post a quit closure on the current
254 // message loop if the destructed Shell object was the last one.
255 static bool quit_message_loop_;
258 } // namespace content
260 #endif // CONTENT_SHELL_BROWSER_SHELL_H_