Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(296)

Side by Side Diff: chrome/browser/instant/instant_loader.cc

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

Powered by Google App Engine
This is Rietveld 408576698