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_EXTENSIONS_EXTENSION_TAB_HELPER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_TAB_HELPER_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_TAB_HELPER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_TAB_HELPER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
10 #include "base/observer_list.h" | 10 #include "base/observer_list.h" |
11 #include "chrome/browser/extensions/app_notify_channel_setup.h" | 11 #include "chrome/browser/extensions/app_notify_channel_setup.h" |
12 #include "chrome/browser/extensions/extension_function_dispatcher.h" | 12 #include "chrome/browser/extensions/extension_function_dispatcher.h" |
13 #include "chrome/browser/extensions/image_loading_tracker.h" | 13 #include "chrome/browser/extensions/image_loading_tracker.h" |
14 #include "chrome/browser/extensions/webstore_inline_installer.h" | 14 #include "chrome/browser/extensions/webstore_inline_installer.h" |
15 #include "chrome/common/web_apps.h" | 15 #include "chrome/common/web_apps.h" |
16 #include "content/public/browser/web_contents_observer.h" | 16 #include "content/public/browser/web_contents_observer.h" |
17 #include "third_party/skia/include/core/SkBitmap.h" | 17 #include "third_party/skia/include/core/SkBitmap.h" |
18 | 18 |
19 class Extension; | |
20 class ExtensionTabHelperDelegate; | 19 class ExtensionTabHelperDelegate; |
21 class TabContentsWrapper; | 20 class TabContentsWrapper; |
22 struct WebApplicationInfo; | 21 struct WebApplicationInfo; |
23 | 22 |
24 namespace content { | 23 namespace content { |
25 struct LoadCommittedDetails; | 24 struct LoadCommittedDetails; |
26 } | 25 } |
27 | 26 |
28 namespace extensions { | 27 namespace extensions { |
29 class ActionBoxController; | 28 class ActionBoxController; |
| 29 class Extension; |
30 class ScriptBadgeController; | 30 class ScriptBadgeController; |
31 class ScriptExecutor; | 31 class ScriptExecutor; |
32 } | 32 } |
33 | 33 |
34 // Per-tab extension helper. Also handles non-extension apps. | 34 // Per-tab extension helper. Also handles non-extension apps. |
35 class ExtensionTabHelper | 35 class ExtensionTabHelper |
36 : public content::WebContentsObserver, | 36 : public content::WebContentsObserver, |
37 public ExtensionFunctionDispatcher::Delegate, | 37 public ExtensionFunctionDispatcher::Delegate, |
38 public ImageLoadingTracker::Observer, | 38 public ImageLoadingTracker::Observer, |
39 public WebstoreInlineInstaller::Delegate, | 39 public WebstoreInlineInstaller::Delegate, |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 | 72 |
73 // App extensions ------------------------------------------------------------ | 73 // App extensions ------------------------------------------------------------ |
74 | 74 |
75 // Sets the extension denoting this as an app. If |extension| is non-null this | 75 // Sets the extension denoting this as an app. If |extension| is non-null this |
76 // tab becomes an app-tab. WebContents does not listen for unload events for | 76 // tab becomes an app-tab. WebContents does not listen for unload events for |
77 // the extension. It's up to consumers of WebContents to do that. | 77 // the extension. It's up to consumers of WebContents to do that. |
78 // | 78 // |
79 // NOTE: this should only be manipulated before the tab is added to a browser. | 79 // NOTE: this should only be manipulated before the tab is added to a browser. |
80 // TODO(sky): resolve if this is the right way to identify an app tab. If it | 80 // TODO(sky): resolve if this is the right way to identify an app tab. If it |
81 // is, than this should be passed in the constructor. | 81 // is, than this should be passed in the constructor. |
82 void SetExtensionApp(const Extension* extension); | 82 void SetExtensionApp(const extensions::Extension* extension); |
83 | 83 |
84 // Convenience for setting the app extension by id. This does nothing if | 84 // Convenience for setting the app extension by id. This does nothing if |
85 // |extension_app_id| is empty, or an extension can't be found given the | 85 // |extension_app_id| is empty, or an extension can't be found given the |
86 // specified id. | 86 // specified id. |
87 void SetExtensionAppById(const std::string& extension_app_id); | 87 void SetExtensionAppById(const std::string& extension_app_id); |
88 | 88 |
89 // Set just the app icon, used by panels created by an extension. | 89 // Set just the app icon, used by panels created by an extension. |
90 void SetExtensionAppIconById(const std::string& extension_app_id); | 90 void SetExtensionAppIconById(const std::string& extension_app_id); |
91 | 91 |
92 const Extension* extension_app() const { return extension_app_; } | 92 const extensions::Extension* extension_app() const { return extension_app_; } |
93 bool is_app() const { return extension_app_ != NULL; } | 93 bool is_app() const { return extension_app_ != NULL; } |
94 const WebApplicationInfo& web_app_info() const { | 94 const WebApplicationInfo& web_app_info() const { |
95 return web_app_info_; | 95 return web_app_info_; |
96 } | 96 } |
97 | 97 |
98 // If an app extension has been explicitly set for this WebContents its icon | 98 // If an app extension has been explicitly set for this WebContents its icon |
99 // is returned. | 99 // is returned. |
100 // | 100 // |
101 // NOTE: the returned icon is larger than 16x16 (its size is | 101 // NOTE: the returned icon is larger than 16x16 (its size is |
102 // Extension::EXTENSION_ICON_SMALLISH). | 102 // Extension::EXTENSION_ICON_SMALLISH). |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 int callback_id); | 143 int callback_id); |
144 void OnGetAppInstallState(const GURL& requestor_url, | 144 void OnGetAppInstallState(const GURL& requestor_url, |
145 int return_route_id, | 145 int return_route_id, |
146 int callback_id); | 146 int callback_id); |
147 void OnRequest(const ExtensionHostMsg_Request_Params& params); | 147 void OnRequest(const ExtensionHostMsg_Request_Params& params); |
148 | 148 |
149 // App extensions related methods: | 149 // App extensions related methods: |
150 | 150 |
151 // Resets app_icon_ and if |extension| is non-null creates a new | 151 // Resets app_icon_ and if |extension| is non-null creates a new |
152 // ImageLoadingTracker to load the extension's image. | 152 // ImageLoadingTracker to load the extension's image. |
153 void UpdateExtensionAppIcon(const Extension* extension); | 153 void UpdateExtensionAppIcon(const extensions::Extension* extension); |
154 | 154 |
155 const Extension* GetExtension(const std::string& extension_app_id); | 155 const extensions::Extension* GetExtension( |
| 156 const std::string& extension_app_id); |
156 | 157 |
157 // ImageLoadingTracker::Observer. | 158 // ImageLoadingTracker::Observer. |
158 virtual void OnImageLoaded(const gfx::Image& image, | 159 virtual void OnImageLoaded(const gfx::Image& image, |
159 const std::string& extension_id, | 160 const std::string& extension_id, |
160 int index) OVERRIDE; | 161 int index) OVERRIDE; |
161 | 162 |
162 // WebstoreInlineInstaller::Delegate. | 163 // WebstoreInlineInstaller::Delegate. |
163 virtual void OnInlineInstallSuccess(int install_id, | 164 virtual void OnInlineInstallSuccess(int install_id, |
164 int return_route_id) OVERRIDE; | 165 int return_route_id) OVERRIDE; |
165 virtual void OnInlineInstallFailure(int install_id, | 166 virtual void OnInlineInstallFailure(int install_id, |
(...skipping 10 matching lines...) Expand all Loading... |
176 | 177 |
177 // Our observers. Declare at top so that it will outlive all other members, | 178 // Our observers. Declare at top so that it will outlive all other members, |
178 // since they might add themselves as observers. | 179 // since they might add themselves as observers. |
179 ObserverList<Observer> observers_; | 180 ObserverList<Observer> observers_; |
180 | 181 |
181 // Delegate for notifying our owner about stuff. Not owned by us. | 182 // Delegate for notifying our owner about stuff. Not owned by us. |
182 ExtensionTabHelperDelegate* delegate_; | 183 ExtensionTabHelperDelegate* delegate_; |
183 | 184 |
184 // If non-null this tab is an app tab and this is the extension the tab was | 185 // If non-null this tab is an app tab and this is the extension the tab was |
185 // created for. | 186 // created for. |
186 const Extension* extension_app_; | 187 const extensions::Extension* extension_app_; |
187 | 188 |
188 // Icon for extension_app_ (if non-null) or a manually-set icon for | 189 // Icon for extension_app_ (if non-null) or a manually-set icon for |
189 // non-extension apps. | 190 // non-extension apps. |
190 SkBitmap extension_app_icon_; | 191 SkBitmap extension_app_icon_; |
191 | 192 |
192 // Process any extension messages coming from the tab. | 193 // Process any extension messages coming from the tab. |
193 ExtensionFunctionDispatcher extension_function_dispatcher_; | 194 ExtensionFunctionDispatcher extension_function_dispatcher_; |
194 | 195 |
195 // Used for loading extension_app_icon_. | 196 // Used for loading extension_app_icon_. |
196 scoped_ptr<ImageLoadingTracker> extension_app_image_loader_; | 197 scoped_ptr<ImageLoadingTracker> extension_app_image_loader_; |
197 | 198 |
198 // Cached web app info data. | 199 // Cached web app info data. |
199 WebApplicationInfo web_app_info_; | 200 WebApplicationInfo web_app_info_; |
200 | 201 |
201 TabContentsWrapper* wrapper_; | 202 TabContentsWrapper* wrapper_; |
202 | 203 |
203 // Either script_executor/action_box_controller will have values, or | 204 // Either script_executor/action_box_controller will have values, or |
204 // script_badge_controller will have a value, depending on whether the action | 205 // script_badge_controller will have a value, depending on whether the action |
205 // box is turned on. | 206 // box is turned on. |
206 scoped_ptr<extensions::ScriptExecutor> script_executor_; | 207 scoped_ptr<extensions::ScriptExecutor> script_executor_; |
207 scoped_ptr<extensions::ActionBoxController> action_box_controller_; | 208 scoped_ptr<extensions::ActionBoxController> action_box_controller_; |
208 scoped_ptr<extensions::ScriptBadgeController> script_badge_controller_; | 209 scoped_ptr<extensions::ScriptBadgeController> script_badge_controller_; |
209 | 210 |
210 DISALLOW_COPY_AND_ASSIGN(ExtensionTabHelper); | 211 DISALLOW_COPY_AND_ASSIGN(ExtensionTabHelper); |
211 }; | 212 }; |
212 | 213 |
213 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_TAB_HELPER_H_ | 214 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_TAB_HELPER_H_ |
OLD | NEW |