OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 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 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 5 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
6 | 6 |
7 #include "base/singleton.h" | 7 #include "base/lazy_instance.h" |
8 #include "chrome/browser/password_manager/password_manager.h" | 8 #include "chrome/browser/password_manager/password_manager.h" |
9 #include "chrome/browser/password_manager_delegate_impl.h" | 9 #include "chrome/browser/password_manager_delegate_impl.h" |
10 #include "chrome/browser/tab_contents/tab_contents.h" | 10 #include "chrome/browser/tab_contents/tab_contents.h" |
11 | 11 |
| 12 static base::LazyInstance<PropertyAccessor<TabContentsWrapper*> > |
| 13 g_tab_contents_wrapper_property_accessor(base::LINKER_INITIALIZED); |
| 14 |
12 //////////////////////////////////////////////////////////////////////////////// | 15 //////////////////////////////////////////////////////////////////////////////// |
13 // TabContentsWrapper, public: | 16 // TabContentsWrapper, public: |
14 | 17 |
15 TabContentsWrapper::TabContentsWrapper(TabContents* contents) | 18 TabContentsWrapper::TabContentsWrapper(TabContents* contents) |
16 : tab_contents_(contents) { | 19 : tab_contents_(contents) { |
17 DCHECK(contents); | 20 DCHECK(contents); |
18 // Stash this in the property bag so it can be retrieved without having to | 21 // Stash this in the property bag so it can be retrieved without having to |
19 // go to a Browser. | 22 // go to a Browser. |
20 property_accessor()->SetProperty(contents->property_bag(), this); | 23 property_accessor()->SetProperty(contents->property_bag(), this); |
21 | 24 |
22 // Needed so that we initialize the password manager on first navigation. | 25 // Needed so that we initialize the password manager on first navigation. |
23 tab_contents()->AddNavigationObserver(this); | 26 tab_contents()->AddNavigationObserver(this); |
24 } | 27 } |
25 | 28 |
26 TabContentsWrapper::~TabContentsWrapper() { | 29 TabContentsWrapper::~TabContentsWrapper() { |
27 // Unregister observers (TabContents outlives supporting objects). | 30 // Unregister observers (TabContents outlives supporting objects). |
28 tab_contents()->RemoveNavigationObserver(password_manager_.get()); | 31 tab_contents()->RemoveNavigationObserver(password_manager_.get()); |
29 } | 32 } |
30 | 33 |
31 PropertyAccessor<TabContentsWrapper*>* TabContentsWrapper::property_accessor() { | 34 PropertyAccessor<TabContentsWrapper*>* TabContentsWrapper::property_accessor() { |
32 return Singleton< PropertyAccessor<TabContentsWrapper*> >::get(); | 35 return g_tab_contents_wrapper_property_accessor.Pointer(); |
33 } | 36 } |
34 | 37 |
35 TabContentsWrapper* TabContentsWrapper::Clone() { | 38 TabContentsWrapper* TabContentsWrapper::Clone() { |
36 TabContents* new_contents = tab_contents()->Clone(); | 39 TabContents* new_contents = tab_contents()->Clone(); |
37 TabContentsWrapper* new_wrapper = new TabContentsWrapper(new_contents); | 40 TabContentsWrapper* new_wrapper = new TabContentsWrapper(new_contents); |
38 // Instantiate the passowrd manager if it has been instantiated here. | 41 // Instantiate the passowrd manager if it has been instantiated here. |
39 if (password_manager_.get()) | 42 if (password_manager_.get()) |
40 new_wrapper->GetPasswordManager(); | 43 new_wrapper->GetPasswordManager(); |
41 return new_wrapper; | 44 return new_wrapper; |
42 } | 45 } |
(...skipping 11 matching lines...) Expand all Loading... |
54 return password_manager_.get(); | 57 return password_manager_.get(); |
55 } | 58 } |
56 | 59 |
57 //////////////////////////////////////////////////////////////////////////////// | 60 //////////////////////////////////////////////////////////////////////////////// |
58 // TabContentsWrapper, WebNavigationObserver implementation: | 61 // TabContentsWrapper, WebNavigationObserver implementation: |
59 | 62 |
60 void TabContentsWrapper::NavigateToPendingEntry() { | 63 void TabContentsWrapper::NavigateToPendingEntry() { |
61 GetPasswordManager(); | 64 GetPasswordManager(); |
62 tab_contents()->RemoveNavigationObserver(this); | 65 tab_contents()->RemoveNavigationObserver(this); |
63 } | 66 } |
OLD | NEW |