OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "omnibox_prerender.h" | 5 #include "omnibox_prerender.h" |
6 | 6 |
7 #include "base/android/jni_string.h" | 7 #include "base/android/jni_string.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "chrome/browser/android/tab_android.h" | 9 #include "chrome/browser/android/tab_android.h" |
10 #include "chrome/browser/autocomplete/autocomplete_match.h" | 10 #include "chrome/browser/autocomplete/autocomplete_match.h" |
11 #include "chrome/browser/autocomplete/autocomplete_result.h" | 11 #include "chrome/browser/autocomplete/autocomplete_result.h" |
12 #include "chrome/browser/predictors/autocomplete_action_predictor.h" | 12 #include "chrome/browser/predictors/autocomplete_action_predictor.h" |
13 #include "chrome/browser/predictors/autocomplete_action_predictor_factory.h" | 13 #include "chrome/browser/predictors/autocomplete_action_predictor_factory.h" |
14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/browser/profiles/profile_android.h" | 15 #include "chrome/browser/profiles/profile_android.h" |
| 16 #include "chrome/browser/ui/search/instant_search_prerenderer.h" |
16 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
17 #include "jni/OmniboxPrerender_jni.h" | 18 #include "jni/OmniboxPrerender_jni.h" |
18 #include "url/gurl.h" | 19 #include "url/gurl.h" |
19 | 20 |
20 using predictors::AutocompleteActionPredictor; | 21 using predictors::AutocompleteActionPredictor; |
21 using predictors::AutocompleteActionPredictorFactory; | 22 using predictors::AutocompleteActionPredictorFactory; |
22 | 23 |
23 OmniboxPrerender::OmniboxPrerender(JNIEnv* env, jobject obj) | 24 OmniboxPrerender::OmniboxPrerender(JNIEnv* env, jobject obj) |
24 : weak_java_omnibox_(env, obj) { | 25 : weak_java_omnibox_(env, obj) { |
25 } | 26 } |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 if (!autocomplete_result) | 82 if (!autocomplete_result) |
82 return; | 83 return; |
83 if (!profile) | 84 if (!profile) |
84 return; | 85 return; |
85 | 86 |
86 const AutocompleteResult::const_iterator default_match( | 87 const AutocompleteResult::const_iterator default_match( |
87 autocomplete_result->default_match()); | 88 autocomplete_result->default_match()); |
88 if (default_match == autocomplete_result->end()) | 89 if (default_match == autocomplete_result->end()) |
89 return; | 90 return; |
90 | 91 |
91 AutocompleteActionPredictor* action_predictor = | |
92 AutocompleteActionPredictorFactory::GetForProfile(profile); | |
93 if (!action_predictor) | |
94 return; | |
95 | |
96 AutocompleteActionPredictor::Action recommended_action = | 92 AutocompleteActionPredictor::Action recommended_action = |
97 AutocompleteActionPredictor::ACTION_NONE; | 93 AutocompleteActionPredictor::ACTION_NONE; |
98 if (action_predictor) { | 94 InstantSearchPrerenderer* prerenderer = |
99 action_predictor-> | 95 InstantSearchPrerenderer::GetForProfile(profile); |
100 RegisterTransitionalMatches(url_string, *autocomplete_result); | 96 if (prerenderer && |
101 recommended_action = | 97 prerenderer->IsAllowed(*default_match, web_contents)) { |
102 action_predictor->RecommendAction(url_string, *default_match); | 98 recommended_action = AutocompleteActionPredictor::ACTION_PRERENDER; |
| 99 } else { |
| 100 AutocompleteActionPredictor* action_predictor = |
| 101 AutocompleteActionPredictorFactory::GetForProfile(profile); |
| 102 if (!action_predictor) |
| 103 return; |
| 104 |
| 105 if (action_predictor) { |
| 106 action_predictor-> |
| 107 RegisterTransitionalMatches(url_string, *autocomplete_result); |
| 108 recommended_action = |
| 109 action_predictor->RecommendAction(url_string, *default_match); |
| 110 } |
103 } | 111 } |
104 | 112 |
105 GURL current_url = GURL(current_url_string); | 113 GURL current_url = GURL(current_url_string); |
106 switch (recommended_action) { | 114 switch (recommended_action) { |
107 case AutocompleteActionPredictor::ACTION_PRERENDER: | 115 case AutocompleteActionPredictor::ACTION_PRERENDER: |
108 // Ask for prerendering if the destination URL is different than the | 116 // Ask for prerendering if the destination URL is different than the |
109 // current URL. | 117 // current URL. |
110 if (default_match->destination_url != current_url) { | 118 if (default_match->destination_url != current_url) { |
111 DoPrerender( | 119 DoPrerender( |
112 *default_match, | 120 *default_match, |
(...skipping 15 matching lines...) Expand all Loading... |
128 void OmniboxPrerender::DoPrerender(const AutocompleteMatch& match, | 136 void OmniboxPrerender::DoPrerender(const AutocompleteMatch& match, |
129 Profile* profile, | 137 Profile* profile, |
130 content::WebContents* web_contents) { | 138 content::WebContents* web_contents) { |
131 DCHECK(profile); | 139 DCHECK(profile); |
132 if (!profile) | 140 if (!profile) |
133 return; | 141 return; |
134 DCHECK(web_contents); | 142 DCHECK(web_contents); |
135 if (!web_contents) | 143 if (!web_contents) |
136 return; | 144 return; |
137 gfx::Rect container_bounds = web_contents->GetContainerBounds(); | 145 gfx::Rect container_bounds = web_contents->GetContainerBounds(); |
| 146 InstantSearchPrerenderer* prerenderer = |
| 147 InstantSearchPrerenderer::GetForProfile(profile); |
| 148 if (prerenderer && prerenderer->IsAllowed(match, web_contents)) { |
| 149 prerenderer->Init( |
| 150 web_contents->GetController().GetSessionStorageNamespaceMap(), |
| 151 container_bounds.size()); |
| 152 return; |
| 153 } |
138 predictors::AutocompleteActionPredictorFactory::GetForProfile(profile)-> | 154 predictors::AutocompleteActionPredictorFactory::GetForProfile(profile)-> |
139 StartPrerendering( | 155 StartPrerendering( |
140 match.destination_url, | 156 match.destination_url, |
141 web_contents->GetController().GetSessionStorageNamespaceMap(), | 157 web_contents->GetController().GetSessionStorageNamespaceMap(), |
142 container_bounds.size()); | 158 container_bounds.size()); |
143 } | 159 } |
OLD | NEW |