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