OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_EXTENSIONS_EXTENSION_VIEW_HOST_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_VIEW_HOST_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_VIEW_HOST_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_VIEW_HOST_H_ |
7 | 7 |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "components/web_modal/web_contents_modal_dialog_host.h" | 9 #include "components/web_modal/web_contents_modal_dialog_host.h" |
10 #include "components/web_modal/web_contents_modal_dialog_manager_delegate.h" | 10 #include "components/web_modal/web_contents_modal_dialog_manager_delegate.h" |
11 #include "extensions/browser/extension_host.h" | 11 #include "extensions/browser/extension_host.h" |
12 | 12 |
13 #if defined(TOOLKIT_VIEWS) | |
14 #include "chrome/browser/ui/views/extensions/extension_view_views.h" | |
15 #elif defined(OS_MACOSX) | |
16 #include "chrome/browser/ui/cocoa/extensions/extension_view_mac.h" | |
17 #elif defined(OS_ANDROID) | |
18 #include "chrome/browser/ui/android/extensions/extension_view_android.h" | |
19 #endif | |
20 | |
21 class Browser; | 13 class Browser; |
22 | 14 |
23 namespace content { | 15 namespace content { |
24 class SiteInstance; | 16 class SiteInstance; |
25 class WebContents; | 17 class WebContents; |
26 } | 18 } |
27 | 19 |
28 namespace extensions { | 20 namespace extensions { |
29 | 21 |
| 22 class ExtensionView; |
| 23 |
30 // The ExtensionHost for an extension that backs a view in the browser UI. For | 24 // The ExtensionHost for an extension that backs a view in the browser UI. For |
31 // example, this could be an extension popup, infobar or dialog, but not a | 25 // example, this could be an extension popup, infobar or dialog, but not a |
32 // background page. | 26 // background page. |
33 class ExtensionViewHost | 27 class ExtensionViewHost |
34 : public ExtensionHost, | 28 : public ExtensionHost, |
35 public web_modal::WebContentsModalDialogManagerDelegate, | 29 public web_modal::WebContentsModalDialogManagerDelegate, |
36 public web_modal::WebContentsModalDialogHost { | 30 public web_modal::WebContentsModalDialogHost { |
37 public: | 31 public: |
38 ExtensionViewHost(const Extension* extension, | 32 ExtensionViewHost(const Extension* extension, |
39 content::SiteInstance* site_instance, | 33 content::SiteInstance* site_instance, |
40 const GURL& url, | 34 const GURL& url, |
41 ViewType host_type); | 35 ViewType host_type); |
42 virtual ~ExtensionViewHost(); | 36 virtual ~ExtensionViewHost(); |
43 | 37 |
44 // TODO(jamescook): Create platform specific subclasses? | 38 ExtensionView* view() { return view_.get(); } |
45 #if defined(TOOLKIT_VIEWS) | 39 const ExtensionView* view() const { return view_.get(); } |
46 typedef ExtensionViewViews PlatformExtensionView; | |
47 #elif defined(OS_MACOSX) | |
48 typedef ExtensionViewMac PlatformExtensionView; | |
49 #elif defined(OS_ANDROID) | |
50 // Android does not support extensions. | |
51 typedef ExtensionViewAndroid PlatformExtensionView; | |
52 #endif | |
53 | |
54 PlatformExtensionView* view() { return view_.get(); } | |
55 const PlatformExtensionView* view() const { return view_.get(); } | |
56 | 40 |
57 // Create an ExtensionView and tie it to this host and |browser|. Note NULL | 41 // Create an ExtensionView and tie it to this host and |browser|. Note NULL |
58 // is a valid argument for |browser|. Extension views may be bound to | 42 // is a valid argument for |browser|. Extension views may be bound to |
59 // tab-contents hosted in ExternalTabContainer objects, which do not | 43 // tab-contents hosted in ExternalTabContainer objects, which do not |
60 // instantiate Browser objects. | 44 // instantiate Browser objects. |
61 void CreateView(Browser* browser); | 45 void CreateView(Browser* browser); |
62 | 46 |
63 void SetAssociatedWebContents(content::WebContents* web_contents); | 47 void SetAssociatedWebContents(content::WebContents* web_contents); |
64 | 48 |
65 // Handles keyboard events that were not handled by HandleKeyboardEvent(). | 49 // Handles keyboard events that were not handled by HandleKeyboardEvent(). |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 virtual WindowController* GetExtensionWindowController() const OVERRIDE; | 106 virtual WindowController* GetExtensionWindowController() const OVERRIDE; |
123 virtual content::WebContents* GetAssociatedWebContents() const OVERRIDE; | 107 virtual content::WebContents* GetAssociatedWebContents() const OVERRIDE; |
124 virtual content::WebContents* GetVisibleWebContents() const OVERRIDE; | 108 virtual content::WebContents* GetVisibleWebContents() const OVERRIDE; |
125 | 109 |
126 // content::NotificationObserver | 110 // content::NotificationObserver |
127 virtual void Observe(int type, | 111 virtual void Observe(int type, |
128 const content::NotificationSource& source, | 112 const content::NotificationSource& source, |
129 const content::NotificationDetails& details) OVERRIDE; | 113 const content::NotificationDetails& details) OVERRIDE; |
130 | 114 |
131 private: | 115 private: |
| 116 // Implemented per-platform. Create the platform-specific ExtensionView. |
| 117 static scoped_ptr<ExtensionView> CreateExtensionView(ExtensionViewHost* host, |
| 118 Browser* browser); |
| 119 |
132 // Insert a default style sheet for Extension Infobars. | 120 // Insert a default style sheet for Extension Infobars. |
133 void InsertInfobarCSS(); | 121 void InsertInfobarCSS(); |
134 | 122 |
135 // Optional view that shows the rendered content in the UI. | 123 // Optional view that shows the rendered content in the UI. |
136 scoped_ptr<PlatformExtensionView> view_; | 124 scoped_ptr<ExtensionView> view_; |
137 | 125 |
138 // The relevant WebContents associated with this ExtensionViewHost, if any. | 126 // The relevant WebContents associated with this ExtensionViewHost, if any. |
139 content::WebContents* associated_web_contents_; | 127 content::WebContents* associated_web_contents_; |
140 | 128 |
141 // Observer to detect when the associated web contents is destroyed. | 129 // Observer to detect when the associated web contents is destroyed. |
142 class AssociatedWebContentsObserver; | 130 class AssociatedWebContentsObserver; |
143 scoped_ptr<AssociatedWebContentsObserver> associated_web_contents_observer_; | 131 scoped_ptr<AssociatedWebContentsObserver> associated_web_contents_observer_; |
144 | 132 |
145 DISALLOW_COPY_AND_ASSIGN(ExtensionViewHost); | 133 DISALLOW_COPY_AND_ASSIGN(ExtensionViewHost); |
146 }; | 134 }; |
147 | 135 |
148 } // namespace extensions | 136 } // namespace extensions |
149 | 137 |
150 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_VIEW_HOST_H_ | 138 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_VIEW_HOST_H_ |
OLD | NEW |