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

Side by Side Diff: extensions/browser/app_window/app_window.h

Issue 616253002: Extract NativeAppWindow from src/extensions Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: might fix athena. similarity=33 Created 6 years, 2 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef EXTENSIONS_BROWSER_APP_WINDOW_APP_WINDOW_H_ 5 #ifndef EXTENSIONS_BROWSER_APP_WINDOW_APP_WINDOW_H_
6 #define EXTENSIONS_BROWSER_APP_WINDOW_APP_WINDOW_H_ 6 #define EXTENSIONS_BROWSER_APP_WINDOW_APP_WINDOW_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
13 #include "components/native_app_window/app_window_create_params.h"
14 #include "components/native_app_window/native_app_window_delegate.h"
13 #include "components/sessions/session_id.h" 15 #include "components/sessions/session_id.h"
14 #include "components/web_modal/popup_manager.h" 16 #include "components/web_modal/popup_manager.h"
15 #include "components/web_modal/web_contents_modal_dialog_manager_delegate.h" 17 #include "components/web_modal/web_contents_modal_dialog_manager_delegate.h"
16 #include "content/public/browser/web_contents_delegate.h" 18 #include "content/public/browser/web_contents_delegate.h"
17 #include "content/public/browser/web_contents_observer.h" 19 #include "content/public/browser/web_contents_observer.h"
18 #include "extensions/browser/extension_icon_image.h" 20 #include "extensions/browser/extension_icon_image.h"
19 #include "extensions/browser/extension_registry_observer.h" 21 #include "extensions/browser/extension_registry_observer.h"
20 #include "ui/base/ui_base_types.h" // WindowShowState 22 #include "ui/base/ui_base_types.h" // WindowShowState
21 #include "ui/gfx/image/image.h" 23 #include "ui/gfx/image/image.h"
22 #include "ui/gfx/rect.h" 24 #include "ui/gfx/rect.h"
23 25
24 class GURL; 26 class GURL;
25 class SkRegion; 27 class SkRegion;
26 28
27 namespace base { 29 namespace base {
28 class DictionaryValue; 30 class DictionaryValue;
29 } 31 }
30 32
31 namespace content { 33 namespace content {
32 class BrowserContext; 34 class BrowserContext;
33 class WebContents; 35 class WebContents;
34 } 36 }
35 37
38 namespace native_app_window {
39 struct DraggableRegion;
40 class NativeAppWindow;
41 }
42
36 namespace ui { 43 namespace ui {
37 class BaseWindow; 44 class BaseWindow;
38 } 45 }
39 46
40 namespace extensions { 47 namespace extensions {
41 48
42 class AppDelegate; 49 class AppDelegate;
43 class AppWebContentsHelper; 50 class AppWebContentsHelper;
44 class Extension; 51 class Extension;
45 class ExtensionRegistry; 52 class ExtensionRegistry;
46 class NativeAppWindow;
47 class PlatformAppBrowserTest; 53 class PlatformAppBrowserTest;
48 class WindowController; 54 class WindowController;
49 55
50 struct DraggableRegion;
51
52 // Manages the web contents for app windows. The implementation for this 56 // Manages the web contents for app windows. The implementation for this
53 // class should create and maintain the WebContents for the window, and handle 57 // class should create and maintain the WebContents for the window, and handle
54 // any message passing between the web contents and the extension system or 58 // any message passing between the web contents and the extension system or
55 // native window. 59 // native window.
56 class AppWindowContents { 60 class AppWindowContents {
57 public: 61 public:
58 AppWindowContents() {} 62 AppWindowContents() {}
59 virtual ~AppWindowContents() {} 63 virtual ~AppWindowContents() {}
60 64
61 // Called to initialize the WebContents, before the app window is created. 65 // Called to initialize the WebContents, before the app window is created.
62 virtual void Initialize(content::BrowserContext* context, 66 virtual void Initialize(content::BrowserContext* context,
63 const GURL& url) = 0; 67 const GURL& url) = 0;
64 68
65 // Called to load the contents, after the app window is created. 69 // Called to load the contents, after the app window is created.
66 virtual void LoadContents(int32 creator_process_id) = 0; 70 virtual void LoadContents(int32 creator_process_id) = 0;
67 71
68 // Called when the native window changes. 72 // Called when the native window changes.
69 virtual void NativeWindowChanged(NativeAppWindow* native_app_window) = 0; 73 virtual void NativeWindowChanged(
74 native_app_window::NativeAppWindow* native_app_window) = 0;
70 75
71 // Called when the native window closes. 76 // Called when the native window closes.
72 virtual void NativeWindowClosed() = 0; 77 virtual void NativeWindowClosed() = 0;
73 78
74 // Called in tests when the window is shown 79 // Called in tests when the window is shown
75 virtual void DispatchWindowShownForTests() const = 0; 80 virtual void DispatchWindowShownForTests() const = 0;
76 81
77 virtual content::WebContents* GetWebContents() const = 0; 82 virtual content::WebContents* GetWebContents() const = 0;
78 83
79 private: 84 private:
80 DISALLOW_COPY_AND_ASSIGN(AppWindowContents); 85 DISALLOW_COPY_AND_ASSIGN(AppWindowContents);
81 }; 86 };
82 87
83 // AppWindow is the type of window used by platform apps. App windows 88 // AppWindow is the type of window used by platform apps. App windows
84 // have a WebContents but none of the chrome of normal browser windows. 89 // have a WebContents but none of the chrome of normal browser windows.
85 class AppWindow : public content::WebContentsDelegate, 90 class AppWindow : public content::WebContentsDelegate,
86 public content::WebContentsObserver, 91 public content::WebContentsObserver,
87 public web_modal::WebContentsModalDialogManagerDelegate, 92 public web_modal::WebContentsModalDialogManagerDelegate,
88 public IconImage::Observer, 93 public IconImage::Observer,
89 public ExtensionRegistryObserver { 94 public ExtensionRegistryObserver,
95 public native_app_window::NativeAppWindowDelegate {
90 public: 96 public:
91 enum WindowType { 97 // TODO(tapted): Delete these forwarding declarations.
92 WINDOW_TYPE_DEFAULT = 1 << 0, // Default app window. 98 typedef native_app_window::AppWindowCreateParams CreateParams;
93 WINDOW_TYPE_PANEL = 1 << 1, // OS controlled panel window (Ash only). 99 typedef native_app_window::BoundsSpecification BoundsSpecification;
94 WINDOW_TYPE_V1_PANEL = 1 << 2, // For apps v1 support in Ash; deprecate
95 // with v1 apps.
96 };
97
98 enum Frame {
99 FRAME_CHROME, // Chrome-style window frame.
100 FRAME_NONE, // Frameless window.
101 };
102
103 enum FullscreenType {
104 // Not fullscreen.
105 FULLSCREEN_TYPE_NONE = 0,
106
107 // Fullscreen entered by the app.window api.
108 FULLSCREEN_TYPE_WINDOW_API = 1 << 0,
109
110 // Fullscreen entered by HTML requestFullscreen().
111 FULLSCREEN_TYPE_HTML_API = 1 << 1,
112
113 // Fullscreen entered by the OS. ChromeOS uses this type of fullscreen to
114 // enter immersive fullscreen when the user hits the <F4> key.
115 FULLSCREEN_TYPE_OS = 1 << 2,
116
117 // Fullscreen mode that could not be exited by the user. ChromeOS uses
118 // this type of fullscreen to run an app in kiosk mode.
119 FULLSCREEN_TYPE_FORCED = 1 << 3,
120 };
121
122 struct BoundsSpecification {
123 // INT_MIN represents an unspecified position component.
124 static const int kUnspecifiedPosition;
125
126 BoundsSpecification();
127 ~BoundsSpecification();
128
129 // INT_MIN designates 'unspecified' for the position components, and 0
130 // designates 'unspecified' for the size components. When unspecified,
131 // they should be replaced with a default value.
132 gfx::Rect bounds;
133
134 gfx::Size minimum_size;
135 gfx::Size maximum_size;
136
137 // Reset the bounds fields to their 'unspecified' values. The minimum and
138 // maximum size constraints remain unchanged.
139 void ResetBounds();
140 };
141
142 struct CreateParams {
143 CreateParams();
144 ~CreateParams();
145
146 WindowType window_type;
147 Frame frame;
148
149 bool has_frame_color;
150 SkColor active_frame_color;
151 SkColor inactive_frame_color;
152 bool alpha_enabled;
153 bool is_ime_window;
154
155 // The initial content/inner bounds specification (excluding any window
156 // decorations).
157 BoundsSpecification content_spec;
158
159 // The initial window/outer bounds specification (including window
160 // decorations).
161 BoundsSpecification window_spec;
162
163 std::string window_key;
164
165 // The process ID of the process that requested the create.
166 int32 creator_process_id;
167
168 // Initial state of the window.
169 ui::WindowShowState state;
170
171 // If true, don't show the window after creation.
172 bool hidden;
173
174 // If true, the window will be resizable by the user. Defaults to true.
175 bool resizable;
176
177 // If true, the window will be focused on creation. Defaults to true.
178 bool focused;
179
180 // If true, the window will stay on top of other windows that are not
181 // configured to be always on top. Defaults to false.
182 bool always_on_top;
183
184 // If true, the window will be visible on all workspaces. Defaults to false.
185 bool visible_on_all_workspaces;
186
187 // The API enables developers to specify content or window bounds. This
188 // function combines them into a single, constrained window size.
189 gfx::Rect GetInitialWindowBounds(const gfx::Insets& frame_insets) const;
190
191 // The API enables developers to specify content or window size constraints.
192 // These functions combine them so that we can work with one set of
193 // constraints.
194 gfx::Size GetContentMinimumSize(const gfx::Insets& frame_insets) const;
195 gfx::Size GetContentMaximumSize(const gfx::Insets& frame_insets) const;
196 gfx::Size GetWindowMinimumSize(const gfx::Insets& frame_insets) const;
197 gfx::Size GetWindowMaximumSize(const gfx::Insets& frame_insets) const;
198 };
199
200 // Convert draggable regions in raw format to SkRegion format. Caller is
201 // responsible for deleting the returned SkRegion instance.
202 static SkRegion* RawDraggableRegionsToSkRegion(
203 const std::vector<DraggableRegion>& regions);
204 100
205 // The constructor and Init methods are public for constructing a AppWindow 101 // The constructor and Init methods are public for constructing a AppWindow
206 // with a non-standard render interface (e.g. v1 apps using Ash Panels). 102 // with a non-standard render interface (e.g. v1 apps using Ash Panels).
207 // Normally AppWindow::Create should be used. 103 // Normally AppWindow::Create should be used.
208 // Takes ownership of |app_delegate| and |delegate|. 104 // Takes ownership of |app_delegate| and |delegate|.
209 AppWindow(content::BrowserContext* context, 105 AppWindow(content::BrowserContext* context,
210 AppDelegate* app_delegate, 106 AppDelegate* app_delegate,
211 const Extension* extension); 107 const Extension* extension);
212 108
213 // Initializes the render interface, web contents, and native window. 109 // Initializes the render interface, web contents, and native window.
214 // |app_window_contents| will become owned by AppWindow. 110 // |app_window_contents| will become owned by AppWindow.
215 void Init(const GURL& url, 111 void Init(const GURL& url,
216 AppWindowContents* app_window_contents, 112 AppWindowContents* app_window_contents,
217 const CreateParams& params); 113 const CreateParams& params);
218 114
219 const std::string& window_key() const { return window_key_; } 115 const std::string& window_key() const { return window_key_; }
220 const SessionID& session_id() const { return session_id_; } 116 const SessionID& session_id() const { return session_id_; }
221 const std::string& extension_id() const { return extension_id_; } 117 const std::string& extension_id() const { return extension_id_; }
222 content::WebContents* web_contents() const; 118 content::WebContents* web_contents() const;
223 WindowType window_type() const { return window_type_; } 119 native_app_window::WindowType window_type() const { return window_type_; }
224 bool window_type_is_panel() const { 120 bool window_type_is_panel() const {
225 return (window_type_ == WINDOW_TYPE_PANEL || 121 return (window_type_ == native_app_window::WINDOW_TYPE_PANEL ||
226 window_type_ == WINDOW_TYPE_V1_PANEL); 122 window_type_ == native_app_window::WINDOW_TYPE_V1_PANEL);
227 } 123 }
228 content::BrowserContext* browser_context() const { return browser_context_; } 124 content::BrowserContext* browser_context() const { return browser_context_; }
229 const gfx::Image& app_icon() const { return app_icon_; } 125 const gfx::Image& app_icon() const { return app_icon_; }
230 const GURL& app_icon_url() const { return app_icon_url_; } 126 const GURL& app_icon_url() const { return app_icon_url_; }
231 const gfx::Image& badge_icon() const { return badge_icon_; } 127 const gfx::Image& badge_icon() const { return badge_icon_; }
232 const GURL& badge_icon_url() const { return badge_icon_url_; } 128 const GURL& badge_icon_url() const { return badge_icon_url_; }
233 bool is_hidden() const { return is_hidden_; } 129 bool is_hidden() const { return is_hidden_; }
234 130
235 const Extension* GetExtension() const; 131 const Extension* GetExtension() const;
236 NativeAppWindow* GetBaseWindow(); 132 native_app_window::NativeAppWindow* GetBaseWindow();
237 gfx::NativeWindow GetNativeWindow(); 133 gfx::NativeWindow GetNativeWindow();
238 134
239 // Returns the bounds that should be reported to the renderer. 135 // Returns the bounds that should be reported to the renderer.
240 gfx::Rect GetClientBounds() const; 136 gfx::Rect GetClientBounds() const;
241 137
242 // NativeAppWindows should call this to determine what the window's title
243 // is on startup and from within UpdateWindowTitle().
244 base::string16 GetTitle() const;
245
246 // Call to notify ShellRegistry and delete the window. Subclasses should
247 // invoke this method instead of using "delete this".
248 void OnNativeClose();
249
250 // Should be called by native implementations when the window size, position,
251 // or minimized/maximized state has changed.
252 void OnNativeWindowChanged();
253
254 // Should be called by native implementations when the window is activated.
255 void OnNativeWindowActivated();
256
257 // Specifies a url for the launcher icon. 138 // Specifies a url for the launcher icon.
258 void SetAppIconUrl(const GURL& icon_url); 139 void SetAppIconUrl(const GURL& icon_url);
259 140
260 // Specifies a url for the window badge. 141 // Specifies a url for the window badge.
261 void SetBadgeIconUrl(const GURL& icon_url); 142 void SetBadgeIconUrl(const GURL& icon_url);
262 143
263 // Clear the current badge. 144 // Clear the current badge.
264 void ClearBadge(); 145 void ClearBadge();
265 146
266 // Set the window shape. Passing a NULL |region| sets the default shape. 147 // Set the window shape. Passing a NULL |region| sets the default shape.
267 void UpdateShape(scoped_ptr<SkRegion> region); 148 void UpdateShape(scoped_ptr<SkRegion> region);
268 149
269 // Called from the render interface to modify the draggable regions. 150 // Called from the render interface to modify the draggable regions.
270 void UpdateDraggableRegions(const std::vector<DraggableRegion>& regions); 151 void UpdateDraggableRegions(
152 const std::vector<native_app_window::DraggableRegion>& regions);
271 153
272 // Updates the app image to |image|. Called internally from the image loader 154 // Updates the app image to |image|. Called internally from the image loader
273 // callback. Also called externally for v1 apps using Ash Panels. 155 // callback. Also called externally for v1 apps using Ash Panels.
274 void UpdateAppIcon(const gfx::Image& image); 156 void UpdateAppIcon(const gfx::Image& image);
275 157
276 // Enable or disable fullscreen mode. |type| specifies which type of 158 // Enable or disable fullscreen mode. |type| specifies which type of
277 // fullscreen mode to change (note that disabling one type of fullscreen may 159 // fullscreen mode to change (note that disabling one type of fullscreen may
278 // not exit fullscreen mode because a window may have a different type of 160 // not exit fullscreen mode because a window may have a different type of
279 // fullscreen enabled). If |type| is not FORCED, checks that the extension has 161 // fullscreen enabled). If |type| is not FORCED, checks that the extension has
280 // the required permission. 162 // the required permission.
281 void SetFullscreen(FullscreenType type, bool enable); 163 void SetFullscreen(native_app_window::FullscreenType type, bool enable);
282 164
283 // Returns true if the app window is in a fullscreen state. 165 // Returns true if the app window is in a fullscreen state.
284 bool IsFullscreen() const; 166 bool IsFullscreen() const;
285 167
286 // Returns true if the app window is in a forced fullscreen state (one that 168 // Returns true if the app window is in a forced fullscreen state (one that
287 // cannot be exited by the user). 169 // cannot be exited by the user).
288 bool IsForcedFullscreen() const; 170 bool IsForcedFullscreen() const;
289 171
290 // Returns true if the app window is in a fullscreen state entered from an 172 // Returns true if the app window is in a fullscreen state entered from an
291 // HTML API request. 173 // HTML API request.
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 // app. 226 // app.
345 void WindowEventsReady(); 227 void WindowEventsReady();
346 228
347 // Whether the app window wants to be alpha enabled. 229 // Whether the app window wants to be alpha enabled.
348 bool requested_alpha_enabled() const { return requested_alpha_enabled_; } 230 bool requested_alpha_enabled() const { return requested_alpha_enabled_; }
349 231
350 void SetAppWindowContentsForTesting(scoped_ptr<AppWindowContents> contents) { 232 void SetAppWindowContentsForTesting(scoped_ptr<AppWindowContents> contents) {
351 app_window_contents_ = contents.Pass(); 233 app_window_contents_ = contents.Pass();
352 } 234 }
353 235
236 // native_app_window::NativeAppWindowDelegate implementation.
237 virtual content::WebContents* GetWebContents() OVERRIDE;
238 virtual content::BrowserContext* GetBrowserContext() OVERRIDE;
239 virtual void OnNativeClose() OVERRIDE;
240 virtual void OnNativeWindowChanged() OVERRIDE;
241 virtual void OnNativeWindowActivated() OVERRIDE;
242 virtual bool RequestedAlphaEnabled() const OVERRIDE;
243 virtual base::string16 GetTitle() const OVERRIDE;
244 virtual native_app_window::WindowType GetWindowType() const OVERRIDE;
245 virtual bool WindowTypeIsPanel() const OVERRIDE;
246
354 protected: 247 protected:
355 virtual ~AppWindow(); 248 virtual ~AppWindow();
356 249
357 private: 250 private:
358 // PlatformAppBrowserTest needs access to web_contents() 251 // PlatformAppBrowserTest needs access to web_contents()
359 friend class PlatformAppBrowserTest; 252 friend class PlatformAppBrowserTest;
360 253
361 // content::WebContentsDelegate implementation. 254 // content::WebContentsDelegate implementation.
362 virtual void CloseContents(content::WebContents* contents) OVERRIDE; 255 virtual void CloseContents(content::WebContents* contents) OVERRIDE;
363 virtual bool ShouldSuppressDialogs() OVERRIDE; 256 virtual bool ShouldSuppressDialogs() OVERRIDE;
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 // not own this object. 378 // not own this object.
486 content::BrowserContext* browser_context_; 379 content::BrowserContext* browser_context_;
487 380
488 const std::string extension_id_; 381 const std::string extension_id_;
489 382
490 // Identifier that is used when saving and restoring geometry for this 383 // Identifier that is used when saving and restoring geometry for this
491 // window. 384 // window.
492 std::string window_key_; 385 std::string window_key_;
493 386
494 const SessionID session_id_; 387 const SessionID session_id_;
495 WindowType window_type_; 388 native_app_window::WindowType window_type_;
496 389
497 // Icon shown in the task bar. 390 // Icon shown in the task bar.
498 gfx::Image app_icon_; 391 gfx::Image app_icon_;
499 392
500 // Icon URL to be used for setting the app icon. If not empty, app_icon_ will 393 // Icon URL to be used for setting the app icon. If not empty, app_icon_ will
501 // be fetched and set using this URL. 394 // be fetched and set using this URL.
502 GURL app_icon_url_; 395 GURL app_icon_url_;
503 396
504 // An object to load the app's icon as an extension resource. 397 // An object to load the app's icon as an extension resource.
505 scoped_ptr<IconImage> app_icon_image_; 398 scoped_ptr<IconImage> app_icon_image_;
506 399
507 // Badge for icon shown in the task bar. 400 // Badge for icon shown in the task bar.
508 gfx::Image badge_icon_; 401 gfx::Image badge_icon_;
509 402
510 // URL to be used for setting the badge on the app icon. 403 // URL to be used for setting the badge on the app icon.
511 GURL badge_icon_url_; 404 GURL badge_icon_url_;
512 405
513 // An object to load the badge as an extension resource. 406 // An object to load the badge as an extension resource.
514 scoped_ptr<IconImage> badge_icon_image_; 407 scoped_ptr<IconImage> badge_icon_image_;
515 408
516 scoped_ptr<NativeAppWindow> native_app_window_; 409 scoped_ptr<native_app_window::NativeAppWindow> native_app_window_;
517 scoped_ptr<AppWindowContents> app_window_contents_; 410 scoped_ptr<AppWindowContents> app_window_contents_;
518 scoped_ptr<AppDelegate> app_delegate_; 411 scoped_ptr<AppDelegate> app_delegate_;
519 scoped_ptr<AppWebContentsHelper> helper_; 412 scoped_ptr<AppWebContentsHelper> helper_;
520 413
521 // Manages popup windows (bubbles, tab-modals) visible overlapping the 414 // Manages popup windows (bubbles, tab-modals) visible overlapping the
522 // app window. 415 // app window.
523 scoped_ptr<web_modal::PopupManager> popup_manager_; 416 scoped_ptr<web_modal::PopupManager> popup_manager_;
524 417
525 base::WeakPtrFactory<AppWindow> image_loader_ptr_factory_; 418 base::WeakPtrFactory<AppWindow> image_loader_ptr_factory_;
526 419
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 453
561 // Whether |alpha_enabled| was set in the CreateParams. 454 // Whether |alpha_enabled| was set in the CreateParams.
562 bool requested_alpha_enabled_; 455 bool requested_alpha_enabled_;
563 456
564 DISALLOW_COPY_AND_ASSIGN(AppWindow); 457 DISALLOW_COPY_AND_ASSIGN(AppWindow);
565 }; 458 };
566 459
567 } // namespace extensions 460 } // namespace extensions
568 461
569 #endif // EXTENSIONS_BROWSER_APP_WINDOW_APP_WINDOW_H_ 462 #endif // EXTENSIONS_BROWSER_APP_WINDOW_APP_WINDOW_H_
OLDNEW
« no previous file with comments | « extensions/browser/api/app_window/app_window_api.cc ('k') | extensions/browser/app_window/app_window.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698