[email protected] | 8809f144 | 2012-01-20 21:21:47 | [diff] [blame^] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 36fb2c7c | 2011-04-04 15:49:08 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 553602e1 | 2011-04-05 17:01:18 | [diff] [blame] | 5 | #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_TAB_HELPER_H_ |
| 6 | #define CHROME_BROWSER_EXTENSIONS_EXTENSION_TAB_HELPER_H_ |
[email protected] | 36fb2c7c | 2011-04-04 15:49:08 | [diff] [blame] | 7 | #pragma once |
| 8 | |
[email protected] | 82a4373 | 2011-10-07 16:09:11 | [diff] [blame] | 9 | #include "base/memory/weak_ptr.h" |
| 10 | #include "chrome/browser/extensions/app_notify_channel_setup.h" |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 11 | #include "chrome/browser/extensions/extension_function_dispatcher.h" |
[email protected] | 36fb2c7c | 2011-04-04 15:49:08 | [diff] [blame] | 12 | #include "chrome/browser/extensions/image_loading_tracker.h" |
[email protected] | 8915f34 | 2011-08-29 22:14:37 | [diff] [blame] | 13 | #include "chrome/browser/extensions/webstore_inline_installer.h" |
[email protected] | 553602e1 | 2011-04-05 17:01:18 | [diff] [blame] | 14 | #include "chrome/common/web_apps.h" |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 15 | #include "content/public/browser/web_contents_observer.h" |
[email protected] | 36fb2c7c | 2011-04-04 15:49:08 | [diff] [blame] | 16 | #include "third_party/skia/include/core/SkBitmap.h" |
| 17 | |
| 18 | class Extension; |
[email protected] | 1739e57d | 2011-11-30 21:18:25 | [diff] [blame] | 19 | class ExtensionTabHelperDelegate; |
[email protected] | 553602e1 | 2011-04-05 17:01:18 | [diff] [blame] | 20 | class TabContentsWrapper; |
| 21 | struct WebApplicationInfo; |
[email protected] | 36fb2c7c | 2011-04-04 15:49:08 | [diff] [blame] | 22 | |
[email protected] | 8286f51a | 2011-05-31 17:39:13 | [diff] [blame] | 23 | namespace content { |
| 24 | struct LoadCommittedDetails; |
| 25 | } |
| 26 | |
[email protected] | 74e5140 | 2011-04-06 14:17:59 | [diff] [blame] | 27 | // Per-tab extension helper. Also handles non-extension apps. |
[email protected] | 82a4373 | 2011-10-07 16:09:11 | [diff] [blame] | 28 | class ExtensionTabHelper |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 29 | : public content::WebContentsObserver, |
[email protected] | 82a4373 | 2011-10-07 16:09:11 | [diff] [blame] | 30 | public ExtensionFunctionDispatcher::Delegate, |
| 31 | public ImageLoadingTracker::Observer, |
| 32 | public WebstoreInlineInstaller::Delegate, |
| 33 | public AppNotifyChannelSetup::Delegate, |
| 34 | public base::SupportsWeakPtr<ExtensionTabHelper> { |
[email protected] | 36fb2c7c | 2011-04-04 15:49:08 | [diff] [blame] | 35 | public: |
[email protected] | 553602e1 | 2011-04-05 17:01:18 | [diff] [blame] | 36 | explicit ExtensionTabHelper(TabContentsWrapper* wrapper); |
[email protected] | 36fb2c7c | 2011-04-04 15:49:08 | [diff] [blame] | 37 | virtual ~ExtensionTabHelper(); |
| 38 | |
| 39 | // Copies the internal state from another ExtensionTabHelper. |
| 40 | void CopyStateFrom(const ExtensionTabHelper& source); |
| 41 | |
[email protected] | 1739e57d | 2011-11-30 21:18:25 | [diff] [blame] | 42 | ExtensionTabHelperDelegate* delegate() const { return delegate_; } |
| 43 | void set_delegate(ExtensionTabHelperDelegate* d) { delegate_ = d; } |
| 44 | |
[email protected] | 36fb2c7c | 2011-04-04 15:49:08 | [diff] [blame] | 45 | // Call this after updating a page action to notify clients about the changes. |
| 46 | void PageActionStateChanged(); |
| 47 | |
[email protected] | 553602e1 | 2011-04-05 17:01:18 | [diff] [blame] | 48 | // Requests application info for the specified page. This is an asynchronous |
| 49 | // request. The delegate is notified by way of OnDidGetApplicationInfo when |
| 50 | // the data is available. |
| 51 | void GetApplicationInfo(int32 page_id); |
| 52 | |
[email protected] | 36fb2c7c | 2011-04-04 15:49:08 | [diff] [blame] | 53 | // App extensions ------------------------------------------------------------ |
| 54 | |
| 55 | // Sets the extension denoting this as an app. If |extension| is non-null this |
| 56 | // tab becomes an app-tab. TabContents does not listen for unload events for |
| 57 | // the extension. It's up to consumers of TabContents to do that. |
| 58 | // |
| 59 | // 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 |
| 61 | // is, than this should be passed in the constructor. |
| 62 | void SetExtensionApp(const Extension* extension); |
| 63 | |
| 64 | // 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 |
| 66 | // specified id. |
| 67 | void SetExtensionAppById(const std::string& extension_app_id); |
| 68 | |
| 69 | const Extension* extension_app() const { return extension_app_; } |
| 70 | bool is_app() const { return extension_app_ != NULL; } |
[email protected] | 553602e1 | 2011-04-05 17:01:18 | [diff] [blame] | 71 | const WebApplicationInfo& web_app_info() const { |
| 72 | return web_app_info_; |
| 73 | } |
[email protected] | 36fb2c7c | 2011-04-04 15:49:08 | [diff] [blame] | 74 | |
| 75 | // If an app extension has been explicitly set for this TabContents its icon |
| 76 | // is returned. |
| 77 | // |
| 78 | // NOTE: the returned icon is larger than 16x16 (its size is |
| 79 | // Extension::EXTENSION_ICON_SMALLISH). |
| 80 | SkBitmap* GetExtensionAppIcon(); |
| 81 | |
[email protected] | 8189899 | 2011-06-14 22:15:00 | [diff] [blame] | 82 | TabContentsWrapper* tab_contents_wrapper() { |
| 83 | return wrapper_; |
| 84 | } |
| 85 | |
[email protected] | ea049a0 | 2011-12-25 21:37:09 | [diff] [blame] | 86 | content::WebContents* web_contents() const { |
| 87 | return content::WebContentsObserver::web_contents(); |
[email protected] | 36fb2c7c | 2011-04-04 15:49:08 | [diff] [blame] | 88 | } |
| 89 | |
[email protected] | 74e5140 | 2011-04-06 14:17:59 | [diff] [blame] | 90 | // Sets a non-extension app icon associated with TabContents and fires an |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 91 | // INVALIDATE_TYPE_TITLE navigation state change to trigger repaint of title. |
[email protected] | 74e5140 | 2011-04-06 14:17:59 | [diff] [blame] | 92 | void SetAppIcon(const SkBitmap& app_icon); |
| 93 | |
[email protected] | 36fb2c7c | 2011-04-04 15:49:08 | [diff] [blame] | 94 | private: |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 95 | // content::WebContentsObserver overrides. |
[email protected] | a6e16aec | 2011-11-11 18:53:04 | [diff] [blame] | 96 | virtual void DidNavigateMainFrame( |
[email protected] | 8286f51a | 2011-05-31 17:39:13 | [diff] [blame] | 97 | const content::LoadCommittedDetails& details, |
[email protected] | 6766b17 | 2011-11-21 18:29:36 | [diff] [blame] | 98 | const content::FrameNavigateParams& params) OVERRIDE; |
[email protected] | 8915f34 | 2011-08-29 22:14:37 | [diff] [blame] | 99 | virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
[email protected] | 553602e1 | 2011-04-05 17:01:18 | [diff] [blame] | 100 | |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 101 | // ExtensionFunctionDispatcher::Delegate overrides. |
[email protected] | 8915f34 | 2011-08-29 22:14:37 | [diff] [blame] | 102 | virtual Browser* GetBrowser() OVERRIDE; |
[email protected] | ea049a0 | 2011-12-25 21:37:09 | [diff] [blame] | 103 | virtual content::WebContents* GetAssociatedWebContents() const OVERRIDE; |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 104 | |
[email protected] | 553602e1 | 2011-04-05 17:01:18 | [diff] [blame] | 105 | // Message handlers. |
| 106 | void OnDidGetApplicationInfo(int32 page_id, const WebApplicationInfo& info); |
| 107 | void OnInstallApplication(const WebApplicationInfo& info); |
[email protected] | a221ef09 | 2011-09-07 01:34:10 | [diff] [blame] | 108 | void OnInlineWebstoreInstall(int install_id, |
| 109 | const std::string& webstore_item_id, |
| 110 | const GURL& requestor_url); |
[email protected] | 2df5db74 | 2011-10-12 01:37:22 | [diff] [blame] | 111 | void OnGetAppNotifyChannel(const GURL& requestor_url, |
| 112 | const std::string& client_id, |
| 113 | int return_route_id, |
| 114 | int callback_id); |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 115 | void OnRequest(const ExtensionHostMsg_Request_Params& params); |
[email protected] | 36fb2c7c | 2011-04-04 15:49:08 | [diff] [blame] | 116 | |
| 117 | // App extensions related methods: |
| 118 | |
| 119 | // Resets app_icon_ and if |extension| is non-null creates a new |
| 120 | // ImageLoadingTracker to load the extension's image. |
| 121 | void UpdateExtensionAppIcon(const Extension* extension); |
| 122 | |
| 123 | // ImageLoadingTracker::Observer. |
| 124 | virtual void OnImageLoaded(SkBitmap* image, const ExtensionResource& resource, |
[email protected] | 8915f34 | 2011-08-29 22:14:37 | [diff] [blame] | 125 | int index) OVERRIDE; |
| 126 | |
| 127 | // WebstoreInlineInstaller::Delegate. |
[email protected] | a221ef09 | 2011-09-07 01:34:10 | [diff] [blame] | 128 | virtual void OnInlineInstallSuccess(int install_id) OVERRIDE; |
| 129 | virtual void OnInlineInstallFailure(int install_id, |
| 130 | const std::string& error) OVERRIDE; |
[email protected] | 36fb2c7c | 2011-04-04 15:49:08 | [diff] [blame] | 131 | |
[email protected] | 82a4373 | 2011-10-07 16:09:11 | [diff] [blame] | 132 | // AppNotifyChannelSetup::Delegate. |
[email protected] | b2689a90 | 2011-12-01 00:41:09 | [diff] [blame] | 133 | virtual void AppNotifyChannelSetupComplete( |
| 134 | const std::string& channel_id, |
| 135 | const std::string& error, |
| 136 | const AppNotifyChannelSetup* setup) OVERRIDE; |
[email protected] | 82a4373 | 2011-10-07 16:09:11 | [diff] [blame] | 137 | |
[email protected] | 36fb2c7c | 2011-04-04 15:49:08 | [diff] [blame] | 138 | // Data for app extensions --------------------------------------------------- |
| 139 | |
[email protected] | 1739e57d | 2011-11-30 21:18:25 | [diff] [blame] | 140 | // Delegate for notifying our owner about stuff. Not owned by us. |
| 141 | ExtensionTabHelperDelegate* delegate_; |
| 142 | |
[email protected] | 36fb2c7c | 2011-04-04 15:49:08 | [diff] [blame] | 143 | // If non-null this tab is an app tab and this is the extension the tab was |
| 144 | // created for. |
| 145 | const Extension* extension_app_; |
| 146 | |
[email protected] | 74e5140 | 2011-04-06 14:17:59 | [diff] [blame] | 147 | // Icon for extension_app_ (if non-null) or a manually-set icon for |
| 148 | // non-extension apps. |
[email protected] | 36fb2c7c | 2011-04-04 15:49:08 | [diff] [blame] | 149 | SkBitmap extension_app_icon_; |
| 150 | |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 151 | // Process any extension messages coming from the tab. |
| 152 | ExtensionFunctionDispatcher extension_function_dispatcher_; |
| 153 | |
[email protected] | 36fb2c7c | 2011-04-04 15:49:08 | [diff] [blame] | 154 | // Used for loading extension_app_icon_. |
| 155 | scoped_ptr<ImageLoadingTracker> extension_app_image_loader_; |
| 156 | |
[email protected] | 553602e1 | 2011-04-05 17:01:18 | [diff] [blame] | 157 | // Cached web app info data. |
| 158 | WebApplicationInfo web_app_info_; |
| 159 | |
| 160 | TabContentsWrapper* wrapper_; |
| 161 | |
[email protected] | 36fb2c7c | 2011-04-04 15:49:08 | [diff] [blame] | 162 | DISALLOW_COPY_AND_ASSIGN(ExtensionTabHelper); |
| 163 | }; |
| 164 | |
[email protected] | 553602e1 | 2011-04-05 17:01:18 | [diff] [blame] | 165 | #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_TAB_HELPER_H_ |