| 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 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 5 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "chrome/browser/autocomplete_history_manager.h" | 9 #include "chrome/browser/autocomplete_history_manager.h" |
| 10 #include "chrome/browser/autofill/autofill_external_delegate.h" | 10 #include "chrome/browser/autofill/autofill_external_delegate.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 | 54 |
| 55 #if defined(OS_WIN) | 55 #if defined(OS_WIN) |
| 56 #include "base/win/metro.h" | 56 #include "base/win/metro.h" |
| 57 #endif | 57 #endif |
| 58 | 58 |
| 59 using content::WebContents; | 59 using content::WebContents; |
| 60 | 60 |
| 61 namespace { | 61 namespace { |
| 62 | 62 |
| 63 static base::LazyInstance<base::PropertyAccessor<TabContents*> > | 63 static base::LazyInstance<base::PropertyAccessor<TabContents*> > |
| 64 g_tab_contents_wrapper_property_accessor = LAZY_INSTANCE_INITIALIZER; | 64 g_tab_contents_property_accessor = LAZY_INSTANCE_INITIALIZER; |
| 65 | 65 |
| 66 } // namespace | 66 } // namespace |
| 67 | 67 |
| 68 //////////////////////////////////////////////////////////////////////////////// | 68 //////////////////////////////////////////////////////////////////////////////// |
| 69 // TabContents, public: | 69 // TabContents, public: |
| 70 | 70 |
| 71 TabContents::TabContents(WebContents* contents) | 71 TabContents::TabContents(WebContents* contents) |
| 72 : content::WebContentsObserver(contents), | 72 : content::WebContentsObserver(contents), |
| 73 in_destructor_(false), | 73 in_destructor_(false), |
| 74 web_contents_(contents) { | 74 web_contents_(contents) { |
| 75 DCHECK(contents); | 75 DCHECK(contents); |
| 76 DCHECK(!GetCurrentWrapperForContents(contents)); | 76 DCHECK(!GetOwningContentsForWebContents(contents)); |
| 77 | 77 |
| 78 chrome::SetViewType(contents, chrome::VIEW_TYPE_TAB_CONTENTS); | 78 chrome::SetViewType(contents, chrome::VIEW_TYPE_TAB_CONTENTS); |
| 79 | 79 |
| 80 // Stash this in the property bag so it can be retrieved without having to | 80 // Stash this in the property bag so it can be retrieved without having to |
| 81 // go to a Browser. | 81 // go to a Browser. |
| 82 property_accessor()->SetProperty(contents->GetPropertyBag(), this); | 82 property_accessor()->SetProperty(contents->GetPropertyBag(), this); |
| 83 | 83 |
| 84 // Create the tab helpers. | 84 // Create the tab helpers. |
| 85 autocomplete_history_manager_.reset(new AutocompleteHistoryManager(contents)); | 85 autocomplete_history_manager_.reset(new AutocompleteHistoryManager(contents)); |
| 86 autofill_manager_ = new AutofillManager(this); | 86 autofill_manager_ = new AutofillManager(this); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED, | 184 chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED, |
| 185 content::Source<TabContents>(this), | 185 content::Source<TabContents>(this), |
| 186 content::NotificationService::NoDetails()); | 186 content::NotificationService::NoDetails()); |
| 187 | 187 |
| 188 // Need to tear down infobars before the WebContents goes away. | 188 // Need to tear down infobars before the WebContents goes away. |
| 189 // TODO(avi): Can we get this handled by the tab helper itself? | 189 // TODO(avi): Can we get this handled by the tab helper itself? |
| 190 infobar_tab_helper_.reset(); | 190 infobar_tab_helper_.reset(); |
| 191 } | 191 } |
| 192 | 192 |
| 193 base::PropertyAccessor<TabContents*>* TabContents::property_accessor() { | 193 base::PropertyAccessor<TabContents*>* TabContents::property_accessor() { |
| 194 return g_tab_contents_wrapper_property_accessor.Pointer(); | 194 return g_tab_contents_property_accessor.Pointer(); |
| 195 } | 195 } |
| 196 | 196 |
| 197 TabContents* TabContents::Clone() { | 197 TabContents* TabContents::Clone() { |
| 198 WebContents* new_contents = web_contents()->Clone(); | 198 WebContents* new_web_contents = web_contents()->Clone(); |
| 199 TabContents* new_wrapper = new TabContents(new_contents); | 199 TabContents* new_tab_contents = new TabContents(new_web_contents); |
| 200 | 200 |
| 201 // TODO(avi): Can we generalize this so that knowledge of the functionings of | 201 // TODO(avi): Can we generalize this so that knowledge of the functionings of |
| 202 // the tab helpers isn't required here? | 202 // the tab helpers isn't required here? |
| 203 new_wrapper->extension_tab_helper()->CopyStateFrom( | 203 new_tab_contents->extension_tab_helper()->CopyStateFrom( |
| 204 *extension_tab_helper_.get()); | 204 *extension_tab_helper_.get()); |
| 205 return new_wrapper; | 205 return new_tab_contents; |
| 206 } |
| 207 |
| 208 // static deprecated |
| 209 TabContents* TabContents::GetCurrentWrapperForContents( |
| 210 WebContents* contents) { |
| 211 return GetOwningContentsForWebContents(contents); |
| 212 } |
| 213 |
| 214 // static deprecated |
| 215 const TabContents* TabContents::GetCurrentWrapperForContents( |
| 216 const WebContents* contents) { |
| 217 return GetOwningContentsForWebContents(contents); |
| 206 } | 218 } |
| 207 | 219 |
| 208 // static | 220 // static |
| 209 TabContents* TabContents::GetCurrentWrapperForContents( | 221 TabContents* TabContents::GetOwningContentsForWebContents( |
| 210 WebContents* contents) { | 222 WebContents* contents) { |
| 211 TabContents** wrapper = | 223 TabContents** tab_contents = |
| 212 property_accessor()->GetProperty(contents->GetPropertyBag()); | 224 property_accessor()->GetProperty(contents->GetPropertyBag()); |
| 213 | 225 |
| 214 return wrapper ? *wrapper : NULL; | 226 return tab_contents ? *tab_contents : NULL; |
| 215 } | 227 } |
| 216 | 228 |
| 217 // static | 229 // static |
| 218 const TabContents* TabContents::GetCurrentWrapperForContents( | 230 const TabContents* TabContents::GetOwningContentsForWebContents( |
| 219 const WebContents* contents) { | 231 const WebContents* contents) { |
| 220 TabContents* const* wrapper = | 232 TabContents* const* tab_contents = |
| 221 property_accessor()->GetProperty(contents->GetPropertyBag()); | 233 property_accessor()->GetProperty(contents->GetPropertyBag()); |
| 222 | 234 |
| 223 return wrapper ? *wrapper : NULL; | 235 return tab_contents ? *tab_contents : NULL; |
| 224 } | 236 } |
| 225 | 237 |
| 226 WebContents* TabContents::web_contents() const { | 238 WebContents* TabContents::web_contents() const { |
| 227 return web_contents_.get(); | 239 return web_contents_.get(); |
| 228 } | 240 } |
| 229 | 241 |
| 230 Profile* TabContents::profile() const { | 242 Profile* TabContents::profile() const { |
| 231 return Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 243 return Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
| 232 } | 244 } |
| 233 | 245 |
| 234 //////////////////////////////////////////////////////////////////////////////// | 246 //////////////////////////////////////////////////////////////////////////////// |
| 235 // WebContentsObserver overrides | 247 // WebContentsObserver overrides |
| 236 | 248 |
| 237 void TabContents::WebContentsDestroyed(WebContents* tab) { | 249 void TabContents::WebContentsDestroyed(WebContents* tab) { |
| 238 // Destruction of the WebContents should only be done by us from our | 250 // Destruction of the WebContents should only be done by us from our |
| 239 // destructor. Otherwise it's very likely we (or one of the helpers we own) | 251 // destructor. Otherwise it's very likely we (or one of the helpers we own) |
| 240 // will attempt to access the WebContents and we'll crash. | 252 // will attempt to access the WebContents and we'll crash. |
| 241 DCHECK(in_destructor_); | 253 DCHECK(in_destructor_); |
| 242 } | 254 } |
| OLD | NEW |