| 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/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| 11 #include "base/observer_list.h" | 11 #include "base/observer_list.h" |
| 12 #include "chrome/browser/extensions/active_tab_permission_manager.h" | 12 #include "chrome/browser/extensions/active_tab_permission_manager.h" |
| 13 #include "chrome/browser/extensions/app_notify_channel_setup.h" | 13 #include "chrome/browser/extensions/app_notify_channel_setup.h" |
| 14 #include "chrome/browser/extensions/extension_function_dispatcher.h" | 14 #include "chrome/browser/extensions/extension_function_dispatcher.h" |
| 15 #include "chrome/browser/extensions/image_loading_tracker.h" | 15 #include "chrome/browser/extensions/image_loading_tracker.h" |
| 16 #include "chrome/browser/extensions/webstore_inline_installer.h" | 16 #include "chrome/browser/extensions/webstore_inline_installer.h" |
| 17 #include "chrome/common/web_apps.h" | 17 #include "chrome/common/web_apps.h" |
| 18 #include "content/public/browser/notification_observer.h" |
| 19 #include "content/public/browser/notification_registrar.h" |
| 18 #include "content/public/browser/web_contents_observer.h" | 20 #include "content/public/browser/web_contents_observer.h" |
| 19 #include "third_party/skia/include/core/SkBitmap.h" | 21 #include "third_party/skia/include/core/SkBitmap.h" |
| 20 | 22 |
| 21 class ExtensionTabHelperDelegate; | |
| 22 class TabContents; | 23 class TabContents; |
| 23 struct WebApplicationInfo; | 24 struct WebApplicationInfo; |
| 24 | 25 |
| 25 namespace content { | 26 namespace content { |
| 26 struct LoadCommittedDetails; | 27 struct LoadCommittedDetails; |
| 27 } | 28 } |
| 28 | 29 |
| 29 namespace extensions { | 30 namespace extensions { |
| 30 class Extension; | 31 class Extension; |
| 31 class LocationBarController; | 32 class LocationBarController; |
| 32 class ScriptBadgeController; | 33 class ScriptBadgeController; |
| 33 class ScriptExecutor; | 34 class ScriptExecutor; |
| 34 } | 35 } |
| 35 | 36 |
| 36 // Per-tab extension helper. Also handles non-extension apps. | 37 // Per-tab extension helper. Also handles non-extension apps. |
| 37 class ExtensionTabHelper | 38 class ExtensionTabHelper |
| 38 : public content::WebContentsObserver, | 39 : public content::WebContentsObserver, |
| 39 public ExtensionFunctionDispatcher::Delegate, | 40 public ExtensionFunctionDispatcher::Delegate, |
| 40 public ImageLoadingTracker::Observer, | 41 public ImageLoadingTracker::Observer, |
| 41 public WebstoreInlineInstaller::Delegate, | 42 public WebstoreInlineInstaller::Delegate, |
| 42 public AppNotifyChannelSetup::Delegate, | 43 public AppNotifyChannelSetup::Delegate, |
| 43 public base::SupportsWeakPtr<ExtensionTabHelper> { | 44 public base::SupportsWeakPtr<ExtensionTabHelper>, |
| 45 public content::NotificationObserver { |
| 44 public: | 46 public: |
| 47 // Different types of action when web app info is available. |
| 48 // OnDidGetApplicationInfo uses this to dispatch calls. |
| 49 enum WebAppAction { |
| 50 NONE, // No action at all. |
| 51 CREATE_SHORTCUT, // Bring up create application shortcut dialog. |
| 52 UPDATE_SHORTCUT // Update icon for app shortcut. |
| 53 }; |
| 54 |
| 45 explicit ExtensionTabHelper(TabContents* tab_contents); | 55 explicit ExtensionTabHelper(TabContents* tab_contents); |
| 46 virtual ~ExtensionTabHelper(); | 56 virtual ~ExtensionTabHelper(); |
| 47 | 57 |
| 48 // Copies the internal state from another ExtensionTabHelper. | 58 // Copies the internal state from another ExtensionTabHelper. |
| 49 void CopyStateFrom(const ExtensionTabHelper& source); | 59 void CopyStateFrom(const ExtensionTabHelper& source); |
| 50 | 60 |
| 51 ExtensionTabHelperDelegate* delegate() const { return delegate_; } | 61 void CreateApplicationShortcuts(); |
| 52 void set_delegate(ExtensionTabHelperDelegate* d) { delegate_ = d; } | 62 bool CanCreateApplicationShortcuts() const; |
| 53 | 63 |
| 54 // Requests application info for the specified page. This is an asynchronous | 64 void set_pending_web_app_action(WebAppAction action) { |
| 55 // request. The delegate is notified by way of OnDidGetApplicationInfo when | 65 pending_web_app_action_ = action; |
| 56 // the data is available. | 66 } |
| 57 void GetApplicationInfo(int32 page_id); | |
| 58 | 67 |
| 59 // Gets the ID of the tab. | 68 // Gets the ID of the tab. |
| 60 int tab_id() const; | 69 int tab_id() const; |
| 61 | 70 |
| 62 // Gets the window ID of the tab. | 71 // Gets the window ID of the tab. |
| 63 int window_id() const; | 72 int window_id() const; |
| 64 | 73 |
| 65 // App extensions ------------------------------------------------------------ | 74 // App extensions ------------------------------------------------------------ |
| 66 | 75 |
| 67 // Sets the extension denoting this as an app. If |extension| is non-null this | 76 // Sets the extension denoting this as an app. If |extension| is non-null this |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 virtual void OnInlineInstallFailure(int install_id, | 173 virtual void OnInlineInstallFailure(int install_id, |
| 165 int return_route_id, | 174 int return_route_id, |
| 166 const std::string& error) OVERRIDE; | 175 const std::string& error) OVERRIDE; |
| 167 | 176 |
| 168 // AppNotifyChannelSetup::Delegate. | 177 // AppNotifyChannelSetup::Delegate. |
| 169 virtual void AppNotifyChannelSetupComplete( | 178 virtual void AppNotifyChannelSetupComplete( |
| 170 const std::string& channel_id, | 179 const std::string& channel_id, |
| 171 const std::string& error, | 180 const std::string& error, |
| 172 const AppNotifyChannelSetup* setup) OVERRIDE; | 181 const AppNotifyChannelSetup* setup) OVERRIDE; |
| 173 | 182 |
| 183 // content::NotificationObserver. |
| 184 virtual void Observe(int type, |
| 185 const content::NotificationSource& source, |
| 186 const content::NotificationDetails& details) OVERRIDE; |
| 187 |
| 188 // Requests application info for the specified page. This is an asynchronous |
| 189 // request. The delegate is notified by way of OnDidGetApplicationInfo when |
| 190 // the data is available. |
| 191 void GetApplicationInfo(int32 page_id); |
| 192 |
| 174 // Data for app extensions --------------------------------------------------- | 193 // Data for app extensions --------------------------------------------------- |
| 175 | 194 |
| 176 // Our observers. Declare at top so that it will outlive all other members, | 195 // Our observers. Declare at top so that it will outlive all other members, |
| 177 // since they might add themselves as observers. | 196 // since they might add themselves as observers. |
| 178 ObserverList<Observer> observers_; | 197 ObserverList<Observer> observers_; |
| 179 | 198 |
| 180 // Delegate for notifying our owner about stuff. Not owned by us. | |
| 181 ExtensionTabHelperDelegate* delegate_; | |
| 182 | |
| 183 // If non-null this tab is an app tab and this is the extension the tab was | 199 // If non-null this tab is an app tab and this is the extension the tab was |
| 184 // created for. | 200 // created for. |
| 185 const extensions::Extension* extension_app_; | 201 const extensions::Extension* extension_app_; |
| 186 | 202 |
| 187 // Icon for extension_app_ (if non-null) or a manually-set icon for | 203 // Icon for extension_app_ (if non-null) or a manually-set icon for |
| 188 // non-extension apps. | 204 // non-extension apps. |
| 189 SkBitmap extension_app_icon_; | 205 SkBitmap extension_app_icon_; |
| 190 | 206 |
| 191 // Process any extension messages coming from the tab. | 207 // Process any extension messages coming from the tab. |
| 192 ExtensionFunctionDispatcher extension_function_dispatcher_; | 208 ExtensionFunctionDispatcher extension_function_dispatcher_; |
| 193 | 209 |
| 194 // Used for loading extension_app_icon_. | 210 // Used for loading extension_app_icon_. |
| 195 scoped_ptr<ImageLoadingTracker> extension_app_image_loader_; | 211 scoped_ptr<ImageLoadingTracker> extension_app_image_loader_; |
| 196 | 212 |
| 197 // Cached web app info data. | 213 // Cached web app info data. |
| 198 WebApplicationInfo web_app_info_; | 214 WebApplicationInfo web_app_info_; |
| 199 | 215 |
| 216 // Which deferred action to perform when OnDidGetApplicationInfo is notified |
| 217 // from a WebContents. |
| 218 WebAppAction pending_web_app_action_; |
| 219 |
| 220 content::NotificationRegistrar registrar_; |
| 221 |
| 200 TabContents* tab_contents_; | 222 TabContents* tab_contents_; |
| 201 | 223 |
| 202 // Either script_executor/location_bar_controller will have values, or | 224 // Either script_executor/location_bar_controller will have values, or |
| 203 // script_badge_controller will have a value, depending on whether the action | 225 // script_badge_controller will have a value, depending on whether the action |
| 204 // box is turned on. | 226 // box is turned on. |
| 205 scoped_ptr<extensions::ScriptExecutor> script_executor_; | 227 scoped_ptr<extensions::ScriptExecutor> script_executor_; |
| 206 scoped_ptr<extensions::LocationBarController> location_bar_controller_; | 228 scoped_ptr<extensions::LocationBarController> location_bar_controller_; |
| 207 scoped_refptr<extensions::ScriptBadgeController> script_badge_controller_; | 229 scoped_refptr<extensions::ScriptBadgeController> script_badge_controller_; |
| 208 | 230 |
| 209 extensions::ActiveTabPermissionManager active_tab_permission_manager_; | 231 extensions::ActiveTabPermissionManager active_tab_permission_manager_; |
| 210 | 232 |
| 211 DISALLOW_COPY_AND_ASSIGN(ExtensionTabHelper); | 233 DISALLOW_COPY_AND_ASSIGN(ExtensionTabHelper); |
| 212 }; | 234 }; |
| 213 | 235 |
| 214 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_TAB_HELPER_H_ | 236 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_TAB_HELPER_H_ |
| OLD | NEW |