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