Commit 4740983c authored by donnd's avatar donnd Committed by Commit bot

[TTS] Add a Java Context linked to existing native

Refactor Contextual Search to use a Java Context linked to the
native Context we've had for a while.

Update the native context have only private data members.

Also fix some minor bugs regarding the panel not updating when
a retap is done, and expanding the selection when it's been
changed.

Additional refactoring includes changing the API to the native
Contextual Search Manager to have StartSearchTermResolutionRequest
not automatically gather surrounding text -- that call must now be
done separately.

Also use WebContents instead of ContentViewCore, and some other
cleanup.

BUG=692824,699305,693297

Review-Url: https://codereview.chromium.org/2706333002
Cr-Commit-Position: refs/heads/master@{#456087}
parent a0edc14c
......@@ -221,15 +221,15 @@ public class ContextualSearchBarControl
}
/**
* Sets the search context to display in the control.
* Sets the details of the context to display in the control.
* @param selection The portion of the context that represents the user's selection.
* @param end The portion of the context after the selection.
*/
public void setSearchContext(String selection, String end) {
public void setContextDetails(String selection, String end) {
cancelSearchTermResolutionAnimation();
hideCaption();
mQuickActionControl.reset();
mContextControl.setSearchContext(selection, end);
mContextControl.setContextDetails(selection, end);
resetSearchBarContextOpacity();
animateDividerLine(false);
}
......
......@@ -43,11 +43,11 @@ public class ContextualSearchContextControl extends OverlayPanelInflater {
}
/**
* Sets the search context to display in the control.
* Sets the details of the search context to display in the control.
* @param selection The portion of the context that represents the user's selection.
* @param end The portion of the context after the selection.
*/
public void setSearchContext(String selection, String end) {
public void setContextDetails(String selection, String end) {
inflate();
mSelectedText.setText(sanitizeText(selection));
......
......@@ -546,14 +546,16 @@ public class ContextualSearchPanel extends OverlayPanel {
}
/**
* Sets the search context to display in the SearchBar.
* Sets the search context details to display in the SearchBar.
* @param selection The portion of the context that represents the user's selection.
* @param end The portion of the context from the selection to its end.
*/
public void setSearchContext(String selection, String end) {
public void setContextDetails(String selection, String end) {
getImageControl().hideStaticImage(true);
getSearchBarControl().setSearchContext(selection, end);
getSearchBarControl().setContextDetails(selection, end);
mPanelMetrics.onSearchRequestStarted();
// Make sure the new Context draws.
requestUpdate();
}
/**
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.contextualsearch;
import org.chromium.base.annotations.CalledByNative;
/**
* Provides a context in which to search, and links to the native ContextualSearchContext.
* Includes the selection, selection offsets, surrounding page content, etc.
*/
public class ContextualSearchContext {
// The initial selection that established this context, or null.
private final String mSelection;
// Pointer to the native instance of this class.
private long mNativePointer;
/**
* Constructs a context that cannot resolve a search term and has a small amount of
* page content.
*/
ContextualSearchContext() {
mNativePointer = nativeInit();
mSelection = null;
}
/**
* Constructs a context that can resolve a search term and has a large amount of
* page content.
* @param selection The current selection.
* @param homeCountry The country where the user usually resides, or an empty string if not
* known.
* @param maySendBasePageUrl Whether policy allows sending the base-page URL to the server.
*/
ContextualSearchContext(String selection, String homeCountry, boolean maySendBasePageUrl) {
mNativePointer = nativeInit();
mSelection = selection;
nativeSetResolveProperties(getNativePointer(), selection, homeCountry, maySendBasePageUrl);
}
/**
* This method should be called to clean up storage when an instance of this class is
* no longer in use. The nativeDestroy will call the destructor on the native instance.
*/
void destroy() {
assert mNativePointer != 0;
nativeDestroy(mNativePointer);
mNativePointer = 0;
}
/**
* @return the original selection.
*/
String getSelection() {
return mSelection;
}
// ============================================================================================
// Native callback support.
// ============================================================================================
@CalledByNative
private long getNativePointer() {
assert mNativePointer != 0;
return mNativePointer;
}
// ============================================================================================
// Native methods.
// ============================================================================================
private native long nativeInit();
private native void nativeDestroy(long nativeContextualSearchContext);
private native void nativeSetResolveProperties(long nativeContextualSearchContext,
String selection, String homeCountry, boolean maySendBasePageUrl);
}
......@@ -15,6 +15,7 @@ import org.chromium.chrome.browser.preferences.ChromePreferenceManager;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.content.browser.ContentViewCore;
import org.chromium.content_public.browser.GestureStateListener;
import org.chromium.content_public.browser.WebContents;
import org.chromium.ui.touch_selection.SelectionEventType;
import java.util.regex.Matcher;
......@@ -355,10 +356,11 @@ public class ContextualSearchSelectionController {
/**
* Handles an unhandled tap gesture.
* @param x The x coordinate in px.
* @param y The y coordinate in px.
*/
void handleShowUnhandledTapUIIfNeeded(int x, int y) {
mWasTapGestureDetected = false;
// TODO(donnd): shouldn't we check == TAP here instead of LONG_PRESS?
// TODO(donnd): refactor to avoid needing a new handler API method as suggested by Pedro.
if (mSelectionType != SelectionType.LONG_PRESS) {
mWasTapGestureDetected = true;
......@@ -403,13 +405,24 @@ public class ContextualSearchSelectionController {
}
/**
* Gets the base page ContentViewCore.
* Deprecated, use getBaseWebContents instead.
* @return The Base Page's {@link ContentViewCore}, or {@code null} if there is no current tab.
*/
@Deprecated
ContentViewCore getBaseContentView() {
Tab currentTab = mActivity.getActivityTab();
return currentTab != null ? currentTab.getContentViewCore() : null;
}
/**
* @return The Base Page's {@link WebContents}, or {@code null} if there is no current tab.
*/
WebContents getBaseWebContents() {
Tab currentTab = mActivity.getActivityTab();
return currentTab != null ? currentTab.getContentViewCore().getWebContents() : null;
}
/**
* Expands the current selection by the specified amounts.
* @param selectionStartAdjust The start offset adjustment of the selection to use to highlight
......@@ -422,10 +435,10 @@ public class ContextualSearchSelectionController {
// crbug.com/508354
if (selectionStartAdjust == 0 && selectionEndAdjust == 0) return;
ContentViewCore basePageContentView = getBaseContentView();
if (basePageContentView != null && basePageContentView.getWebContents() != null) {
WebContents basePageWebContents = getBaseWebContents();
if (basePageWebContents != null) {
mDidExpandSelection = true;
basePageContentView.getWebContents().adjustSelectionByCharacterOffset(
basePageWebContents.adjustSelectionByCharacterOffset(
selectionStartAdjust, selectionEndAdjust);
}
}
......
......@@ -225,6 +225,7 @@ chrome_java_sources = [
"java/src/org/chromium/chrome/browser/contextmenu/ContextMenuTitleView.java",
"java/src/org/chromium/chrome/browser/contextualsearch/BarOverlapTapSuppression.java",
"java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchBlacklist.java",
"java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchContext.java",
"java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchFieldTrial.java",
"java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchHeuristic.java",
"java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchHeuristics.java",
......
......@@ -114,8 +114,7 @@ public class ContextualSearchTapEventTest extends ChromeActivityTestCaseBase<Chr
@Override
protected void nativeGatherSurroundingText(long nativeContextualSearchManager,
String selection, String homeCountry, WebContents webContents,
boolean maySendBasePageUrl) {}
ContextualSearchContext contextualSearchContext, WebContents baseWebContents) {}
/**
* @return A stubbed ContentViewCore for mocking text selection.
......@@ -140,7 +139,7 @@ public class ContextualSearchTapEventTest extends ChromeActivityTestCaseBase<Chr
}
@Override
public StubbedContentViewCore getBaseContentView() {
StubbedContentViewCore getBaseContentView() {
return mContentViewCore;
}
}
......
......@@ -3985,6 +3985,7 @@ if (is_android) {
"../android/java/src/org/chromium/chrome/browser/compositor/scene_layer/ToolbarSceneLayer.java",
"../android/java/src/org/chromium/chrome/browser/contextmenu/ContextMenuHelper.java",
"../android/java/src/org/chromium/chrome/browser/contextmenu/ContextMenuParams.java",
"../android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchContext.java",
"../android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchManager.java",
"../android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchTabHelper.java",
"../android/java/src/org/chromium/chrome/browser/contextualsearch/CtrSuppression.java",
......
......@@ -31,6 +31,7 @@
#include "chrome/browser/android/compositor/scene_layer/tab_strip_scene_layer.h"
#include "chrome/browser/android/compositor/scene_layer/toolbar_scene_layer.h"
#include "chrome/browser/android/compositor/tab_content_manager.h"
#include "chrome/browser/android/contextualsearch/contextual_search_context.h"
#include "chrome/browser/android/contextualsearch/contextual_search_manager.h"
#include "chrome/browser/android/contextualsearch/contextual_search_tab_helper.h"
#include "chrome/browser/android/contextualsearch/ctr_suppression.h"
......@@ -267,6 +268,7 @@ static base::android::RegistrationMethod kChromeRegisteredMethods[] = {
{"ContentSuggestionsNotificationHelper",
ntp_snippets::ContentSuggestionsNotificationHelper::Register},
{"ContextMenuHelper", RegisterContextMenuHelper},
{"ContextualSearchContext", RegisterContextualSearchContext},
{"ContextualSearchManager", RegisterContextualSearchManager},
{"ContextualSearchSceneLayer", RegisterContextualSearchSceneLayer},
{"ContextualSearchTabHelper", RegisterContextualSearchTabHelper},
......
......@@ -2,7 +2,20 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/android/contextualsearch/contextual_search_context.h"
#include <chrome/browser/android/contextualsearch/contextual_search_context.h>
#include "base/android/jni_string.h"
#include "content/public/browser/browser_thread.h"
#include "jni/ContextualSearchContext_jni.h"
ContextualSearchContext::ContextualSearchContext(JNIEnv* env, jobject obj)
: can_resolve(false),
can_send_base_page_url(false),
start_offset(0),
end_offset(0) {
java_object_.Reset(env, obj);
}
ContextualSearchContext::ContextualSearchContext(
const std::string& selected_text,
......@@ -11,8 +24,111 @@ ContextualSearchContext::ContextualSearchContext(
const std::string& encoding)
: selected_text(selected_text),
home_country(home_country),
page_url(page_url),
encoding(encoding) {}
base_page_url(page_url),
base_page_encoding(encoding) {
java_object_ = nullptr;
}
ContextualSearchContext::~ContextualSearchContext() {
}
// static
ContextualSearchContext*
ContextualSearchContext::FromJavaContextualSearchContext(
const base::android::JavaRef<jobject>& j_contextual_search_context) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
if (j_contextual_search_context.is_null())
return NULL;
ContextualSearchContext* contextual_search_context =
reinterpret_cast<ContextualSearchContext*>(
Java_ContextualSearchContext_getNativePointer(
base::android::AttachCurrentThread(),
j_contextual_search_context));
return contextual_search_context;
}
void ContextualSearchContext::SetResolveProperties(
JNIEnv* env,
jobject obj,
const base::android::JavaParamRef<jstring>& j_selection,
const base::android::JavaParamRef<jstring>& j_home_country,
jboolean j_may_send_base_page_url) {
can_resolve = true;
selected_text = base::android::ConvertJavaStringToUTF8(env, j_selection);
home_country = base::android::ConvertJavaStringToUTF8(env, j_home_country);
can_send_base_page_url = j_may_send_base_page_url;
}
// Accessors
bool ContextualSearchContext::CanResolve() const {
return can_resolve;
}
bool ContextualSearchContext::CanSendBasePageUrl() const {
return can_send_base_page_url;
}
const GURL ContextualSearchContext::GetBasePageUrl() const {
return base_page_url;
}
void ContextualSearchContext::SetBasePageUrl(const GURL& base_page_url) {
this->base_page_url = base_page_url;
}
const std::string ContextualSearchContext::GetBasePageEncoding() const {
return base_page_encoding;
}
void ContextualSearchContext::SetBasePageEncoding(
const std::string& base_page_encoding) {
this->base_page_encoding = base_page_encoding;
}
const std::string ContextualSearchContext::GetHomeCountry() const {
return home_country;
}
void ContextualSearchContext::SetSelectionSurroundings(
int start_offset,
int end_offset,
const base::string16& surrounding_text) {
this->start_offset = start_offset;
this->end_offset = end_offset;
this->surrounding_text = surrounding_text;
}
const std::string ContextualSearchContext::GetOriginalSelectedText() const {
return selected_text;
}
const base::string16 ContextualSearchContext::GetSurroundingText() const {
return surrounding_text;
}
int ContextualSearchContext::GetStartOffset() const {
return start_offset;
}
int ContextualSearchContext::GetEndOffset() const {
return end_offset;
}
// Java wrapper boilerplate
void ContextualSearchContext::Destroy(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj) {
delete this;
}
bool RegisterContextualSearchContext(JNIEnv* env) {
return RegisterNativesImpl(env);
}
jlong Init(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj) {
ContextualSearchContext* context = new ContextualSearchContext(env, obj);
return reinterpret_cast<intptr_t>(context);
}
......@@ -7,6 +7,7 @@
#include <string>
#include "base/android/jni_android.h"
#include "base/macros.h"
#include "url/gurl.h"
......@@ -14,22 +15,88 @@
// text.
struct ContextualSearchContext {
public:
ContextualSearchContext(JNIEnv* env, jobject obj);
// Constructor for tests.
ContextualSearchContext(const std::string& selected_text,
const std::string& home_country,
const GURL& page_url,
const std::string& encoding);
~ContextualSearchContext();
const std::string selected_text;
const std::string home_country;
const GURL page_url;
const std::string encoding;
// Calls the destructor. Should be called when this native object is no
// longer needed.
void Destroy(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj);
// Returns the native |ContextualSearchContext| given the Java object.
static ContextualSearchContext* FromJavaContextualSearchContext(
const base::android::JavaRef<jobject>& j_contextual_search_context);
// Returns whether this context can be resolved.
// The context can be resolved only after calling SetResolveProperites.
bool CanResolve() const;
// Returns whether the base page URL may be sent (according to the Java
// policy).
bool CanSendBasePageUrl() const;
// Sets the properties needed to resolve a context.
void SetResolveProperties(
JNIEnv* env,
jobject obj,
const base::android::JavaParamRef<jstring>& j_selection,
const base::android::JavaParamRef<jstring>& j_home_country,
jboolean j_may_send_base_page_url);
// Gets the URL of the base page.
const GURL GetBasePageUrl() const;
// Sets the URL of the base page.
void SetBasePageUrl(const GURL& base_page_url);
// Gets the encoding of the base page. This is not very important, since
// the surrounding text stored here in a base::string16 is implicitly encoded
// in UTF-16 (see http://www.chromium.org/developers/chromium-string-usage).
const std::string GetBasePageEncoding() const;
void SetBasePageEncoding(const std::string& base_page_encoding);
// Gets the country code of the home country of the user, or an empty string.
const std::string GetHomeCountry() const;
// Sets the selection and surroundings.
void SetSelectionSurroundings(int start_offset,
int end_offset,
const base::string16& surrounding_text);
// Gets the original selection.
const std::string GetOriginalSelectedText() const;
// Gets the text surrounding the selection (including the selection).
const base::string16 GetSurroundingText() const;
// Gets the start offset of the selection within the surrounding text (in
// characters).
int GetStartOffset() const;
// Gets the end offset of the selection within the surrounding text (in
// characters).
int GetEndOffset() const;
private:
bool can_resolve;
bool can_send_base_page_url;
std::string selected_text;
std::string home_country;
GURL base_page_url;
std::string base_page_encoding;
base::string16 surrounding_text;
int start_offset;
int end_offset;
// The linked Java object.
base::android::ScopedJavaGlobalRef<jobject> java_object_;
DISALLOW_COPY_AND_ASSIGN(ContextualSearchContext);
};
bool RegisterContextualSearchContext(JNIEnv* env);
#endif // CHROME_BROWSER_ANDROID_CONTEXTUALSEARCH_CONTEXTUAL_SEARCH_CONTEXT_H_
......@@ -43,11 +43,6 @@ class ContextualSearchDelegate
// Provides the Resolved Search Term, called when the Resolve Request returns.
typedef base::Callback<void(const ResolvedSearchTerm&)>
SearchTermResolutionCallback;
// Provides the surrounding text and selection start/end when Blink gathers
// surrounding text for the Context.
typedef base::Callback<
void(const base::string16&, int, int)>
HandleSurroundingsCallback;
// Provides limited surrounding text for icing.
typedef base::Callback<
void(const std::string&, const base::string16&, size_t, size_t)>
......@@ -66,24 +61,19 @@ class ContextualSearchDelegate
const IcingCallback& icing_callback);
~ContextualSearchDelegate() override;
// Gathers surrounding text and starts an asynchronous search term resolution
// request. The "search term" is the best query to issue for a section of text
// in the context of a web page. When the response is available the callback
// specified in the constructor is run.
void StartSearchTermResolutionRequest(const std::string& selection,
const std::string& home_country,
content::WebContents* web_contents,
bool may_send_base_page_url);
// Gathers surrounding text and saves it locally for a future query.
void GatherAndSaveSurroundingText(const std::string& selection,
const std::string& home_country,
content::WebContents* web_contents,
bool may_send_base_page_url);
// Continues making a Search Term Resolution request, once the surrounding
// text has been gathered.
void ContinueSearchTermResolutionRequest();
// Gathers surrounding text and saves it locally in the given context.
void GatherAndSaveSurroundingText(
ContextualSearchContext* contextual_search_context,
content::WebContents* web_contents);
// Starts an asynchronous search term resolution request.
// The given context includes some content from a web page and must be able
// to resolve.
// When the response is available the callback specified in the constructor
// is run.
void StartSearchTermResolutionRequest(
ContextualSearchContext* contextual_search_context,
content::WebContents* web_contents);
// Gets the target language for translation purposes for this user.
std::string GetTargetLanguage();
......@@ -93,10 +83,15 @@ class ContextualSearchDelegate
// For testing.
void set_context_for_testing(ContextualSearchContext* context) {
context_.reset(context);
context_ = context;
}
private:
// Friend our test which allows our private methods to be used in helper
// functions. FRIEND_TEST_ALL_PREFIXES just friends individual prefixes.
// Needed for |ResolveSearchTermFromContext|.
friend class ContextualSearchDelegateTest;
// TODO(donnd): consider removing the following since the above covers this.
FRIEND_TEST_ALL_PREFIXES(ContextualSearchDelegateTest,
SurroundingTextHighMaximum);
FRIEND_TEST_ALL_PREFIXES(ContextualSearchDelegateTest,
......@@ -118,12 +113,9 @@ class ContextualSearchDelegate
// net::URLFetcherDelegate:
void OnURLFetchComplete(const net::URLFetcher* source) override;
// Builds the ContextualSearchContext in the current context from
// the given parameters.
void BuildContext(const std::string& selection,
const std::string& home_country,
content::WebContents* web_contents,
bool may_send_base_page_url);
// Resolves the search term specified by the current context.
// Only needed for tests. TODO(donnd): make private and friend?
void ResolveSearchTermFromContext();
// Builds and returns the search term resolution request URL.
// |selection| is used as the default query.
......@@ -136,17 +128,9 @@ class ContextualSearchDelegate
const std::string& base_page_url,
const bool may_send_base_page_url);
// Will gather the surrounding text from the |content_view_core| and call the
// |callback|.
void GatherSurroundingTextWithCallback(const std::string& selection,
const std::string& home_country,
content::WebContents* web_contents,
bool may_send_base_page_url,
HandleSurroundingsCallback callback);
// Callback for GatherSurroundingTextWithCallback(). Will start the search
// term resolution request.
void StartSearchTermRequestFromSelection(
// Callback for GatherAndSaveSurroundingText, called when surrounding text is
// available.
void OnTextSurroundingSelectionAvailable(
const base::string16& surrounding_text,
int start_offset,
int end_offset);
......@@ -243,7 +227,8 @@ class ContextualSearchDelegate
IcingCallback icing_callback_;
// Used to hold the context until an upcoming search term request is started.
std::unique_ptr<ContextualSearchContext> context_;
// Owned by the Java ContextualSearchContext.
ContextualSearchContext* context_;
DISALLOW_COPY_AND_ASSIGN(ContextualSearchDelegate);
};
......
......@@ -95,10 +95,9 @@ class ContextualSearchDelegateTest : public testing::Test {
// ContextualSearchDelegate class takes ownership of the context.
delegate_->set_context_for_testing(test_context_);
test_context_->start_offset = start_offset;
test_context_->end_offset = end_offset;
test_context_->surrounding_text = surrounding_text;
delegate_->ContinueSearchTermResolutionRequest();
test_context_->SetSelectionSurroundings(start_offset, end_offset,
surrounding_text);
delegate_->ResolveSearchTermFromContext();
fetcher_ = test_factory_.GetFetcherByID(
ContextualSearchDelegate::kContextualSearchURLFetcherID);
ASSERT_TRUE(fetcher_);
......@@ -147,9 +146,8 @@ class ContextualSearchDelegateTest : public testing::Test {
int end_offset) {
test_context_ = new ContextualSearchContext(
"Bogus", std::string(), GURL(kSomeSpecificBasePage), "utf-8");
test_context_->surrounding_text = surrounding_text;
test_context_->start_offset = start_offset;
test_context_->end_offset = end_offset;
test_context_->SetSelectionSurroundings(start_offset, end_offset,
surrounding_text);
// ContextualSearchDelegate class takes ownership of the context.
delegate_->set_context_for_testing(test_context_);
}
......
......@@ -65,40 +65,32 @@ void ContextualSearchManager::Destroy(JNIEnv* env,
void ContextualSearchManager::StartSearchTermResolutionRequest(
JNIEnv* env,
const JavaParamRef<jobject>& obj,
const JavaParamRef<jstring>& j_selection,
const JavaParamRef<jstring>& j_home_country,
const JavaParamRef<jobject>& j_base_web_contents,
jboolean j_may_send_base_page_url) {
const base::android::JavaParamRef<jobject>& j_contextual_search_context,
const JavaParamRef<jobject>& j_base_web_contents) {
WebContents* base_web_contents =
WebContents::FromJavaWebContents(j_base_web_contents);
DCHECK(base_web_contents);
std::string selection(
base::android::ConvertJavaStringToUTF8(env, j_selection));
std::string home_country(
base::android::ConvertJavaStringToUTF8(env, j_home_country));
bool may_send_base_page_url = j_may_send_base_page_url;
ContextualSearchContext* contextual_search_context =
ContextualSearchContext::FromJavaContextualSearchContext(
j_contextual_search_context);
// Calls back to OnSearchTermResolutionResponse.
delegate_->StartSearchTermResolutionRequest(
selection, home_country, base_web_contents, may_send_base_page_url);
delegate_->StartSearchTermResolutionRequest(contextual_search_context,
base_web_contents);
}
void ContextualSearchManager::GatherSurroundingText(
JNIEnv* env,
const JavaParamRef<jobject>& obj,
const JavaParamRef<jstring>& j_selection,
const JavaParamRef<jstring>& j_home_country,
const JavaParamRef<jobject>& j_base_web_contents,
jboolean j_may_send_base_page_url) {
const base::android::JavaParamRef<jobject>& j_contextual_search_context,
const JavaParamRef<jobject>& j_base_web_contents) {
WebContents* base_web_contents =
WebContents::FromJavaWebContents(j_base_web_contents);
DCHECK(base_web_contents);
std::string selection(
base::android::ConvertJavaStringToUTF8(env, j_selection));
std::string home_country(
base::android::ConvertJavaStringToUTF8(env, j_home_country));
bool may_send_base_page_url = j_may_send_base_page_url;
delegate_->GatherAndSaveSurroundingText(
selection, home_country, base_web_contents, may_send_base_page_url);
ContextualSearchContext* contextual_search_context =
ContextualSearchContext::FromJavaContextualSearchContext(
j_contextual_search_context);
delegate_->GatherAndSaveSurroundingText(contextual_search_context,
base_web_contents);
}
base::android::ScopedJavaLocalRef<jstring>
......
......@@ -33,25 +33,20 @@ class ContextualSearchManager
// content view core object).
// Any outstanding server requests are canceled.
// When the server responds with the search term, the Java object is notified
// by
// calling OnSearchTermResolutionResponse().
// by calling OnSearchTermResolutionResponse().
void StartSearchTermResolutionRequest(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj,
const base::android::JavaParamRef<jstring>& j_selection,
const base::android::JavaParamRef<jstring>& j_home_country,
const base::android::JavaParamRef<jobject>& j_base_web_contents,
jboolean j_may_send_base_page_url);
const base::android::JavaParamRef<jobject>& j_contextual_search_context,
const base::android::JavaParamRef<jobject>& j_base_web_contents);
// Gathers the surrounding text around the selection and saves it locally.
// Does not send a search term resolution request to the server.
void GatherSurroundingText(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj,
const base::android::JavaParamRef<jstring>& j_selection,
const base::android::JavaParamRef<jstring>& j_home_country,
const base::android::JavaParamRef<jobject>& j_base_web_contents,
jboolean j_may_send_base_page_url);
const base::android::JavaParamRef<jobject>& j_contextual_search_context,
const base::android::JavaParamRef<jobject>& j_base_web_contents);
// Gets the target language for translation purposes.
base::android::ScopedJavaLocalRef<jstring> GetTargetLanguage(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment