OLD | NEW |
| (Empty) |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_BROWSER_TAB_CONTENTS_WRAPPER_H_ | |
6 #define CHROME_BROWSER_TAB_CONTENTS_WRAPPER_H_ | |
7 #pragma once | |
8 | |
9 #include "base/scoped_ptr.h" | |
10 #include "chrome/browser/tab_contents/tab_contents.h" | |
11 #include "chrome/browser/tab_contents/web_navigation_observer.h" | |
12 | |
13 class Extension; | |
14 class NavigationController; | |
15 class PasswordManager; | |
16 class PasswordManagerDelegate; | |
17 class TabContentsDelegate; | |
18 | |
19 // Wraps TabContents and all of its supporting objetcs in order to control | |
20 // their ownership and lifetime, while allowing TabContents to remain generic | |
21 // and re-usable in other projects. | |
22 // TODO(pinkerton): Eventually, this class will become TabContents as far as | |
23 // the browser front-end is concerned, and the current TabContents will be | |
24 // renamed to something like WebPage or WebView (ben's suggestions). | |
25 class TabContentsWrapper : public WebNavigationObserver { | |
26 public: | |
27 // Takes ownership of |contents|, which must be heap-allocated (as it lives | |
28 // in a scoped_ptr) and can not be NULL. | |
29 explicit TabContentsWrapper(TabContents* contents); | |
30 ~TabContentsWrapper(); | |
31 | |
32 // Used to retrieve this object from |tab_contents_|, which is placed in | |
33 // its property bag to avoid adding additional interfaces. | |
34 static PropertyAccessor<TabContentsWrapper*>* property_accessor(); | |
35 | |
36 // Create a TabContentsWrapper with the same state as this one. The returned | |
37 // heap-allocated pointer is owned by the caller. | |
38 TabContentsWrapper* Clone(); | |
39 | |
40 TabContents* tab_contents() const { return tab_contents_.get(); } | |
41 NavigationController& controller() const { | |
42 return tab_contents()->controller(); | |
43 } | |
44 TabContentsView* view() const { return tab_contents()->view(); } | |
45 RenderViewHost* render_view_host() const { | |
46 return tab_contents()->render_view_host(); | |
47 } | |
48 Profile* profile() const { return tab_contents()->profile(); } | |
49 TabContentsDelegate* delegate() const { return tab_contents()->delegate(); } | |
50 void set_delegate(TabContentsDelegate* d) { tab_contents()->set_delegate(d); } | |
51 | |
52 // Convenience methods until extensions are removed from TabContents. | |
53 void SetExtensionAppById(const std::string& extension_app_id) { | |
54 tab_contents()->SetExtensionAppById(extension_app_id); | |
55 } | |
56 const Extension* extension_app() const { | |
57 return tab_contents()->extension_app(); | |
58 } | |
59 bool is_app() const { return tab_contents()->is_app(); } | |
60 | |
61 // Returns the PasswordManager, creating it if necessary. | |
62 PasswordManager* GetPasswordManager(); | |
63 | |
64 // WebNavigationObserver overrides: | |
65 virtual void NavigateToPendingEntry(); | |
66 | |
67 private: | |
68 // PasswordManager and its delegate, lazily created. The delegate must | |
69 // outlive the manager, per documentation in password_manager.h. | |
70 scoped_ptr<PasswordManagerDelegate> password_manager_delegate_; | |
71 scoped_ptr<PasswordManager> password_manager_; | |
72 | |
73 // The supporting objects need to outlive the TabContents dtor (as they may | |
74 // be called upon during its execution). As a result, this must come last | |
75 // in the list. | |
76 scoped_ptr<TabContents> tab_contents_; | |
77 }; | |
78 | |
79 #endif // CHROME_BROWSER_TAB_CONTENTS_WRAPPER_H_ | |
OLD | NEW |