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 <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 680 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
691 url_ = url; | 691 url_ = url; |
692 user_text_ = new_user_text; | 692 user_text_ = new_user_text; |
693 verbatim_ = verbatim; | 693 verbatim_ = verbatim; |
694 last_suggestion_.clear(); | 694 last_suggestion_.clear(); |
695 needs_reload_ = false; | 695 needs_reload_ = false; |
696 | 696 |
697 bool created_preview_contents = preview_contents_.get() == NULL; | 697 bool created_preview_contents = preview_contents_.get() == NULL; |
698 if (created_preview_contents) | 698 if (created_preview_contents) |
699 CreatePreviewContents(tab_contents); | 699 CreatePreviewContents(tab_contents); |
700 | 700 |
| 701 // Carry over the user agent override setting to the new entry. |
| 702 content::NavigationEntry* entry = |
| 703 tab_contents->web_contents()->GetController().GetActiveEntry(); |
| 704 bool override_user_agent = entry && entry->GetIsOverridingUserAgent(); |
| 705 |
701 if (template_url) { | 706 if (template_url) { |
702 DCHECK(template_url_id_ == template_url->id()); | 707 DCHECK(template_url_id_ == template_url->id()); |
703 if (!created_preview_contents) { | 708 if (!created_preview_contents) { |
704 if (is_determining_if_page_supports_instant()) { | 709 if (is_determining_if_page_supports_instant()) { |
705 // The page hasn't loaded yet. Note it, but send down the text anyway. | 710 // The page hasn't loaded yet. Note it, but send down the text anyway. |
706 frame_load_observer_->set_text(user_text_); | 711 frame_load_observer_->set_text(user_text_); |
707 frame_load_observer_->set_verbatim(verbatim); | 712 frame_load_observer_->set_verbatim(verbatim); |
708 preview_tab_contents_delegate_->set_user_typed_before_load(); | 713 preview_tab_contents_delegate_->set_user_typed_before_load(); |
709 } | 714 } |
710 // TODO: support real cursor position. | 715 // TODO: support real cursor position. |
(...skipping 11 matching lines...) Expand all Loading... |
722 complete_suggested_text_); | 727 complete_suggested_text_); |
723 string16 user_text_lower = base::i18n::ToLower(user_text_); | 728 string16 user_text_lower = base::i18n::ToLower(user_text_); |
724 if (!verbatim && | 729 if (!verbatim && |
725 complete_suggested_text_lower.size() > user_text_lower.size() && | 730 complete_suggested_text_lower.size() > user_text_lower.size() && |
726 !complete_suggested_text_lower.compare(0, user_text_lower.size(), | 731 !complete_suggested_text_lower.compare(0, user_text_lower.size(), |
727 user_text_lower)) { | 732 user_text_lower)) { |
728 *suggested_text = last_suggestion_ = | 733 *suggested_text = last_suggestion_ = |
729 complete_suggested_text_.substr(user_text_.size()); | 734 complete_suggested_text_.substr(user_text_.size()); |
730 } | 735 } |
731 } else { | 736 } else { |
732 LoadInstantURL(template_url, transition_type, user_text_, verbatim); | 737 LoadInstantURL(template_url, transition_type, user_text_, verbatim, |
| 738 override_user_agent); |
733 } | 739 } |
734 } else { | 740 } else { |
735 DCHECK(template_url_id_ == 0); | 741 DCHECK(template_url_id_ == 0); |
736 preview_tab_contents_delegate_->PrepareForNewLoad(); | 742 preview_tab_contents_delegate_->PrepareForNewLoad(); |
737 frame_load_observer_.reset(NULL); | 743 frame_load_observer_.reset(NULL); |
738 preview_contents_->web_contents()->GetController().LoadURL( | 744 |
739 url_, content::Referrer(), transition_type, std::string()); | 745 preview_contents_->web_contents()->GetController(). |
| 746 LoadURLWithUserAgentOverride(url_, content::Referrer(), transition_type, |
| 747 false, std::string(), override_user_agent); |
740 } | 748 } |
741 return true; | 749 return true; |
742 } | 750 } |
743 | 751 |
744 void InstantLoader::SetOmniboxBounds(const gfx::Rect& bounds) { | 752 void InstantLoader::SetOmniboxBounds(const gfx::Rect& bounds) { |
745 if (omnibox_bounds_ == bounds) | 753 if (omnibox_bounds_ == bounds) |
746 return; | 754 return; |
747 | 755 |
748 // Don't update the page while the mouse is down. http://crbug.com/71952 | 756 // Don't update the page while the mouse is down. http://crbug.com/71952 |
749 if (IsMouseDownFromActivate()) | 757 if (IsMouseDownFromActivate()) |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
853 void InstantLoader::MaybeLoadInstantURL(TabContents* tab_contents, | 861 void InstantLoader::MaybeLoadInstantURL(TabContents* tab_contents, |
854 const TemplateURL* template_url) { | 862 const TemplateURL* template_url) { |
855 DCHECK(template_url_id_ == template_url->id()); | 863 DCHECK(template_url_id_ == template_url->id()); |
856 | 864 |
857 // If we already have a |preview_contents_|, future search queries will be | 865 // If we already have a |preview_contents_|, future search queries will be |
858 // issued into it (see the "if (!created_preview_contents)" block in |Update| | 866 // issued into it (see the "if (!created_preview_contents)" block in |Update| |
859 // above), so there is no need to load the |template_url|'s instant URL. | 867 // above), so there is no need to load the |template_url|'s instant URL. |
860 if (preview_contents_.get()) | 868 if (preview_contents_.get()) |
861 return; | 869 return; |
862 | 870 |
| 871 // Carry over the user agent override setting to the new entry. |
| 872 content::NavigationEntry* entry = |
| 873 tab_contents->web_contents()->GetController().GetActiveEntry(); |
| 874 bool override_user_agent = entry && entry->GetIsOverridingUserAgent(); |
| 875 |
863 CreatePreviewContents(tab_contents); | 876 CreatePreviewContents(tab_contents); |
864 LoadInstantURL(template_url, content::PAGE_TRANSITION_GENERATED, string16(), | 877 LoadInstantURL(template_url, content::PAGE_TRANSITION_GENERATED, string16(), |
865 true); | 878 true, override_user_agent); |
866 } | 879 } |
867 | 880 |
868 bool InstantLoader::IsNavigationPending() const { | 881 bool InstantLoader::IsNavigationPending() const { |
869 return preview_contents_.get() && | 882 return preview_contents_.get() && |
870 preview_contents_->web_contents()->GetController().GetPendingEntry(); | 883 preview_contents_->web_contents()->GetController().GetPendingEntry(); |
871 } | 884 } |
872 | 885 |
873 void InstantLoader::Observe(int type, | 886 void InstantLoader::Observe(int type, |
874 const content::NotificationSource& source, | 887 const content::NotificationSource& source, |
875 const content::NotificationDetails& details) { | 888 const content::NotificationDetails& details) { |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1100 | 1113 |
1101 registrar_.Add( | 1114 registrar_.Add( |
1102 this, | 1115 this, |
1103 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 1116 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
1104 content::Source<NavigationController>( | 1117 content::Source<NavigationController>( |
1105 &preview_contents_->web_contents()->GetController())); | 1118 &preview_contents_->web_contents()->GetController())); |
1106 | 1119 |
1107 gfx::Rect tab_bounds; | 1120 gfx::Rect tab_bounds; |
1108 tab_contents->web_contents()->GetView()->GetContainerBounds(&tab_bounds); | 1121 tab_contents->web_contents()->GetView()->GetContainerBounds(&tab_bounds); |
1109 preview_contents_->web_contents()->GetView()->SizeContents(tab_bounds.size()); | 1122 preview_contents_->web_contents()->GetView()->SizeContents(tab_bounds.size()); |
| 1123 |
| 1124 // Carry over the user agent override string. |
| 1125 const std::string& override = |
| 1126 tab_contents->web_contents()->GetUserAgentOverride(); |
| 1127 preview_contents_->web_contents()->SetUserAgentOverride(override); |
1110 } | 1128 } |
1111 | 1129 |
1112 void InstantLoader::CreatePreviewContents(TabContents* tab_contents) { | 1130 void InstantLoader::CreatePreviewContents(TabContents* tab_contents) { |
1113 WebContents* new_contents = WebContents::Create( | 1131 WebContents* new_contents = WebContents::Create( |
1114 tab_contents->profile(), NULL, MSG_ROUTING_NONE, NULL, NULL); | 1132 tab_contents->profile(), NULL, MSG_ROUTING_NONE, NULL, NULL); |
1115 preview_contents_.reset(new TabContents(new_contents)); | 1133 preview_contents_.reset(new TabContents(new_contents)); |
1116 AddPreviewUsageForHistogram(template_url_id_, PREVIEW_CREATED, group_); | 1134 AddPreviewUsageForHistogram(template_url_id_, PREVIEW_CREATED, group_); |
1117 session_storage_namespace_ = GetSessionStorageNamespace(tab_contents); | 1135 session_storage_namespace_ = GetSessionStorageNamespace(tab_contents); |
1118 preview_tab_contents_delegate_.reset(new TabContentsDelegateImpl(this)); | 1136 preview_tab_contents_delegate_.reset(new TabContentsDelegateImpl(this)); |
1119 SetupPreviewContents(tab_contents); | 1137 SetupPreviewContents(tab_contents); |
1120 | 1138 |
1121 preview_contents_->web_contents()->ShowContents(); | 1139 preview_contents_->web_contents()->ShowContents(); |
1122 } | 1140 } |
1123 | 1141 |
1124 void InstantLoader::LoadInstantURL(const TemplateURL* template_url, | 1142 void InstantLoader::LoadInstantURL(const TemplateURL* template_url, |
1125 content::PageTransition transition_type, | 1143 content::PageTransition transition_type, |
1126 const string16& user_text, | 1144 const string16& user_text, |
1127 bool verbatim) { | 1145 bool verbatim, |
| 1146 bool override_user_agent) { |
1128 preview_tab_contents_delegate_->PrepareForNewLoad(); | 1147 preview_tab_contents_delegate_->PrepareForNewLoad(); |
1129 | 1148 |
1130 // Load the instant URL. We don't reflect the url we load in url() as | 1149 // Load the instant URL. We don't reflect the url we load in url() as |
1131 // callers expect that we're loading the URL they tell us to. | 1150 // callers expect that we're loading the URL they tell us to. |
1132 // | 1151 // |
1133 // This uses an empty string for the replacement text as the url doesn't | 1152 // This uses an empty string for the replacement text as the url doesn't |
1134 // really have the search params, but we need to use the replace | 1153 // really have the search params, but we need to use the replace |
1135 // functionality so that embeded tags (like {google:baseURL}) are escaped | 1154 // functionality so that embeded tags (like {google:baseURL}) are escaped |
1136 // correctly. | 1155 // correctly. |
1137 // TODO(sky): having to use a replaceable url is a bit of a hack here. | 1156 // TODO(sky): having to use a replaceable url is a bit of a hack here. |
1138 GURL instant_url(template_url->instant_url_ref().ReplaceSearchTerms( | 1157 GURL instant_url(template_url->instant_url_ref().ReplaceSearchTerms( |
1139 string16(), TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); | 1158 string16(), TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); |
1140 CommandLine* cl = CommandLine::ForCurrentProcess(); | 1159 CommandLine* cl = CommandLine::ForCurrentProcess(); |
1141 if (cl->HasSwitch(switches::kInstantURL)) | 1160 if (cl->HasSwitch(switches::kInstantURL)) |
1142 instant_url = GURL(cl->GetSwitchValueASCII(switches::kInstantURL)); | 1161 instant_url = GURL(cl->GetSwitchValueASCII(switches::kInstantURL)); |
1143 preview_contents_->web_contents()->GetController().LoadURL( | 1162 |
1144 instant_url, content::Referrer(), transition_type, std::string()); | 1163 preview_contents_->web_contents()->GetController(). |
| 1164 LoadURLWithUserAgentOverride(instant_url, content::Referrer(), |
| 1165 transition_type, false, std::string(), override_user_agent); |
| 1166 |
1145 RenderViewHost* host = preview_contents_->web_contents()->GetRenderViewHost(); | 1167 RenderViewHost* host = preview_contents_->web_contents()->GetRenderViewHost(); |
1146 preview_contents_->web_contents()->HideContents(); | 1168 preview_contents_->web_contents()->HideContents(); |
1147 | 1169 |
1148 // If user_text is empty, this must be a preload of the search homepage. In | 1170 // If user_text is empty, this must be a preload of the search homepage. In |
1149 // that case, send down a SearchBoxResize message, which will switch the page | 1171 // that case, send down a SearchBoxResize message, which will switch the page |
1150 // to "search results" UI. This avoids flicker when the page is shown with | 1172 // to "search results" UI. This avoids flicker when the page is shown with |
1151 // results. In addition, we don't want the page accidentally causing the | 1173 // results. In addition, we don't want the page accidentally causing the |
1152 // preloaded page to be displayed yet (by calling setSuggestions), so don't | 1174 // preloaded page to be displayed yet (by calling setSuggestions), so don't |
1153 // send a SearchBoxChange message. | 1175 // send a SearchBoxChange message. |
1154 if (user_text.empty()) { | 1176 if (user_text.empty()) { |
1155 host->Send(new ChromeViewMsg_SearchBoxResize( | 1177 host->Send(new ChromeViewMsg_SearchBoxResize( |
1156 host->GetRoutingID(), GetOmniboxBoundsInTermsOfPreview())); | 1178 host->GetRoutingID(), GetOmniboxBoundsInTermsOfPreview())); |
1157 } else { | 1179 } else { |
1158 host->Send(new ChromeViewMsg_SearchBoxChange( | 1180 host->Send(new ChromeViewMsg_SearchBoxChange( |
1159 host->GetRoutingID(), user_text, verbatim, 0, 0)); | 1181 host->GetRoutingID(), user_text, verbatim, 0, 0)); |
1160 } | 1182 } |
1161 | 1183 |
1162 frame_load_observer_.reset(new FrameLoadObserver( | 1184 frame_load_observer_.reset(new FrameLoadObserver( |
1163 this, preview_contents()->web_contents(), user_text, verbatim)); | 1185 this, preview_contents()->web_contents(), user_text, verbatim)); |
1164 } | 1186 } |
OLD | NEW |