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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchManager.java

Issue 1463583004: [Contextual Search] Trigger translation on long-press. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Renamed field trial flag to use "auto-detect" instead of long-press, check both disable flags, add … Created 5 years, 1 month 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
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 package org.chromium.chrome.browser.contextualsearch; 5 package org.chromium.chrome.browser.contextualsearch;
6 6
7 import android.app.Activity; 7 import android.app.Activity;
8 import android.content.Context; 8 import android.content.Context;
9 import android.view.View; 9 import android.view.View;
10 import android.view.ViewGroup; 10 import android.view.ViewGroup;
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 mNetworkCommunicator.getBasePageUrl())) { 484 mNetworkCommunicator.getBasePageUrl())) {
485 mNetworkCommunicator.startSearchTermResolutionRequest( 485 mNetworkCommunicator.startSearchTermResolutionRequest(
486 mSelectionController.getSelectedText()); 486 mSelectionController.getSelectedText());
487 didRequestSurroundings = true; 487 didRequestSurroundings = true;
488 // Cache the target languages in case they are needed for translatio n. 488 // Cache the target languages in case they are needed for translatio n.
489 if (!mPolicy.disableForceTranslationOnebox()) getReadableLanguages() ; 489 if (!mPolicy.disableForceTranslationOnebox()) getReadableLanguages() ;
490 } else { 490 } else {
491 boolean shouldPrefetch = mPolicy.shouldPrefetchSearchResult(isTap); 491 boolean shouldPrefetch = mPolicy.shouldPrefetchSearchResult(isTap);
492 mSearchRequest = new ContextualSearchRequest(mSelectionController.ge tSelectedText(), 492 mSearchRequest = new ContextualSearchRequest(mSelectionController.ge tSelectedText(),
493 null, shouldPrefetch); 493 null, shouldPrefetch);
494 // TODO(donnd): figure out a way to do translation on long-press sel ections. 494 // Always trigger translation using auto-detect when we're not resol ving,
495 // unless disabled by policy.
496 boolean doForceTranslate = !mPolicy.disableAutoDetectTranslationOneb ox();
pedro (no code reviews) 2015/11/20 23:56:25 Nit: rename doForceTranslate to shouldAutoDetectTr
Donn Denman 2015/11/21 01:14:00 Done.
497 if (doForceTranslate) {
498 // Use the empty string for the source language in order to trig ger auto-detect.
499 // The translation one-box won't actually show when the source t ext ends up being
500 // the same as the target text, so we err on over-triggering.
501 mSearchRequest.forceTranslation("",
pedro (no code reviews) 2015/11/20 23:56:25 Nit: Similarly, consider having a new CSRequest me
Donn Denman 2015/11/21 01:14:00 Done.
502 mPolicy.bestTargetLanguage(getWritableLanguages()));
503 // TODO(donnd): Do we really want to log only when translating o n long-press?
504 ContextualSearchUma.logTranslateOnebox(doForceTranslate);
505 }
495 mDidStartLoadingResolvedSearchRequest = false; 506 mDidStartLoadingResolvedSearchRequest = false;
496 mSearchPanel.displaySearchTerm(mSelectionController.getSelectedText( )); 507 mSearchPanel.displaySearchTerm(mSelectionController.getSelectedText( ));
497 if (shouldPrefetch) loadSearchUrl(); 508 if (shouldPrefetch) loadSearchUrl();
498 } 509 }
499 510
500 if (!didRequestSurroundings) { 511 if (!didRequestSurroundings) {
501 // Gather surrounding text for Icing integration, which will make th e selection and 512 // Gather surrounding text for Icing integration, which will make th e selection and
502 // a shorter version of the surroundings available for Conversationa l Search. 513 // a shorter version of the surroundings available for Conversationa l Search.
503 // Although the surroundings are extracted, they will not be sent to the server as 514 // Although the surroundings are extracted, they will not be sent to the server as
504 // part of search term resolution, just sent to Icing which keeps th em local until 515 // part of search term resolution, just sent to Icing which keeps th em local until
(...skipping 787 matching lines...) Expand 10 before | Expand all | Expand 10 after
1292 private native void nativeDestroy(long nativeContextualSearchManager); 1303 private native void nativeDestroy(long nativeContextualSearchManager);
1293 private native void nativeStartSearchTermResolutionRequest(long nativeContex tualSearchManager, 1304 private native void nativeStartSearchTermResolutionRequest(long nativeContex tualSearchManager,
1294 String selection, boolean useResolvedSearchTerm, ContentViewCore bas eContentViewCore, 1305 String selection, boolean useResolvedSearchTerm, ContentViewCore bas eContentViewCore,
1295 boolean maySendBasePageUrl); 1306 boolean maySendBasePageUrl);
1296 private native void nativeGatherSurroundingText(long nativeContextualSearchM anager, 1307 private native void nativeGatherSurroundingText(long nativeContextualSearchM anager,
1297 String selection, boolean useResolvedSearchTerm, ContentViewCore bas eContentViewCore, 1308 String selection, boolean useResolvedSearchTerm, ContentViewCore bas eContentViewCore,
1298 boolean maySendBasePageUrl); 1309 boolean maySendBasePageUrl);
1299 private native String nativeGetTargetLanguage(long nativeContextualSearchMan ager); 1310 private native String nativeGetTargetLanguage(long nativeContextualSearchMan ager);
1300 private native String nativeGetAcceptLanguages(long nativeContextualSearchMa nager); 1311 private native String nativeGetAcceptLanguages(long nativeContextualSearchMa nager);
1301 } 1312 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698