Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(669)

Side by Side Diff: chrome/browser/ui/app_list/search_answer_web_contents_delegate.cc

Issue 2840673002: Opening links clicked from the answer card in a new tab. (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/ui/app_list/search_answer_web_contents_delegate.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/browser_navigator.h"
11 #include "chrome/browser/ui/browser_navigator_params.h"
9 #include "content/public/browser/navigation_handle.h" 12 #include "content/public/browser/navigation_handle.h"
10 #include "content/public/browser/render_view_host.h" 13 #include "content/public/browser/render_view_host.h"
11 #include "content/public/browser/web_contents.h" 14 #include "content/public/browser/web_contents.h"
12 #include "content/public/browser/web_contents_delegate.h" 15 #include "content/public/browser/web_contents_delegate.h"
16 #include "content/public/common/renderer_preferences.h"
13 #include "net/http/http_response_headers.h" 17 #include "net/http/http_response_headers.h"
14 #include "net/http/http_status_code.h" 18 #include "net/http/http_status_code.h"
15 #include "ui/app_list/app_list_model.h" 19 #include "ui/app_list/app_list_model.h"
16 #include "ui/app_list/app_list_switches.h" 20 #include "ui/app_list/app_list_switches.h"
17 #include "ui/app_list/search_box_model.h" 21 #include "ui/app_list/search_box_model.h"
18 #include "ui/views/controls/webview/webview.h" 22 #include "ui/views/controls/webview/webview.h"
19 23
20 namespace app_list { 24 namespace app_list {
21 25
22 SearchAnswerWebContentsDelegate::SearchAnswerWebContentsDelegate( 26 SearchAnswerWebContentsDelegate::SearchAnswerWebContentsDelegate(
23 content::BrowserContext* browser_context, 27 Profile* profile,
24 app_list::AppListModel* model) 28 app_list::AppListModel* model)
25 : model_(model), 29 : profile_(profile),
26 web_view_(base::MakeUnique<views::WebView>(browser_context)), 30 model_(model),
31 web_view_(base::MakeUnique<views::WebView>(profile)),
27 web_contents_( 32 web_contents_(
28 content::WebContents::Create(content::WebContents::CreateParams( 33 content::WebContents::Create(content::WebContents::CreateParams(
29 browser_context, 34 profile,
30 content::SiteInstance::Create(browser_context)))), 35 content::SiteInstance::Create(profile)))),
31 answer_server_url_(switches::AnswerServerUrl()) { 36 answer_server_url_(switches::AnswerServerUrl()) {
37 // We need the OpenURLFromTab() to get called.
38 web_contents_->GetMutableRendererPrefs()
39 ->browser_handles_all_top_level_requests = true;
40 web_contents_->GetRenderViewHost()->SyncRendererPrefs();
41
32 Observe(web_contents_.get()); 42 Observe(web_contents_.get());
33 web_contents_->SetDelegate(this); 43 web_contents_->SetDelegate(this);
34 web_view_->set_owned_by_client(); 44 web_view_->set_owned_by_client();
35 web_view_->SetWebContents(web_contents_.get()); 45 web_view_->SetWebContents(web_contents_.get());
36 } 46 }
37 47
38 SearchAnswerWebContentsDelegate::~SearchAnswerWebContentsDelegate() {} 48 SearchAnswerWebContentsDelegate::~SearchAnswerWebContentsDelegate() {}
39 49
40 views::View* SearchAnswerWebContentsDelegate::web_view() { 50 views::View* SearchAnswerWebContentsDelegate::web_view() {
41 return web_view_.get(); 51 return web_view_.get();
(...skipping 30 matching lines...) Expand all
72 // We are going to call WebContents::GetPreferredSize(). 82 // We are going to call WebContents::GetPreferredSize().
73 web_contents_->GetRenderViewHost()->EnablePreferredSizeMode(); 83 web_contents_->GetRenderViewHost()->EnablePreferredSizeMode();
74 } 84 }
75 85
76 void SearchAnswerWebContentsDelegate::UpdatePreferredSize( 86 void SearchAnswerWebContentsDelegate::UpdatePreferredSize(
77 content::WebContents* web_contents, 87 content::WebContents* web_contents,
78 const gfx::Size& pref_size) { 88 const gfx::Size& pref_size) {
79 web_view_->SetPreferredSize(pref_size); 89 web_view_->SetPreferredSize(pref_size);
80 } 90 }
81 91
92 content::WebContents* SearchAnswerWebContentsDelegate::OpenURLFromTab(
93 content::WebContents* source,
94 const content::OpenURLParams& params) {
95 if (!params.user_gesture)
96 return WebContentsDelegate::OpenURLFromTab(source, params);
97
98 // Open the user-clicked link in a new browser tab. This will automatically
99 // close the app list.
100 chrome::NavigateParams new_tab_params(profile_, params.url,
101 params.transition);
102 new_tab_params.disposition = WindowOpenDisposition::NEW_FOREGROUND_TAB;
103 new_tab_params.window_action = chrome::NavigateParams::SHOW_WINDOW;
104
105 chrome::Navigate(&new_tab_params);
106
107 return new_tab_params.target_contents;
108 }
109
82 void SearchAnswerWebContentsDelegate::DidFinishNavigation( 110 void SearchAnswerWebContentsDelegate::DidFinishNavigation(
83 content::NavigationHandle* navigation_handle) { 111 content::NavigationHandle* navigation_handle) {
84 if (navigation_handle->GetURL() != current_request_url_) 112 if (navigation_handle->GetURL() != current_request_url_)
85 return; 113 return;
86 114
87 if (!navigation_handle->HasCommitted() || navigation_handle->IsErrorPage() || 115 if (!navigation_handle->HasCommitted() || navigation_handle->IsErrorPage() ||
88 !navigation_handle->IsInMainFrame()) { 116 !navigation_handle->IsInMainFrame()) {
89 return; 117 return;
90 } 118 }
91 119
92 const net::HttpResponseHeaders* headers = 120 const net::HttpResponseHeaders* headers =
93 navigation_handle->GetResponseHeaders(); 121 navigation_handle->GetResponseHeaders();
94 if (!headers || headers->response_code() != net::HTTP_OK || 122 if (!headers || headers->response_code() != net::HTTP_OK ||
95 !headers->HasHeaderValue("has_answer", "true")) { 123 !headers->HasHeaderValue("has_answer", "true")) {
96 return; 124 return;
97 } 125 }
98 126
99 received_answer_ = true; 127 received_answer_ = true;
100 } 128 }
101 129
102 void SearchAnswerWebContentsDelegate::DidStopLoading() { 130 void SearchAnswerWebContentsDelegate::DidStopLoading() {
103 if (!received_answer_) 131 if (!received_answer_)
104 return; 132 return;
105 133
106 model_->SetSearchAnswerAvailable(true); 134 model_->SetSearchAnswerAvailable(true);
107 } 135 }
108 136
109 } // namespace app_list 137 } // namespace app_list
OLDNEW
« no previous file with comments | « chrome/browser/ui/app_list/search_answer_web_contents_delegate.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698