blob: b732595cd94497dc7485cd2a2078c78f0030d177 [file] [log] [blame]
[email protected]8809f1442012-01-20 21:21:471// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]36fb2c7c2011-04-04 15:49:082// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]553602e12011-04-05 17:01:185#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_TAB_HELPER_H_
6#define CHROME_BROWSER_EXTENSIONS_EXTENSION_TAB_HELPER_H_
[email protected]36fb2c7c2011-04-04 15:49:087#pragma once
8
[email protected]82a43732011-10-07 16:09:119#include "base/memory/weak_ptr.h"
10#include "chrome/browser/extensions/app_notify_channel_setup.h"
[email protected]c5dbef02011-05-13 05:06:0911#include "chrome/browser/extensions/extension_function_dispatcher.h"
[email protected]36fb2c7c2011-04-04 15:49:0812#include "chrome/browser/extensions/image_loading_tracker.h"
[email protected]8915f342011-08-29 22:14:3713#include "chrome/browser/extensions/webstore_inline_installer.h"
[email protected]553602e12011-04-05 17:01:1814#include "chrome/common/web_apps.h"
[email protected]d8c660432011-12-22 20:51:2515#include "content/public/browser/web_contents_observer.h"
[email protected]36fb2c7c2011-04-04 15:49:0816#include "third_party/skia/include/core/SkBitmap.h"
17
18class Extension;
[email protected]1739e57d2011-11-30 21:18:2519class ExtensionTabHelperDelegate;
[email protected]553602e12011-04-05 17:01:1820class TabContentsWrapper;
21struct WebApplicationInfo;
[email protected]36fb2c7c2011-04-04 15:49:0822
[email protected]8286f51a2011-05-31 17:39:1323namespace content {
24struct LoadCommittedDetails;
25}
26
[email protected]74e51402011-04-06 14:17:5927// Per-tab extension helper. Also handles non-extension apps.
[email protected]82a43732011-10-07 16:09:1128class ExtensionTabHelper
[email protected]d8c660432011-12-22 20:51:2529 : public content::WebContentsObserver,
[email protected]82a43732011-10-07 16:09:1130 public ExtensionFunctionDispatcher::Delegate,
31 public ImageLoadingTracker::Observer,
32 public WebstoreInlineInstaller::Delegate,
33 public AppNotifyChannelSetup::Delegate,
34 public base::SupportsWeakPtr<ExtensionTabHelper> {
[email protected]36fb2c7c2011-04-04 15:49:0835 public:
[email protected]553602e12011-04-05 17:01:1836 explicit ExtensionTabHelper(TabContentsWrapper* wrapper);
[email protected]36fb2c7c2011-04-04 15:49:0837 virtual ~ExtensionTabHelper();
38
39 // Copies the internal state from another ExtensionTabHelper.
40 void CopyStateFrom(const ExtensionTabHelper& source);
41
[email protected]1739e57d2011-11-30 21:18:2542 ExtensionTabHelperDelegate* delegate() const { return delegate_; }
43 void set_delegate(ExtensionTabHelperDelegate* d) { delegate_ = d; }
44
[email protected]36fb2c7c2011-04-04 15:49:0845 // Call this after updating a page action to notify clients about the changes.
46 void PageActionStateChanged();
47
[email protected]553602e12011-04-05 17:01:1848 // 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]36fb2c7c2011-04-04 15:49:0853 // 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]553602e12011-04-05 17:01:1871 const WebApplicationInfo& web_app_info() const {
72 return web_app_info_;
73 }
[email protected]36fb2c7c2011-04-04 15:49:0874
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]81898992011-06-14 22:15:0082 TabContentsWrapper* tab_contents_wrapper() {
83 return wrapper_;
84 }
85
[email protected]ea049a02011-12-25 21:37:0986 content::WebContents* web_contents() const {
87 return content::WebContentsObserver::web_contents();
[email protected]36fb2c7c2011-04-04 15:49:0888 }
89
[email protected]74e51402011-04-06 14:17:5990 // Sets a non-extension app icon associated with TabContents and fires an
[email protected]d9083482012-01-06 00:38:4691 // INVALIDATE_TYPE_TITLE navigation state change to trigger repaint of title.
[email protected]74e51402011-04-06 14:17:5992 void SetAppIcon(const SkBitmap& app_icon);
93
[email protected]36fb2c7c2011-04-04 15:49:0894 private:
[email protected]d8c660432011-12-22 20:51:2595 // content::WebContentsObserver overrides.
[email protected]a6e16aec2011-11-11 18:53:0496 virtual void DidNavigateMainFrame(
[email protected]8286f51a2011-05-31 17:39:1397 const content::LoadCommittedDetails& details,
[email protected]6766b172011-11-21 18:29:3698 const content::FrameNavigateParams& params) OVERRIDE;
[email protected]8915f342011-08-29 22:14:3799 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
[email protected]553602e12011-04-05 17:01:18100
[email protected]c5dbef02011-05-13 05:06:09101 // ExtensionFunctionDispatcher::Delegate overrides.
[email protected]8915f342011-08-29 22:14:37102 virtual Browser* GetBrowser() OVERRIDE;
[email protected]ea049a02011-12-25 21:37:09103 virtual content::WebContents* GetAssociatedWebContents() const OVERRIDE;
[email protected]c5dbef02011-05-13 05:06:09104
[email protected]553602e12011-04-05 17:01:18105 // Message handlers.
106 void OnDidGetApplicationInfo(int32 page_id, const WebApplicationInfo& info);
107 void OnInstallApplication(const WebApplicationInfo& info);
[email protected]a221ef092011-09-07 01:34:10108 void OnInlineWebstoreInstall(int install_id,
109 const std::string& webstore_item_id,
110 const GURL& requestor_url);
[email protected]2df5db742011-10-12 01:37:22111 void OnGetAppNotifyChannel(const GURL& requestor_url,
112 const std::string& client_id,
113 int return_route_id,
114 int callback_id);
[email protected]c5dbef02011-05-13 05:06:09115 void OnRequest(const ExtensionHostMsg_Request_Params& params);
[email protected]36fb2c7c2011-04-04 15:49:08116
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]8915f342011-08-29 22:14:37125 int index) OVERRIDE;
126
127 // WebstoreInlineInstaller::Delegate.
[email protected]a221ef092011-09-07 01:34:10128 virtual void OnInlineInstallSuccess(int install_id) OVERRIDE;
129 virtual void OnInlineInstallFailure(int install_id,
130 const std::string& error) OVERRIDE;
[email protected]36fb2c7c2011-04-04 15:49:08131
[email protected]82a43732011-10-07 16:09:11132 // AppNotifyChannelSetup::Delegate.
[email protected]b2689a902011-12-01 00:41:09133 virtual void AppNotifyChannelSetupComplete(
134 const std::string& channel_id,
135 const std::string& error,
136 const AppNotifyChannelSetup* setup) OVERRIDE;
[email protected]82a43732011-10-07 16:09:11137
[email protected]36fb2c7c2011-04-04 15:49:08138 // Data for app extensions ---------------------------------------------------
139
[email protected]1739e57d2011-11-30 21:18:25140 // Delegate for notifying our owner about stuff. Not owned by us.
141 ExtensionTabHelperDelegate* delegate_;
142
[email protected]36fb2c7c2011-04-04 15:49:08143 // 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]74e51402011-04-06 14:17:59147 // Icon for extension_app_ (if non-null) or a manually-set icon for
148 // non-extension apps.
[email protected]36fb2c7c2011-04-04 15:49:08149 SkBitmap extension_app_icon_;
150
[email protected]c5dbef02011-05-13 05:06:09151 // Process any extension messages coming from the tab.
152 ExtensionFunctionDispatcher extension_function_dispatcher_;
153
[email protected]36fb2c7c2011-04-04 15:49:08154 // Used for loading extension_app_icon_.
155 scoped_ptr<ImageLoadingTracker> extension_app_image_loader_;
156
[email protected]553602e12011-04-05 17:01:18157 // Cached web app info data.
158 WebApplicationInfo web_app_info_;
159
160 TabContentsWrapper* wrapper_;
161
[email protected]36fb2c7c2011-04-04 15:49:08162 DISALLOW_COPY_AND_ASSIGN(ExtensionTabHelper);
163};
164
[email protected]553602e12011-04-05 17:01:18165#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_TAB_HELPER_H_