Roll src/third_party/skia 2440fcd:4de8c3a
[chromium-blink-merge.git] / content / shell / browser / shell.h
blobf6dfe1be0e6104bd0e0b6bbc54ad7cd1f394670b
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 scoped_ptr<BluetoothChooser> RunBluetoothChooser(
139 WebContents* web_contents,
140 const BluetoothChooser::EventHandler& event_handler,
141 const GURL& origin) override;
142 #if defined(OS_MACOSX)
143 void HandleKeyboardEvent(WebContents* source,
144 const NativeWebKeyboardEvent& event) override;
145 #endif
146 bool AddMessageToConsole(WebContents* source,
147 int32 level,
148 const base::string16& message,
149 int32 line_no,
150 const base::string16& source_id) override;
151 void RendererUnresponsive(WebContents* source) override;
152 void ActivateContents(WebContents* contents) override;
153 void DeactivateContents(WebContents* contents) override;
154 bool HandleContextMenu(const content::ContextMenuParams& params) override;
156 static gfx::Size GetShellDefaultSize();
158 private:
159 enum UIControl {
160 BACK_BUTTON,
161 FORWARD_BUTTON,
162 STOP_BUTTON
165 class DevToolsWebContentsObserver;
167 explicit Shell(WebContents* web_contents);
169 // Helper to create a new Shell given a newly created WebContents.
170 static Shell* CreateShell(WebContents* web_contents,
171 const gfx::Size& initial_size);
173 // Helper for one time initialization of application
174 static void PlatformInitialize(const gfx::Size& default_window_size);
175 // Helper for one time deinitialization of platform specific state.
176 static void PlatformExit();
178 // Adjust the size when Blink sends 0 for width and/or height.
179 // This happens when Blink requests a default-sized window.
180 static gfx::Size AdjustWindowSize(const gfx::Size& initial_size);
182 // All the methods that begin with Platform need to be implemented by the
183 // platform specific Shell implementation.
184 // Called from the destructor to let each platform do any necessary cleanup.
185 void PlatformCleanUp();
186 // Creates the main window GUI.
187 void PlatformCreateWindow(int width, int height);
188 // Links the WebContents into the newly created window.
189 void PlatformSetContents();
190 // Resize the content area and GUI.
191 void PlatformResizeSubViews();
192 // Enable/disable a button.
193 void PlatformEnableUIControl(UIControl control, bool is_enabled);
194 // Updates the url in the url bar.
195 void PlatformSetAddressBarURL(const GURL& url);
196 // Sets whether the spinner is spinning.
197 void PlatformSetIsLoading(bool loading);
198 // Set the title of shell window
199 void PlatformSetTitle(const base::string16& title);
200 // User right-clicked on the web view
201 bool PlatformHandleContextMenu(const content::ContextMenuParams& params);
202 #if defined(OS_ANDROID)
203 void PlatformToggleFullscreenModeForTab(WebContents* web_contents,
204 bool enter_fullscreen);
205 bool PlatformIsFullscreenForTabOrPending(
206 const WebContents* web_contents) const;
207 #endif
209 gfx::NativeView GetContentView();
211 void ToggleFullscreenModeForTab(WebContents* web_contents,
212 bool enter_fullscreen);
213 // WebContentsObserver
214 void TitleWasSet(NavigationEntry* entry, bool explicit_set) override;
216 void InnerShowDevTools();
217 void OnDevToolsWebContentsDestroyed();
219 scoped_ptr<ShellJavaScriptDialogManager> dialog_manager_;
221 scoped_ptr<WebContents> web_contents_;
223 scoped_ptr<DevToolsWebContentsObserver> devtools_observer_;
224 ShellDevToolsFrontend* devtools_frontend_;
226 bool is_fullscreen_;
228 gfx::NativeWindow window_;
229 gfx::NativeEditView url_edit_view_;
231 gfx::Size content_size_;
233 #if defined(OS_ANDROID)
234 base::android::ScopedJavaGlobalRef<jobject> java_object_;
235 #elif defined(USE_AURA)
236 #if defined(OS_CHROMEOS)
237 static wm::WMTestHelper* wm_test_helper_;
238 static gfx::Screen* test_screen_;
239 #endif
240 #if defined(TOOLKIT_VIEWS)
241 static views::ViewsDelegate* views_delegate_;
243 views::Widget* window_widget_;
244 #endif // defined(TOOLKIT_VIEWS)
245 static ShellPlatformDataAura* platform_;
246 #endif // defined(USE_AURA)
248 bool headless_;
250 // A container of all the open windows. We use a vector so we can keep track
251 // of ordering.
252 static std::vector<Shell*> windows_;
254 static base::Callback<void(Shell*)> shell_created_callback_;
256 // True if the destructur of Shell should post a quit closure on the current
257 // message loop if the destructed Shell object was the last one.
258 static bool quit_message_loop_;
261 } // namespace content
263 #endif // CONTENT_SHELL_BROWSER_SHELL_H_