Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(490)

Side by Side Diff: chrome/browser/ui/extensions/shell_window.h

Issue 16702003: Move ShellWindow into apps component. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: yar Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 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_EXTENSIONS_SHELL_WINDOW_H_
6 #define CHROME_BROWSER_UI_EXTENSIONS_SHELL_WINDOW_H_
7
8 #include "base/memory/scoped_ptr.h"
9 #include "base/memory/weak_ptr.h"
10 #include "chrome/browser/extensions/extension_keybinding_registry.h"
11 #include "chrome/browser/sessions/session_id.h"
12 #include "chrome/browser/ui/chrome_web_modal_dialog_manager_delegate.h"
13 #include "content/public/browser/notification_observer.h"
14 #include "content/public/browser/notification_registrar.h"
15 #include "content/public/browser/web_contents_delegate.h"
16 #include "content/public/common/console_message_level.h"
17 #include "ui/base/ui_base_types.h" // WindowShowState
18 #include "ui/gfx/image/image.h"
19 #include "ui/gfx/rect.h"
20
21 class GURL;
22 class Profile;
23 class NativeAppWindow;
24 class SkRegion;
25
26 namespace content {
27 class WebContents;
28 }
29
30 namespace extensions {
31 class Extension;
32 class PlatformAppBrowserTest;
33 class WindowController;
34
35 struct DraggableRegion;
36 }
37
38 namespace ui {
39 class BaseWindow;
40 }
41
42 // Manages the web contents for Shell Windows. The implementation for this
43 // class should create and maintain the WebContents for the window, and handle
44 // any message passing between the web contents and the extension system or
45 // native window.
46 class ShellWindowContents {
47 public:
48 ShellWindowContents() {}
49 virtual ~ShellWindowContents() {}
50
51 // Called to initialize the WebContents, before the app window is created.
52 virtual void Initialize(Profile* profile, const GURL& url) = 0;
53
54 // Called to load the contents, after the app window is created.
55 virtual void LoadContents(int32 creator_process_id) = 0;
56
57 // Called when the native window changes.
58 virtual void NativeWindowChanged(NativeAppWindow* native_app_window) = 0;
59
60 // Called when the native window closes.
61 virtual void NativeWindowClosed() = 0;
62
63 virtual content::WebContents* GetWebContents() const = 0;
64
65 private:
66 DISALLOW_COPY_AND_ASSIGN(ShellWindowContents);
67 };
68
69 // ShellWindow is the type of window used by platform apps. Shell windows
70 // have a WebContents but none of the chrome of normal browser windows.
71 class ShellWindow : public content::NotificationObserver,
72 public content::WebContentsDelegate,
73 public extensions::ExtensionKeybindingRegistry::Delegate,
74 public ChromeWebModalDialogManagerDelegate {
75 public:
76 enum WindowType {
77 WINDOW_TYPE_DEFAULT = 1 << 0, // Default shell window.
78 WINDOW_TYPE_PANEL = 1 << 1, // OS controlled panel window (Ash only).
79 WINDOW_TYPE_V1_PANEL = 1 << 2, // For apps v1 support in Ash; deprecate
80 // with v1 apps.
81 };
82
83 enum Frame {
84 FRAME_CHROME, // Chrome-style window frame.
85 FRAME_NONE, // Frameless window.
86 };
87
88 struct CreateParams {
89 CreateParams();
90 ~CreateParams();
91
92 WindowType window_type;
93 Frame frame;
94 bool transparent_background; // Only supported on ash.
95
96 // Specify the initial content bounds of the window (excluding any window
97 // decorations). INT_MIN designates 'unspecified' for the position
98 // components, and 0 for the size components. When unspecified, they should
99 // be replaced with a default value.
100 gfx::Rect bounds;
101
102 gfx::Size minimum_size;
103 gfx::Size maximum_size;
104
105 std::string window_key;
106
107 // The process ID of the process that requested the create.
108 int32 creator_process_id;
109
110 // Initial state of the window.
111 ui::WindowShowState state;
112
113 // If true, don't show the window after creation.
114 bool hidden;
115
116 // If true, the window will be resizable by the user. Defaults to true.
117 bool resizable;
118
119 // If true, the window will be focused on creation. Defaults to true.
120 bool focused;
121 };
122
123 // Helper function for creating and intiailizing a v2 app window.
124 static ShellWindow* Create(Profile* profile,
125 const extensions::Extension* extension,
126 const GURL& url,
127 const CreateParams& params);
128
129 // Convert draggable regions in raw format to SkRegion format. Caller is
130 // responsible for deleting the returned SkRegion instance.
131 static SkRegion* RawDraggableRegionsToSkRegion(
132 const std::vector<extensions::DraggableRegion>& regions);
133
134 // The constructor and Init methods are public for constructing a ShellWindow
135 // with a non-standard render interface (e.g. v1 apps using Ash Panels).
136 // Normally ShellWindow::Create should be used.
137 ShellWindow(Profile* profile, const extensions::Extension* extension);
138
139 // Initializes the render interface, web contents, and native window.
140 // |shell_window_contents| will become owned by ShellWindow.
141 void Init(const GURL& url,
142 ShellWindowContents* shell_window_contents,
143 const CreateParams& params);
144
145
146 const std::string& window_key() const { return window_key_; }
147 const SessionID& session_id() const { return session_id_; }
148 const extensions::Extension* extension() const { return extension_; }
149 const std::string& extension_id() const { return extension_id_; }
150 content::WebContents* web_contents() const;
151 WindowType window_type() const { return window_type_; }
152 bool window_type_is_panel() const {
153 return (window_type_ == WINDOW_TYPE_PANEL ||
154 window_type_ == WINDOW_TYPE_V1_PANEL);
155 }
156 Profile* profile() const { return profile_; }
157 const gfx::Image& app_icon() const { return app_icon_; }
158 const GURL& app_icon_url() { return app_icon_url_; }
159
160 NativeAppWindow* GetBaseWindow();
161 gfx::NativeWindow GetNativeWindow();
162
163 // Returns the bounds that should be reported to the renderer.
164 gfx::Rect GetClientBounds() const;
165
166 // This will return a slightly smaller icon then the app_icon to be used in
167 // application lists.
168 scoped_ptr<gfx::Image> GetAppListIcon();
169
170 // NativeAppWindows should call this to determine what the window's title
171 // is on startup and from within UpdateWindowTitle().
172 string16 GetTitle() const;
173
174 // Call to notify ShellRegistry and delete the window. Subclasses should
175 // invoke this method instead of using "delete this".
176 void OnNativeClose();
177
178 // Should be called by native implementations when the window size, position,
179 // or minimized/maximized state has changed.
180 void OnNativeWindowChanged();
181
182 // Should be called by native implementations when the window is activated.
183 void OnNativeWindowActivated();
184
185 // Specifies a url for the launcher icon.
186 void SetAppIconUrl(const GURL& icon_url);
187
188 // Called from the render interface to modify the draggable regions.
189 void UpdateDraggableRegions(
190 const std::vector<extensions::DraggableRegion>& regions);
191
192 // Updates the app image to |image|. Called internally from the image loader
193 // callback. Also called externally for v1 apps using Ash Panels.
194 void UpdateAppIcon(const gfx::Image& image);
195
196 // Transitions window into fullscreen, maximized, minimized or restores based
197 // on chrome.app.window API.
198 void Fullscreen();
199 void Maximize();
200 void Minimize();
201 void Restore();
202
203 ShellWindowContents* shell_window_contents_for_test() {
204 return shell_window_contents_.get();
205 }
206
207 static void DisableExternalOpenForTesting();
208
209 protected:
210 virtual ~ShellWindow();
211
212 private:
213 // PlatformAppBrowserTest needs access to web_contents()
214 friend class extensions::PlatformAppBrowserTest;
215
216 // content::WebContentsDelegate implementation.
217 virtual void CloseContents(content::WebContents* contents) OVERRIDE;
218 virtual bool ShouldSuppressDialogs() OVERRIDE;
219 virtual content::ColorChooser* OpenColorChooser(
220 content::WebContents* web_contents, SkColor color) OVERRIDE;
221 virtual void RunFileChooser(
222 content::WebContents* tab,
223 const content::FileChooserParams& params) OVERRIDE;
224 virtual bool IsPopupOrPanel(
225 const content::WebContents* source) const OVERRIDE;
226 virtual void MoveContents(
227 content::WebContents* source, const gfx::Rect& pos) OVERRIDE;
228 virtual void NavigationStateChanged(const content::WebContents* source,
229 unsigned changed_flags) OVERRIDE;
230 virtual void ToggleFullscreenModeForTab(content::WebContents* source,
231 bool enter_fullscreen) OVERRIDE;
232 virtual bool IsFullscreenForTabOrPending(
233 const content::WebContents* source) const OVERRIDE;
234 virtual void RequestMediaAccessPermission(
235 content::WebContents* web_contents,
236 const content::MediaStreamRequest& request,
237 const content::MediaResponseCallback& callback) OVERRIDE;
238 virtual content::WebContents* OpenURLFromTab(
239 content::WebContents* source,
240 const content::OpenURLParams& params) OVERRIDE;
241 virtual void AddNewContents(content::WebContents* source,
242 content::WebContents* new_contents,
243 WindowOpenDisposition disposition,
244 const gfx::Rect& initial_pos,
245 bool user_gesture,
246 bool* was_blocked) OVERRIDE;
247 virtual void HandleKeyboardEvent(
248 content::WebContents* source,
249 const content::NativeWebKeyboardEvent& event) OVERRIDE;
250 virtual void RequestToLockMouse(content::WebContents* web_contents,
251 bool user_gesture,
252 bool last_unlocked_by_target) OVERRIDE;
253
254 // content::NotificationObserver implementation.
255 virtual void Observe(int type,
256 const content::NotificationSource& source,
257 const content::NotificationDetails& details) OVERRIDE;
258
259 // Helper method to add a message to the renderer's DevTools console.
260 void AddMessageToDevToolsConsole(content::ConsoleMessageLevel level,
261 const std::string& message);
262
263 // Saves the window geometry/position/screen bounds.
264 void SaveWindowPosition();
265
266 // Helper method to adjust the cached bounds so that we can make sure it can
267 // be visible on the screen. See http://crbug.com/145752 .
268 void AdjustBoundsToBeVisibleOnScreen(
269 const gfx::Rect& cached_bounds,
270 const gfx::Rect& cached_screen_bounds,
271 const gfx::Rect& current_screen_bounds,
272 const gfx::Size& minimum_size,
273 gfx::Rect* bounds) const;
274
275 // Load the app's image, firing a load state change when loaded.
276 void UpdateExtensionAppIcon();
277
278 void OnImageLoaded(const gfx::Image& image);
279
280 // extensions::ExtensionKeybindingRegistry::Delegate implementation.
281 virtual extensions::ActiveTabPermissionGranter*
282 GetActiveTabPermissionGranter() OVERRIDE;
283
284 // web_modal::WebContentsModalDialogManagerDelegate implementation.
285 virtual web_modal::WebContentsModalDialogHost*
286 GetWebContentsModalDialogHost() OVERRIDE;
287
288 // Callback from web_contents()->DownloadFavicon.
289 void DidDownloadFavicon(int id,
290 int http_status_code,
291 const GURL& image_url,
292 int requested_size,
293 const std::vector<SkBitmap>& bitmaps);
294
295 Profile* profile_; // weak pointer - owned by ProfileManager.
296 // weak pointer - owned by ExtensionService.
297 const extensions::Extension* extension_;
298 const std::string extension_id_;
299
300 // Identifier that is used when saving and restoring geometry for this
301 // window.
302 std::string window_key_;
303
304 const SessionID session_id_;
305 WindowType window_type_;
306 content::NotificationRegistrar registrar_;
307
308 // Icon shown in the task bar.
309 gfx::Image app_icon_;
310
311 // Icon URL to be used for setting the app icon. If not empty, app_icon_ will
312 // be fetched and set using this URL.
313 GURL app_icon_url_;
314
315 scoped_ptr<NativeAppWindow> native_app_window_;
316 scoped_ptr<ShellWindowContents> shell_window_contents_;
317
318 base::WeakPtrFactory<ShellWindow> image_loader_ptr_factory_;
319
320 // Fullscreen entered by app.window api.
321 bool fullscreen_for_window_api_;
322 // Fullscreen entered by HTML requestFullscreen.
323 bool fullscreen_for_tab_;
324
325 DISALLOW_COPY_AND_ASSIGN(ShellWindow);
326 };
327
328 #endif // CHROME_BROWSER_UI_EXTENSIONS_SHELL_WINDOW_H_
OLDNEW
« no previous file with comments | « chrome/browser/ui/extensions/native_app_window.h ('k') | chrome/browser/ui/extensions/shell_window.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698