| 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_UI_TAB_CONTENTS_TAB_CONTENTS_WRAPPER_H_ | 5 #ifndef CHROME_BROWSER_UI_TAB_CONTENTS_TAB_CONTENTS_WRAPPER_H_ |
| 6 #define CHROME_BROWSER_UI_TAB_CONTENTS_TAB_CONTENTS_WRAPPER_H_ | 6 #define CHROME_BROWSER_UI_TAB_CONTENTS_TAB_CONTENTS_WRAPPER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 10 #include "base/compiler_specific.h" | |
| 11 #include "base/memory/ref_counted.h" | |
| 12 #include "base/memory/scoped_ptr.h" | |
| 13 #include "base/property_bag.h" | |
| 14 #include "content/public/browser/web_contents_observer.h" | |
| 15 | 10 |
| 16 class AlternateErrorPageTabObserver; | 11 typedef TabContents TabContentsWrapper; |
| 17 class AutocompleteHistoryManager; | |
| 18 class AutofillManager; | |
| 19 class AutofillExternalDelegate; | |
| 20 class AutomationTabHelper; | |
| 21 class BlockedContentTabHelper; | |
| 22 class BookmarkTabHelper; | |
| 23 class ConstrainedWindowTabHelper; | |
| 24 class CoreTabHelper; | |
| 25 class ExtensionTabHelper; | |
| 26 class ExternalProtocolObserver; | |
| 27 class FaviconTabHelper; | |
| 28 class FindTabHelper; | |
| 29 class HistoryTabHelper; | |
| 30 class HungPluginTabHelper; | |
| 31 class InfoBarTabHelper; | |
| 32 class OmniboxSearchHint; | |
| 33 class PasswordManager; | |
| 34 class PasswordManagerDelegate; | |
| 35 class PDFTabObserver; | |
| 36 class PluginObserver; | |
| 37 class PrefsTabHelper; | |
| 38 class Profile; | |
| 39 class RestoreTabHelper; | |
| 40 class SadTabHelper; | |
| 41 class SearchEngineTabHelper; | |
| 42 class SnapshotTabHelper; | |
| 43 class TabContentsSSLHelper; | |
| 44 class TabSpecificContentSettings; | |
| 45 class ThumbnailGenerator; | |
| 46 class TranslateTabHelper; | |
| 47 class WebIntentPickerController; | |
| 48 | |
| 49 #if defined(ENABLE_ONE_CLICK_SIGNIN) | |
| 50 class OneClickSigninHelper; | |
| 51 #endif | |
| 52 | |
| 53 namespace browser_sync { | |
| 54 class SyncedTabDelegate; | |
| 55 } | |
| 56 | |
| 57 namespace extensions { | |
| 58 class WebNavigationTabObserver; | |
| 59 } | |
| 60 | |
| 61 namespace prerender { | |
| 62 class PrerenderTabHelper; | |
| 63 } | |
| 64 | |
| 65 namespace printing { | |
| 66 class PrintViewManager; | |
| 67 class PrintPreviewMessageHandler; | |
| 68 } | |
| 69 | |
| 70 namespace safe_browsing { | |
| 71 class SafeBrowsingTabObserver; | |
| 72 } | |
| 73 | |
| 74 // Wraps WebContents and all of its supporting objects in order to control | |
| 75 // their ownership and lifetime. | |
| 76 // | |
| 77 // WARNING: Not every place where HTML can run has a TabContentsWrapper. This | |
| 78 // class is *only* used in a visible, actual, tab inside a browser. Examples of | |
| 79 // things that do not have tab wrappers include: | |
| 80 // - Extension background pages and popup bubbles | |
| 81 // - HTML notification bubbles | |
| 82 // - Screensavers on Chrome OS | |
| 83 // - Other random places we decide to display HTML over time | |
| 84 // | |
| 85 // Consider carefully whether your feature is something that makes sense only | |
| 86 // when a tab is displayed, or could make sense in other cases we use HTML. It | |
| 87 // may makes sense to push down into WebContents and make configurable, or at | |
| 88 // least to make easy for other WebContents hosts to include and support. | |
| 89 // | |
| 90 // TODO(avi): Eventually, this class will become TabContents as far as | |
| 91 // the browser front-end is concerned. | |
| 92 class TabContentsWrapper : public content::WebContentsObserver { | |
| 93 public: | |
| 94 // Takes ownership of |contents|, which must be heap-allocated (as it lives | |
| 95 // in a scoped_ptr) and can not be NULL. | |
| 96 explicit TabContentsWrapper(content::WebContents* contents); | |
| 97 virtual ~TabContentsWrapper(); | |
| 98 | |
| 99 // Create a TabContentsWrapper with the same state as this one. The returned | |
| 100 // heap-allocated pointer is owned by the caller. | |
| 101 TabContentsWrapper* Clone(); | |
| 102 | |
| 103 // Helper to retrieve the existing instance that wraps a given WebContents. | |
| 104 // Returns NULL if there is no such existing instance. | |
| 105 // NOTE: This is not intended for general use. It is intended for situations | |
| 106 // like callbacks from content/ where only a WebContents is available. In the | |
| 107 // general case, please do NOT use this; plumb TabContentsWrapper through the | |
| 108 // chrome/ code instead of WebContents. | |
| 109 static TabContentsWrapper* GetCurrentWrapperForContents( | |
| 110 content::WebContents* contents); | |
| 111 static const TabContentsWrapper* GetCurrentWrapperForContents( | |
| 112 const content::WebContents* contents); | |
| 113 | |
| 114 // Returns the WebContents that this wraps. | |
| 115 content::WebContents* web_contents() const; | |
| 116 | |
| 117 // Returns the Profile that is associated with this TabContentsWrapper. | |
| 118 Profile* profile() const; | |
| 119 | |
| 120 // True if this TabContentsWrapper is being torn down. | |
| 121 bool in_destructor() const { return in_destructor_; } | |
| 122 | |
| 123 // Tab Helpers --------------------------------------------------------------- | |
| 124 | |
| 125 AutocompleteHistoryManager* autocomplete_history_manager() { | |
| 126 return autocomplete_history_manager_.get(); | |
| 127 } | |
| 128 | |
| 129 AutofillManager* autofill_manager() { return autofill_manager_.get(); } | |
| 130 | |
| 131 // Used only for testing/automation. | |
| 132 AutomationTabHelper* automation_tab_helper() { | |
| 133 return automation_tab_helper_.get(); | |
| 134 } | |
| 135 | |
| 136 BlockedContentTabHelper* blocked_content_tab_helper() { | |
| 137 return blocked_content_tab_helper_.get(); | |
| 138 } | |
| 139 | |
| 140 BookmarkTabHelper* bookmark_tab_helper() { | |
| 141 return bookmark_tab_helper_.get(); | |
| 142 } | |
| 143 | |
| 144 ConstrainedWindowTabHelper* constrained_window_tab_helper() { | |
| 145 return constrained_window_tab_helper_.get(); | |
| 146 } | |
| 147 | |
| 148 CoreTabHelper* core_tab_helper() { return core_tab_helper_.get(); } | |
| 149 | |
| 150 ExtensionTabHelper* extension_tab_helper() { | |
| 151 return extension_tab_helper_.get(); | |
| 152 } | |
| 153 | |
| 154 const ExtensionTabHelper* extension_tab_helper() const { | |
| 155 return extension_tab_helper_.get(); | |
| 156 } | |
| 157 | |
| 158 FaviconTabHelper* favicon_tab_helper() { return favicon_tab_helper_.get(); } | |
| 159 FindTabHelper* find_tab_helper() { return find_tab_helper_.get(); } | |
| 160 HistoryTabHelper* history_tab_helper() { return history_tab_helper_.get(); } | |
| 161 HungPluginTabHelper* hung_plugin_tab_helper() { | |
| 162 return hung_plugin_tab_helper_.get(); | |
| 163 } | |
| 164 InfoBarTabHelper* infobar_tab_helper() { return infobar_tab_helper_.get(); } | |
| 165 | |
| 166 #if defined(ENABLE_ONE_CLICK_SIGNIN) | |
| 167 OneClickSigninHelper* one_click_signin_helper() { | |
| 168 return one_click_signin_helper_.get(); | |
| 169 } | |
| 170 #endif | |
| 171 | |
| 172 PasswordManager* password_manager() { return password_manager_.get(); } | |
| 173 PrefsTabHelper* prefs_tab_helper() { return prefs_tab_helper_.get(); } | |
| 174 | |
| 175 prerender::PrerenderTabHelper* prerender_tab_helper() { | |
| 176 return prerender_tab_helper_.get(); | |
| 177 } | |
| 178 | |
| 179 printing::PrintViewManager* print_view_manager() { | |
| 180 return print_view_manager_.get(); | |
| 181 } | |
| 182 | |
| 183 RestoreTabHelper* restore_tab_helper() { | |
| 184 return restore_tab_helper_.get(); | |
| 185 } | |
| 186 | |
| 187 const RestoreTabHelper* restore_tab_helper() const { | |
| 188 return restore_tab_helper_.get(); | |
| 189 } | |
| 190 | |
| 191 SadTabHelper* sad_tab_helper() { return sad_tab_helper_.get(); } | |
| 192 | |
| 193 SearchEngineTabHelper* search_engine_tab_helper() { | |
| 194 return search_engine_tab_helper_.get(); | |
| 195 } | |
| 196 | |
| 197 SnapshotTabHelper* snapshot_tab_helper() { | |
| 198 return snapshot_tab_helper_.get(); | |
| 199 } | |
| 200 | |
| 201 TabContentsSSLHelper* ssl_helper() { return ssl_helper_.get(); } | |
| 202 | |
| 203 browser_sync::SyncedTabDelegate* synced_tab_delegate() { | |
| 204 return synced_tab_delegate_.get(); | |
| 205 } | |
| 206 | |
| 207 TabSpecificContentSettings* content_settings() { | |
| 208 return content_settings_.get(); | |
| 209 } | |
| 210 | |
| 211 // NOTE: This returns NULL unless in-browser thumbnail generation is enabled. | |
| 212 ThumbnailGenerator* thumbnail_generator() { | |
| 213 return thumbnail_generator_.get(); | |
| 214 } | |
| 215 | |
| 216 TranslateTabHelper* translate_tab_helper() { | |
| 217 return translate_tab_helper_.get(); | |
| 218 } | |
| 219 | |
| 220 WebIntentPickerController* web_intent_picker_controller() { | |
| 221 return web_intent_picker_controller_.get(); | |
| 222 } | |
| 223 | |
| 224 // Overrides ----------------------------------------------------------------- | |
| 225 | |
| 226 // content::WebContentsObserver overrides: | |
| 227 virtual void WebContentsDestroyed(content::WebContents* tab) OVERRIDE; | |
| 228 | |
| 229 private: | |
| 230 // Used to retrieve this object from |web_contents_|, which is placed in | |
| 231 // its property bag to avoid adding additional interfaces. | |
| 232 static base::PropertyAccessor<TabContentsWrapper*>* property_accessor(); | |
| 233 | |
| 234 // Tab Helpers --------------------------------------------------------------- | |
| 235 // (These provide API for callers and have a getter function listed in the | |
| 236 // "Tab Helpers" section in the member functions area, above.) | |
| 237 | |
| 238 scoped_ptr<AutocompleteHistoryManager> autocomplete_history_manager_; | |
| 239 scoped_refptr<AutofillManager> autofill_manager_; | |
| 240 scoped_ptr<AutofillExternalDelegate> autofill_external_delegate_; | |
| 241 scoped_ptr<AutomationTabHelper> automation_tab_helper_; | |
| 242 scoped_ptr<BlockedContentTabHelper> blocked_content_tab_helper_; | |
| 243 scoped_ptr<BookmarkTabHelper> bookmark_tab_helper_; | |
| 244 scoped_ptr<ConstrainedWindowTabHelper> constrained_window_tab_helper_; | |
| 245 scoped_ptr<CoreTabHelper> core_tab_helper_; | |
| 246 scoped_ptr<ExtensionTabHelper> extension_tab_helper_; | |
| 247 scoped_ptr<FaviconTabHelper> favicon_tab_helper_; | |
| 248 scoped_ptr<FindTabHelper> find_tab_helper_; | |
| 249 scoped_ptr<HistoryTabHelper> history_tab_helper_; | |
| 250 scoped_ptr<HungPluginTabHelper> hung_plugin_tab_helper_; | |
| 251 scoped_ptr<InfoBarTabHelper> infobar_tab_helper_; | |
| 252 | |
| 253 // PasswordManager and its delegate. The delegate must outlive the manager, | |
| 254 // per documentation in password_manager.h. | |
| 255 scoped_ptr<PasswordManagerDelegate> password_manager_delegate_; | |
| 256 scoped_ptr<PasswordManager> password_manager_; | |
| 257 | |
| 258 scoped_ptr<PrefsTabHelper> prefs_tab_helper_; | |
| 259 scoped_ptr<prerender::PrerenderTabHelper> prerender_tab_helper_; | |
| 260 | |
| 261 // Handles print job for this contents. | |
| 262 scoped_ptr<printing::PrintViewManager> print_view_manager_; | |
| 263 | |
| 264 scoped_ptr<RestoreTabHelper> restore_tab_helper_; | |
| 265 scoped_ptr<SadTabHelper> sad_tab_helper_; | |
| 266 scoped_ptr<SearchEngineTabHelper> search_engine_tab_helper_; | |
| 267 scoped_ptr<SnapshotTabHelper> snapshot_tab_helper_; | |
| 268 scoped_ptr<TabContentsSSLHelper> ssl_helper_; | |
| 269 scoped_ptr<browser_sync::SyncedTabDelegate> synced_tab_delegate_; | |
| 270 | |
| 271 // The TabSpecificContentSettings object is used to query the blocked content | |
| 272 // state by various UI elements. | |
| 273 scoped_ptr<TabSpecificContentSettings> content_settings_; | |
| 274 | |
| 275 scoped_ptr<ThumbnailGenerator> thumbnail_generator_; | |
| 276 scoped_ptr<TranslateTabHelper> translate_tab_helper_; | |
| 277 | |
| 278 // Handles displaying a web intents picker to the user. | |
| 279 scoped_ptr<WebIntentPickerController> web_intent_picker_controller_; | |
| 280 | |
| 281 // Per-tab observers --------------------------------------------------------- | |
| 282 // (These provide no API for callers; objects that need to exist 1:1 with tabs | |
| 283 // and silently do their thing live here.) | |
| 284 | |
| 285 scoped_ptr<AlternateErrorPageTabObserver> alternate_error_page_tab_observer_; | |
| 286 scoped_ptr<extensions::WebNavigationTabObserver> webnavigation_observer_; | |
| 287 scoped_ptr<ExternalProtocolObserver> external_protocol_observer_; | |
| 288 scoped_ptr<OmniboxSearchHint> omnibox_search_hint_; | |
| 289 #if defined(ENABLE_ONE_CLICK_SIGNIN) | |
| 290 scoped_ptr<OneClickSigninHelper> one_click_signin_helper_; | |
| 291 #endif | |
| 292 scoped_ptr<PDFTabObserver> pdf_tab_observer_; | |
| 293 scoped_ptr<PluginObserver> plugin_observer_; | |
| 294 scoped_ptr<printing::PrintPreviewMessageHandler> print_preview_; | |
| 295 scoped_ptr<safe_browsing::SafeBrowsingTabObserver> | |
| 296 safe_browsing_tab_observer_; | |
| 297 | |
| 298 // WebContents (MUST BE LAST) ------------------------------------------------ | |
| 299 | |
| 300 // If true, we're running the destructor. | |
| 301 bool in_destructor_; | |
| 302 | |
| 303 // The supporting objects need to outlive the WebContents dtor (as they may | |
| 304 // be called upon during its execution). As a result, this must come last | |
| 305 // in the list. | |
| 306 scoped_ptr<content::WebContents> web_contents_; | |
| 307 | |
| 308 DISALLOW_COPY_AND_ASSIGN(TabContentsWrapper); | |
| 309 }; | |
| 310 | 12 |
| 311 #endif // CHROME_BROWSER_UI_TAB_CONTENTS_TAB_CONTENTS_WRAPPER_H_ | 13 #endif // CHROME_BROWSER_UI_TAB_CONTENTS_TAB_CONTENTS_WRAPPER_H_ |
| OLD | NEW |