Chromium Code Reviews| 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> |
| (...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 702 complete_suggested_text_); | 702 complete_suggested_text_); |
| 703 string16 user_text_lower = base::i18n::ToLower(user_text_); | 703 string16 user_text_lower = base::i18n::ToLower(user_text_); |
| 704 if (!verbatim && | 704 if (!verbatim && |
| 705 complete_suggested_text_lower.size() > user_text_lower.size() && | 705 complete_suggested_text_lower.size() > user_text_lower.size() && |
| 706 !complete_suggested_text_lower.compare(0, user_text_lower.size(), | 706 !complete_suggested_text_lower.compare(0, user_text_lower.size(), |
| 707 user_text_lower)) { | 707 user_text_lower)) { |
| 708 *suggested_text = last_suggestion_ = | 708 *suggested_text = last_suggestion_ = |
| 709 complete_suggested_text_.substr(user_text_.size()); | 709 complete_suggested_text_.substr(user_text_.size()); |
| 710 } | 710 } |
| 711 } else { | 711 } else { |
| 712 preview_tab_contents_delegate_->PrepareForNewLoad(); | 712 LoadInstantURL(tab_contents, template_url, transition_type, user_text_, |
| 713 | 713 verbatim); |
| 714 // Load the instant URL. We don't reflect the url we load in url() as | |
| 715 // callers expect that we're loading the URL they tell us to. | |
| 716 // | |
| 717 // This uses an empty string for the replacement text as the url doesn't | |
| 718 // really have the search params, but we need to use the replace | |
| 719 // functionality so that embeded tags (like {google:baseURL}) are escaped | |
| 720 // correctly. | |
| 721 // TODO(sky): having to use a replaceable url is a bit of a hack here. | |
| 722 GURL instant_url( | |
| 723 template_url->instant_url()->ReplaceSearchTerms( | |
| 724 *template_url, string16(), -1, string16())); | |
| 725 CommandLine* cl = CommandLine::ForCurrentProcess(); | |
| 726 if (cl->HasSwitch(switches::kInstantURL)) | |
| 727 instant_url = GURL(cl->GetSwitchValueASCII(switches::kInstantURL)); | |
| 728 preview_contents_->controller().LoadURL( | |
| 729 instant_url, GURL(), transition_type); | |
| 730 RenderViewHost* host = preview_contents_->render_view_host(); | |
| 731 host->Send(new ViewMsg_SearchBoxChange( | |
| 732 host->routing_id(), user_text_, verbatim, 0, 0)); | |
| 733 frame_load_observer_.reset( | |
| 734 new FrameLoadObserver(this, | |
| 735 preview_contents()->tab_contents(), | |
| 736 user_text_, | |
| 737 verbatim)); | |
| 738 } | 714 } |
| 739 } else { | 715 } else { |
| 740 DCHECK(template_url_id_ == 0); | 716 DCHECK(template_url_id_ == 0); |
| 741 preview_tab_contents_delegate_->PrepareForNewLoad(); | 717 preview_tab_contents_delegate_->PrepareForNewLoad(); |
| 742 frame_load_observer_.reset(NULL); | 718 frame_load_observer_.reset(NULL); |
| 743 preview_contents_->controller().LoadURL(url_, GURL(), transition_type); | 719 preview_contents_->controller().LoadURL(url_, GURL(), transition_type); |
| 744 } | 720 } |
| 745 return true; | 721 return true; |
| 746 } | 722 } |
| 747 | 723 |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1027 Source<NavigationController>(&preview_contents_->controller())); | 1003 Source<NavigationController>(&preview_contents_->controller())); |
| 1028 #endif | 1004 #endif |
| 1029 | 1005 |
| 1030 registrar_.Add( | 1006 registrar_.Add( |
| 1031 this, | 1007 this, |
| 1032 NotificationType::NAV_ENTRY_COMMITTED, | 1008 NotificationType::NAV_ENTRY_COMMITTED, |
| 1033 Source<NavigationController>(&preview_contents_->controller())); | 1009 Source<NavigationController>(&preview_contents_->controller())); |
| 1034 | 1010 |
| 1035 preview_contents_->tab_contents()->ShowContents(); | 1011 preview_contents_->tab_contents()->ShowContents(); |
| 1036 } | 1012 } |
| 1013 | |
| 1014 void InstantLoader::LoadInstantURL(TabContentsWrapper* tab_contents, | |
|
sky
2011/05/20 20:52:18
Position should match header (and next method).
sreeram
2011/05/21 03:18:27
Done.
| |
| 1015 const TemplateURL* template_url, | |
| 1016 PageTransition::Type transition_type, | |
| 1017 const string16& user_text, | |
| 1018 bool verbatim) { | |
| 1019 preview_tab_contents_delegate_->PrepareForNewLoad(); | |
| 1020 | |
| 1021 // Load the instant URL. We don't reflect the url we load in url() as | |
| 1022 // callers expect that we're loading the URL they tell us to. | |
| 1023 // | |
| 1024 // This uses an empty string for the replacement text as the url doesn't | |
| 1025 // really have the search params, but we need to use the replace | |
| 1026 // functionality so that embeded tags (like {google:baseURL}) are escaped | |
| 1027 // correctly. | |
| 1028 // TODO(sky): having to use a replaceable url is a bit of a hack here. | |
| 1029 GURL instant_url(template_url->instant_url()->ReplaceSearchTerms( | |
| 1030 *template_url, string16(), -1, string16())); | |
| 1031 CommandLine* cl = CommandLine::ForCurrentProcess(); | |
| 1032 if (cl->HasSwitch(switches::kInstantURL)) | |
| 1033 instant_url = GURL(cl->GetSwitchValueASCII(switches::kInstantURL)); | |
| 1034 preview_contents_->controller().LoadURL(instant_url, GURL(), transition_type); | |
| 1035 RenderViewHost* host = preview_contents_->render_view_host(); | |
| 1036 host->Send(new ViewMsg_SearchBoxChange( | |
| 1037 host->routing_id(), user_text, verbatim, 0, 0)); | |
| 1038 frame_load_observer_.reset(new FrameLoadObserver( | |
| 1039 this, preview_contents()->tab_contents(), user_text, verbatim)); | |
| 1040 } | |
| 1041 | |
| 1042 void InstantLoader::MaybeLoadInstantURL(TabContentsWrapper* tab_contents, | |
| 1043 const TemplateURL* template_url) { | |
| 1044 DCHECK(template_url_id_ == template_url->id()); | |
| 1045 | |
| 1046 // If we already have a |preview_contents_|, future search queries will be | |
| 1047 // issued into it (see the "if (!created_preview_contents)" block in |Update| | |
| 1048 // above), so there is no need to load the |template_url|'s instant URL. | |
| 1049 if (preview_contents_.get()) | |
| 1050 return; | |
| 1051 | |
| 1052 CommandLine* cl = CommandLine::ForCurrentProcess(); | |
|
sky
2011/05/20 20:52:18
Put this check in InstantController, not here.
sreeram
2011/05/21 03:18:27
Done.
| |
| 1053 if (!cl->HasSwitch(switches::kPreloadInstantSearch)) | |
| 1054 return; | |
| 1055 | |
| 1056 CreatePreviewContents(tab_contents); | |
| 1057 LoadInstantURL(tab_contents, template_url, PageTransition::GENERATED, | |
| 1058 string16(), true); | |
|
sky
2011/05/20 20:52:18
Won't this ultimately result in calls back to Page
sreeram
2011/05/21 03:18:27
No. Several reasons why PageFinishedLoading won't
| |
| 1059 } | |
| OLD | NEW |