| 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_H_ |
| 6 #define CHROME_BROWSER_UI_TAB_CONTENTS_TAB_CONTENTS_WRAPPER_H_ | 6 #define CHROME_BROWSER_UI_TAB_CONTENTS_TAB_CONTENTS_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/property_bag.h" | 13 #include "base/property_bag.h" |
| 14 #include "content/public/browser/web_contents_observer.h" | 14 #include "content/public/browser/web_contents_observer.h" |
| 15 | 15 |
| 16 class AlternateErrorPageTabObserver; | 16 class AlternateErrorPageTabObserver; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 class PrintPreviewMessageHandler; | 67 class PrintPreviewMessageHandler; |
| 68 } | 68 } |
| 69 | 69 |
| 70 namespace safe_browsing { | 70 namespace safe_browsing { |
| 71 class SafeBrowsingTabObserver; | 71 class SafeBrowsingTabObserver; |
| 72 } | 72 } |
| 73 | 73 |
| 74 // Wraps WebContents and all of its supporting objects in order to control | 74 // Wraps WebContents and all of its supporting objects in order to control |
| 75 // their ownership and lifetime. | 75 // their ownership and lifetime. |
| 76 // | 76 // |
| 77 // WARNING: Not every place where HTML can run has a TabContentsWrapper. This | 77 // WARNING: Not every place where HTML can run has a TabContents. This class is |
| 78 // class is *only* used in a visible, actual, tab inside a browser. Examples of | 78 // *only* used in a visible, actual, tab inside a browser. Examples of things |
| 79 // things that do not have tab wrappers include: | 79 // that do not have a TabContents include: |
| 80 // - Extension background pages and popup bubbles | 80 // - Extension background pages and popup bubbles |
| 81 // - HTML notification bubbles | 81 // - HTML notification bubbles |
| 82 // - Screensavers on Chrome OS | 82 // - Screensavers on Chrome OS |
| 83 // - Other random places we decide to display HTML over time | 83 // - Other random places we decide to display HTML over time |
| 84 // | 84 // |
| 85 // Consider carefully whether your feature is something that makes sense only | 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 | 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 | 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. | 88 // least to make easy for other WebContents hosts to include and support. |
| 89 // | 89 // |
| 90 // TODO(avi): Eventually, this class will become TabContents as far as | 90 // TODO(avi): Eventually, this class will become TabContents as far as |
| 91 // the browser front-end is concerned. | 91 // the browser front-end is concerned. |
| 92 class TabContentsWrapper : public content::WebContentsObserver { | 92 class TabContents : public content::WebContentsObserver { |
| 93 public: | 93 public: |
| 94 // Takes ownership of |contents|, which must be heap-allocated (as it lives | 94 // Takes ownership of |contents|, which must be heap-allocated (as it lives |
| 95 // in a scoped_ptr) and can not be NULL. | 95 // in a scoped_ptr) and can not be NULL. |
| 96 explicit TabContentsWrapper(content::WebContents* contents); | 96 explicit TabContents(content::WebContents* contents); |
| 97 virtual ~TabContentsWrapper(); | 97 virtual ~TabContents(); |
| 98 | 98 |
| 99 // Create a TabContentsWrapper with the same state as this one. The returned | 99 // Create a TabContents with the same state as this one. The returned |
| 100 // heap-allocated pointer is owned by the caller. | 100 // heap-allocated pointer is owned by the caller. |
| 101 TabContentsWrapper* Clone(); | 101 TabContents* Clone(); |
| 102 | 102 |
| 103 // Helper to retrieve the existing instance that wraps a given WebContents. | 103 // Helper to retrieve the existing instance that owns a given WebContents. |
| 104 // Returns NULL if there is no such existing instance. | 104 // Returns NULL if there is no such existing instance. |
| 105 // NOTE: This is not intended for general use. It is intended for situations | 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 | 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 | 107 // general case, please do NOT use this; plumb TabContents through the chrome/ |
| 108 // chrome/ code instead of WebContents. | 108 // code instead of WebContents. |
| 109 static TabContentsWrapper* GetCurrentWrapperForContents( | 109 static TabContents* GetCurrentWrapperForContents( |
| 110 content::WebContents* contents); | 110 content::WebContents* contents); |
| 111 static const TabContentsWrapper* GetCurrentWrapperForContents( | 111 static const TabContents* GetCurrentWrapperForContents( |
| 112 const content::WebContents* contents); | 112 const content::WebContents* contents); |
| 113 | 113 |
| 114 // Returns the WebContents that this wraps. | 114 // Returns the WebContents that this owns. |
| 115 content::WebContents* web_contents() const; | 115 content::WebContents* web_contents() const; |
| 116 | 116 |
| 117 // Returns the Profile that is associated with this TabContentsWrapper. | 117 // Returns the Profile that is associated with this TabContents. |
| 118 Profile* profile() const; | 118 Profile* profile() const; |
| 119 | 119 |
| 120 // True if this TabContentsWrapper is being torn down. | 120 // True if this TabContents is being torn down. |
| 121 bool in_destructor() const { return in_destructor_; } | 121 bool in_destructor() const { return in_destructor_; } |
| 122 | 122 |
| 123 // Tab Helpers --------------------------------------------------------------- | 123 // Tab Helpers --------------------------------------------------------------- |
| 124 | 124 |
| 125 AutocompleteHistoryManager* autocomplete_history_manager() { | 125 AutocompleteHistoryManager* autocomplete_history_manager() { |
| 126 return autocomplete_history_manager_.get(); | 126 return autocomplete_history_manager_.get(); |
| 127 } | 127 } |
| 128 | 128 |
| 129 AutofillManager* autofill_manager() { return autofill_manager_.get(); } | 129 AutofillManager* autofill_manager() { return autofill_manager_.get(); } |
| 130 | 130 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 } | 222 } |
| 223 | 223 |
| 224 // Overrides ----------------------------------------------------------------- | 224 // Overrides ----------------------------------------------------------------- |
| 225 | 225 |
| 226 // content::WebContentsObserver overrides: | 226 // content::WebContentsObserver overrides: |
| 227 virtual void WebContentsDestroyed(content::WebContents* tab) OVERRIDE; | 227 virtual void WebContentsDestroyed(content::WebContents* tab) OVERRIDE; |
| 228 | 228 |
| 229 private: | 229 private: |
| 230 // Used to retrieve this object from |web_contents_|, which is placed in | 230 // Used to retrieve this object from |web_contents_|, which is placed in |
| 231 // its property bag to avoid adding additional interfaces. | 231 // its property bag to avoid adding additional interfaces. |
| 232 static base::PropertyAccessor<TabContentsWrapper*>* property_accessor(); | 232 static base::PropertyAccessor<TabContents*>* property_accessor(); |
| 233 | 233 |
| 234 // Tab Helpers --------------------------------------------------------------- | 234 // Tab Helpers --------------------------------------------------------------- |
| 235 // (These provide API for callers and have a getter function listed in the | 235 // (These provide API for callers and have a getter function listed in the |
| 236 // "Tab Helpers" section in the member functions area, above.) | 236 // "Tab Helpers" section in the member functions area, above.) |
| 237 | 237 |
| 238 scoped_ptr<AutocompleteHistoryManager> autocomplete_history_manager_; | 238 scoped_ptr<AutocompleteHistoryManager> autocomplete_history_manager_; |
| 239 scoped_refptr<AutofillManager> autofill_manager_; | 239 scoped_refptr<AutofillManager> autofill_manager_; |
| 240 scoped_ptr<AutofillExternalDelegate> autofill_external_delegate_; | 240 scoped_ptr<AutofillExternalDelegate> autofill_external_delegate_; |
| 241 scoped_ptr<AutomationTabHelper> automation_tab_helper_; | 241 scoped_ptr<AutomationTabHelper> automation_tab_helper_; |
| 242 scoped_ptr<BlockedContentTabHelper> blocked_content_tab_helper_; | 242 scoped_ptr<BlockedContentTabHelper> blocked_content_tab_helper_; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 // WebContents (MUST BE LAST) ------------------------------------------------ | 298 // WebContents (MUST BE LAST) ------------------------------------------------ |
| 299 | 299 |
| 300 // If true, we're running the destructor. | 300 // If true, we're running the destructor. |
| 301 bool in_destructor_; | 301 bool in_destructor_; |
| 302 | 302 |
| 303 // The supporting objects need to outlive the WebContents dtor (as they may | 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 | 304 // be called upon during its execution). As a result, this must come last |
| 305 // in the list. | 305 // in the list. |
| 306 scoped_ptr<content::WebContents> web_contents_; | 306 scoped_ptr<content::WebContents> web_contents_; |
| 307 | 307 |
| 308 DISALLOW_COPY_AND_ASSIGN(TabContentsWrapper); | 308 DISALLOW_COPY_AND_ASSIGN(TabContents); |
| 309 }; | 309 }; |
| 310 | 310 |
| 311 #endif // CHROME_BROWSER_UI_TAB_CONTENTS_TAB_CONTENTS_WRAPPER_H_ | 311 #endif // CHROME_BROWSER_UI_TAB_CONTENTS_TAB_CONTENTS_H_ |
| OLD | NEW |