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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchContext.java

Issue 2706333002: [TTS] Add a Java Context linked to existing native (Closed)
Patch Set: Nothing, I think. Created 3 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchContext.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchContext.java b/chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchContext.java
new file mode 100644
index 0000000000000000000000000000000000000000..1ad2a6528e5087d7f6ce242986cf5256414961c9
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchContext.java
@@ -0,0 +1,77 @@
+// 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);
+}

Powered by Google App Engine
This is Rietveld 408576698