| 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 72 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 73 | 73 |
| 74 private: | 74 private: |
| 75 // Message from renderer indicating the page has suggestions. | 75 // Message from renderer indicating the page has suggestions. |
| 76 void OnSetSuggestions(int page_id, | 76 void OnSetSuggestions(int page_id, |
| 77 const std::vector<InstantSuggestion>& suggestions); | 77 const std::vector<InstantSuggestion>& suggestions); |
| 78 | 78 |
| 79 // Message from the renderer determining whether it supports the Instant API. | 79 // Message from the renderer determining whether it supports the Instant API. |
| 80 void OnInstantSupportDetermined(int page_id, bool result); | 80 void OnInstantSupportDetermined(int page_id, bool result); |
| 81 | 81 |
| 82 // Message from the renderer requesting the preview be resized. |
| 83 void OnSetInstantPreviewHeight(int page_id, |
| 84 int height, |
| 85 InstantSizeUnits units); |
| 86 |
| 82 void CommitFromPointerReleaseIfNecessary(); | 87 void CommitFromPointerReleaseIfNecessary(); |
| 83 void MaybeSetAndNotifyInstantSupportDetermined(bool supports_instant); | 88 void MaybeSetAndNotifyInstantSupportDetermined(bool supports_instant); |
| 84 | 89 |
| 85 InstantLoader* const loader_; | 90 InstantLoader* const loader_; |
| 86 | 91 |
| 87 // True if the mouse or a touch pointer is down from an activate. | 92 // True if the mouse or a touch pointer is down from an activate. |
| 88 bool is_pointer_down_from_activate_; | 93 bool is_pointer_down_from_activate_; |
| 89 | 94 |
| 90 DISALLOW_COPY_AND_ASSIGN(WebContentsDelegateImpl); | 95 DISALLOW_COPY_AND_ASSIGN(WebContentsDelegateImpl); |
| 91 }; | 96 }; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 } | 188 } |
| 184 } | 189 } |
| 185 | 190 |
| 186 bool InstantLoader::WebContentsDelegateImpl::OnMessageReceived( | 191 bool InstantLoader::WebContentsDelegateImpl::OnMessageReceived( |
| 187 const IPC::Message& message) { | 192 const IPC::Message& message) { |
| 188 bool handled = true; | 193 bool handled = true; |
| 189 IPC_BEGIN_MESSAGE_MAP(WebContentsDelegateImpl, message) | 194 IPC_BEGIN_MESSAGE_MAP(WebContentsDelegateImpl, message) |
| 190 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SetSuggestions, OnSetSuggestions) | 195 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SetSuggestions, OnSetSuggestions) |
| 191 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_InstantSupportDetermined, | 196 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_InstantSupportDetermined, |
| 192 OnInstantSupportDetermined) | 197 OnInstantSupportDetermined) |
| 198 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SetInstantPreviewHeight, |
| 199 OnSetInstantPreviewHeight); |
| 193 IPC_MESSAGE_UNHANDLED(handled = false) | 200 IPC_MESSAGE_UNHANDLED(handled = false) |
| 194 IPC_END_MESSAGE_MAP() | 201 IPC_END_MESSAGE_MAP() |
| 195 return handled; | 202 return handled; |
| 196 } | 203 } |
| 197 | 204 |
| 198 void InstantLoader::WebContentsDelegateImpl::OnSetSuggestions( | 205 void InstantLoader::WebContentsDelegateImpl::OnSetSuggestions( |
| 199 int page_id, | 206 int page_id, |
| 200 const std::vector<InstantSuggestion>& suggestions) { | 207 const std::vector<InstantSuggestion>& suggestions) { |
| 201 DCHECK(loader_->preview_contents() && | 208 DCHECK(loader_->preview_contents() && |
| 202 loader_->preview_contents_->web_contents()); | 209 loader_->preview_contents_->web_contents()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 220 // TODO(sreeram): Remove this 'if' bandaid once bug 141875 is confirmed fixed. | 227 // TODO(sreeram): Remove this 'if' bandaid once bug 141875 is confirmed fixed. |
| 221 if (!loader_->preview_contents() || | 228 if (!loader_->preview_contents() || |
| 222 !loader_->preview_contents_->web_contents()) | 229 !loader_->preview_contents_->web_contents()) |
| 223 return; | 230 return; |
| 224 content::NavigationEntry* entry = loader_->preview_contents_->web_contents()-> | 231 content::NavigationEntry* entry = loader_->preview_contents_->web_contents()-> |
| 225 GetController().GetActiveEntry(); | 232 GetController().GetActiveEntry(); |
| 226 if (entry && page_id == entry->GetPageID()) | 233 if (entry && page_id == entry->GetPageID()) |
| 227 MaybeSetAndNotifyInstantSupportDetermined(result); | 234 MaybeSetAndNotifyInstantSupportDetermined(result); |
| 228 } | 235 } |
| 229 | 236 |
| 237 void InstantLoader::WebContentsDelegateImpl::OnSetInstantPreviewHeight( |
| 238 int page_id, |
| 239 int height, |
| 240 InstantSizeUnits units) { |
| 241 DCHECK(loader_->preview_contents() && |
| 242 loader_->preview_contents_->web_contents()); |
| 243 // TODO(sreeram): Remove this 'if' bandaid once bug 141875 is confirmed fixed. |
| 244 if (!loader_->preview_contents() || |
| 245 !loader_->preview_contents_->web_contents()) |
| 246 return; |
| 247 content::NavigationEntry* entry = loader_->preview_contents_->web_contents()-> |
| 248 GetController().GetActiveEntry(); |
| 249 if (entry && page_id == entry->GetPageID()) { |
| 250 MaybeSetAndNotifyInstantSupportDetermined(true); |
| 251 loader_->loader_delegate_->SetInstantPreviewHeight(loader_, height, units); |
| 252 } |
| 253 } |
| 230 | 254 |
| 231 void InstantLoader::WebContentsDelegateImpl | 255 void InstantLoader::WebContentsDelegateImpl |
| 232 ::CommitFromPointerReleaseIfNecessary() { | 256 ::CommitFromPointerReleaseIfNecessary() { |
| 233 if (is_pointer_down_from_activate_) { | 257 if (is_pointer_down_from_activate_) { |
| 234 is_pointer_down_from_activate_ = false; | 258 is_pointer_down_from_activate_ = false; |
| 235 loader_->loader_delegate_->CommitInstantLoader(loader_); | 259 loader_->loader_delegate_->CommitInstantLoader(loader_); |
| 236 } | 260 } |
| 237 } | 261 } |
| 238 | 262 |
| 239 void InstantLoader::WebContentsDelegateImpl | 263 void InstantLoader::WebContentsDelegateImpl |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 TabContents* new_tc) { | 418 TabContents* new_tc) { |
| 395 DCHECK(old_tc == preview_contents_); | 419 DCHECK(old_tc == preview_contents_); |
| 396 CleanupPreviewContents(); | 420 CleanupPreviewContents(); |
| 397 // We release here without deleting so that the caller still has the | 421 // We release here without deleting so that the caller still has the |
| 398 // responsibility for deleting the TabContents. | 422 // responsibility for deleting the TabContents. |
| 399 ignore_result(preview_contents_.release()); | 423 ignore_result(preview_contents_.release()); |
| 400 preview_contents_.reset(new_tc); | 424 preview_contents_.reset(new_tc); |
| 401 SetupPreviewContents(); | 425 SetupPreviewContents(); |
| 402 loader_delegate_->SwappedTabContents(this); | 426 loader_delegate_->SwappedTabContents(this); |
| 403 } | 427 } |
| OLD | NEW |