| 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/instant/instant_loader.h" | 5 #include "chrome/browser/instant/instant_loader.h" |
| 6 | 6 |
| 7 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 7 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| 8 #include "chrome/browser/history/history_types.h" | 8 #include "chrome/browser/history/history_types.h" |
| 9 #include "chrome/browser/instant/instant_loader_delegate.h" | 9 #include "chrome/browser/instant/instant_loader_delegate.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 OnInstantSupportDetermined) | 193 OnInstantSupportDetermined) |
| 194 IPC_MESSAGE_UNHANDLED(handled = false) | 194 IPC_MESSAGE_UNHANDLED(handled = false) |
| 195 IPC_END_MESSAGE_MAP() | 195 IPC_END_MESSAGE_MAP() |
| 196 return handled; | 196 return handled; |
| 197 } | 197 } |
| 198 | 198 |
| 199 void InstantLoader::WebContentsDelegateImpl::OnSetSuggestions( | 199 void InstantLoader::WebContentsDelegateImpl::OnSetSuggestions( |
| 200 int page_id, | 200 int page_id, |
| 201 const std::vector<string16>& suggestions, | 201 const std::vector<string16>& suggestions, |
| 202 InstantCompleteBehavior behavior) { | 202 InstantCompleteBehavior behavior) { |
| 203 DCHECK(loader_->preview_contents() && |
| 204 loader_->preview_contents_->web_contents()); |
| 205 // TODO(sreeram): Remove this 'if' bandaid once bug 141875 is confirmed fixed. |
| 206 if (!loader_->preview_contents() || |
| 207 !loader_->preview_contents_->web_contents()) { |
| 208 return; |
| 209 } |
| 203 content::NavigationEntry* entry = loader_->preview_contents_->web_contents()-> | 210 content::NavigationEntry* entry = loader_->preview_contents_->web_contents()-> |
| 204 GetController().GetActiveEntry(); | 211 GetController().GetActiveEntry(); |
| 205 if (entry && page_id == entry->GetPageID()) { | 212 if (entry && page_id == entry->GetPageID()) { |
| 206 MaybeSetAndNotifyInstantSupportDetermined(true); | 213 MaybeSetAndNotifyInstantSupportDetermined(true); |
| 207 loader_->loader_delegate_->SetSuggestions(loader_, suggestions, behavior); | 214 loader_->loader_delegate_->SetSuggestions(loader_, suggestions, behavior); |
| 208 } | 215 } |
| 209 } | 216 } |
| 210 | 217 |
| 211 void InstantLoader::WebContentsDelegateImpl::OnInstantSupportDetermined( | 218 void InstantLoader::WebContentsDelegateImpl::OnInstantSupportDetermined( |
| 212 int page_id, | 219 int page_id, |
| 213 bool result) { | 220 bool result) { |
| 221 DCHECK(loader_->preview_contents() && |
| 222 loader_->preview_contents_->web_contents()); |
| 223 // TODO(sreeram): Remove this 'if' bandaid once bug 141875 is confirmed fixed. |
| 224 if (!loader_->preview_contents() || |
| 225 !loader_->preview_contents_->web_contents()) { |
| 226 return; |
| 227 } |
| 214 content::NavigationEntry* entry = loader_->preview_contents_->web_contents()-> | 228 content::NavigationEntry* entry = loader_->preview_contents_->web_contents()-> |
| 215 GetController().GetActiveEntry(); | 229 GetController().GetActiveEntry(); |
| 216 if (entry && page_id == entry->GetPageID()) | 230 if (entry && page_id == entry->GetPageID()) |
| 217 MaybeSetAndNotifyInstantSupportDetermined(result); | 231 MaybeSetAndNotifyInstantSupportDetermined(result); |
| 218 } | 232 } |
| 219 | 233 |
| 220 | 234 |
| 221 void InstantLoader::WebContentsDelegateImpl | 235 void InstantLoader::WebContentsDelegateImpl |
| 222 ::CommitFromPointerReleaseIfNecessary() { | 236 ::CommitFromPointerReleaseIfNecessary() { |
| 223 if (is_pointer_down_from_activate_) { | 237 if (is_pointer_down_from_activate_) { |
| 224 is_pointer_down_from_activate_ = false; | 238 is_pointer_down_from_activate_ = false; |
| 225 loader_->loader_delegate_->CommitInstantLoader(loader_); | 239 loader_->loader_delegate_->CommitInstantLoader(loader_); |
| 226 } | 240 } |
| 227 } | 241 } |
| 228 | 242 |
| 229 void InstantLoader::WebContentsDelegateImpl | 243 void InstantLoader::WebContentsDelegateImpl |
| 230 ::MaybeSetAndNotifyInstantSupportDetermined(bool supports_instant) { | 244 ::MaybeSetAndNotifyInstantSupportDetermined(bool supports_instant) { |
| 231 // If we already determined that the loader supports Instant, nothing to do. | 245 // If we already determined that the loader supports Instant, nothing to do. |
| 232 if (loader_->supports_instant_) | 246 if (loader_->supports_instant_) |
| 233 return; | 247 return; |
| 234 | 248 |
| 249 // If the page doesn't support the Instant API, InstantController schedules |
| 250 // the loader for destruction. Stop sending the controller any more messages, |
| 251 // by severing the connection from the WebContents to us (its delegate). |
| 252 if (!supports_instant) { |
| 253 loader_->preview_contents_->web_contents()->SetDelegate(NULL); |
| 254 Observe(NULL); |
| 255 } |
| 256 |
| 235 loader_->supports_instant_ = supports_instant; | 257 loader_->supports_instant_ = supports_instant; |
| 236 loader_->loader_delegate_->InstantSupportDetermined(loader_, | 258 loader_->loader_delegate_->InstantSupportDetermined(loader_, |
| 237 supports_instant); | 259 supports_instant); |
| 238 | |
| 239 // If the page doesn't support the Instant API, InstantController schedules | |
| 240 // the loader for destruction. Stop sending the controller any more messages, | |
| 241 // by severing the connection from the WebContents to us (its delegate). | |
| 242 if (!supports_instant) | |
| 243 loader_->preview_contents_->web_contents()->SetDelegate(NULL); | |
| 244 } | 260 } |
| 245 | 261 |
| 246 // InstantLoader --------------------------------------------------------------- | 262 // InstantLoader --------------------------------------------------------------- |
| 247 | 263 |
| 248 InstantLoader::InstantLoader(InstantLoaderDelegate* delegate, | 264 InstantLoader::InstantLoader(InstantLoaderDelegate* delegate, |
| 249 const std::string& instant_url, | 265 const std::string& instant_url, |
| 250 const TabContents* tab_contents) | 266 const TabContents* tab_contents) |
| 251 : loader_delegate_(delegate), | 267 : loader_delegate_(delegate), |
| 252 preview_contents_(new TabContents(content::WebContents::Create( | 268 preview_contents_(new TabContents(content::WebContents::Create( |
| 253 tab_contents->profile(), NULL, MSG_ROUTING_NONE, | 269 tab_contents->profile(), NULL, MSG_ROUTING_NONE, |
| 254 tab_contents->web_contents(), | 270 tab_contents->web_contents(), |
| 255 tab_contents->web_contents()->GetController(). | 271 tab_contents->web_contents()->GetController(). |
| 256 GetSessionStorageNamespace()))), | 272 GetSessionStorageNamespace()))), |
| 257 preview_delegate_(new WebContentsDelegateImpl( | |
| 258 ALLOW_THIS_IN_INITIALIZER_LIST(this))), | |
| 259 supports_instant_(false), | 273 supports_instant_(false), |
| 260 instant_url_(instant_url) { | 274 instant_url_(instant_url) { |
| 261 } | 275 } |
| 262 | 276 |
| 263 InstantLoader::~InstantLoader() { | 277 InstantLoader::~InstantLoader() { |
| 264 if (preview_contents()) | 278 if (preview_contents()) |
| 265 preview_contents_->web_contents()->SetDelegate(NULL); | 279 preview_contents_->web_contents()->SetDelegate(NULL); |
| 266 } | 280 } |
| 267 | 281 |
| 268 void InstantLoader::Init() { | 282 void InstantLoader::Init() { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 rwhv->SetTakesFocusOnlyOnMouseDown(true); | 330 rwhv->SetTakesFocusOnlyOnMouseDown(true); |
| 317 } | 331 } |
| 318 return; | 332 return; |
| 319 } | 333 } |
| 320 NOTREACHED(); | 334 NOTREACHED(); |
| 321 #endif | 335 #endif |
| 322 } | 336 } |
| 323 | 337 |
| 324 void InstantLoader::SetupPreviewContents() { | 338 void InstantLoader::SetupPreviewContents() { |
| 325 content::WebContents* new_contents = preview_contents_->web_contents(); | 339 content::WebContents* new_contents = preview_contents_->web_contents(); |
| 340 preview_delegate_.reset(new WebContentsDelegateImpl(this)); |
| 326 WebContentsDelegateImpl* new_delegate = preview_delegate_.get(); | 341 WebContentsDelegateImpl* new_delegate = preview_delegate_.get(); |
| 327 new_contents->SetDelegate(new_delegate); | 342 new_contents->SetDelegate(new_delegate); |
| 328 | 343 |
| 329 // Disable popups and such (mainly to avoid losing focus and reverting the | 344 // Disable popups and such (mainly to avoid losing focus and reverting the |
| 330 // preview prematurely). | 345 // preview prematurely). |
| 331 preview_contents_->blocked_content_tab_helper()->SetAllContentsBlocked(true); | 346 preview_contents_->blocked_content_tab_helper()->SetAllContentsBlocked(true); |
| 332 preview_contents_->constrained_window_tab_helper()->set_delegate( | 347 preview_contents_->constrained_window_tab_helper()->set_delegate( |
| 333 new_delegate); | 348 new_delegate); |
| 334 preview_contents_->content_settings()->SetPopupsBlocked(true); | 349 preview_contents_->content_settings()->SetPopupsBlocked(true); |
| 335 preview_contents_->core_tab_helper()->set_delegate(new_delegate); | 350 preview_contents_->core_tab_helper()->set_delegate(new_delegate); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 346 } | 361 } |
| 347 registrar_.Add(this, content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, | 362 registrar_.Add(this, content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, |
| 348 content::Source<content::NavigationController>( | 363 content::Source<content::NavigationController>( |
| 349 &new_contents->GetController())); | 364 &new_contents->GetController())); |
| 350 #endif | 365 #endif |
| 351 } | 366 } |
| 352 | 367 |
| 353 void InstantLoader::CleanupPreviewContents() { | 368 void InstantLoader::CleanupPreviewContents() { |
| 354 content::WebContents* old_contents = preview_contents_->web_contents(); | 369 content::WebContents* old_contents = preview_contents_->web_contents(); |
| 355 old_contents->SetDelegate(NULL); | 370 old_contents->SetDelegate(NULL); |
| 371 preview_delegate_.reset(); |
| 356 | 372 |
| 357 preview_contents_->blocked_content_tab_helper()->SetAllContentsBlocked(false); | 373 preview_contents_->blocked_content_tab_helper()->SetAllContentsBlocked(false); |
| 358 preview_contents_->constrained_window_tab_helper()->set_delegate(NULL); | 374 preview_contents_->constrained_window_tab_helper()->set_delegate(NULL); |
| 359 preview_contents_->content_settings()->SetPopupsBlocked(false); | 375 preview_contents_->content_settings()->SetPopupsBlocked(false); |
| 360 preview_contents_->core_tab_helper()->set_delegate(NULL); | 376 preview_contents_->core_tab_helper()->set_delegate(NULL); |
| 361 if (ThumbnailGenerator* tg = preview_contents_->thumbnail_generator()) | 377 if (ThumbnailGenerator* tg = preview_contents_->thumbnail_generator()) |
| 362 tg->set_enabled(true); | 378 tg->set_enabled(true); |
| 363 | 379 |
| 364 #if defined(OS_MACOSX) | 380 #if defined(OS_MACOSX) |
| 365 if (content::RenderWidgetHostView* rwhv = | 381 if (content::RenderWidgetHostView* rwhv = |
| (...skipping 10 matching lines...) Expand all Loading... |
| 376 TabContents* new_tc) { | 392 TabContents* new_tc) { |
| 377 DCHECK(old_tc == preview_contents_); | 393 DCHECK(old_tc == preview_contents_); |
| 378 CleanupPreviewContents(); | 394 CleanupPreviewContents(); |
| 379 // We release here without deleting so that the caller still has the | 395 // We release here without deleting so that the caller still has the |
| 380 // responsibility for deleting the TabContents. | 396 // responsibility for deleting the TabContents. |
| 381 ignore_result(preview_contents_.release()); | 397 ignore_result(preview_contents_.release()); |
| 382 preview_contents_.reset(new_tc); | 398 preview_contents_.reset(new_tc); |
| 383 SetupPreviewContents(); | 399 SetupPreviewContents(); |
| 384 loader_delegate_->SwappedTabContents(this); | 400 loader_delegate_->SwappedTabContents(this); |
| 385 } | 401 } |
| OLD | NEW |