diff options
Diffstat (limited to 'chrome/browser/ui/extensions/shell_window.h')
-rw-r--r-- | chrome/browser/ui/extensions/shell_window.h | 76 |
1 files changed, 48 insertions, 28 deletions
diff --git a/chrome/browser/ui/extensions/shell_window.h b/chrome/browser/ui/extensions/shell_window.h index 981c725..4d66ae0 100644 --- a/chrome/browser/ui/extensions/shell_window.h +++ b/chrome/browser/ui/extensions/shell_window.h @@ -6,14 +6,13 @@ #define CHROME_BROWSER_UI_EXTENSIONS_SHELL_WINDOW_H_ #include "base/memory/scoped_ptr.h" -#include "chrome/browser/extensions/extension_function_dispatcher.h" +#include "base/memory/weak_ptr.h" #include "chrome/browser/extensions/extension_keybinding_registry.h" #include "chrome/browser/sessions/session_id.h" #include "chrome/browser/ui/base_window.h" #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" #include "content/public/browser/web_contents_delegate.h" -#include "content/public/browser/web_contents_observer.h" #include "content/public/common/console_message_level.h" #include "ui/gfx/image/image.h" #include "ui/gfx/rect.h" @@ -34,12 +33,37 @@ class WindowController; struct DraggableRegion; } +// Manages the web contents for Shell Windows. The implementation for this +// class should create and maintain the WebContents for the window, and handle +// any message passing between the web contents and the extension system or +// native window. +class ShellWindowContents { + public: + ShellWindowContents() {} + virtual ~ShellWindowContents() {} + + // Called to initialize the WebContents, before the app window is created. + virtual void Initialize(Profile* profile, const GURL& url) = 0; + + // Called to load the contents, after the app window is created. + virtual void LoadContents(int32 creator_process_id) = 0; + + // Called when the native window changes. + virtual void NativeWindowChanged(NativeAppWindow* native_app_window) = 0; + + // Called when the native window closes. + virtual void NativeWindowClosed() = 0; + + virtual content::WebContents* GetWebContents() const = 0; + + private: + DISALLOW_COPY_AND_ASSIGN(ShellWindowContents); +}; + // ShellWindow is the type of window used by platform apps. Shell windows // have a WebContents but none of the chrome of normal browser windows. class ShellWindow : public content::NotificationObserver, public content::WebContentsDelegate, - public content::WebContentsObserver, - public ExtensionFunctionDispatcher::Delegate, public extensions::ExtensionKeybindingRegistry::Delegate { public: enum WindowType { @@ -78,6 +102,7 @@ class ShellWindow : public content::NotificationObserver, bool hidden; }; + // Helper function for creating and intiailizing a v2 app window. static ShellWindow* Create(Profile* profile, const extensions::Extension* extension, const GURL& url, @@ -88,10 +113,22 @@ class ShellWindow : public content::NotificationObserver, static SkRegion* RawDraggableRegionsToSkRegion( const std::vector<extensions::DraggableRegion>& regions); + // The constructor and Init methods are public for constructing a ShellWindow + // with a non-standard render interface (e.g. v1 apps using Ash Panels). + // Normally ShellWindow::Create should be used. + ShellWindow(Profile* profile, const extensions::Extension* extension); + + // Initializes the render interface, web contents, and native window. + // |shell_window_contents| will become owned by ShellWindow. + void Init(const GURL& url, + ShellWindowContents* shell_window_contents, + const CreateParams& params); + + const std::string& window_key() const { return window_key_; } const SessionID& session_id() const { return session_id_; } const extensions::Extension* extension() const { return extension_; } - content::WebContents* web_contents() const { return web_contents_.get(); } + content::WebContents* web_contents() const; WindowType window_type() const { return window_type_; } Profile* profile() const { return profile_; } const gfx::Image& app_icon() const { return app_icon_; } @@ -107,7 +144,7 @@ class ShellWindow : public content::NotificationObserver, // NativeAppWindows should call this to determine what the window's title // is on startup and from within UpdateWindowTitle(). - virtual string16 GetTitle() const; + string16 GetTitle() const; // Call to notify ShellRegistry and delete the window. Subclasses should // invoke this method instead of using "delete this". @@ -120,22 +157,17 @@ class ShellWindow : public content::NotificationObserver, // Specifies a url for the launcher icon. void SetAppIconUrl(const GURL& icon_url); + // Called from the render interface to modify the draggable regions. + void UpdateDraggableRegions( + const std::vector<extensions::DraggableRegion>& regions); + protected: - ShellWindow(Profile* profile, - const extensions::Extension* extension); virtual ~ShellWindow(); private: // PlatformAppBrowserTest needs access to web_contents() friend class extensions::PlatformAppBrowserTest; - // Instantiates a platform-specific ShellWindow subclass (one implementation - // per platform). Public users of ShellWindow should use ShellWindow::Create. - void Init(const GURL& url, const CreateParams& params); - - // content::WebContentsObserver implementation. - virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; - // content::WebContentsDelegate implementation. virtual void CloseContents(content::WebContents* contents) OVERRIDE; virtual bool ShouldSuppressDialogs() OVERRIDE; @@ -177,14 +209,6 @@ class ShellWindow : public content::NotificationObserver, const content::NotificationSource& source, const content::NotificationDetails& details) OVERRIDE; - // ExtensionFunctionDispatcher::Delegate implementation. - virtual extensions::WindowController* GetExtensionWindowController() const - OVERRIDE; - virtual content::WebContents* GetAssociatedWebContents() const OVERRIDE; - - // Message handlers. - void OnRequest(const ExtensionHostMsg_Request_Params& params); - // Helper method to add a message to the renderer's DevTools console. void AddMessageToDevToolsConsole(content::ConsoleMessageLevel level, const std::string& message); @@ -192,9 +216,6 @@ class ShellWindow : public content::NotificationObserver, // Saves the window geometry/position. void SaveWindowPosition(); - virtual void UpdateDraggableRegions( - const std::vector<extensions::DraggableRegion>& regions); - // Load the app's image, firing a load state change when loaded. void UpdateExtensionAppIcon(); @@ -222,10 +243,8 @@ class ShellWindow : public content::NotificationObserver, std::string window_key_; const SessionID session_id_; - scoped_ptr<content::WebContents> web_contents_; WindowType window_type_; content::NotificationRegistrar registrar_; - ExtensionFunctionDispatcher extension_function_dispatcher_; // Icon shown in the task bar. gfx::Image app_icon_; @@ -235,6 +254,7 @@ class ShellWindow : public content::NotificationObserver, GURL app_icon_url_; scoped_ptr<NativeAppWindow> native_app_window_; + scoped_ptr<ShellWindowContents> shell_window_contents_; base::WeakPtrFactory<ShellWindow> weak_ptr_factory_; |