Add ICU message format support
[chromium-blink-merge.git] / content / shell / browser / shell.h
blobcf461712b130146f79d93233482713c36671b8ce
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 bool HandleContextMenu(const content::ContextMenuParams& params) override;
152 static gfx::Size GetShellDefaultSize();
154 private:
155 enum UIControl {
156 BACK_BUTTON,
157 FORWARD_BUTTON,
158 STOP_BUTTON
161 class DevToolsWebContentsObserver;
163 explicit Shell(WebContents* web_contents);
165 // Helper to create a new Shell given a newly created WebContents.
166 static Shell* CreateShell(WebContents* web_contents,
167 const gfx::Size& initial_size);
169 // Helper for one time initialization of application
170 static void PlatformInitialize(const gfx::Size& default_window_size);
171 // Helper for one time deinitialization of platform specific state.
172 static void PlatformExit();
174 // Adjust the size when Blink sends 0 for width and/or height.
175 // This happens when Blink requests a default-sized window.
176 static gfx::Size AdjustWindowSize(const gfx::Size& initial_size);
178 // All the methods that begin with Platform need to be implemented by the
179 // platform specific Shell implementation.
180 // Called from the destructor to let each platform do any necessary cleanup.
181 void PlatformCleanUp();
182 // Creates the main window GUI.
183 void PlatformCreateWindow(int width, int height);
184 // Links the WebContents into the newly created window.
185 void PlatformSetContents();
186 // Resize the content area and GUI.
187 void PlatformResizeSubViews();
188 // Enable/disable a button.
189 void PlatformEnableUIControl(UIControl control, bool is_enabled);
190 // Updates the url in the url bar.
191 void PlatformSetAddressBarURL(const GURL& url);
192 // Sets whether the spinner is spinning.
193 void PlatformSetIsLoading(bool loading);
194 // Set the title of shell window
195 void PlatformSetTitle(const base::string16& title);
196 // User right-clicked on the web view
197 bool PlatformHandleContextMenu(const content::ContextMenuParams& params);
198 #if defined(OS_ANDROID)
199 void PlatformToggleFullscreenModeForTab(WebContents* web_contents,
200 bool enter_fullscreen);
201 bool PlatformIsFullscreenForTabOrPending(
202 const WebContents* web_contents) const;
203 #endif
205 gfx::NativeView GetContentView();
207 void ToggleFullscreenModeForTab(WebContents* web_contents,
208 bool enter_fullscreen);
209 // WebContentsObserver
210 void TitleWasSet(NavigationEntry* entry, bool explicit_set) override;
212 void InnerShowDevTools();
213 void OnDevToolsWebContentsDestroyed();
215 scoped_ptr<ShellJavaScriptDialogManager> dialog_manager_;
217 scoped_ptr<WebContents> web_contents_;
219 scoped_ptr<DevToolsWebContentsObserver> devtools_observer_;
220 ShellDevToolsFrontend* devtools_frontend_;
222 bool is_fullscreen_;
224 gfx::NativeWindow window_;
225 gfx::NativeEditView url_edit_view_;
227 gfx::Size content_size_;
229 #if defined(OS_ANDROID)
230 base::android::ScopedJavaGlobalRef<jobject> java_object_;
231 #elif defined(USE_AURA)
232 #if defined(OS_CHROMEOS)
233 static wm::WMTestHelper* wm_test_helper_;
234 static gfx::Screen* test_screen_;
235 #endif
236 #if defined(TOOLKIT_VIEWS)
237 static views::ViewsDelegate* views_delegate_;
239 views::Widget* window_widget_;
240 #endif // defined(TOOLKIT_VIEWS)
241 static ShellPlatformDataAura* platform_;
242 #endif // defined(USE_AURA)
244 bool headless_;
246 // A container of all the open windows. We use a vector so we can keep track
247 // of ordering.
248 static std::vector<Shell*> windows_;
250 static base::Callback<void(Shell*)> shell_created_callback_;
252 // True if the destructur of Shell should post a quit closure on the current
253 // message loop if the destructed Shell object was the last one.
254 static bool quit_message_loop_;
257 } // namespace content
259 #endif // CONTENT_SHELL_BROWSER_SHELL_H_