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 |
27 // Per-tab extension helper. Also handles non-extension apps. | 28 // Per-tab extension helper. Also handles non-extension apps. |
28 class ExtensionTabHelper | 29 class ExtensionTabHelper |
29 : public content::WebContentsObserver, | 30 : public content::WebContentsObserver, |
30 public ExtensionFunctionDispatcher::Delegate, | 31 public ExtensionFunctionDispatcher::Delegate, |
31 public ImageLoadingTracker::Observer, | 32 public ImageLoadingTracker::Observer, |
32 public WebstoreInlineInstaller::Delegate, | 33 public WebstoreInlineInstaller::Delegate, |
33 public AppNotifyChannelSetup::Delegate, | 34 public AppNotifyChannelSetup::Delegate, |
34 public base::SupportsWeakPtr<ExtensionTabHelper> { | 35 public base::SupportsWeakPtr<ExtensionTabHelper> { |
35 public: | 36 public: |
| 37 class Observer { |
| 38 public: |
| 39 // Called when the page action state (such as visibility, title) changes. |
| 40 virtual void OnPageActionStateChanged() = 0; |
| 41 |
| 42 protected: |
| 43 virtual ~Observer() {} |
| 44 }; |
| 45 |
36 explicit ExtensionTabHelper(TabContentsWrapper* wrapper); | 46 explicit ExtensionTabHelper(TabContentsWrapper* wrapper); |
37 virtual ~ExtensionTabHelper(); | 47 virtual ~ExtensionTabHelper(); |
38 | 48 |
39 // Copies the internal state from another ExtensionTabHelper. | 49 // Copies the internal state from another ExtensionTabHelper. |
40 void CopyStateFrom(const ExtensionTabHelper& source); | 50 void CopyStateFrom(const ExtensionTabHelper& source); |
41 | 51 |
42 ExtensionTabHelperDelegate* delegate() const { return delegate_; } | 52 ExtensionTabHelperDelegate* delegate() const { return delegate_; } |
43 void set_delegate(ExtensionTabHelperDelegate* d) { delegate_ = d; } | 53 void set_delegate(ExtensionTabHelperDelegate* d) { delegate_ = d; } |
44 | 54 |
45 // Call this after updating a page action to notify clients about the changes. | 55 // Call this after updating a page action to notify clients about the changes. |
46 void PageActionStateChanged(); | 56 void PageActionStateChanged(); |
47 | 57 |
48 // Requests application info for the specified page. This is an asynchronous | 58 // Requests application info for the specified page. This is an asynchronous |
49 // request. The delegate is notified by way of OnDidGetApplicationInfo when | 59 // request. The delegate is notified by way of OnDidGetApplicationInfo when |
50 // the data is available. | 60 // the data is available. |
51 void GetApplicationInfo(int32 page_id); | 61 void GetApplicationInfo(int32 page_id); |
52 | 62 |
| 63 // Observer management. |
| 64 void AddObserver(Observer* observer); |
| 65 void RemoveObserver(Observer* observer); |
| 66 |
53 // App extensions ------------------------------------------------------------ | 67 // App extensions ------------------------------------------------------------ |
54 | 68 |
55 // Sets the extension denoting this as an app. If |extension| is non-null this | 69 // 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 | 70 // 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. | 71 // the extension. It's up to consumers of WebContents to do that. |
58 // | 72 // |
59 // NOTE: this should only be manipulated before the tab is added to a browser. | 73 // 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 | 74 // 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. | 75 // is, than this should be passed in the constructor. |
62 void SetExtensionApp(const Extension* extension); | 76 void SetExtensionApp(const Extension* extension); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 ExtensionFunctionDispatcher extension_function_dispatcher_; | 179 ExtensionFunctionDispatcher extension_function_dispatcher_; |
166 | 180 |
167 // Used for loading extension_app_icon_. | 181 // Used for loading extension_app_icon_. |
168 scoped_ptr<ImageLoadingTracker> extension_app_image_loader_; | 182 scoped_ptr<ImageLoadingTracker> extension_app_image_loader_; |
169 | 183 |
170 // Cached web app info data. | 184 // Cached web app info data. |
171 WebApplicationInfo web_app_info_; | 185 WebApplicationInfo web_app_info_; |
172 | 186 |
173 TabContentsWrapper* wrapper_; | 187 TabContentsWrapper* wrapper_; |
174 | 188 |
| 189 ObserverList<Observer> observers_; |
| 190 |
175 DISALLOW_COPY_AND_ASSIGN(ExtensionTabHelper); | 191 DISALLOW_COPY_AND_ASSIGN(ExtensionTabHelper); |
176 }; | 192 }; |
177 | 193 |
178 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_TAB_HELPER_H_ | 194 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_TAB_HELPER_H_ |
OLD | NEW |