OLD | NEW |
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 "chrome/browser/extensions/extension_function_dispatcher.h" | 9 #include "chrome/browser/extensions/extension_function_dispatcher.h" |
10 #include "chrome/browser/sessions/session_id.h" | 10 #include "chrome/browser/sessions/session_id.h" |
11 #include "chrome/browser/ui/base_window.h" | 11 #include "chrome/browser/ui/base_window.h" |
12 #include "content/public/browser/notification_observer.h" | 12 #include "content/public/browser/notification_observer.h" |
13 #include "content/public/browser/notification_registrar.h" | 13 #include "content/public/browser/notification_registrar.h" |
14 #include "content/public/browser/web_contents_delegate.h" | 14 #include "content/public/browser/web_contents_delegate.h" |
15 #include "content/public/browser/web_contents_observer.h" | 15 #include "content/public/browser/web_contents_observer.h" |
16 #include "content/public/common/console_message_level.h" | 16 #include "content/public/common/console_message_level.h" |
17 #include "ui/gfx/rect.h" | 17 #include "ui/gfx/rect.h" |
18 | 18 |
19 class GURL; | 19 class GURL; |
20 class Profile; | 20 class Profile; |
21 class TabContents; | 21 class TabContents; |
| 22 class NativeShellWindow; |
22 | 23 |
23 namespace content { | 24 namespace content { |
24 class WebContents; | 25 class WebContents; |
25 } | 26 } |
26 | 27 |
27 namespace extensions { | 28 namespace extensions { |
28 class Extension; | 29 class Extension; |
29 class WindowController; | 30 class WindowController; |
30 struct DraggableRegion; | 31 struct DraggableRegion; |
31 } | 32 } |
32 | 33 |
33 // ShellWindow is the type of window used by platform apps. Shell windows | 34 // ShellWindow is the type of window used by platform apps. Shell windows |
34 // have a WebContents but none of the chrome of normal browser windows. | 35 // have a WebContents but none of the chrome of normal browser windows. |
35 class ShellWindow : public content::NotificationObserver, | 36 class ShellWindow : public content::NotificationObserver, |
36 public content::WebContentsDelegate, | 37 public content::WebContentsDelegate, |
37 public content::WebContentsObserver, | 38 public content::WebContentsObserver, |
38 public ExtensionFunctionDispatcher::Delegate, | 39 public ExtensionFunctionDispatcher::Delegate { |
39 public BaseWindow { | |
40 public: | 40 public: |
41 struct CreateParams { | 41 struct CreateParams { |
42 enum Frame { | 42 enum Frame { |
43 FRAME_CHROME, // Chrome-style window frame. | 43 FRAME_CHROME, // Chrome-style window frame. |
44 FRAME_NONE, // Frameless window. | 44 FRAME_NONE, // Frameless window. |
45 }; | 45 }; |
46 | 46 |
47 CreateParams(); | 47 CreateParams(); |
48 | 48 |
49 Frame frame; | 49 Frame frame; |
50 // Specify the initial bounds of the window. If empty, the window will be a | 50 // Specify the initial bounds of the window. If empty, the window will be a |
51 // default size. | 51 // default size. |
52 gfx::Rect bounds; | 52 gfx::Rect bounds; |
53 gfx::Size minimum_size; | 53 gfx::Size minimum_size; |
54 gfx::Size maximum_size; | 54 gfx::Size maximum_size; |
55 }; | 55 }; |
56 | 56 |
57 static ShellWindow* Create(Profile* profile, | 57 static ShellWindow* Create(Profile* profile, |
58 const extensions::Extension* extension, | 58 const extensions::Extension* extension, |
59 const GURL& url, | 59 const GURL& url, |
60 const CreateParams& params); | 60 const CreateParams& params); |
61 | 61 |
62 const SessionID& session_id() const { return session_id_; } | 62 const SessionID& session_id() const { return session_id_; } |
63 const extensions::Extension* extension() const { return extension_; } | 63 const extensions::Extension* extension() const { return extension_; } |
64 const TabContents* tab_contents() const { return contents_.get(); } | 64 const TabContents* tab_contents() const { return contents_.get(); } |
65 content::WebContents* web_contents() const { return web_contents_; } | 65 content::WebContents* web_contents() const { return web_contents_; } |
| 66 Profile* profile() const { return profile_; } |
66 | 67 |
67 protected: | 68 BaseWindow* GetBaseWindow(); |
68 ShellWindow(Profile* profile, | 69 gfx::NativeWindow GetNativeWindow() { |
69 const extensions::Extension* extension, | 70 return GetBaseWindow()->GetNativeWindow(); |
70 const GURL& url); | 71 } |
71 virtual ~ShellWindow(); | |
72 | 72 |
73 // Called when the title of the window changes. | 73 // NativeShellWindows should call this to determine what the window's title |
74 virtual void UpdateWindowTitle() {} | 74 // is on startup and from within UpdateWindowTitle(). |
75 // Sub-classes should call this to determine what the window's title is on | |
76 // startup and from within UpdateWindowTitle(). | |
77 virtual string16 GetTitle() const; | 75 virtual string16 GetTitle() const; |
78 | 76 |
79 virtual void SetFullscreen(bool fullscreen) {} | |
80 virtual bool IsFullscreenOrPending() const; | |
81 | |
82 // Called when the draggable regions are changed. | |
83 virtual void UpdateDraggableRegions( | |
84 const std::vector<extensions::DraggableRegion>& regions) {} | |
85 | |
86 // Call to notify ShellRegistry and delete the window. Subclasses should | 77 // Call to notify ShellRegistry and delete the window. Subclasses should |
87 // invoke this method instead of using "delete this". | 78 // invoke this method instead of using "delete this". |
88 void OnNativeClose(); | 79 void OnNativeClose(); |
89 | 80 |
| 81 protected: |
| 82 ShellWindow(Profile* profile, |
| 83 const extensions::Extension* extension); |
| 84 virtual ~ShellWindow(); |
| 85 |
90 private: | 86 private: |
91 // PlatformAppBrowserTest needs access to web_contents() | 87 // PlatformAppBrowserTest needs access to web_contents() |
92 friend class PlatformAppBrowserTest; | 88 friend class PlatformAppBrowserTest; |
93 | 89 |
94 // Instantiates a platform-specific ShellWindow subclass (one implementation | 90 // Instantiates a platform-specific ShellWindow subclass (one implementation |
95 // per platform). Public users of ShellWindow should use ShellWindow::Create. | 91 // per platform). Public users of ShellWindow should use ShellWindow::Create. |
96 static ShellWindow* CreateImpl(Profile* profile, | 92 void Init(const GURL& url, const CreateParams& params); |
97 const extensions::Extension* extension, | |
98 const GURL& url, | |
99 const CreateParams& params); | |
100 | 93 |
101 // content::WebContentsObserver implementation. | 94 // content::WebContentsObserver implementation. |
102 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 95 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
103 | 96 |
104 // content::WebContentsDelegate implementation. | 97 // content::WebContentsDelegate implementation. |
105 virtual void CloseContents(content::WebContents* contents) OVERRIDE; | 98 virtual void CloseContents(content::WebContents* contents) OVERRIDE; |
106 virtual bool ShouldSuppressDialogs() OVERRIDE; | 99 virtual bool ShouldSuppressDialogs() OVERRIDE; |
107 virtual void WebIntentDispatch( | 100 virtual void WebIntentDispatch( |
108 content::WebContents* web_contents, | 101 content::WebContents* web_contents, |
109 content::WebIntentsDispatcher* intents_dispatcher) OVERRIDE; | 102 content::WebIntentsDispatcher* intents_dispatcher) OVERRIDE; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 virtual extensions::WindowController* GetExtensionWindowController() const | 135 virtual extensions::WindowController* GetExtensionWindowController() const |
143 OVERRIDE; | 136 OVERRIDE; |
144 | 137 |
145 // Message handlers. | 138 // Message handlers. |
146 void OnRequest(const ExtensionHostMsg_Request_Params& params); | 139 void OnRequest(const ExtensionHostMsg_Request_Params& params); |
147 | 140 |
148 // Helper method to add a message to the renderer's DevTools console. | 141 // Helper method to add a message to the renderer's DevTools console. |
149 void AddMessageToDevToolsConsole(content::ConsoleMessageLevel level, | 142 void AddMessageToDevToolsConsole(content::ConsoleMessageLevel level, |
150 const std::string& message); | 143 const std::string& message); |
151 | 144 |
| 145 virtual void UpdateDraggableRegions( |
| 146 const std::vector<extensions::DraggableRegion>& regions); |
| 147 |
152 Profile* profile_; // weak pointer - owned by ProfileManager. | 148 Profile* profile_; // weak pointer - owned by ProfileManager. |
153 // weak pointer - owned by ExtensionService. | 149 // weak pointer - owned by ExtensionService. |
154 const extensions::Extension* extension_; | 150 const extensions::Extension* extension_; |
155 | 151 |
156 const SessionID session_id_; | 152 const SessionID session_id_; |
157 scoped_ptr<TabContents> contents_; | 153 scoped_ptr<TabContents> contents_; |
158 // web_contents_ is owned by contents_. | 154 // web_contents_ is owned by contents_. |
159 content::WebContents* web_contents_; | 155 content::WebContents* web_contents_; |
160 content::NotificationRegistrar registrar_; | 156 content::NotificationRegistrar registrar_; |
161 ExtensionFunctionDispatcher extension_function_dispatcher_; | 157 ExtensionFunctionDispatcher extension_function_dispatcher_; |
162 | 158 |
| 159 scoped_ptr<NativeShellWindow> native_window_; |
| 160 |
163 DISALLOW_COPY_AND_ASSIGN(ShellWindow); | 161 DISALLOW_COPY_AND_ASSIGN(ShellWindow); |
164 }; | 162 }; |
165 | 163 |
166 #endif // CHROME_BROWSER_UI_EXTENSIONS_SHELL_WINDOW_H_ | 164 #endif // CHROME_BROWSER_UI_EXTENSIONS_SHELL_WINDOW_H_ |
OLD | NEW |