| 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/instant/instant_loader_delegate.h" | 8 #include "chrome/browser/instant/instant_loader_delegate.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/thumbnails/thumbnail_tab_helper.h" | 10 #include "chrome/browser/thumbnails/thumbnail_tab_helper.h" |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 const GURL& validated_url, | 83 const GURL& validated_url, |
| 84 bool is_main_frame, | 84 bool is_main_frame, |
| 85 content::RenderViewHost* render_view_host) OVERRIDE; | 85 content::RenderViewHost* render_view_host) OVERRIDE; |
| 86 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 86 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 87 | 87 |
| 88 private: | 88 private: |
| 89 // Message from renderer indicating the page has suggestions. | 89 // Message from renderer indicating the page has suggestions. |
| 90 void OnSetSuggestions(int page_id, | 90 void OnSetSuggestions(int page_id, |
| 91 const std::vector<InstantSuggestion>& suggestions); | 91 const std::vector<InstantSuggestion>& suggestions); |
| 92 | 92 |
| 93 // Message from renderer indicating whether the page has a custom logo to |
| 94 // display on the NTP. |
| 95 void OnSetHasCustomLogo(int page_id, bool has_logo); |
| 96 |
| 93 // Message from the renderer determining whether it supports the Instant API. | 97 // Message from the renderer determining whether it supports the Instant API. |
| 94 void OnInstantSupportDetermined(int page_id, bool result); | 98 void OnInstantSupportDetermined(int page_id, bool result); |
| 95 | 99 |
| 96 // Message from the renderer requesting the preview be resized. | 100 // Message from the renderer requesting the preview be resized. |
| 97 void OnSetInstantPreviewHeight(int page_id, | 101 void OnSetInstantPreviewHeight(int page_id, |
| 98 int height, | 102 int height, |
| 99 InstantSizeUnits units); | 103 InstantSizeUnits units); |
| 100 | 104 |
| 101 void CommitFromPointerReleaseIfNecessary(); | 105 void CommitFromPointerReleaseIfNecessary(); |
| 102 void MaybeSetAndNotifyInstantSupportDetermined(bool supports_instant); | 106 void MaybeSetAndNotifyInstantSupportDetermined(bool supports_instant); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 Send(new ChromeViewMsg_DetermineIfPageSupportsInstant(routing_id())); | 197 Send(new ChromeViewMsg_DetermineIfPageSupportsInstant(routing_id())); |
| 194 loader_->loader_delegate_->InstantLoaderPreviewLoaded(loader_); | 198 loader_->loader_delegate_->InstantLoaderPreviewLoaded(loader_); |
| 195 } | 199 } |
| 196 } | 200 } |
| 197 | 201 |
| 198 bool InstantLoader::WebContentsDelegateImpl::OnMessageReceived( | 202 bool InstantLoader::WebContentsDelegateImpl::OnMessageReceived( |
| 199 const IPC::Message& message) { | 203 const IPC::Message& message) { |
| 200 bool handled = true; | 204 bool handled = true; |
| 201 IPC_BEGIN_MESSAGE_MAP(WebContentsDelegateImpl, message) | 205 IPC_BEGIN_MESSAGE_MAP(WebContentsDelegateImpl, message) |
| 202 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SetSuggestions, OnSetSuggestions) | 206 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SetSuggestions, OnSetSuggestions) |
| 207 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SetHasCustomLogo, |
| 208 OnSetHasCustomLogo); |
| 203 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_InstantSupportDetermined, | 209 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_InstantSupportDetermined, |
| 204 OnInstantSupportDetermined) | 210 OnInstantSupportDetermined) |
| 205 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SetInstantPreviewHeight, | 211 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SetInstantPreviewHeight, |
| 206 OnSetInstantPreviewHeight); | 212 OnSetInstantPreviewHeight); |
| 207 IPC_MESSAGE_UNHANDLED(handled = false) | 213 IPC_MESSAGE_UNHANDLED(handled = false) |
| 208 IPC_END_MESSAGE_MAP() | 214 IPC_END_MESSAGE_MAP() |
| 209 return handled; | 215 return handled; |
| 210 } | 216 } |
| 211 | 217 |
| 212 void InstantLoader::WebContentsDelegateImpl::OnSetSuggestions( | 218 void InstantLoader::WebContentsDelegateImpl::OnSetSuggestions( |
| 213 int page_id, | 219 int page_id, |
| 214 const std::vector<InstantSuggestion>& suggestions) { | 220 const std::vector<InstantSuggestion>& suggestions) { |
| 215 DCHECK(loader_->preview_contents()); | 221 DCHECK(loader_->preview_contents()); |
| 216 DCHECK(loader_->preview_contents_->web_contents()); | 222 DCHECK(loader_->preview_contents_->web_contents()); |
| 217 content::NavigationEntry* entry = loader_->preview_contents_->web_contents()-> | 223 content::NavigationEntry* entry = loader_->preview_contents_->web_contents()-> |
| 218 GetController().GetActiveEntry(); | 224 GetController().GetActiveEntry(); |
| 219 if (entry && page_id == entry->GetPageID()) { | 225 if (entry && page_id == entry->GetPageID()) { |
| 220 MaybeSetAndNotifyInstantSupportDetermined(true); | 226 MaybeSetAndNotifyInstantSupportDetermined(true); |
| 221 loader_->loader_delegate_->SetSuggestions(loader_, suggestions); | 227 loader_->loader_delegate_->SetSuggestions(loader_, suggestions); |
| 222 } | 228 } |
| 223 } | 229 } |
| 224 | 230 |
| 231 // Message from renderer indicating whether the page has a custom logo to |
| 232 // display on the NTP. |
| 233 void InstantLoader::WebContentsDelegateImpl::OnSetHasCustomLogo( |
| 234 int page_id, |
| 235 bool has_logo) { |
| 236 DCHECK(loader_->preview_contents()); |
| 237 DCHECK(loader_->preview_contents_->web_contents()); |
| 238 content::NavigationEntry* entry = loader_->preview_contents_->web_contents()-> |
| 239 GetController().GetActiveEntry(); |
| 240 if (entry && page_id == entry->GetPageID()) { |
| 241 MaybeSetAndNotifyInstantSupportDetermined(true); |
| 242 loader_->loader_delegate_->SetHasCustomLogo(loader_, has_logo); |
| 243 } |
| 244 } |
| 245 |
| 225 void InstantLoader::WebContentsDelegateImpl::OnInstantSupportDetermined( | 246 void InstantLoader::WebContentsDelegateImpl::OnInstantSupportDetermined( |
| 226 int page_id, | 247 int page_id, |
| 227 bool result) { | 248 bool result) { |
| 228 DCHECK(loader_->preview_contents()); | 249 DCHECK(loader_->preview_contents()); |
| 229 DCHECK(loader_->preview_contents_->web_contents()); | 250 DCHECK(loader_->preview_contents_->web_contents()); |
| 230 content::NavigationEntry* entry = loader_->preview_contents_->web_contents()-> | 251 content::NavigationEntry* entry = loader_->preview_contents_->web_contents()-> |
| 231 GetController().GetActiveEntry(); | 252 GetController().GetActiveEntry(); |
| 232 if (entry && page_id == entry->GetPageID()) | 253 if (entry && page_id == entry->GetPageID()) |
| 233 MaybeSetAndNotifyInstantSupportDetermined(result); | 254 MaybeSetAndNotifyInstantSupportDetermined(result); |
| 234 } | 255 } |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 content::WebContents* new_contents) { | 483 content::WebContents* new_contents) { |
| 463 DCHECK_EQ(old_contents, preview_contents_->web_contents()); | 484 DCHECK_EQ(old_contents, preview_contents_->web_contents()); |
| 464 CleanupPreviewContents(); | 485 CleanupPreviewContents(); |
| 465 // We release here without deleting so that the caller still has the | 486 // We release here without deleting so that the caller still has the |
| 466 // responsibility for deleting the TabContents. | 487 // responsibility for deleting the TabContents. |
| 467 ignore_result(preview_contents_.release()); | 488 ignore_result(preview_contents_.release()); |
| 468 preview_contents_.reset(TabContents::FromWebContents(new_contents)); | 489 preview_contents_.reset(TabContents::FromWebContents(new_contents)); |
| 469 SetupPreviewContents(); | 490 SetupPreviewContents(); |
| 470 loader_delegate_->SwappedTabContents(this); | 491 loader_delegate_->SwappedTabContents(this); |
| 471 } | 492 } |
| OLD | NEW |