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" | |
11 #include "chrome/browser/extensions/app_notify_channel_setup.h" | 10 #include "chrome/browser/extensions/app_notify_channel_setup.h" |
12 #include "chrome/browser/extensions/extension_function_dispatcher.h" | 11 #include "chrome/browser/extensions/extension_function_dispatcher.h" |
13 #include "chrome/browser/extensions/image_loading_tracker.h" | 12 #include "chrome/browser/extensions/image_loading_tracker.h" |
14 #include "chrome/browser/extensions/webstore_inline_installer.h" | 13 #include "chrome/browser/extensions/webstore_inline_installer.h" |
15 #include "chrome/common/web_apps.h" | 14 #include "chrome/common/web_apps.h" |
16 #include "content/public/browser/web_contents_observer.h" | 15 #include "content/public/browser/web_contents_observer.h" |
17 #include "third_party/skia/include/core/SkBitmap.h" | 16 #include "third_party/skia/include/core/SkBitmap.h" |
18 | 17 |
19 class Extension; | 18 class Extension; |
20 class ExtensionTabHelperDelegate; | 19 class ExtensionTabHelperDelegate; |
21 class TabContentsWrapper; | 20 class TabContentsWrapper; |
22 struct WebApplicationInfo; | 21 struct WebApplicationInfo; |
23 | 22 |
24 namespace content { | 23 namespace content { |
25 struct LoadCommittedDetails; | 24 struct LoadCommittedDetails; |
26 } | 25 } |
27 | 26 |
28 namespace extensions { | |
29 class ActionBoxController; | |
30 class ScriptExecutor; | |
31 } | |
32 | |
33 // Per-tab extension helper. Also handles non-extension apps. | 27 // Per-tab extension helper. Also handles non-extension apps. |
34 class ExtensionTabHelper | 28 class ExtensionTabHelper |
35 : public content::WebContentsObserver, | 29 : public content::WebContentsObserver, |
36 public ExtensionFunctionDispatcher::Delegate, | 30 public ExtensionFunctionDispatcher::Delegate, |
37 public ImageLoadingTracker::Observer, | 31 public ImageLoadingTracker::Observer, |
38 public WebstoreInlineInstaller::Delegate, | 32 public WebstoreInlineInstaller::Delegate, |
39 public AppNotifyChannelSetup::Delegate, | 33 public AppNotifyChannelSetup::Delegate, |
40 public base::SupportsWeakPtr<ExtensionTabHelper> { | 34 public base::SupportsWeakPtr<ExtensionTabHelper> { |
41 public: | 35 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 | |
51 explicit ExtensionTabHelper(TabContentsWrapper* wrapper); | 36 explicit ExtensionTabHelper(TabContentsWrapper* wrapper); |
52 virtual ~ExtensionTabHelper(); | 37 virtual ~ExtensionTabHelper(); |
53 | 38 |
54 // Copies the internal state from another ExtensionTabHelper. | 39 // Copies the internal state from another ExtensionTabHelper. |
55 void CopyStateFrom(const ExtensionTabHelper& source); | 40 void CopyStateFrom(const ExtensionTabHelper& source); |
56 | 41 |
57 ExtensionTabHelperDelegate* delegate() const { return delegate_; } | 42 ExtensionTabHelperDelegate* delegate() const { return delegate_; } |
58 void set_delegate(ExtensionTabHelperDelegate* d) { delegate_ = d; } | 43 void set_delegate(ExtensionTabHelperDelegate* d) { delegate_ = d; } |
59 | 44 |
60 // Call this after updating a page action to notify clients about the changes. | 45 // Call this after updating a page action to notify clients about the changes. |
61 void PageActionStateChanged(); | 46 void PageActionStateChanged(); |
62 | 47 |
63 // Requests application info for the specified page. This is an asynchronous | 48 // Requests application info for the specified page. This is an asynchronous |
64 // request. The delegate is notified by way of OnDidGetApplicationInfo when | 49 // request. The delegate is notified by way of OnDidGetApplicationInfo when |
65 // the data is available. | 50 // the data is available. |
66 void GetApplicationInfo(int32 page_id); | 51 void GetApplicationInfo(int32 page_id); |
67 | 52 |
68 // Observer management. | |
69 void AddObserver(Observer* observer); | |
70 void RemoveObserver(Observer* observer); | |
71 | |
72 // App extensions ------------------------------------------------------------ | 53 // App extensions ------------------------------------------------------------ |
73 | 54 |
74 // Sets the extension denoting this as an app. If |extension| is non-null this | 55 // Sets the extension denoting this as an app. If |extension| is non-null this |
75 // tab becomes an app-tab. WebContents does not listen for unload events for | 56 // tab becomes an app-tab. WebContents does not listen for unload events for |
76 // the extension. It's up to consumers of WebContents to do that. | 57 // the extension. It's up to consumers of WebContents to do that. |
77 // | 58 // |
78 // NOTE: this should only be manipulated before the tab is added to a browser. | 59 // NOTE: this should only be manipulated before the tab is added to a browser. |
79 // TODO(sky): resolve if this is the right way to identify an app tab. If it | 60 // TODO(sky): resolve if this is the right way to identify an app tab. If it |
80 // is, than this should be passed in the constructor. | 61 // is, than this should be passed in the constructor. |
81 void SetExtensionApp(const Extension* extension); | 62 void SetExtensionApp(const Extension* extension); |
(...skipping 20 matching lines...) Expand all Loading... |
102 SkBitmap* GetExtensionAppIcon(); | 83 SkBitmap* GetExtensionAppIcon(); |
103 | 84 |
104 TabContentsWrapper* tab_contents_wrapper() { | 85 TabContentsWrapper* tab_contents_wrapper() { |
105 return wrapper_; | 86 return wrapper_; |
106 } | 87 } |
107 | 88 |
108 content::WebContents* web_contents() const { | 89 content::WebContents* web_contents() const { |
109 return content::WebContentsObserver::web_contents(); | 90 return content::WebContentsObserver::web_contents(); |
110 } | 91 } |
111 | 92 |
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 | |
120 // Sets a non-extension app icon associated with WebContents and fires an | 93 // Sets a non-extension app icon associated with WebContents and fires an |
121 // INVALIDATE_TYPE_TITLE navigation state change to trigger repaint of title. | 94 // INVALIDATE_TYPE_TITLE navigation state change to trigger repaint of title. |
122 void SetAppIcon(const SkBitmap& app_icon); | 95 void SetAppIcon(const SkBitmap& app_icon); |
123 | 96 |
124 private: | 97 private: |
125 // content::WebContentsObserver overrides. | 98 // content::WebContentsObserver overrides. |
126 virtual void DidNavigateMainFrame( | 99 virtual void DidNavigateMainFrame( |
127 const content::LoadCommittedDetails& details, | 100 const content::LoadCommittedDetails& details, |
128 const content::FrameNavigateParams& params) OVERRIDE; | 101 const content::FrameNavigateParams& params) OVERRIDE; |
129 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 102 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 ExtensionFunctionDispatcher extension_function_dispatcher_; | 165 ExtensionFunctionDispatcher extension_function_dispatcher_; |
193 | 166 |
194 // Used for loading extension_app_icon_. | 167 // Used for loading extension_app_icon_. |
195 scoped_ptr<ImageLoadingTracker> extension_app_image_loader_; | 168 scoped_ptr<ImageLoadingTracker> extension_app_image_loader_; |
196 | 169 |
197 // Cached web app info data. | 170 // Cached web app info data. |
198 WebApplicationInfo web_app_info_; | 171 WebApplicationInfo web_app_info_; |
199 | 172 |
200 TabContentsWrapper* wrapper_; | 173 TabContentsWrapper* wrapper_; |
201 | 174 |
202 scoped_ptr<extensions::ScriptExecutor> script_executor_; | |
203 | |
204 scoped_ptr<extensions::ActionBoxController> action_box_controller_; | |
205 | |
206 ObserverList<Observer> observers_; | |
207 | |
208 DISALLOW_COPY_AND_ASSIGN(ExtensionTabHelper); | 175 DISALLOW_COPY_AND_ASSIGN(ExtensionTabHelper); |
209 }; | 176 }; |
210 | 177 |
211 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_TAB_HELPER_H_ | 178 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_TAB_HELPER_H_ |
OLD | NEW |