summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/tab_helper.h
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/extensions/tab_helper.h')
-rw-r--r--chrome/browser/extensions/tab_helper.h236
1 files changed, 236 insertions, 0 deletions
diff --git a/chrome/browser/extensions/tab_helper.h b/chrome/browser/extensions/tab_helper.h
new file mode 100644
index 0000000..13cac4e
--- /dev/null
+++ b/chrome/browser/extensions/tab_helper.h
@@ -0,0 +1,236 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_EXTENSIONS_TAB_HELPER_H_
+#define CHROME_BROWSER_EXTENSIONS_TAB_HELPER_H_
+
+#include "base/memory/ref_counted.h"
+#include "base/memory/weak_ptr.h"
+#include "base/observer_list.h"
+#include "chrome/browser/extensions/active_tab_permission_manager.h"
+#include "chrome/browser/extensions/app_notify_channel_setup.h"
+#include "chrome/browser/extensions/extension_function_dispatcher.h"
+#include "chrome/browser/extensions/image_loading_tracker.h"
+#include "chrome/browser/extensions/webstore_inline_installer.h"
+#include "chrome/common/web_apps.h"
+#include "content/public/browser/notification_observer.h"
+#include "content/public/browser/notification_registrar.h"
+#include "content/public/browser/web_contents_observer.h"
+#include "third_party/skia/include/core/SkBitmap.h"
+
+class TabContents;
+struct WebApplicationInfo;
+
+namespace content {
+struct LoadCommittedDetails;
+}
+
+namespace extensions {
+class Extension;
+class LocationBarController;
+class ScriptBadgeController;
+class ScriptExecutor;
+
+// Per-tab extension helper. Also handles non-extension apps.
+class TabHelper : public content::WebContentsObserver,
+ public ExtensionFunctionDispatcher::Delegate,
+ public ImageLoadingTracker::Observer,
+ public WebstoreInlineInstaller::Delegate,
+ public AppNotifyChannelSetup::Delegate,
+ public base::SupportsWeakPtr<TabHelper>,
+ public content::NotificationObserver {
+ public:
+ // Different types of action when web app info is available.
+ // OnDidGetApplicationInfo uses this to dispatch calls.
+ enum WebAppAction {
+ NONE, // No action at all.
+ CREATE_SHORTCUT, // Bring up create application shortcut dialog.
+ UPDATE_SHORTCUT // Update icon for app shortcut.
+ };
+
+ explicit TabHelper(TabContents* tab_contents);
+ virtual ~TabHelper();
+
+ // Copies the internal state from another TabHelper.
+ void CopyStateFrom(const TabHelper& source);
+
+ void CreateApplicationShortcuts();
+ bool CanCreateApplicationShortcuts() const;
+
+ void set_pending_web_app_action(WebAppAction action) {
+ pending_web_app_action_ = action;
+ }
+
+ // Gets the ID of the tab.
+ int tab_id() const;
+
+ // Gets the window ID of the tab.
+ int window_id() const;
+
+ // App extensions ------------------------------------------------------------
+
+ // Sets the extension denoting this as an app. If |extension| is non-null this
+ // tab becomes an app-tab. WebContents does not listen for unload events for
+ // the extension. It's up to consumers of WebContents to do that.
+ //
+ // NOTE: this should only be manipulated before the tab is added to a browser.
+ // TODO(sky): resolve if this is the right way to identify an app tab. If it
+ // is, than this should be passed in the constructor.
+ void SetExtensionApp(const Extension* extension);
+
+ // Convenience for setting the app extension by id. This does nothing if
+ // |extension_app_id| is empty, or an extension can't be found given the
+ // specified id.
+ void SetExtensionAppById(const std::string& extension_app_id);
+
+ // Set just the app icon, used by panels created by an extension.
+ void SetExtensionAppIconById(const std::string& extension_app_id);
+
+ const Extension* extension_app() const { return extension_app_; }
+ bool is_app() const { return extension_app_ != NULL; }
+ const WebApplicationInfo& web_app_info() const {
+ return web_app_info_;
+ }
+
+ // If an app extension has been explicitly set for this WebContents its icon
+ // is returned.
+ //
+ // NOTE: the returned icon is larger than 16x16 (its size is
+ // Extension::EXTENSION_ICON_SMALLISH).
+ SkBitmap* GetExtensionAppIcon();
+
+ TabContents* tab_contents() {
+ return tab_contents_;
+ }
+
+ content::WebContents* web_contents() const {
+ return content::WebContentsObserver::web_contents();
+ }
+
+ ScriptExecutor* script_executor() {
+ return script_executor_.get();
+ }
+
+ LocationBarController* location_bar_controller() {
+ return location_bar_controller_.get();
+ }
+
+ ActiveTabPermissionManager* active_tab_permission_manager() {
+ return &active_tab_permission_manager_;
+ }
+
+ // Sets a non-extension app icon associated with WebContents and fires an
+ // INVALIDATE_TYPE_TITLE navigation state change to trigger repaint of title.
+ void SetAppIcon(const SkBitmap& app_icon);
+
+ private:
+ // content::WebContentsObserver overrides.
+ virtual void RenderViewCreated(
+ content::RenderViewHost* render_view_host) OVERRIDE;
+ virtual void DidNavigateMainFrame(
+ const content::LoadCommittedDetails& details,
+ const content::FrameNavigateParams& params) OVERRIDE;
+ virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
+
+ // ExtensionFunctionDispatcher::Delegate overrides.
+ virtual ExtensionWindowController* GetExtensionWindowController()
+ const OVERRIDE;
+ virtual content::WebContents* GetAssociatedWebContents() const OVERRIDE;
+
+ // Message handlers.
+ void OnDidGetApplicationInfo(int32 page_id, const WebApplicationInfo& info);
+ void OnInstallApplication(const WebApplicationInfo& info);
+ void OnInlineWebstoreInstall(int install_id,
+ int return_route_id,
+ const std::string& webstore_item_id,
+ const GURL& requestor_url);
+ void OnGetAppNotifyChannel(const GURL& requestor_url,
+ const std::string& client_id,
+ int return_route_id,
+ int callback_id);
+ void OnGetAppInstallState(const GURL& requestor_url,
+ int return_route_id,
+ int callback_id);
+ void OnRequest(const ExtensionHostMsg_Request_Params& params);
+
+ // App extensions related methods:
+
+ // Resets app_icon_ and if |extension| is non-null creates a new
+ // ImageLoadingTracker to load the extension's image.
+ void UpdateExtensionAppIcon(const Extension* extension);
+
+ const Extension* GetExtension(
+ const std::string& extension_app_id);
+
+ // ImageLoadingTracker::Observer.
+ virtual void OnImageLoaded(const gfx::Image& image,
+ const std::string& extension_id,
+ int index) OVERRIDE;
+
+ // WebstoreInlineInstaller::Delegate.
+ virtual void OnInlineInstallSuccess(int install_id,
+ int return_route_id) OVERRIDE;
+ virtual void OnInlineInstallFailure(int install_id,
+ int return_route_id,
+ const std::string& error) OVERRIDE;
+
+ // AppNotifyChannelSetup::Delegate.
+ virtual void AppNotifyChannelSetupComplete(
+ const std::string& channel_id,
+ const std::string& error,
+ const AppNotifyChannelSetup* setup) OVERRIDE;
+
+ // content::NotificationObserver.
+ virtual void Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) OVERRIDE;
+
+ // Requests application info for the specified page. This is an asynchronous
+ // request. The delegate is notified by way of OnDidGetApplicationInfo when
+ // the data is available.
+ void GetApplicationInfo(int32 page_id);
+
+ // Data for app extensions ---------------------------------------------------
+
+ // Our observers. Declare at top so that it will outlive all other members,
+ // since they might add themselves as observers.
+ ObserverList<Observer> observers_;
+
+ // If non-null this tab is an app tab and this is the extension the tab was
+ // created for.
+ const Extension* extension_app_;
+
+ // Icon for extension_app_ (if non-null) or a manually-set icon for
+ // non-extension apps.
+ SkBitmap extension_app_icon_;
+
+ // Process any extension messages coming from the tab.
+ ExtensionFunctionDispatcher extension_function_dispatcher_;
+
+ // Used for loading extension_app_icon_.
+ scoped_ptr<ImageLoadingTracker> extension_app_image_loader_;
+
+ // Cached web app info data.
+ WebApplicationInfo web_app_info_;
+
+ // Which deferred action to perform when OnDidGetApplicationInfo is notified
+ // from a WebContents.
+ WebAppAction pending_web_app_action_;
+
+ content::NotificationRegistrar registrar_;
+
+ TabContents* tab_contents_;
+
+ scoped_ptr<ScriptExecutor> script_executor_;
+
+ scoped_ptr<LocationBarController> location_bar_controller_;
+
+ ActiveTabPermissionManager active_tab_permission_manager_;
+
+ DISALLOW_COPY_AND_ASSIGN(TabHelper);
+};
+
+} // namespace extensions
+
+#endif // CHROME_BROWSER_EXTENSIONS_TAB_HELPER_H_