1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 package org.chromium.chrome.browser.toolbar;
7 import org.chromium.base.CalledByNative;
8 import org.chromium.content_public.browser.WebContents;
11 * Provides a way of accessing toolbar data and state.
13 public class ToolbarModel {
16 * Delegate for providing additional information to the model.
18 public interface ToolbarModelDelegate {
20 * @return The currently active WebContents being used by the Toolbar.
22 @CalledByNative("ToolbarModelDelegate")
23 WebContents getActiveWebContents();
26 private long mNativeToolbarModelAndroid;
29 * Initialize the native counterpart of this model.
30 * @param delegate The delegate that will be used by the model.
32 public void initialize(ToolbarModelDelegate delegate) {
33 mNativeToolbarModelAndroid = nativeInit(delegate);
37 * Destroys the native ToolbarModel.
39 public void destroy() {
40 if (mNativeToolbarModelAndroid == 0) return;
41 nativeDestroy(mNativeToolbarModelAndroid);
42 mNativeToolbarModelAndroid = 0;
45 /** @return The search terms extracted from the current url if query extraction is enabled. */
46 public String getSearchTerms() {
47 if (mNativeToolbarModelAndroid == 0) return null;
48 return nativeGetSearchTerms(mNativeToolbarModelAndroid);
51 /** @return The parameter in the url that triggers query extraction. */
52 public String getQueryExtractionParam() {
53 if (mNativeToolbarModelAndroid == 0) return null;
54 return nativeGetQueryExtractionParam(mNativeToolbarModelAndroid);
57 /** @return The chip text from the search URL. */
58 public String getCorpusChipText() {
59 if (mNativeToolbarModelAndroid == 0) return null;
60 return nativeGetCorpusChipText(mNativeToolbarModelAndroid);
63 private native long nativeInit(ToolbarModelDelegate delegate);
64 private native void nativeDestroy(long nativeToolbarModelAndroid);
65 private native String nativeGetSearchTerms(long nativeToolbarModelAndroid);
66 private native String nativeGetQueryExtractionParam(long nativeToolbarModelAndroid);
67 private native String nativeGetCorpusChipText(long nativeToolbarModelAndroid);