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 #include "chrome/browser/tab_contents_wrapper.h" |
| 6 |
| 7 #include "chrome/browser/password_manager/password_manager.h" |
| 8 #include "chrome/browser/password_manager_delegate_impl.h" |
| 9 #include "chrome/browser/tab_contents/tab_contents.h" |
| 10 |
| 11 |
| 12 TabContentsWrapper::TabContentsWrapper(TabContents* contents) |
| 13 : tab_contents_(contents) { |
| 14 DCHECK(contents); |
| 15 // Stash this in the property bag so it can be retrieved without having to |
| 16 // go to a Browser. |
| 17 property_accessor()->SetProperty(contents->property_bag(), this); |
| 18 } |
| 19 |
| 20 TabContentsWrapper::~TabContentsWrapper() { |
| 21 // Unregister observers (TabContents outlives supporting objects). |
| 22 tab_contents()->RemoveNavigationObserver(password_manager_.get()); |
| 23 } |
| 24 |
| 25 PropertyAccessor<TabContentsWrapper*>* TabContentsWrapper::property_accessor() { |
| 26 return Singleton< PropertyAccessor<TabContentsWrapper*> >::get(); |
| 27 } |
| 28 |
| 29 PasswordManager* TabContentsWrapper::GetPasswordManager() { |
| 30 if (!password_manager_.get()) { |
| 31 // Create the delegate then create the manager. |
| 32 password_manager_delegate_.reset( |
| 33 new PasswordManagerDelegateImpl(tab_contents())); |
| 34 password_manager_.reset( |
| 35 new PasswordManager(password_manager_delegate_.get())); |
| 36 // Register the manager to receive navigation notifications. |
| 37 tab_contents()->AddNavigationObserver(password_manager_.get()); |
| 38 } |
| 39 return password_manager_.get(); |
| 40 } |
| 41 |
| 42 TabContentsWrapper* TabContentsWrapper::Clone() { |
| 43 TabContents* new_contents = tab_contents()->Clone(); |
| 44 TabContentsWrapper* new_wrapper = new TabContentsWrapper(new_contents); |
| 45 // Instantiate the passowrd manager if it has been instantiated here. |
| 46 if (password_manager_.get()) |
| 47 new_wrapper->GetPasswordManager(); |
| 48 return new_wrapper; |
| 49 } |
OLD | NEW |