| 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 "chrome/browser/extensions/app_notify_channel_setup.h" | 10 #include "chrome/browser/extensions/app_notify_channel_setup.h" |
| 11 #include "chrome/browser/extensions/extension_function_dispatcher.h" | 11 #include "chrome/browser/extensions/extension_function_dispatcher.h" |
| 12 #include "chrome/browser/extensions/image_loading_tracker.h" | 12 #include "chrome/browser/extensions/image_loading_tracker.h" |
| 13 #include "chrome/browser/extensions/webstore_inline_installer.h" | 13 #include "chrome/browser/extensions/webstore_inline_installer.h" |
| 14 #include "chrome/common/web_apps.h" | 14 #include "chrome/common/web_apps.h" |
| 15 #include "content/public/browser/web_contents_observer.h" | 15 #include "content/public/browser/web_contents_observer.h" |
| 16 #include "third_party/skia/include/core/SkBitmap.h" | 16 #include "third_party/skia/include/core/SkBitmap.h" |
| 17 | 17 |
| 18 class Extension; | |
| 19 class ExtensionTabHelperDelegate; | 18 class ExtensionTabHelperDelegate; |
| 20 class TabContentsWrapper; | 19 class TabContentsWrapper; |
| 21 struct WebApplicationInfo; | 20 struct WebApplicationInfo; |
| 22 | 21 |
| 23 namespace content { | 22 namespace content { |
| 24 struct LoadCommittedDetails; | 23 struct LoadCommittedDetails; |
| 25 } | 24 } |
| 26 | 25 |
| 26 namespace extensions { |
| 27 class Extension; |
| 28 } |
| 29 |
| 27 // Per-tab extension helper. Also handles non-extension apps. | 30 // Per-tab extension helper. Also handles non-extension apps. |
| 28 class ExtensionTabHelper | 31 class ExtensionTabHelper |
| 29 : public content::WebContentsObserver, | 32 : public content::WebContentsObserver, |
| 30 public ExtensionFunctionDispatcher::Delegate, | 33 public ExtensionFunctionDispatcher::Delegate, |
| 31 public ImageLoadingTracker::Observer, | 34 public ImageLoadingTracker::Observer, |
| 32 public WebstoreInlineInstaller::Delegate, | 35 public WebstoreInlineInstaller::Delegate, |
| 33 public AppNotifyChannelSetup::Delegate, | 36 public AppNotifyChannelSetup::Delegate, |
| 34 public base::SupportsWeakPtr<ExtensionTabHelper> { | 37 public base::SupportsWeakPtr<ExtensionTabHelper> { |
| 35 public: | 38 public: |
| 36 explicit ExtensionTabHelper(TabContentsWrapper* wrapper); | 39 explicit ExtensionTabHelper(TabContentsWrapper* wrapper); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 52 | 55 |
| 53 // App extensions ------------------------------------------------------------ | 56 // App extensions ------------------------------------------------------------ |
| 54 | 57 |
| 55 // Sets the extension denoting this as an app. If |extension| is non-null this | 58 // Sets the extension denoting this as an app. If |extension| is non-null this |
| 56 // tab becomes an app-tab. WebContents does not listen for unload events for | 59 // tab becomes an app-tab. WebContents does not listen for unload events for |
| 57 // the extension. It's up to consumers of WebContents to do that. | 60 // the extension. It's up to consumers of WebContents to do that. |
| 58 // | 61 // |
| 59 // NOTE: this should only be manipulated before the tab is added to a browser. | 62 // NOTE: this should only be manipulated before the tab is added to a browser. |
| 60 // TODO(sky): resolve if this is the right way to identify an app tab. If it | 63 // TODO(sky): resolve if this is the right way to identify an app tab. If it |
| 61 // is, than this should be passed in the constructor. | 64 // is, than this should be passed in the constructor. |
| 62 void SetExtensionApp(const Extension* extension); | 65 void SetExtensionApp(const extensions::Extension* extension); |
| 63 | 66 |
| 64 // Convenience for setting the app extension by id. This does nothing if | 67 // Convenience for setting the app extension by id. This does nothing if |
| 65 // |extension_app_id| is empty, or an extension can't be found given the | 68 // |extension_app_id| is empty, or an extension can't be found given the |
| 66 // specified id. | 69 // specified id. |
| 67 void SetExtensionAppById(const std::string& extension_app_id); | 70 void SetExtensionAppById(const std::string& extension_app_id); |
| 68 | 71 |
| 69 // Set just the app icon, used by panels created by an extension. | 72 // Set just the app icon, used by panels created by an extension. |
| 70 void SetExtensionAppIconById(const std::string& extension_app_id); | 73 void SetExtensionAppIconById(const std::string& extension_app_id); |
| 71 | 74 |
| 72 const Extension* extension_app() const { return extension_app_; } | 75 const extensions::Extension* extension_app() const { return extension_app_; } |
| 73 bool is_app() const { return extension_app_ != NULL; } | 76 bool is_app() const { return extension_app_ != NULL; } |
| 74 const WebApplicationInfo& web_app_info() const { | 77 const WebApplicationInfo& web_app_info() const { |
| 75 return web_app_info_; | 78 return web_app_info_; |
| 76 } | 79 } |
| 77 | 80 |
| 78 // If an app extension has been explicitly set for this WebContents its icon | 81 // If an app extension has been explicitly set for this WebContents its icon |
| 79 // is returned. | 82 // is returned. |
| 80 // | 83 // |
| 81 // NOTE: the returned icon is larger than 16x16 (its size is | 84 // NOTE: the returned icon is larger than 16x16 (its size is |
| 82 // Extension::EXTENSION_ICON_SMALLISH). | 85 // Extension::EXTENSION_ICON_SMALLISH). |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 int callback_id); | 122 int callback_id); |
| 120 void OnGetAppInstallState(const GURL& requestor_url, | 123 void OnGetAppInstallState(const GURL& requestor_url, |
| 121 int return_route_id, | 124 int return_route_id, |
| 122 int callback_id); | 125 int callback_id); |
| 123 void OnRequest(const ExtensionHostMsg_Request_Params& params); | 126 void OnRequest(const ExtensionHostMsg_Request_Params& params); |
| 124 | 127 |
| 125 // App extensions related methods: | 128 // App extensions related methods: |
| 126 | 129 |
| 127 // Resets app_icon_ and if |extension| is non-null creates a new | 130 // Resets app_icon_ and if |extension| is non-null creates a new |
| 128 // ImageLoadingTracker to load the extension's image. | 131 // ImageLoadingTracker to load the extension's image. |
| 129 void UpdateExtensionAppIcon(const Extension* extension); | 132 void UpdateExtensionAppIcon(const extensions::Extension* extension); |
| 130 | 133 |
| 131 const Extension* GetExtension(const std::string& extension_app_id); | 134 const extensions::Extension* GetExtension( |
| 135 const std::string& extension_app_id); |
| 132 | 136 |
| 133 // ImageLoadingTracker::Observer. | 137 // ImageLoadingTracker::Observer. |
| 134 virtual void OnImageLoaded(const gfx::Image& image, | 138 virtual void OnImageLoaded(const gfx::Image& image, |
| 135 const std::string& extension_id, | 139 const std::string& extension_id, |
| 136 int index) OVERRIDE; | 140 int index) OVERRIDE; |
| 137 | 141 |
| 138 // WebstoreInlineInstaller::Delegate. | 142 // WebstoreInlineInstaller::Delegate. |
| 139 virtual void OnInlineInstallSuccess(int install_id, | 143 virtual void OnInlineInstallSuccess(int install_id, |
| 140 int return_route_id) OVERRIDE; | 144 int return_route_id) OVERRIDE; |
| 141 virtual void OnInlineInstallFailure(int install_id, | 145 virtual void OnInlineInstallFailure(int install_id, |
| 142 int return_route_id, | 146 int return_route_id, |
| 143 const std::string& error) OVERRIDE; | 147 const std::string& error) OVERRIDE; |
| 144 | 148 |
| 145 // AppNotifyChannelSetup::Delegate. | 149 // AppNotifyChannelSetup::Delegate. |
| 146 virtual void AppNotifyChannelSetupComplete( | 150 virtual void AppNotifyChannelSetupComplete( |
| 147 const std::string& channel_id, | 151 const std::string& channel_id, |
| 148 const std::string& error, | 152 const std::string& error, |
| 149 const AppNotifyChannelSetup* setup) OVERRIDE; | 153 const AppNotifyChannelSetup* setup) OVERRIDE; |
| 150 | 154 |
| 151 // Data for app extensions --------------------------------------------------- | 155 // Data for app extensions --------------------------------------------------- |
| 152 | 156 |
| 153 // Delegate for notifying our owner about stuff. Not owned by us. | 157 // Delegate for notifying our owner about stuff. Not owned by us. |
| 154 ExtensionTabHelperDelegate* delegate_; | 158 ExtensionTabHelperDelegate* delegate_; |
| 155 | 159 |
| 156 // If non-null this tab is an app tab and this is the extension the tab was | 160 // If non-null this tab is an app tab and this is the extension the tab was |
| 157 // created for. | 161 // created for. |
| 158 const Extension* extension_app_; | 162 const extensions::Extension* extension_app_; |
| 159 | 163 |
| 160 // Icon for extension_app_ (if non-null) or a manually-set icon for | 164 // Icon for extension_app_ (if non-null) or a manually-set icon for |
| 161 // non-extension apps. | 165 // non-extension apps. |
| 162 SkBitmap extension_app_icon_; | 166 SkBitmap extension_app_icon_; |
| 163 | 167 |
| 164 // Process any extension messages coming from the tab. | 168 // Process any extension messages coming from the tab. |
| 165 ExtensionFunctionDispatcher extension_function_dispatcher_; | 169 ExtensionFunctionDispatcher extension_function_dispatcher_; |
| 166 | 170 |
| 167 // Used for loading extension_app_icon_. | 171 // Used for loading extension_app_icon_. |
| 168 scoped_ptr<ImageLoadingTracker> extension_app_image_loader_; | 172 scoped_ptr<ImageLoadingTracker> extension_app_image_loader_; |
| 169 | 173 |
| 170 // Cached web app info data. | 174 // Cached web app info data. |
| 171 WebApplicationInfo web_app_info_; | 175 WebApplicationInfo web_app_info_; |
| 172 | 176 |
| 173 TabContentsWrapper* wrapper_; | 177 TabContentsWrapper* wrapper_; |
| 174 | 178 |
| 175 DISALLOW_COPY_AND_ASSIGN(ExtensionTabHelper); | 179 DISALLOW_COPY_AND_ASSIGN(ExtensionTabHelper); |
| 176 }; | 180 }; |
| 177 | 181 |
| 178 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_TAB_HELPER_H_ | 182 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_TAB_HELPER_H_ |
| OLD | NEW |