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

Side by Side Diff: apps/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
« no previous file with comments | « apps/apps.gypi ('k') | apps/shell_window.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 CHROME_BROWSER_UI_EXTENSIONS_SHELL_WINDOW_H_ 5 #ifndef CHROME_BROWSER_UI_EXTENSIONS_SHELL_WINDOW_H_
6 #define CHROME_BROWSER_UI_EXTENSIONS_SHELL_WINDOW_H_ 6 #define CHROME_BROWSER_UI_EXTENSIONS_SHELL_WINDOW_H_
7 7
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/memory/weak_ptr.h" 9 #include "base/memory/weak_ptr.h"
10 #include "chrome/browser/extensions/extension_keybinding_registry.h" 10 #include "chrome/browser/extensions/extension_keybinding_registry.h"
11 #include "chrome/browser/sessions/session_id.h" 11 #include "chrome/browser/sessions/session_id.h"
12 #include "chrome/browser/ui/chrome_web_modal_dialog_manager_delegate.h" 12 #include "components/web_modal/web_contents_modal_dialog_manager_delegate.h"
13 #include "content/public/browser/notification_observer.h" 13 #include "content/public/browser/notification_observer.h"
14 #include "content/public/browser/notification_registrar.h" 14 #include "content/public/browser/notification_registrar.h"
15 #include "content/public/browser/web_contents_delegate.h" 15 #include "content/public/browser/web_contents_delegate.h"
16 #include "content/public/common/console_message_level.h" 16 #include "content/public/common/console_message_level.h"
17 #include "ui/base/ui_base_types.h" // WindowShowState 17 #include "ui/base/ui_base_types.h" // WindowShowState
18 #include "ui/gfx/image/image.h" 18 #include "ui/gfx/image/image.h"
19 #include "ui/gfx/rect.h" 19 #include "ui/gfx/rect.h"
20 20
21 class GURL; 21 class GURL;
22 class Profile; 22 class Profile;
23 class NativeAppWindow; 23 class NativeAppWindow;
24 class SkRegion; 24 class SkRegion;
25 25
26 namespace content { 26 namespace content {
27 class WebContents; 27 class WebContents;
28 } 28 }
29 29
30 namespace extensions { 30 namespace extensions {
31 class Extension; 31 class Extension;
32 class PlatformAppBrowserTest; 32 class PlatformAppBrowserTest;
33 class WindowController; 33 class WindowController;
34 34
35 struct DraggableRegion; 35 struct DraggableRegion;
36 } 36 }
37 37
38 namespace ui { 38 namespace ui {
39 class BaseWindow; 39 class BaseWindow;
40 } 40 }
41 41
42 namespace apps {
43
42 // Manages the web contents for Shell Windows. The implementation for this 44 // Manages the web contents for Shell Windows. The implementation for this
43 // class should create and maintain the WebContents for the window, and handle 45 // 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 46 // any message passing between the web contents and the extension system or
45 // native window. 47 // native window.
46 class ShellWindowContents { 48 class ShellWindowContents {
47 public: 49 public:
48 ShellWindowContents() {} 50 ShellWindowContents() {}
49 virtual ~ShellWindowContents() {} 51 virtual ~ShellWindowContents() {}
50 52
51 // Called to initialize the WebContents, before the app window is created. 53 // Called to initialize the WebContents, before the app window is created.
(...skipping 11 matching lines...) Expand all
63 virtual content::WebContents* GetWebContents() const = 0; 65 virtual content::WebContents* GetWebContents() const = 0;
64 66
65 private: 67 private:
66 DISALLOW_COPY_AND_ASSIGN(ShellWindowContents); 68 DISALLOW_COPY_AND_ASSIGN(ShellWindowContents);
67 }; 69 };
68 70
69 // ShellWindow is the type of window used by platform apps. Shell windows 71 // 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. 72 // have a WebContents but none of the chrome of normal browser windows.
71 class ShellWindow : public content::NotificationObserver, 73 class ShellWindow : public content::NotificationObserver,
72 public content::WebContentsDelegate, 74 public content::WebContentsDelegate,
73 public extensions::ExtensionKeybindingRegistry::Delegate, 75 public web_modal::WebContentsModalDialogManagerDelegate,
74 public ChromeWebModalDialogManagerDelegate { 76 public extensions::ExtensionKeybindingRegistry::Delegate {
75 public: 77 public:
76 enum WindowType { 78 enum WindowType {
77 WINDOW_TYPE_DEFAULT = 1 << 0, // Default shell window. 79 WINDOW_TYPE_DEFAULT = 1 << 0, // Default shell window.
78 WINDOW_TYPE_PANEL = 1 << 1, // OS controlled panel window (Ash only). 80 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 81 WINDOW_TYPE_V1_PANEL = 1 << 2, // For apps v1 support in Ash; deprecate
80 // with v1 apps. 82 // with v1 apps.
81 }; 83 };
82 84
83 enum Frame { 85 enum Frame {
84 FRAME_CHROME, // Chrome-style window frame. 86 FRAME_CHROME, // Chrome-style window frame.
(...skipping 28 matching lines...) Expand all
113 // If true, don't show the window after creation. 115 // If true, don't show the window after creation.
114 bool hidden; 116 bool hidden;
115 117
116 // If true, the window will be resizable by the user. Defaults to true. 118 // If true, the window will be resizable by the user. Defaults to true.
117 bool resizable; 119 bool resizable;
118 120
119 // If true, the window will be focused on creation. Defaults to true. 121 // If true, the window will be focused on creation. Defaults to true.
120 bool focused; 122 bool focused;
121 }; 123 };
122 124
125 class Delegate {
126 public:
127 virtual ~Delegate();
128
129 // General initialization.
130 virtual void InitWebContents(content::WebContents* web_contents) = 0;
131
132 // Link handling.
133 virtual content::WebContents* OpenURLFromTab(
134 Profile* profile,
135 content::WebContents* source,
136 const content::OpenURLParams& params) = 0;
137 virtual void AddNewContents(Profile* profile,
138 content::WebContents* new_contents,
139 WindowOpenDisposition disposition,
140 const gfx::Rect& initial_pos,
141 bool user_gesture,
142 bool* was_blocked) = 0;
143
144 // Feature support.
145 virtual content::ColorChooser* ShowColorChooser(
146 content::WebContents* web_contents,
147 SkColor initial_color) = 0;
148 virtual void RunFileChooser(content::WebContents* tab,
149 const content::FileChooserParams& params) = 0;
150 virtual void RequestMediaAccessPermission(
151 content::WebContents* web_contents,
152 const content::MediaStreamRequest& request,
153 const content::MediaResponseCallback& callback,
154 const extensions::Extension* extension) = 0;
155 virtual int PreferredIconSize() = 0;
156
157 // Web contents modal dialog support.
158 virtual void SetWebContentsBlocked(content::WebContents* web_contents,
159 bool blocked) = 0;
160 virtual bool IsWebContentsVisible(content::WebContents* web_contents) = 0;
161 };
162
123 // Helper function for creating and intiailizing a v2 app window. 163 // Helper function for creating and intiailizing a v2 app window.
164 // The created shell window will take ownership of |delegate|.
124 static ShellWindow* Create(Profile* profile, 165 static ShellWindow* Create(Profile* profile,
166 Delegate* delegate,
125 const extensions::Extension* extension, 167 const extensions::Extension* extension,
126 const GURL& url, 168 const GURL& url,
127 const CreateParams& params); 169 const CreateParams& params);
128 170
129 // Convert draggable regions in raw format to SkRegion format. Caller is 171 // Convert draggable regions in raw format to SkRegion format. Caller is
130 // responsible for deleting the returned SkRegion instance. 172 // responsible for deleting the returned SkRegion instance.
131 static SkRegion* RawDraggableRegionsToSkRegion( 173 static SkRegion* RawDraggableRegionsToSkRegion(
132 const std::vector<extensions::DraggableRegion>& regions); 174 const std::vector<extensions::DraggableRegion>& regions);
133 175
134 // The constructor and Init methods are public for constructing a ShellWindow 176 // 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). 177 // with a non-standard render interface (e.g. v1 apps using Ash Panels).
136 // Normally ShellWindow::Create should be used. 178 // Normally ShellWindow::Create should be used.
137 ShellWindow(Profile* profile, const extensions::Extension* extension); 179 // The constructed shell window takes ownership of |delegate|.
180 ShellWindow(Profile* profile,
181 Delegate* delegate,
182 const extensions::Extension* extension);
138 183
139 // Initializes the render interface, web contents, and native window. 184 // Initializes the render interface, web contents, and native window.
140 // |shell_window_contents| will become owned by ShellWindow. 185 // |shell_window_contents| will become owned by ShellWindow.
141 void Init(const GURL& url, 186 void Init(const GURL& url,
142 ShellWindowContents* shell_window_contents, 187 ShellWindowContents* shell_window_contents,
143 const CreateParams& params); 188 const CreateParams& params);
144 189
145 190
146 const std::string& window_key() const { return window_key_; } 191 const std::string& window_key() const { return window_key_; }
147 const SessionID& session_id() const { return session_id_; } 192 const SessionID& session_id() const { return session_id_; }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 // on chrome.app.window API. 242 // on chrome.app.window API.
198 void Fullscreen(); 243 void Fullscreen();
199 void Maximize(); 244 void Maximize();
200 void Minimize(); 245 void Minimize();
201 void Restore(); 246 void Restore();
202 247
203 ShellWindowContents* shell_window_contents_for_test() { 248 ShellWindowContents* shell_window_contents_for_test() {
204 return shell_window_contents_.get(); 249 return shell_window_contents_.get();
205 } 250 }
206 251
207 static void DisableExternalOpenForTesting();
208
209 protected: 252 protected:
210 virtual ~ShellWindow(); 253 virtual ~ShellWindow();
211 254
212 private: 255 private:
213 // PlatformAppBrowserTest needs access to web_contents() 256 // PlatformAppBrowserTest needs access to web_contents()
214 friend class extensions::PlatformAppBrowserTest; 257 friend class extensions::PlatformAppBrowserTest;
215 258
216 // content::WebContentsDelegate implementation. 259 // content::WebContentsDelegate implementation.
217 virtual void CloseContents(content::WebContents* contents) OVERRIDE; 260 virtual void CloseContents(content::WebContents* contents) OVERRIDE;
218 virtual bool ShouldSuppressDialogs() OVERRIDE; 261 virtual bool ShouldSuppressDialogs() OVERRIDE;
(...skipping 30 matching lines...) Expand all
249 const content::NativeWebKeyboardEvent& event) OVERRIDE; 292 const content::NativeWebKeyboardEvent& event) OVERRIDE;
250 virtual void RequestToLockMouse(content::WebContents* web_contents, 293 virtual void RequestToLockMouse(content::WebContents* web_contents,
251 bool user_gesture, 294 bool user_gesture,
252 bool last_unlocked_by_target) OVERRIDE; 295 bool last_unlocked_by_target) OVERRIDE;
253 296
254 // content::NotificationObserver implementation. 297 // content::NotificationObserver implementation.
255 virtual void Observe(int type, 298 virtual void Observe(int type,
256 const content::NotificationSource& source, 299 const content::NotificationSource& source,
257 const content::NotificationDetails& details) OVERRIDE; 300 const content::NotificationDetails& details) OVERRIDE;
258 301
302 // web_modal::WebContentsModalDialogManagerDelegate implementation.
303 virtual void SetWebContentsBlocked(content::WebContents* web_contents,
304 bool blocked) OVERRIDE;
305 virtual bool IsWebContentsVisible(
306 content::WebContents* web_contents) OVERRIDE;
307
259 // Helper method to add a message to the renderer's DevTools console. 308 // Helper method to add a message to the renderer's DevTools console.
260 void AddMessageToDevToolsConsole(content::ConsoleMessageLevel level, 309 void AddMessageToDevToolsConsole(content::ConsoleMessageLevel level,
261 const std::string& message); 310 const std::string& message);
262 311
263 // Saves the window geometry/position/screen bounds. 312 // Saves the window geometry/position/screen bounds.
264 void SaveWindowPosition(); 313 void SaveWindowPosition();
265 314
266 // Helper method to adjust the cached bounds so that we can make sure it can 315 // 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 . 316 // be visible on the screen. See http://crbug.com/145752 .
268 void AdjustBoundsToBeVisibleOnScreen( 317 void AdjustBoundsToBeVisibleOnScreen(
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 356
308 // Icon shown in the task bar. 357 // Icon shown in the task bar.
309 gfx::Image app_icon_; 358 gfx::Image app_icon_;
310 359
311 // Icon URL to be used for setting the app icon. If not empty, app_icon_ will 360 // Icon URL to be used for setting the app icon. If not empty, app_icon_ will
312 // be fetched and set using this URL. 361 // be fetched and set using this URL.
313 GURL app_icon_url_; 362 GURL app_icon_url_;
314 363
315 scoped_ptr<NativeAppWindow> native_app_window_; 364 scoped_ptr<NativeAppWindow> native_app_window_;
316 scoped_ptr<ShellWindowContents> shell_window_contents_; 365 scoped_ptr<ShellWindowContents> shell_window_contents_;
366 scoped_ptr<Delegate> delegate_;
317 367
318 base::WeakPtrFactory<ShellWindow> image_loader_ptr_factory_; 368 base::WeakPtrFactory<ShellWindow> image_loader_ptr_factory_;
319 369
320 // Fullscreen entered by app.window api. 370 // Fullscreen entered by app.window api.
321 bool fullscreen_for_window_api_; 371 bool fullscreen_for_window_api_;
322 // Fullscreen entered by HTML requestFullscreen. 372 // Fullscreen entered by HTML requestFullscreen.
323 bool fullscreen_for_tab_; 373 bool fullscreen_for_tab_;
324 374
325 DISALLOW_COPY_AND_ASSIGN(ShellWindow); 375 DISALLOW_COPY_AND_ASSIGN(ShellWindow);
326 }; 376 };
327 377
378 } // namespace apps
379
328 #endif // CHROME_BROWSER_UI_EXTENSIONS_SHELL_WINDOW_H_ 380 #endif // CHROME_BROWSER_UI_EXTENSIONS_SHELL_WINDOW_H_
OLDNEW
« no previous file with comments | « apps/apps.gypi ('k') | apps/shell_window.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698