OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/i18n/case_conversion.h" | 13 #include "base/i18n/case_conversion.h" |
14 #include "base/string_number_conversions.h" | 14 #include "base/string_number_conversions.h" |
15 #include "base/timer.h" | 15 #include "base/timer.h" |
16 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
17 #include "base/values.h" | 17 #include "base/values.h" |
18 #include "chrome/browser/favicon/favicon_service.h" | 18 #include "chrome/browser/favicon/favicon_service.h" |
19 #include "chrome/browser/history/history_marshaling.h" | 19 #include "chrome/browser/history/history_marshaling.h" |
20 #include "chrome/browser/history/history_tab_helper.h" | 20 #include "chrome/browser/history/history_tab_helper.h" |
21 #include "chrome/browser/instant/instant_loader_delegate.h" | 21 #include "chrome/browser/instant/instant_loader_delegate.h" |
22 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
23 #include "chrome/browser/search_engines/template_url.h" | 23 #include "chrome/browser/search_engines/template_url.h" |
24 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" | 24 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" |
25 #include "chrome/browser/ui/download/download_tab_helper.h" | |
26 #include "chrome/browser/ui/download/download_tab_helper_delegate.h" | |
27 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 25 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
28 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper_delegate.h" | 26 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper_delegate.h" |
29 #include "chrome/common/chrome_notification_types.h" | 27 #include "chrome/common/chrome_notification_types.h" |
30 #include "chrome/common/chrome_switches.h" | 28 #include "chrome/common/chrome_switches.h" |
31 #include "chrome/common/render_messages.h" | 29 #include "chrome/common/render_messages.h" |
32 #include "content/browser/renderer_host/render_view_host.h" | 30 #include "content/browser/renderer_host/render_view_host.h" |
33 #include "content/browser/renderer_host/render_widget_host.h" | 31 #include "content/browser/renderer_host/render_widget_host.h" |
34 #include "content/browser/renderer_host/render_widget_host_view.h" | 32 #include "content/browser/renderer_host/render_widget_host_view.h" |
35 #include "content/browser/tab_contents/navigation_details.h" | 33 #include "content/browser/tab_contents/navigation_details.h" |
36 #include "content/browser/tab_contents/navigation_entry.h" | 34 #include "content/browser/tab_contents/navigation_entry.h" |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 break; | 139 break; |
142 } | 140 } |
143 } | 141 } |
144 | 142 |
145 // TabContentsDelegateImpl ----------------------------------------------------- | 143 // TabContentsDelegateImpl ----------------------------------------------------- |
146 | 144 |
147 class InstantLoader::TabContentsDelegateImpl | 145 class InstantLoader::TabContentsDelegateImpl |
148 : public TabContentsDelegate, | 146 : public TabContentsDelegate, |
149 public TabContentsWrapperDelegate, | 147 public TabContentsWrapperDelegate, |
150 public NotificationObserver, | 148 public NotificationObserver, |
151 public TabContentsObserver, | 149 public TabContentsObserver { |
152 public DownloadTabHelperDelegate { | |
153 public: | 150 public: |
154 explicit TabContentsDelegateImpl(InstantLoader* loader); | 151 explicit TabContentsDelegateImpl(InstantLoader* loader); |
155 | 152 |
156 // Invoked prior to loading a new URL. | 153 // Invoked prior to loading a new URL. |
157 void PrepareForNewLoad(); | 154 void PrepareForNewLoad(); |
158 | 155 |
159 // Invoked when the preview paints. Invokes PreviewPainted on the loader. | 156 // Invoked when the preview paints. Invokes PreviewPainted on the loader. |
160 void PreviewPainted(); | 157 void PreviewPainted(); |
161 | 158 |
162 bool is_mouse_down_from_activate() const { | 159 bool is_mouse_down_from_activate() const { |
(...skipping 28 matching lines...) Expand all Loading... |
191 virtual void BeforeUnloadFired(TabContents* tab, | 188 virtual void BeforeUnloadFired(TabContents* tab, |
192 bool proceed, | 189 bool proceed, |
193 bool* proceed_to_fire_unload) OVERRIDE; | 190 bool* proceed_to_fire_unload) OVERRIDE; |
194 virtual void SetFocusToLocationBar(bool select_all) OVERRIDE; | 191 virtual void SetFocusToLocationBar(bool select_all) OVERRIDE; |
195 virtual bool ShouldFocusPageAfterCrash() OVERRIDE; | 192 virtual bool ShouldFocusPageAfterCrash() OVERRIDE; |
196 virtual void LostCapture() OVERRIDE; | 193 virtual void LostCapture() OVERRIDE; |
197 // If the user drags, we won't get a mouse up (at least on Linux). Commit the | 194 // If the user drags, we won't get a mouse up (at least on Linux). Commit the |
198 // instant result when the drag ends, so that during the drag the page won't | 195 // instant result when the drag ends, so that during the drag the page won't |
199 // move around. | 196 // move around. |
200 virtual void DragEnded() OVERRIDE; | 197 virtual void DragEnded() OVERRIDE; |
| 198 virtual bool CanDownload(int request_id) OVERRIDE; |
201 virtual void HandleMouseUp() OVERRIDE; | 199 virtual void HandleMouseUp() OVERRIDE; |
202 virtual void HandleMouseActivate() OVERRIDE; | 200 virtual void HandleMouseActivate() OVERRIDE; |
203 virtual bool OnGoToEntryOffset(int offset) OVERRIDE; | 201 virtual bool OnGoToEntryOffset(int offset) OVERRIDE; |
204 virtual bool ShouldAddNavigationToHistory( | 202 virtual bool ShouldAddNavigationToHistory( |
205 const history::HistoryAddPageArgs& add_page_args, | 203 const history::HistoryAddPageArgs& add_page_args, |
206 NavigationType::Type navigation_type) OVERRIDE; | 204 NavigationType::Type navigation_type) OVERRIDE; |
207 | 205 |
208 // TabContentsWrapperDelegate: | 206 // TabContentsWrapperDelegate: |
209 virtual void SwapTabContents(TabContentsWrapper* old_tc, | 207 virtual void SwapTabContents(TabContentsWrapper* old_tc, |
210 TabContentsWrapper* new_tc) OVERRIDE; | 208 TabContentsWrapper* new_tc) OVERRIDE; |
211 | 209 |
212 // TabContentsObserver: | 210 // TabContentsObserver: |
213 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 211 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
214 | 212 |
215 // DownloadTabHelperDelegate: | |
216 virtual bool CanDownload(int request_id) OVERRIDE; | |
217 virtual void OnStartDownload(DownloadItem* download, | |
218 TabContentsWrapper* tab) OVERRIDE; | |
219 | |
220 private: | 213 private: |
221 typedef std::vector<scoped_refptr<history::HistoryAddPageArgs> > | 214 typedef std::vector<scoped_refptr<history::HistoryAddPageArgs> > |
222 AddPageVector; | 215 AddPageVector; |
223 | 216 |
224 // Message from renderer indicating the page has suggestions. | 217 // Message from renderer indicating the page has suggestions. |
225 void OnSetSuggestions( | 218 void OnSetSuggestions( |
226 int32 page_id, | 219 int32 page_id, |
227 const std::vector<std::string>& suggestions, | 220 const std::vector<std::string>& suggestions, |
228 InstantCompleteBehavior behavior); | 221 InstantCompleteBehavior behavior); |
229 | 222 |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 } | 457 } |
465 | 458 |
466 void InstantLoader::TabContentsDelegateImpl::LostCapture() { | 459 void InstantLoader::TabContentsDelegateImpl::LostCapture() { |
467 CommitFromMouseReleaseIfNecessary(); | 460 CommitFromMouseReleaseIfNecessary(); |
468 } | 461 } |
469 | 462 |
470 void InstantLoader::TabContentsDelegateImpl::DragEnded() { | 463 void InstantLoader::TabContentsDelegateImpl::DragEnded() { |
471 CommitFromMouseReleaseIfNecessary(); | 464 CommitFromMouseReleaseIfNecessary(); |
472 } | 465 } |
473 | 466 |
| 467 bool InstantLoader::TabContentsDelegateImpl::CanDownload(int request_id) { |
| 468 // Downloads are disabled. |
| 469 return false; |
| 470 } |
| 471 |
474 void InstantLoader::TabContentsDelegateImpl::HandleMouseUp() { | 472 void InstantLoader::TabContentsDelegateImpl::HandleMouseUp() { |
475 CommitFromMouseReleaseIfNecessary(); | 473 CommitFromMouseReleaseIfNecessary(); |
476 } | 474 } |
477 | 475 |
478 void InstantLoader::TabContentsDelegateImpl::HandleMouseActivate() { | 476 void InstantLoader::TabContentsDelegateImpl::HandleMouseActivate() { |
479 is_mouse_down_from_activate_ = true; | 477 is_mouse_down_from_activate_ = true; |
480 } | 478 } |
481 | 479 |
482 bool InstantLoader::TabContentsDelegateImpl::OnGoToEntryOffset(int offset) { | 480 bool InstantLoader::TabContentsDelegateImpl::OnGoToEntryOffset(int offset) { |
483 return false; | 481 return false; |
(...skipping 26 matching lines...) Expand all Loading... |
510 bool handled = true; | 508 bool handled = true; |
511 IPC_BEGIN_MESSAGE_MAP(TabContentsDelegateImpl, message) | 509 IPC_BEGIN_MESSAGE_MAP(TabContentsDelegateImpl, message) |
512 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSuggestions, OnSetSuggestions) | 510 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSuggestions, OnSetSuggestions) |
513 IPC_MESSAGE_HANDLER(ViewHostMsg_InstantSupportDetermined, | 511 IPC_MESSAGE_HANDLER(ViewHostMsg_InstantSupportDetermined, |
514 OnInstantSupportDetermined) | 512 OnInstantSupportDetermined) |
515 IPC_MESSAGE_UNHANDLED(handled = false) | 513 IPC_MESSAGE_UNHANDLED(handled = false) |
516 IPC_END_MESSAGE_MAP() | 514 IPC_END_MESSAGE_MAP() |
517 return handled; | 515 return handled; |
518 } | 516 } |
519 | 517 |
520 bool InstantLoader::TabContentsDelegateImpl::CanDownload(int request_id) { | |
521 // Downloads are disabled. | |
522 return false; | |
523 } | |
524 | |
525 void InstantLoader::TabContentsDelegateImpl::OnStartDownload( | |
526 DownloadItem* download, TabContentsWrapper* tab) { | |
527 // Downloads are disabled. | |
528 } | |
529 | |
530 void InstantLoader::TabContentsDelegateImpl::OnSetSuggestions( | 518 void InstantLoader::TabContentsDelegateImpl::OnSetSuggestions( |
531 int32 page_id, | 519 int32 page_id, |
532 const std::vector<std::string>& suggestions, | 520 const std::vector<std::string>& suggestions, |
533 InstantCompleteBehavior behavior) { | 521 InstantCompleteBehavior behavior) { |
534 TabContentsWrapper* source = loader_->preview_contents(); | 522 TabContentsWrapper* source = loader_->preview_contents(); |
535 if (!source->controller().GetActiveEntry() || | 523 if (!source->controller().GetActiveEntry() || |
536 page_id != source->controller().GetActiveEntry()->page_id()) | 524 page_id != source->controller().GetActiveEntry()->page_id()) |
537 return; | 525 return; |
538 | 526 |
539 if (suggestions.empty()) | 527 if (suggestions.empty()) |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
746 #if defined(OS_MACOSX) | 734 #if defined(OS_MACOSX) |
747 preview_contents_->tab_contents()->GetRenderWidgetHostView()-> | 735 preview_contents_->tab_contents()->GetRenderWidgetHostView()-> |
748 SetTakesFocusOnlyOnMouseDown(false); | 736 SetTakesFocusOnlyOnMouseDown(false); |
749 registrar_.Remove( | 737 registrar_.Remove( |
750 this, | 738 this, |
751 content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, | 739 content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, |
752 Source<NavigationController>(&preview_contents_->controller())); | 740 Source<NavigationController>(&preview_contents_->controller())); |
753 #endif | 741 #endif |
754 } | 742 } |
755 preview_contents_->tab_contents()->set_delegate(NULL); | 743 preview_contents_->tab_contents()->set_delegate(NULL); |
756 preview_contents_->download_tab_helper()->set_delegate(NULL); | |
757 ready_ = false; | 744 ready_ = false; |
758 } | 745 } |
759 update_bounds_timer_.Stop(); | 746 update_bounds_timer_.Stop(); |
760 return preview_contents_.release(); | 747 return preview_contents_.release(); |
761 } | 748 } |
762 | 749 |
763 bool InstantLoader::ShouldCommitInstantOnMouseUp() { | 750 bool InstantLoader::ShouldCommitInstantOnMouseUp() { |
764 return delegate_->ShouldCommitInstantOnMouseUp(); | 751 return delegate_->ShouldCommitInstantOnMouseUp(); |
765 } | 752 } |
766 | 753 |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
942 DCHECK(old_tc == preview_contents_); | 929 DCHECK(old_tc == preview_contents_); |
943 // We release here without deleting so that the caller still has reponsibility | 930 // We release here without deleting so that the caller still has reponsibility |
944 // for deleting the TabContentsWrapper. | 931 // for deleting the TabContentsWrapper. |
945 ignore_result(preview_contents_.release()); | 932 ignore_result(preview_contents_.release()); |
946 preview_contents_.reset(new_tc); | 933 preview_contents_.reset(new_tc); |
947 | 934 |
948 // Make sure the new preview contents acts like the old one. | 935 // Make sure the new preview contents acts like the old one. |
949 SetupPreviewContents(old_tc); | 936 SetupPreviewContents(old_tc); |
950 | 937 |
951 // Cleanup the old preview contents. | 938 // Cleanup the old preview contents. |
952 old_tc->download_tab_helper()->set_delegate(NULL); | |
953 old_tc->tab_contents()->set_delegate(NULL); | 939 old_tc->tab_contents()->set_delegate(NULL); |
954 old_tc->set_delegate(NULL); | 940 old_tc->set_delegate(NULL); |
955 | 941 |
956 #if defined(OS_MACOSX) | 942 #if defined(OS_MACOSX) |
957 registrar_.Remove(this, | 943 registrar_.Remove(this, |
958 content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, | 944 content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, |
959 Source<NavigationController>(&old_tc->controller())); | 945 Source<NavigationController>(&old_tc->controller())); |
960 #endif | 946 #endif |
961 registrar_.Remove(this, | 947 registrar_.Remove(this, |
962 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 948 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
(...skipping 13 matching lines...) Expand all Loading... |
976 preview_tab_contents_delegate_.get()); | 962 preview_tab_contents_delegate_.get()); |
977 preview_contents_->blocked_content_tab_helper()->SetAllContentsBlocked(true); | 963 preview_contents_->blocked_content_tab_helper()->SetAllContentsBlocked(true); |
978 | 964 |
979 // Propagate the max page id. That way if we end up merging the two | 965 // Propagate the max page id. That way if we end up merging the two |
980 // NavigationControllers (which happens if we commit) none of the page ids | 966 // NavigationControllers (which happens if we commit) none of the page ids |
981 // will overlap. | 967 // will overlap. |
982 int32 max_page_id = tab_contents->tab_contents()->GetMaxPageID(); | 968 int32 max_page_id = tab_contents->tab_contents()->GetMaxPageID(); |
983 if (max_page_id != -1) | 969 if (max_page_id != -1) |
984 preview_contents_->controller().set_max_restored_page_id(max_page_id + 1); | 970 preview_contents_->controller().set_max_restored_page_id(max_page_id + 1); |
985 | 971 |
986 preview_contents_->download_tab_helper()->set_delegate( | |
987 preview_tab_contents_delegate_.get()); | |
988 | |
989 #if defined(OS_MACOSX) | 972 #if defined(OS_MACOSX) |
990 // If |preview_contents_| does not currently have a RWHV, we will call | 973 // If |preview_contents_| does not currently have a RWHV, we will call |
991 // SetTakesFocusOnlyOnMouseDown() as a result of the | 974 // SetTakesFocusOnlyOnMouseDown() as a result of the |
992 // RENDER_VIEW_HOST_CHANGED notification. | 975 // RENDER_VIEW_HOST_CHANGED notification. |
993 if (preview_contents_->tab_contents()->GetRenderWidgetHostView()) { | 976 if (preview_contents_->tab_contents()->GetRenderWidgetHostView()) { |
994 preview_contents_->tab_contents()->GetRenderWidgetHostView()-> | 977 preview_contents_->tab_contents()->GetRenderWidgetHostView()-> |
995 SetTakesFocusOnlyOnMouseDown(true); | 978 SetTakesFocusOnlyOnMouseDown(true); |
996 } | 979 } |
997 registrar_.Add( | 980 registrar_.Add( |
998 this, | 981 this, |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1041 CommandLine* cl = CommandLine::ForCurrentProcess(); | 1024 CommandLine* cl = CommandLine::ForCurrentProcess(); |
1042 if (cl->HasSwitch(switches::kInstantURL)) | 1025 if (cl->HasSwitch(switches::kInstantURL)) |
1043 instant_url = GURL(cl->GetSwitchValueASCII(switches::kInstantURL)); | 1026 instant_url = GURL(cl->GetSwitchValueASCII(switches::kInstantURL)); |
1044 preview_contents_->controller().LoadURL(instant_url, GURL(), transition_type); | 1027 preview_contents_->controller().LoadURL(instant_url, GURL(), transition_type); |
1045 RenderViewHost* host = preview_contents_->render_view_host(); | 1028 RenderViewHost* host = preview_contents_->render_view_host(); |
1046 host->Send(new ViewMsg_SearchBoxChange( | 1029 host->Send(new ViewMsg_SearchBoxChange( |
1047 host->routing_id(), user_text, verbatim, 0, 0)); | 1030 host->routing_id(), user_text, verbatim, 0, 0)); |
1048 frame_load_observer_.reset(new FrameLoadObserver( | 1031 frame_load_observer_.reset(new FrameLoadObserver( |
1049 this, preview_contents()->tab_contents(), user_text, verbatim)); | 1032 this, preview_contents()->tab_contents(), user_text, verbatim)); |
1050 } | 1033 } |
OLD | NEW |