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 "base/observer_list.h" |
10 #include "chrome/browser/extensions/app_notify_channel_setup.h" | 11 #include "chrome/browser/extensions/app_notify_channel_setup.h" |
11 #include "chrome/browser/extensions/extension_function_dispatcher.h" | 12 #include "chrome/browser/extensions/extension_function_dispatcher.h" |
12 #include "chrome/browser/extensions/image_loading_tracker.h" | 13 #include "chrome/browser/extensions/image_loading_tracker.h" |
13 #include "chrome/browser/extensions/webstore_inline_installer.h" | 14 #include "chrome/browser/extensions/webstore_inline_installer.h" |
14 #include "chrome/common/web_apps.h" | 15 #include "chrome/common/web_apps.h" |
15 #include "content/public/browser/web_contents_observer.h" | 16 #include "content/public/browser/web_contents_observer.h" |
16 #include "third_party/skia/include/core/SkBitmap.h" | 17 #include "third_party/skia/include/core/SkBitmap.h" |
17 | 18 |
18 class Extension; | 19 class Extension; |
19 class ExtensionTabHelperDelegate; | 20 class ExtensionTabHelperDelegate; |
20 class TabContentsWrapper; | 21 class TabContentsWrapper; |
21 struct WebApplicationInfo; | 22 struct WebApplicationInfo; |
22 | 23 |
23 namespace content { | 24 namespace content { |
24 struct LoadCommittedDetails; | 25 struct LoadCommittedDetails; |
25 } | 26 } |
26 | 27 |
| 28 namespace extensions { |
| 29 class ActionBoxController; |
| 30 class ScriptExecutor; |
| 31 } |
| 32 |
27 // Per-tab extension helper. Also handles non-extension apps. | 33 // Per-tab extension helper. Also handles non-extension apps. |
28 class ExtensionTabHelper | 34 class ExtensionTabHelper |
29 : public content::WebContentsObserver, | 35 : public content::WebContentsObserver, |
30 public ExtensionFunctionDispatcher::Delegate, | 36 public ExtensionFunctionDispatcher::Delegate, |
31 public ImageLoadingTracker::Observer, | 37 public ImageLoadingTracker::Observer, |
32 public WebstoreInlineInstaller::Delegate, | 38 public WebstoreInlineInstaller::Delegate, |
33 public AppNotifyChannelSetup::Delegate, | 39 public AppNotifyChannelSetup::Delegate, |
34 public base::SupportsWeakPtr<ExtensionTabHelper> { | 40 public base::SupportsWeakPtr<ExtensionTabHelper> { |
35 public: | 41 public: |
| 42 class Observer { |
| 43 public: |
| 44 // Called when the page action state (such as visibility, title) changes. |
| 45 virtual void OnPageActionStateChanged() = 0; |
| 46 |
| 47 protected: |
| 48 virtual ~Observer() {} |
| 49 }; |
| 50 |
36 explicit ExtensionTabHelper(TabContentsWrapper* wrapper); | 51 explicit ExtensionTabHelper(TabContentsWrapper* wrapper); |
37 virtual ~ExtensionTabHelper(); | 52 virtual ~ExtensionTabHelper(); |
38 | 53 |
39 // Copies the internal state from another ExtensionTabHelper. | 54 // Copies the internal state from another ExtensionTabHelper. |
40 void CopyStateFrom(const ExtensionTabHelper& source); | 55 void CopyStateFrom(const ExtensionTabHelper& source); |
41 | 56 |
42 ExtensionTabHelperDelegate* delegate() const { return delegate_; } | 57 ExtensionTabHelperDelegate* delegate() const { return delegate_; } |
43 void set_delegate(ExtensionTabHelperDelegate* d) { delegate_ = d; } | 58 void set_delegate(ExtensionTabHelperDelegate* d) { delegate_ = d; } |
44 | 59 |
45 // Call this after updating a page action to notify clients about the changes. | 60 // Call this after updating a page action to notify clients about the changes. |
46 void PageActionStateChanged(); | 61 void PageActionStateChanged(); |
47 | 62 |
48 // Requests application info for the specified page. This is an asynchronous | 63 // Requests application info for the specified page. This is an asynchronous |
49 // request. The delegate is notified by way of OnDidGetApplicationInfo when | 64 // request. The delegate is notified by way of OnDidGetApplicationInfo when |
50 // the data is available. | 65 // the data is available. |
51 void GetApplicationInfo(int32 page_id); | 66 void GetApplicationInfo(int32 page_id); |
52 | 67 |
| 68 // Observer management. |
| 69 void AddObserver(Observer* observer); |
| 70 void RemoveObserver(Observer* observer); |
| 71 |
53 // App extensions ------------------------------------------------------------ | 72 // App extensions ------------------------------------------------------------ |
54 | 73 |
55 // Sets the extension denoting this as an app. If |extension| is non-null this | 74 // 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 | 75 // 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. | 76 // the extension. It's up to consumers of WebContents to do that. |
58 // | 77 // |
59 // NOTE: this should only be manipulated before the tab is added to a browser. | 78 // 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 | 79 // 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. | 80 // is, than this should be passed in the constructor. |
62 void SetExtensionApp(const Extension* extension); | 81 void SetExtensionApp(const Extension* extension); |
(...skipping 20 matching lines...) Expand all Loading... |
83 SkBitmap* GetExtensionAppIcon(); | 102 SkBitmap* GetExtensionAppIcon(); |
84 | 103 |
85 TabContentsWrapper* tab_contents_wrapper() { | 104 TabContentsWrapper* tab_contents_wrapper() { |
86 return wrapper_; | 105 return wrapper_; |
87 } | 106 } |
88 | 107 |
89 content::WebContents* web_contents() const { | 108 content::WebContents* web_contents() const { |
90 return content::WebContentsObserver::web_contents(); | 109 return content::WebContentsObserver::web_contents(); |
91 } | 110 } |
92 | 111 |
| 112 extensions::ScriptExecutor* script_executor() { |
| 113 return script_executor_.get(); |
| 114 } |
| 115 |
| 116 extensions::ActionBoxController* action_box_controller() { |
| 117 return action_box_controller_.get(); |
| 118 } |
| 119 |
93 // Sets a non-extension app icon associated with WebContents and fires an | 120 // Sets a non-extension app icon associated with WebContents and fires an |
94 // INVALIDATE_TYPE_TITLE navigation state change to trigger repaint of title. | 121 // INVALIDATE_TYPE_TITLE navigation state change to trigger repaint of title. |
95 void SetAppIcon(const SkBitmap& app_icon); | 122 void SetAppIcon(const SkBitmap& app_icon); |
96 | 123 |
97 private: | 124 private: |
98 // content::WebContentsObserver overrides. | 125 // content::WebContentsObserver overrides. |
99 virtual void DidNavigateMainFrame( | 126 virtual void DidNavigateMainFrame( |
100 const content::LoadCommittedDetails& details, | 127 const content::LoadCommittedDetails& details, |
101 const content::FrameNavigateParams& params) OVERRIDE; | 128 const content::FrameNavigateParams& params) OVERRIDE; |
102 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 129 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 const std::string& error) OVERRIDE; | 170 const std::string& error) OVERRIDE; |
144 | 171 |
145 // AppNotifyChannelSetup::Delegate. | 172 // AppNotifyChannelSetup::Delegate. |
146 virtual void AppNotifyChannelSetupComplete( | 173 virtual void AppNotifyChannelSetupComplete( |
147 const std::string& channel_id, | 174 const std::string& channel_id, |
148 const std::string& error, | 175 const std::string& error, |
149 const AppNotifyChannelSetup* setup) OVERRIDE; | 176 const AppNotifyChannelSetup* setup) OVERRIDE; |
150 | 177 |
151 // Data for app extensions --------------------------------------------------- | 178 // Data for app extensions --------------------------------------------------- |
152 | 179 |
| 180 // Our observers. Declare at top so that it will outlive all other members, |
| 181 // since they might add themselves as observers. |
| 182 ObserverList<Observer> observers_; |
| 183 |
153 // Delegate for notifying our owner about stuff. Not owned by us. | 184 // Delegate for notifying our owner about stuff. Not owned by us. |
154 ExtensionTabHelperDelegate* delegate_; | 185 ExtensionTabHelperDelegate* delegate_; |
155 | 186 |
156 // If non-null this tab is an app tab and this is the extension the tab was | 187 // If non-null this tab is an app tab and this is the extension the tab was |
157 // created for. | 188 // created for. |
158 const Extension* extension_app_; | 189 const Extension* extension_app_; |
159 | 190 |
160 // Icon for extension_app_ (if non-null) or a manually-set icon for | 191 // Icon for extension_app_ (if non-null) or a manually-set icon for |
161 // non-extension apps. | 192 // non-extension apps. |
162 SkBitmap extension_app_icon_; | 193 SkBitmap extension_app_icon_; |
163 | 194 |
164 // Process any extension messages coming from the tab. | 195 // Process any extension messages coming from the tab. |
165 ExtensionFunctionDispatcher extension_function_dispatcher_; | 196 ExtensionFunctionDispatcher extension_function_dispatcher_; |
166 | 197 |
167 // Used for loading extension_app_icon_. | 198 // Used for loading extension_app_icon_. |
168 scoped_ptr<ImageLoadingTracker> extension_app_image_loader_; | 199 scoped_ptr<ImageLoadingTracker> extension_app_image_loader_; |
169 | 200 |
170 // Cached web app info data. | 201 // Cached web app info data. |
171 WebApplicationInfo web_app_info_; | 202 WebApplicationInfo web_app_info_; |
172 | 203 |
173 TabContentsWrapper* wrapper_; | 204 TabContentsWrapper* wrapper_; |
174 | 205 |
| 206 scoped_ptr<extensions::ScriptExecutor> script_executor_; |
| 207 |
| 208 scoped_ptr<extensions::ActionBoxController> action_box_controller_; |
| 209 |
175 DISALLOW_COPY_AND_ASSIGN(ExtensionTabHelper); | 210 DISALLOW_COPY_AND_ASSIGN(ExtensionTabHelper); |
176 }; | 211 }; |
177 | 212 |
178 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_TAB_HELPER_H_ | 213 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_TAB_HELPER_H_ |
OLD | NEW |