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/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
17 #include "content/public/browser/web_contents_delegate.h" | 17 #include "content/public/browser/web_contents_delegate.h" |
18 #include "content/public/common/renderer_preferences.h" | 18 #include "content/public/common/renderer_preferences.h" |
19 #include "net/http/http_response_headers.h" | 19 #include "net/http/http_response_headers.h" |
20 #include "net/http/http_status_code.h" | 20 #include "net/http/http_status_code.h" |
21 #include "ui/app_list/app_list_features.h" | 21 #include "ui/app_list/app_list_features.h" |
22 #include "ui/app_list/app_list_model.h" | 22 #include "ui/app_list/app_list_model.h" |
23 #include "ui/app_list/search_box_model.h" | 23 #include "ui/app_list/search_box_model.h" |
| 24 #include "ui/views/controls/webview/web_contents_set_background_color.h" |
24 #include "ui/views/controls/webview/webview.h" | 25 #include "ui/views/controls/webview/webview.h" |
25 #include "ui/views/widget/widget.h" | 26 #include "ui/views/widget/widget.h" |
26 | 27 |
27 namespace app_list { | 28 namespace app_list { |
28 | 29 |
29 namespace { | 30 namespace { |
30 | 31 |
31 enum class SearchAnswerRequestResult { | 32 enum class SearchAnswerRequestResult { |
32 REQUEST_RESULT_ANOTHER_REQUEST_STARTED = 0, | 33 REQUEST_RESULT_ANOTHER_REQUEST_STARTED = 0, |
33 REQUEST_RESULT_REQUEST_FAILED = 1, | 34 REQUEST_RESULT_REQUEST_FAILED = 1, |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 web_contents_->GetRenderViewHost()->SyncRendererPrefs(); | 99 web_contents_->GetRenderViewHost()->SyncRendererPrefs(); |
99 | 100 |
100 Observe(web_contents_.get()); | 101 Observe(web_contents_.get()); |
101 web_contents_->SetDelegate(this); | 102 web_contents_->SetDelegate(this); |
102 web_view_->set_owned_by_client(); | 103 web_view_->set_owned_by_client(); |
103 web_view_->SetWebContents(web_contents_.get()); | 104 web_view_->SetWebContents(web_contents_.get()); |
104 if (features::IsAnswerCardDarkRunEnabled()) | 105 if (features::IsAnswerCardDarkRunEnabled()) |
105 web_view_->SetFocusBehavior(views::View::FocusBehavior::NEVER); | 106 web_view_->SetFocusBehavior(views::View::FocusBehavior::NEVER); |
106 | 107 |
107 model->AddObserver(this); | 108 model->AddObserver(this); |
| 109 |
| 110 // Make the webview transparent since it's going to be shown on top of a |
| 111 // highlightable button. |
| 112 views::WebContentsSetBackgroundColor::CreateForWebContentsWithColor( |
| 113 web_contents_.get(), SK_ColorTRANSPARENT); |
108 } | 114 } |
109 | 115 |
110 SearchAnswerWebContentsDelegate::~SearchAnswerWebContentsDelegate() { | 116 SearchAnswerWebContentsDelegate::~SearchAnswerWebContentsDelegate() { |
111 RecordReceivedAnswerFinalResult(); | 117 RecordReceivedAnswerFinalResult(); |
112 model_->RemoveObserver(this); | 118 model_->RemoveObserver(this); |
113 } | 119 } |
114 | 120 |
115 views::View* SearchAnswerWebContentsDelegate::web_view() { | 121 views::View* SearchAnswerWebContentsDelegate::web_view() { |
116 return web_view_.get(); | 122 return web_view_.get(); |
117 } | 123 } |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 web_contents_->GetRenderViewHost()->EnablePreferredSizeMode(); | 167 web_contents_->GetRenderViewHost()->EnablePreferredSizeMode(); |
162 } | 168 } |
163 | 169 |
164 void SearchAnswerWebContentsDelegate::UpdatePreferredSize( | 170 void SearchAnswerWebContentsDelegate::UpdatePreferredSize( |
165 content::WebContents* web_contents, | 171 content::WebContents* web_contents, |
166 const gfx::Size& pref_size) { | 172 const gfx::Size& pref_size) { |
167 is_card_size_ok_ = | 173 is_card_size_ok_ = |
168 IsCardSizeOk(pref_size) || features::IsAnswerCardDarkRunEnabled(); | 174 IsCardSizeOk(pref_size) || features::IsAnswerCardDarkRunEnabled(); |
169 model_->SetSearchAnswerAvailable(is_card_size_ok_ && received_answer_ && | 175 model_->SetSearchAnswerAvailable(is_card_size_ok_ && received_answer_ && |
170 !web_contents_->IsLoading()); | 176 !web_contents_->IsLoading()); |
171 if (!features::IsAnswerCardDarkRunEnabled()) | 177 web_view_->SetPreferredSize(pref_size); |
172 web_view_->SetPreferredSize(pref_size); | |
173 if (!answer_loaded_time_.is_null()) { | 178 if (!answer_loaded_time_.is_null()) { |
174 UMA_HISTOGRAM_TIMES("SearchAnswer.ResizeAfterLoadTime", | 179 UMA_HISTOGRAM_TIMES("SearchAnswer.ResizeAfterLoadTime", |
175 base::TimeTicks::Now() - answer_loaded_time_); | 180 base::TimeTicks::Now() - answer_loaded_time_); |
176 } | 181 } |
177 } | 182 } |
178 | 183 |
179 content::WebContents* SearchAnswerWebContentsDelegate::OpenURLFromTab( | 184 content::WebContents* SearchAnswerWebContentsDelegate::OpenURLFromTab( |
180 content::WebContents* source, | 185 content::WebContents* source, |
181 const content::OpenURLParams& params) { | 186 const content::OpenURLParams& params) { |
182 if (!params.user_gesture) | 187 if (!params.user_gesture) |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 return; | 281 return; |
277 | 282 |
278 RecordRequestResult( | 283 RecordRequestResult( |
279 is_card_size_ok_ | 284 is_card_size_ok_ |
280 ? SearchAnswerRequestResult::REQUEST_RESULT_RECEIVED_ANSWER | 285 ? SearchAnswerRequestResult::REQUEST_RESULT_RECEIVED_ANSWER |
281 : SearchAnswerRequestResult:: | 286 : SearchAnswerRequestResult:: |
282 REQUEST_RESULT_RECEIVED_ANSWER_TOO_LARGE); | 287 REQUEST_RESULT_RECEIVED_ANSWER_TOO_LARGE); |
283 } | 288 } |
284 | 289 |
285 } // namespace app_list | 290 } // namespace app_list |
OLD | NEW |