| 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_wrapper.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" |
| 11 #include "chrome/browser/autofill/autofill_manager.h" | 11 #include "chrome/browser/autofill/autofill_manager.h" |
| 12 #include "chrome/browser/automation/automation_tab_helper.h" | 12 #include "chrome/browser/automation/automation_tab_helper.h" |
| 13 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 13 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| 14 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api.h" | 14 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api.h" |
| 15 #include "chrome/browser/extensions/extension_tab_helper.h" | 15 #include "chrome/browser/extensions/extension_tab_helper.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 #include "content/public/browser/web_contents.h" | 52 #include "content/public/browser/web_contents.h" |
| 53 | 53 |
| 54 #if defined(OS_WIN) | 54 #if defined(OS_WIN) |
| 55 #include "base/win/metro.h" | 55 #include "base/win/metro.h" |
| 56 #endif | 56 #endif |
| 57 | 57 |
| 58 using content::WebContents; | 58 using content::WebContents; |
| 59 | 59 |
| 60 namespace { | 60 namespace { |
| 61 | 61 |
| 62 static base::LazyInstance<base::PropertyAccessor<TabContentsWrapper*> > | 62 static base::LazyInstance<base::PropertyAccessor<TabContents*> > |
| 63 g_tab_contents_wrapper_property_accessor = LAZY_INSTANCE_INITIALIZER; | 63 g_tab_contents_wrapper_property_accessor = LAZY_INSTANCE_INITIALIZER; |
| 64 | 64 |
| 65 } // namespace | 65 } // namespace |
| 66 | 66 |
| 67 //////////////////////////////////////////////////////////////////////////////// | 67 //////////////////////////////////////////////////////////////////////////////// |
| 68 // TabContentsWrapper, public: | 68 // TabContents, public: |
| 69 | 69 |
| 70 TabContentsWrapper::TabContentsWrapper(WebContents* contents) | 70 TabContents::TabContents(WebContents* contents) |
| 71 : content::WebContentsObserver(contents), | 71 : content::WebContentsObserver(contents), |
| 72 in_destructor_(false), | 72 in_destructor_(false), |
| 73 web_contents_(contents) { | 73 web_contents_(contents) { |
| 74 DCHECK(contents); | 74 DCHECK(contents); |
| 75 DCHECK(!GetCurrentWrapperForContents(contents)); | 75 DCHECK(!GetCurrentWrapperForContents(contents)); |
| 76 | 76 |
| 77 chrome::SetViewType(contents, chrome::VIEW_TYPE_TAB_CONTENTS); | 77 chrome::SetViewType(contents, chrome::VIEW_TYPE_TAB_CONTENTS); |
| 78 | 78 |
| 79 // Stash this in the property bag so it can be retrieved without having to | 79 // Stash this in the property bag so it can be retrieved without having to |
| 80 // go to a Browser. | 80 // go to a Browser. |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 // We don't want to check that the profile is already connected at this time | 158 // We don't want to check that the profile is already connected at this time |
| 159 // because the connected state may change while this tab is open. Having a | 159 // because the connected state may change while this tab is open. Having a |
| 160 // one-click signin helper attached does not cause problems if the profile | 160 // one-click signin helper attached does not cause problems if the profile |
| 161 // happens to be already connected. | 161 // happens to be already connected. |
| 162 #if defined(ENABLE_ONE_CLICK_SIGNIN) | 162 #if defined(ENABLE_ONE_CLICK_SIGNIN) |
| 163 if (OneClickSigninHelper::CanOffer(contents, false)) | 163 if (OneClickSigninHelper::CanOffer(contents, false)) |
| 164 one_click_signin_helper_.reset(new OneClickSigninHelper(contents)); | 164 one_click_signin_helper_.reset(new OneClickSigninHelper(contents)); |
| 165 #endif | 165 #endif |
| 166 } | 166 } |
| 167 | 167 |
| 168 TabContentsWrapper::~TabContentsWrapper() { | 168 TabContents::~TabContents() { |
| 169 in_destructor_ = true; | 169 in_destructor_ = true; |
| 170 | 170 |
| 171 // Need to reset |thumbnail_generator_| here before |web_contents_| is | 171 // Need to reset |thumbnail_generator_| here before |web_contents_| is |
| 172 // deleted because destructing |web_contents_| can end up causing the | 172 // deleted because destructing |web_contents_| can end up causing the |
| 173 // thumbnailer to generate a thumbnail. Since TabContentsWrapper can be | 173 // thumbnailer to generate a thumbnail. Since TabContents can be |
| 174 // destructed during shutdown, trying to generate a thumbnail by sending an | 174 // destructed during shutdown, trying to generate a thumbnail by sending an |
| 175 // IPC message to the GPU process is not safe. Sending | 175 // IPC message to the GPU process is not safe. Sending |
| 176 // chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED can also cause the thumbnailer | 176 // chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED can also cause the thumbnailer |
| 177 // to generate a thumbnail, so this must be placed before sending the | 177 // to generate a thumbnail, so this must be placed before sending the |
| 178 // notification. | 178 // notification. |
| 179 thumbnail_generator_.reset(); | 179 thumbnail_generator_.reset(); |
| 180 | 180 |
| 181 content::NotificationService::current()->Notify( | 181 content::NotificationService::current()->Notify( |
| 182 chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED, | 182 chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED, |
| 183 content::Source<TabContentsWrapper>(this), | 183 content::Source<TabContents>(this), |
| 184 content::NotificationService::NoDetails()); | 184 content::NotificationService::NoDetails()); |
| 185 | 185 |
| 186 // Need to tear down infobars before the WebContents goes away. | 186 // Need to tear down infobars before the WebContents goes away. |
| 187 // TODO(avi): Can we get this handled by the tab helper itself? | 187 // TODO(avi): Can we get this handled by the tab helper itself? |
| 188 infobar_tab_helper_.reset(); | 188 infobar_tab_helper_.reset(); |
| 189 } | 189 } |
| 190 | 190 |
| 191 base::PropertyAccessor<TabContentsWrapper*>* | 191 base::PropertyAccessor<TabContents*>* TabContents::property_accessor() { |
| 192 TabContentsWrapper::property_accessor() { | |
| 193 return g_tab_contents_wrapper_property_accessor.Pointer(); | 192 return g_tab_contents_wrapper_property_accessor.Pointer(); |
| 194 } | 193 } |
| 195 | 194 |
| 196 TabContentsWrapper* TabContentsWrapper::Clone() { | 195 TabContents* TabContents::Clone() { |
| 197 WebContents* new_contents = web_contents()->Clone(); | 196 WebContents* new_contents = web_contents()->Clone(); |
| 198 TabContentsWrapper* new_wrapper = new TabContentsWrapper(new_contents); | 197 TabContents* new_wrapper = new TabContents(new_contents); |
| 199 | 198 |
| 200 // TODO(avi): Can we generalize this so that knowledge of the functionings of | 199 // TODO(avi): Can we generalize this so that knowledge of the functionings of |
| 201 // the tab helpers isn't required here? | 200 // the tab helpers isn't required here? |
| 202 new_wrapper->extension_tab_helper()->CopyStateFrom( | 201 new_wrapper->extension_tab_helper()->CopyStateFrom( |
| 203 *extension_tab_helper_.get()); | 202 *extension_tab_helper_.get()); |
| 204 return new_wrapper; | 203 return new_wrapper; |
| 205 } | 204 } |
| 206 | 205 |
| 207 // static | 206 // static |
| 208 TabContentsWrapper* TabContentsWrapper::GetCurrentWrapperForContents( | 207 TabContents* TabContents::GetCurrentWrapperForContents( |
| 209 WebContents* contents) { | 208 WebContents* contents) { |
| 210 TabContentsWrapper** wrapper = | 209 TabContents** wrapper = |
| 211 property_accessor()->GetProperty(contents->GetPropertyBag()); | 210 property_accessor()->GetProperty(contents->GetPropertyBag()); |
| 212 | 211 |
| 213 return wrapper ? *wrapper : NULL; | 212 return wrapper ? *wrapper : NULL; |
| 214 } | 213 } |
| 215 | 214 |
| 216 // static | 215 // static |
| 217 const TabContentsWrapper* TabContentsWrapper::GetCurrentWrapperForContents( | 216 const TabContents* TabContents::GetCurrentWrapperForContents( |
| 218 const WebContents* contents) { | 217 const WebContents* contents) { |
| 219 TabContentsWrapper* const* wrapper = | 218 TabContents* const* wrapper = |
| 220 property_accessor()->GetProperty(contents->GetPropertyBag()); | 219 property_accessor()->GetProperty(contents->GetPropertyBag()); |
| 221 | 220 |
| 222 return wrapper ? *wrapper : NULL; | 221 return wrapper ? *wrapper : NULL; |
| 223 } | 222 } |
| 224 | 223 |
| 225 WebContents* TabContentsWrapper::web_contents() const { | 224 WebContents* TabContents::web_contents() const { |
| 226 return web_contents_.get(); | 225 return web_contents_.get(); |
| 227 } | 226 } |
| 228 | 227 |
| 229 Profile* TabContentsWrapper::profile() const { | 228 Profile* TabContents::profile() const { |
| 230 return Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 229 return Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
| 231 } | 230 } |
| 232 | 231 |
| 233 //////////////////////////////////////////////////////////////////////////////// | 232 //////////////////////////////////////////////////////////////////////////////// |
| 234 // WebContentsObserver overrides | 233 // WebContentsObserver overrides |
| 235 | 234 |
| 236 void TabContentsWrapper::WebContentsDestroyed(WebContents* tab) { | 235 void TabContents::WebContentsDestroyed(WebContents* tab) { |
| 237 // Destruction of the WebContents should only be done by us from our | 236 // Destruction of the WebContents should only be done by us from our |
| 238 // destructor. Otherwise it's very likely we (or one of the helpers we own) | 237 // destructor. Otherwise it's very likely we (or one of the helpers we own) |
| 239 // will attempt to access the WebContents and we'll crash. | 238 // will attempt to access the WebContents and we'll crash. |
| 240 DCHECK(in_destructor_); | 239 DCHECK(in_destructor_); |
| 241 } | 240 } |
| OLD | NEW |