Chromium Code Reviews| 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_web_contents_delegate.h" | 5 #include "chrome/browser/ui/app_list/search_answer_web_contents_delegate.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/metrics/histogram_macros.h" | 8 #include "base/metrics/histogram_macros.h" |
| 9 #include "base/metrics/user_metrics.h" | 9 #include "base/metrics/user_metrics.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/ui/browser_navigator.h" | 12 #include "chrome/browser/ui/browser_navigator.h" |
| 13 #include "chrome/browser/ui/browser_navigator_params.h" | 13 #include "chrome/browser/ui/browser_navigator_params.h" |
| 14 #include "content/public/browser/navigation_handle.h" | 14 #include "content/public/browser/navigation_handle.h" |
| 15 #include "content/public/browser/render_view_host.h" | 15 #include "content/public/browser/render_view_host.h" |
| 16 #include "content/public/browser/render_widget_host.h" | |
| 17 #include "content/public/browser/render_widget_host_view.h" | |
| 16 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
| 17 #include "content/public/browser/web_contents_delegate.h" | 19 #include "content/public/browser/web_contents_delegate.h" |
| 18 #include "content/public/common/renderer_preferences.h" | 20 #include "content/public/common/renderer_preferences.h" |
| 19 #include "net/http/http_response_headers.h" | 21 #include "net/http/http_response_headers.h" |
| 20 #include "net/http/http_status_code.h" | 22 #include "net/http/http_status_code.h" |
| 21 #include "ui/app_list/app_list_features.h" | 23 #include "ui/app_list/app_list_features.h" |
| 22 #include "ui/app_list/app_list_model.h" | 24 #include "ui/app_list/app_list_model.h" |
| 23 #include "ui/app_list/search_box_model.h" | 25 #include "ui/app_list/search_box_model.h" |
| 24 #include "ui/views/controls/webview/webview.h" | 26 #include "ui/views/controls/webview/webview.h" |
| 25 #include "ui/views/widget/widget.h" | 27 #include "ui/views/widget/widget.h" |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 152 | 154 |
| 153 content::NavigationController::LoadURLParams load_params( | 155 content::NavigationController::LoadURLParams load_params( |
| 154 current_request_url_); | 156 current_request_url_); |
| 155 load_params.transition_type = ui::PAGE_TRANSITION_AUTO_TOPLEVEL; | 157 load_params.transition_type = ui::PAGE_TRANSITION_AUTO_TOPLEVEL; |
| 156 load_params.should_clear_history_list = true; | 158 load_params.should_clear_history_list = true; |
| 157 web_contents_->GetController().LoadURLWithParams(load_params); | 159 web_contents_->GetController().LoadURLWithParams(load_params); |
| 158 server_request_start_time_ = base::TimeTicks::Now(); | 160 server_request_start_time_ = base::TimeTicks::Now(); |
| 159 | 161 |
| 160 // We are going to call WebContents::GetPreferredSize(). | 162 // We are going to call WebContents::GetPreferredSize(). |
| 161 web_contents_->GetRenderViewHost()->EnablePreferredSizeMode(); | 163 web_contents_->GetRenderViewHost()->EnablePreferredSizeMode(); |
| 164 | |
| 165 // Make the webview transparent since it's going to be shown on top of a | |
| 166 // highlightable button. | |
| 167 content::RenderWidgetHostView* render_view_host_view = | |
| 168 web_contents_->GetRenderViewHost()->GetWidget()->GetView(); | |
| 169 // The RenderWidgetHostView may be null if the renderer has crashed. | |
| 170 if (render_view_host_view) | |
| 171 render_view_host_view->SetBackgroundColor(SK_ColorTRANSPARENT); | |
|
xiyuan
2017/05/25 16:42:53
There might be a few edge cases. We had WebContent
vadimt
2017/05/25 20:15:16
Done.
| |
| 162 } | 172 } |
| 163 | 173 |
| 164 void SearchAnswerWebContentsDelegate::UpdatePreferredSize( | 174 void SearchAnswerWebContentsDelegate::UpdatePreferredSize( |
| 165 content::WebContents* web_contents, | 175 content::WebContents* web_contents, |
| 166 const gfx::Size& pref_size) { | 176 const gfx::Size& pref_size) { |
| 167 is_card_size_ok_ = | 177 is_card_size_ok_ = |
| 168 IsCardSizeOk(pref_size) || features::IsAnswerCardDarkRunEnabled(); | 178 IsCardSizeOk(pref_size) || features::IsAnswerCardDarkRunEnabled(); |
| 169 model_->SetSearchAnswerAvailable(is_card_size_ok_ && received_answer_ && | 179 model_->SetSearchAnswerAvailable(is_card_size_ok_ && received_answer_ && |
| 170 !web_contents_->IsLoading()); | 180 !web_contents_->IsLoading()); |
| 171 if (!features::IsAnswerCardDarkRunEnabled()) | 181 web_view_->SetPreferredSize(pref_size); |
| 172 web_view_->SetPreferredSize(pref_size); | |
| 173 if (!answer_loaded_time_.is_null()) { | 182 if (!answer_loaded_time_.is_null()) { |
| 174 UMA_HISTOGRAM_TIMES("SearchAnswer.ResizeAfterLoadTime", | 183 UMA_HISTOGRAM_TIMES("SearchAnswer.ResizeAfterLoadTime", |
| 175 base::TimeTicks::Now() - answer_loaded_time_); | 184 base::TimeTicks::Now() - answer_loaded_time_); |
| 176 } | 185 } |
| 177 } | 186 } |
| 178 | 187 |
| 179 content::WebContents* SearchAnswerWebContentsDelegate::OpenURLFromTab( | 188 content::WebContents* SearchAnswerWebContentsDelegate::OpenURLFromTab( |
| 180 content::WebContents* source, | 189 content::WebContents* source, |
| 181 const content::OpenURLParams& params) { | 190 const content::OpenURLParams& params) { |
| 182 if (!params.user_gesture) | 191 if (!params.user_gesture) |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 276 return; | 285 return; |
| 277 | 286 |
| 278 RecordRequestResult( | 287 RecordRequestResult( |
| 279 is_card_size_ok_ | 288 is_card_size_ok_ |
| 280 ? SearchAnswerRequestResult::REQUEST_RESULT_RECEIVED_ANSWER | 289 ? SearchAnswerRequestResult::REQUEST_RESULT_RECEIVED_ANSWER |
| 281 : SearchAnswerRequestResult:: | 290 : SearchAnswerRequestResult:: |
| 282 REQUEST_RESULT_RECEIVED_ANSWER_TOO_LARGE); | 291 REQUEST_RESULT_RECEIVED_ANSWER_TOO_LARGE); |
| 283 } | 292 } |
| 284 | 293 |
| 285 } // namespace app_list | 294 } // namespace app_list |
| OLD | NEW |