OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/ui/app_list/search/answer_card/answer_card_search_provi
der.h" | 5 #include "chrome/browser/ui/app_list/search/answer_card/answer_card_search_provi
der.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
11 #include "base/metrics/user_metrics.h" | 11 #include "base/metrics/user_metrics.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "chrome/browser/ui/app_list/search/answer_card/answer_card_result.h" | 13 #include "chrome/browser/ui/app_list/search/answer_card/answer_card_result.h" |
14 #include "chrome/browser/ui/browser_navigator.h" | |
15 #include "chrome/browser/ui/browser_navigator_params.h" | |
16 #include "content/public/browser/navigation_handle.h" | 14 #include "content/public/browser/navigation_handle.h" |
17 #include "content/public/browser/page_navigator.h" | |
18 #include "net/http/http_response_headers.h" | 15 #include "net/http/http_response_headers.h" |
19 #include "net/http/http_status_code.h" | 16 #include "net/http/http_status_code.h" |
20 #include "ui/app_list/app_list_features.h" | 17 #include "ui/app_list/app_list_features.h" |
21 #include "ui/app_list/app_list_model.h" | 18 #include "ui/app_list/app_list_model.h" |
22 #include "ui/app_list/search_box_model.h" | 19 #include "ui/app_list/search_box_model.h" |
23 | 20 |
24 namespace app_list { | 21 namespace app_list { |
25 | 22 |
26 namespace { | 23 namespace { |
27 | 24 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 void AnswerCardSearchProvider::UpdatePreferredSize(const gfx::Size& pref_size) { | 94 void AnswerCardSearchProvider::UpdatePreferredSize(const gfx::Size& pref_size) { |
98 preferred_size_ = pref_size; | 95 preferred_size_ = pref_size; |
99 OnResultAvailable(received_answer_ && IsCardSizeOk() && | 96 OnResultAvailable(received_answer_ && IsCardSizeOk() && |
100 !contents_->IsLoading()); | 97 !contents_->IsLoading()); |
101 if (!answer_loaded_time_.is_null()) { | 98 if (!answer_loaded_time_.is_null()) { |
102 UMA_HISTOGRAM_TIMES("SearchAnswer.ResizeAfterLoadTime", | 99 UMA_HISTOGRAM_TIMES("SearchAnswer.ResizeAfterLoadTime", |
103 base::TimeTicks::Now() - answer_loaded_time_); | 100 base::TimeTicks::Now() - answer_loaded_time_); |
104 } | 101 } |
105 } | 102 } |
106 | 103 |
107 content::WebContents* AnswerCardSearchProvider::OpenURLFromTab( | |
108 const content::OpenURLParams& params) { | |
109 // Open the user-clicked link in the browser taking into account the requested | |
110 // disposition. | |
111 chrome::NavigateParams new_tab_params(profile_, params.url, | |
112 params.transition); | |
113 | |
114 new_tab_params.disposition = params.disposition; | |
115 | |
116 if (params.disposition == WindowOpenDisposition::NEW_BACKGROUND_TAB) { | |
117 // When the user asks to open a link as a background tab, we show an | |
118 // activated window with the new activated tab after the user closes the | |
119 // launcher. So it's "background" relative to the launcher itself. | |
120 new_tab_params.disposition = WindowOpenDisposition::NEW_FOREGROUND_TAB; | |
121 new_tab_params.window_action = chrome::NavigateParams::SHOW_WINDOW_INACTIVE; | |
122 } | |
123 | |
124 chrome::Navigate(&new_tab_params); | |
125 | |
126 base::RecordAction(base::UserMetricsAction("SearchAnswer_OpenedUrl")); | |
127 | |
128 return new_tab_params.target_contents; | |
129 } | |
130 | |
131 void AnswerCardSearchProvider::DidFinishNavigation( | 104 void AnswerCardSearchProvider::DidFinishNavigation( |
132 content::NavigationHandle* navigation_handle) { | 105 content::NavigationHandle* navigation_handle) { |
133 if (navigation_handle->GetURL() != current_request_url_) { | 106 if (navigation_handle->GetURL() != current_request_url_) { |
134 RecordRequestResult( | 107 RecordRequestResult( |
135 SearchAnswerRequestResult::REQUEST_RESULT_ANOTHER_REQUEST_STARTED); | 108 SearchAnswerRequestResult::REQUEST_RESULT_ANOTHER_REQUEST_STARTED); |
136 return; | 109 return; |
137 } | 110 } |
138 | 111 |
139 if (!navigation_handle->HasCommitted() || navigation_handle->IsErrorPage() || | 112 if (!navigation_handle->HasCommitted() || navigation_handle->IsErrorPage() || |
140 !navigation_handle->IsInMainFrame()) { | 113 !navigation_handle->IsInMainFrame()) { |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 if (!headers->HasHeaderValue("SearchAnswer-HasResult", "true")) | 187 if (!headers->HasHeaderValue("SearchAnswer-HasResult", "true")) |
215 return false; | 188 return false; |
216 if (!headers->GetNormalizedHeader("SearchAnswer-OpenResultUrl", &result_url_)) | 189 if (!headers->GetNormalizedHeader("SearchAnswer-OpenResultUrl", &result_url_)) |
217 return false; | 190 return false; |
218 if (!headers->GetNormalizedHeader("SearchAnswer-Title", &result_title_)) | 191 if (!headers->GetNormalizedHeader("SearchAnswer-Title", &result_title_)) |
219 return false; | 192 return false; |
220 return true; | 193 return true; |
221 } | 194 } |
222 | 195 |
223 } // namespace app_list | 196 } // namespace app_list |
OLD | NEW |