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

Side by Side Diff: chrome/browser/android/contextualsearch/contextual_search_delegate.cc

Issue 2157793002: Remove ContentViewCore::RequestTextSurroundingSelection (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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 | « no previous file | content/browser/android/content_view_core_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/android/contextualsearch/contextual_search_delegate.h" 5 #include "chrome/browser/android/contextualsearch/contextual_search_delegate.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/json/json_string_value_serializer.h" 11 #include "base/json/json_string_value_serializer.h"
12 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "chrome/browser/android/contextualsearch/contextual_search_field_trial. h" 15 #include "chrome/browser/android/contextualsearch/contextual_search_field_trial. h"
16 #include "chrome/browser/android/contextualsearch/resolved_search_term.h" 16 #include "chrome/browser/android/contextualsearch/resolved_search_term.h"
17 #include "chrome/browser/android/proto/client_discourse_context.pb.h" 17 #include "chrome/browser/android/proto/client_discourse_context.pb.h"
18 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/profiles/profile_manager.h" 19 #include "chrome/browser/profiles/profile_manager.h"
20 #include "chrome/browser/sync/profile_sync_service_factory.h" 20 #include "chrome/browser/sync/profile_sync_service_factory.h"
21 #include "chrome/browser/translate/translate_service.h" 21 #include "chrome/browser/translate/translate_service.h"
22 #include "chrome/common/pref_names.h" 22 #include "chrome/common/pref_names.h"
23 #include "components/browser_sync/browser/profile_sync_service.h" 23 #include "components/browser_sync/browser/profile_sync_service.h"
24 #include "components/prefs/pref_service.h" 24 #include "components/prefs/pref_service.h"
25 #include "components/search_engines/template_url_service.h" 25 #include "components/search_engines/template_url_service.h"
26 #include "components/variations/net/variations_http_headers.h" 26 #include "components/variations/net/variations_http_headers.h"
27 #include "components/variations/variations_associated_data.h" 27 #include "components/variations/variations_associated_data.h"
28 #include "content/public/browser/android/content_view_core.h" 28 #include "content/public/browser/android/content_view_core.h"
29 #include "content/public/browser/render_frame_host.h"
29 #include "content/public/browser/web_contents.h" 30 #include "content/public/browser/web_contents.h"
30 #include "net/base/escape.h" 31 #include "net/base/escape.h"
31 #include "net/http/http_status_code.h" 32 #include "net/http/http_status_code.h"
32 #include "net/url_request/url_fetcher.h" 33 #include "net/url_request/url_fetcher.h"
33 #include "url/gurl.h" 34 #include "url/gurl.h"
34 35
35 using content::ContentViewCore; 36 using content::ContentViewCore;
37 using content::RenderFrameHost;
38 using content::WebContents;
36 39
37 namespace { 40 namespace {
38 41
39 const char kContextualSearchResponseDisplayTextParam[] = "display_text"; 42 const char kContextualSearchResponseDisplayTextParam[] = "display_text";
40 const char kContextualSearchResponseSelectedTextParam[] = "selected_text"; 43 const char kContextualSearchResponseSelectedTextParam[] = "selected_text";
41 const char kContextualSearchResponseSearchTermParam[] = "search_term"; 44 const char kContextualSearchResponseSearchTermParam[] = "search_term";
42 const char kContextualSearchResponseLanguageParam[] = "lang"; 45 const char kContextualSearchResponseLanguageParam[] = "lang";
43 const char kContextualSearchResponseResolvedTermParam[] = "resolved_term"; 46 const char kContextualSearchResponseResolvedTermParam[] = "resolved_term";
44 const char kContextualSearchPreventPreload[] = "prevent_preload"; 47 const char kContextualSearchPreventPreload[] = "prevent_preload";
45 const char kContextualSearchMentions[] = "mentions"; 48 const char kContextualSearchMentions[] = "mentions";
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 } 230 }
228 return request; 231 return request;
229 } 232 }
230 233
231 void ContextualSearchDelegate::GatherSurroundingTextWithCallback( 234 void ContextualSearchDelegate::GatherSurroundingTextWithCallback(
232 const std::string& selection, 235 const std::string& selection,
233 bool use_resolved_search_term, 236 bool use_resolved_search_term,
234 content::ContentViewCore* content_view_core, 237 content::ContentViewCore* content_view_core,
235 bool may_send_base_page_url, 238 bool may_send_base_page_url,
236 HandleSurroundingsCallback callback) { 239 HandleSurroundingsCallback callback) {
240 DCHECK(content_view_core && content_view_core->GetWebContents());
241 DCHECK(!callback.is_null());
242 DCHECK(!selection.empty());
243 RenderFrameHost* focused_frame =
244 content_view_core->GetWebContents()->GetFocusedFrame();
245 // If already one request is in progress, then return immediately with empty
246 // result.
247 if (!focused_frame || focused_frame->HasTextSurroundingSelectionCallback()) {
no sievers 2016/07/18 22:41:18 Can you remove HasTextSurroundingSelectionCallback
AKV 2016/07/20 12:32:07 Done.
248 callback.Run(base::string16(), 0, 0);
249 return;
250 }
237 // Immediately cancel any request that's in flight, since we're building a new 251 // Immediately cancel any request that's in flight, since we're building a new
238 // context (and the response disposes of any existing context). 252 // context (and the response disposes of any existing context).
239 search_term_fetcher_.reset(); 253 search_term_fetcher_.reset();
240 BuildContext(selection, use_resolved_search_term, content_view_core, 254 BuildContext(selection, use_resolved_search_term, content_view_core,
241 may_send_base_page_url); 255 may_send_base_page_url);
242 content_view_core->RequestTextSurroundingSelection( 256 focused_frame->SendTextSurroundingSelectionRequest(
243 field_trial_->GetSurroundingSize(), callback); 257 callback, field_trial_->GetSurroundingSize());
244 } 258 }
245 259
246 void ContextualSearchDelegate::BuildContext( 260 void ContextualSearchDelegate::BuildContext(
247 const std::string& selection, 261 const std::string& selection,
248 bool use_resolved_search_term, 262 bool use_resolved_search_term,
249 content::ContentViewCore* content_view_core, 263 content::ContentViewCore* content_view_core,
250 bool may_send_base_page_url) { 264 bool may_send_base_page_url) {
251 // Decide if the URL should be sent with the context. 265 // Decide if the URL should be sent with the context.
252 GURL page_url(content_view_core->GetWebContents()->GetURL()); 266 GURL page_url(content_view_core->GetWebContents()->GetURL());
253 GURL url_to_send; 267 GURL url_to_send;
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 end_offset -= trim; 520 end_offset -= trim;
507 } 521 }
508 if (result_text.length() > end_offset + padding_each_side_pinned) { 522 if (result_text.length() > end_offset + padding_each_side_pinned) {
509 // Trim the end. 523 // Trim the end.
510 result_text = result_text.substr(0, end_offset + padding_each_side_pinned); 524 result_text = result_text.substr(0, end_offset + padding_each_side_pinned);
511 } 525 }
512 *start = start_offset; 526 *start = start_offset;
513 *end = end_offset; 527 *end = end_offset;
514 return result_text; 528 return result_text;
515 } 529 }
OLDNEW
« no previous file with comments | « no previous file | content/browser/android/content_view_core_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698