Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(48)

Side by Side Diff: chrome/browser/extensions/tab_helper.h

Issue 10917026: Switch Extensions::TabHelper to use WebContents, WebContentsUserData. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase only Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_TAB_HELPER_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_TAB_HELPER_H_
6 #define CHROME_BROWSER_EXTENSIONS_TAB_HELPER_H_ 6 #define CHROME_BROWSER_EXTENSIONS_TAB_HELPER_H_
7 7
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/memory/weak_ptr.h" 9 #include "base/memory/weak_ptr.h"
10 #include "base/observer_list.h" 10 #include "base/observer_list.h"
11 #include "chrome/browser/extensions/active_tab_permission_manager.h" 11 #include "chrome/browser/extensions/active_tab_permission_manager.h"
12 #include "chrome/browser/extensions/app_notify_channel_setup.h" 12 #include "chrome/browser/extensions/app_notify_channel_setup.h"
13 #include "chrome/browser/extensions/extension_function_dispatcher.h" 13 #include "chrome/browser/extensions/extension_function_dispatcher.h"
14 #include "chrome/browser/extensions/image_loading_tracker.h" 14 #include "chrome/browser/extensions/image_loading_tracker.h"
15 #include "chrome/browser/extensions/script_executor.h" 15 #include "chrome/browser/extensions/script_executor.h"
16 #include "chrome/browser/extensions/webstore_inline_installer.h" 16 #include "chrome/browser/extensions/webstore_inline_installer.h"
17 #include "chrome/browser/tab_contents/web_contents_user_data.h"
17 #include "chrome/common/web_apps.h" 18 #include "chrome/common/web_apps.h"
18 #include "content/public/browser/notification_observer.h" 19 #include "content/public/browser/notification_observer.h"
19 #include "content/public/browser/notification_registrar.h" 20 #include "content/public/browser/notification_registrar.h"
20 #include "content/public/browser/web_contents_observer.h" 21 #include "content/public/browser/web_contents_observer.h"
21 #include "third_party/skia/include/core/SkBitmap.h" 22 #include "third_party/skia/include/core/SkBitmap.h"
22 23
23 class TabContents;
24 struct WebApplicationInfo; 24 struct WebApplicationInfo;
25 25
26 namespace content { 26 namespace content {
27 struct LoadCommittedDetails; 27 struct LoadCommittedDetails;
28 } 28 }
29 29
30 namespace extensions { 30 namespace extensions {
31 class Extension; 31 class Extension;
32 class LocationBarController; 32 class LocationBarController;
33 class ScriptBadgeController; 33 class ScriptBadgeController;
34 class ScriptExecutor; 34 class ScriptExecutor;
35 35
36 // Per-tab extension helper. Also handles non-extension apps. 36 // Per-tab extension helper. Also handles non-extension apps.
37 class TabHelper : public content::WebContentsObserver, 37 class TabHelper : public content::WebContentsObserver,
38 public ExtensionFunctionDispatcher::Delegate, 38 public ExtensionFunctionDispatcher::Delegate,
39 public ImageLoadingTracker::Observer, 39 public ImageLoadingTracker::Observer,
40 public WebstoreInlineInstaller::Delegate, 40 public WebstoreInlineInstaller::Delegate,
41 public AppNotifyChannelSetup::Delegate, 41 public AppNotifyChannelSetup::Delegate,
42 public base::SupportsWeakPtr<TabHelper>, 42 public base::SupportsWeakPtr<TabHelper>,
43 public content::NotificationObserver { 43 public content::NotificationObserver,
44 public WebContentsUserData<TabHelper> {
44 public: 45 public:
45 // Different types of action when web app info is available. 46 // Different types of action when web app info is available.
46 // OnDidGetApplicationInfo uses this to dispatch calls. 47 // OnDidGetApplicationInfo uses this to dispatch calls.
47 enum WebAppAction { 48 enum WebAppAction {
48 NONE, // No action at all. 49 NONE, // No action at all.
49 CREATE_SHORTCUT, // Bring up create application shortcut dialog. 50 CREATE_SHORTCUT, // Bring up create application shortcut dialog.
50 UPDATE_SHORTCUT // Update icon for app shortcut. 51 UPDATE_SHORTCUT // Update icon for app shortcut.
51 }; 52 };
52 53
53 explicit TabHelper(TabContents* tab_contents); 54 explicit TabHelper(content::WebContents* web_contents);
54 virtual ~TabHelper(); 55 virtual ~TabHelper();
55 56 static int kUserDataKey;
56 // Copies the internal state from another TabHelper.
57 void CopyStateFrom(const TabHelper& source);
58 57
59 void CreateApplicationShortcuts(); 58 void CreateApplicationShortcuts();
60 bool CanCreateApplicationShortcuts() const; 59 bool CanCreateApplicationShortcuts() const;
61 60
62 void set_pending_web_app_action(WebAppAction action) { 61 void set_pending_web_app_action(WebAppAction action) {
63 pending_web_app_action_ = action; 62 pending_web_app_action_ = action;
64 } 63 }
65 64
66 // App extensions ------------------------------------------------------------ 65 // App extensions ------------------------------------------------------------
67 66
(...skipping 20 matching lines...) Expand all
88 return web_app_info_; 87 return web_app_info_;
89 } 88 }
90 89
91 // If an app extension has been explicitly set for this WebContents its icon 90 // If an app extension has been explicitly set for this WebContents its icon
92 // is returned. 91 // is returned.
93 // 92 //
94 // NOTE: the returned icon is larger than 16x16 (its size is 93 // NOTE: the returned icon is larger than 16x16 (its size is
95 // Extension::EXTENSION_ICON_SMALLISH). 94 // Extension::EXTENSION_ICON_SMALLISH).
96 SkBitmap* GetExtensionAppIcon(); 95 SkBitmap* GetExtensionAppIcon();
97 96
98 TabContents* tab_contents() {
99 return tab_contents_;
100 }
101
102 content::WebContents* web_contents() const { 97 content::WebContents* web_contents() const {
103 return content::WebContentsObserver::web_contents(); 98 return content::WebContentsObserver::web_contents();
104 } 99 }
105 100
106 ScriptExecutor* script_executor() { 101 ScriptExecutor* script_executor() {
107 return &script_executor_; 102 return &script_executor_;
108 } 103 }
109 104
110 LocationBarController* location_bar_controller() { 105 LocationBarController* location_bar_controller() {
111 return location_bar_controller_.get(); 106 return location_bar_controller_.get();
112 } 107 }
113 108
114 ActiveTabPermissionManager* active_tab_permission_manager() { 109 ActiveTabPermissionManager* active_tab_permission_manager() {
115 return &active_tab_permission_manager_; 110 return active_tab_permission_manager_.get();
116 } 111 }
117 112
118 // Sets a non-extension app icon associated with WebContents and fires an 113 // Sets a non-extension app icon associated with WebContents and fires an
119 // INVALIDATE_TYPE_TITLE navigation state change to trigger repaint of title. 114 // INVALIDATE_TYPE_TITLE navigation state change to trigger repaint of title.
120 void SetAppIcon(const SkBitmap& app_icon); 115 void SetAppIcon(const SkBitmap& app_icon);
121 116
122 private: 117 private:
123 // content::WebContentsObserver overrides. 118 // content::WebContentsObserver overrides.
124 virtual void RenderViewCreated( 119 virtual void RenderViewCreated(
125 content::RenderViewHost* render_view_host) OVERRIDE; 120 content::RenderViewHost* render_view_host) OVERRIDE;
126 virtual void DidNavigateMainFrame( 121 virtual void DidNavigateMainFrame(
127 const content::LoadCommittedDetails& details, 122 const content::LoadCommittedDetails& details,
128 const content::FrameNavigateParams& params) OVERRIDE; 123 const content::FrameNavigateParams& params) OVERRIDE;
129 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 124 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
125 virtual void DidCloneToNewWebContents(
126 content::WebContents* old_web_contents,
127 content::WebContents* new_web_contents) OVERRIDE;
130 128
131 // ExtensionFunctionDispatcher::Delegate overrides. 129 // ExtensionFunctionDispatcher::Delegate overrides.
132 virtual extensions::WindowController* GetExtensionWindowController() 130 virtual extensions::WindowController* GetExtensionWindowController()
133 const OVERRIDE; 131 const OVERRIDE;
134 virtual content::WebContents* GetAssociatedWebContents() const OVERRIDE; 132 virtual content::WebContents* GetAssociatedWebContents() const OVERRIDE;
135 133
136 // Message handlers. 134 // Message handlers.
137 void OnDidGetApplicationInfo(int32 page_id, const WebApplicationInfo& info); 135 void OnDidGetApplicationInfo(int32 page_id, const WebApplicationInfo& info);
138 void OnInstallApplication(const WebApplicationInfo& info); 136 void OnInstallApplication(const WebApplicationInfo& info);
139 void OnInlineWebstoreInstall(int install_id, 137 void OnInlineWebstoreInstall(int install_id,
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 206
209 // Cached web app info data. 207 // Cached web app info data.
210 WebApplicationInfo web_app_info_; 208 WebApplicationInfo web_app_info_;
211 209
212 // Which deferred action to perform when OnDidGetApplicationInfo is notified 210 // Which deferred action to perform when OnDidGetApplicationInfo is notified
213 // from a WebContents. 211 // from a WebContents.
214 WebAppAction pending_web_app_action_; 212 WebAppAction pending_web_app_action_;
215 213
216 content::NotificationRegistrar registrar_; 214 content::NotificationRegistrar registrar_;
217 215
218 TabContents* tab_contents_;
219
220 ScriptExecutor script_executor_; 216 ScriptExecutor script_executor_;
221 217
222 scoped_ptr<LocationBarController> location_bar_controller_; 218 scoped_ptr<LocationBarController> location_bar_controller_;
223 219
224 ActiveTabPermissionManager active_tab_permission_manager_; 220 scoped_ptr<ActiveTabPermissionManager> active_tab_permission_manager_;
225 221
226 DISALLOW_COPY_AND_ASSIGN(TabHelper); 222 DISALLOW_COPY_AND_ASSIGN(TabHelper);
227 }; 223 };
228 224
229 } // namespace extensions 225 } // namespace extensions
230 226
231 #endif // CHROME_BROWSER_EXTENSIONS_TAB_HELPER_H_ 227 #endif // CHROME_BROWSER_EXTENSIONS_TAB_HELPER_H_
OLDNEW
« no previous file with comments | « chrome/browser/extensions/script_badge_controller_unittest.cc ('k') | chrome/browser/extensions/tab_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698