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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "chrome/browser/extensions/extension_function_dispatcher.h" |
10 #include "chrome/browser/sessions/session_id.h" | 11 #include "chrome/browser/sessions/session_id.h" |
11 #include "chrome/browser/extensions/extension_host.h" | |
12 #include "chrome/browser/ui/base_window.h" | 12 #include "chrome/browser/ui/base_window.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" |
| 16 #include "content/public/browser/web_contents_observer.h" |
15 | 17 |
16 class Extension; | 18 class Extension; |
17 class ExtensionHost; | |
18 class ExtensionWindowController; | 19 class ExtensionWindowController; |
19 class GURL; | 20 class GURL; |
20 class Profile; | 21 class Profile; |
21 | 22 |
22 namespace content { | 23 namespace content { |
23 class WebContents; | 24 class WebContents; |
24 } | 25 } |
25 | 26 |
| 27 // ShellWindow is the type of window used by platform apps. Shell windows |
| 28 // have a WebContents but none of the chrome of normal browser windows. |
26 class ShellWindow : public content::NotificationObserver, | 29 class ShellWindow : public content::NotificationObserver, |
| 30 public content::WebContentsDelegate, |
| 31 public content::WebContentsObserver, |
| 32 public ExtensionFunctionDispatcher::Delegate, |
27 public BaseWindow { | 33 public BaseWindow { |
28 public: | 34 public: |
| 35 static ShellWindow* Create(Profile* profile, |
| 36 const Extension* extension, |
| 37 const GURL& url); |
| 38 |
| 39 const SessionID& session_id() const { return session_id_; } |
| 40 const ExtensionWindowController* extension_window_controller() const { |
| 41 return extension_window_controller_.get(); |
| 42 } |
| 43 |
| 44 protected: |
29 // TODO(mihaip): Switch from hardcoded defaults to passing in the window | 45 // TODO(mihaip): Switch from hardcoded defaults to passing in the window |
30 // creation parameters to ShellWindow::Create. | 46 // creation parameters to ShellWindow::Create. |
31 static const int kDefaultWidth = 512; | 47 static const int kDefaultWidth = 512; |
32 static const int kDefaultHeight = 384; | 48 static const int kDefaultHeight = 384; |
33 | 49 |
34 content::WebContents* web_contents() const { return host_->host_contents(); } | 50 ShellWindow(Profile* profile, |
35 const SessionID& session_id() const { return session_id_; } | 51 const Extension* extension, |
36 const ExtensionWindowController* extension_window_controller() const { | 52 const GURL& url); |
37 return extension_window_controller_.get(); | 53 virtual ~ShellWindow(); |
38 } | |
39 | 54 |
40 static ShellWindow* Create(Profile* profile, | 55 const Extension* extension() const { return extension_; } |
41 const Extension* extension, | 56 content::WebContents* web_contents() const { return web_contents_.get(); } |
42 const GURL& url); | 57 |
| 58 private: |
| 59 // PlatformAppBrowserTest needs access to web_contents() |
| 60 friend class PlatformAppBrowserTest; |
| 61 |
| 62 // Instantiates a platform-specific ShellWindow subclass (one implementation |
| 63 // per platform). Public users of ShellWindow should use ShellWindow::Create. |
| 64 static ShellWindow* CreateImpl(Profile* profile, |
| 65 const Extension* extension, |
| 66 const GURL& url); |
| 67 |
| 68 // content::WebContentsObserver |
| 69 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 70 |
| 71 // content::WebContentsDelegate |
| 72 virtual void CloseContents(content::WebContents* contents) OVERRIDE; |
| 73 virtual bool ShouldSuppressDialogs() OVERRIDE; |
43 | 74 |
44 // content::NotificationObserver implementation. | 75 // content::NotificationObserver implementation. |
45 virtual void Observe(int type, | 76 virtual void Observe(int type, |
46 const content::NotificationSource& source, | 77 const content::NotificationSource& source, |
47 const content::NotificationDetails& details) OVERRIDE; | 78 const content::NotificationDetails& details) OVERRIDE; |
48 | 79 |
49 protected: | 80 virtual ExtensionWindowController* GetExtensionWindowController() const |
50 explicit ShellWindow(ExtensionHost* host_); | 81 OVERRIDE; |
51 virtual ~ShellWindow(); | |
52 | 82 |
53 // Instantiates a platform-specific ShellWindow subclass (one implementation | 83 // Message handlers. |
54 // per platform). Public users of ShellWindow should use ShellWindow::Create. | 84 void OnRequest(const ExtensionHostMsg_Request_Params& params); |
55 static ShellWindow* CreateShellWindow(ExtensionHost* host); | 85 |
| 86 Profile* profile_; // weak pointer - owned by ProfileManager. |
| 87 const Extension* extension_; // weak pointer - owned by ExtensionService. |
56 | 88 |
57 const SessionID session_id_; | 89 const SessionID session_id_; |
58 scoped_ptr<ExtensionHost> host_; | 90 scoped_ptr<content::WebContents> web_contents_; |
59 content::NotificationRegistrar registrar_; | 91 content::NotificationRegistrar registrar_; |
60 scoped_ptr<ExtensionWindowController> extension_window_controller_; | 92 scoped_ptr<ExtensionWindowController> extension_window_controller_; |
| 93 ExtensionFunctionDispatcher extension_function_dispatcher_; |
61 | 94 |
62 private: | |
63 DISALLOW_COPY_AND_ASSIGN(ShellWindow); | 95 DISALLOW_COPY_AND_ASSIGN(ShellWindow); |
64 }; | 96 }; |
65 | 97 |
66 #endif // CHROME_BROWSER_UI_EXTENSIONS_SHELL_WINDOW_H_ | 98 #endif // CHROME_BROWSER_UI_EXTENSIONS_SHELL_WINDOW_H_ |
OLD | NEW |