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.chrome.browser.ui.toolbar.ToolbarModelSecurityLevel;
9 import org.chromium.content_public.browser.WebContents;
12 * Provides a way of accessing toolbar data and state.
14 public class ToolbarModel {
17 * Delegate for providing additional information to the model.
19 public interface ToolbarModelDelegate {
21 * @return The currently active WebContents being used by the Toolbar.
23 @CalledByNative("ToolbarModelDelegate")
24 WebContents getActiveWebContents();
27 private long mNativeToolbarModelAndroid;
30 * Fetch the security level for a given web contents.
32 * @param webContents The web contents to get the security level for.
33 * @return The ToolbarModelSecurityLevel for the specified web contents.
35 * @see ToolbarModelSecurityLevel
37 public static int getSecurityLevelForWebContents(WebContents webContents) {
38 if (webContents == null) return ToolbarModelSecurityLevel.NONE;
39 return nativeGetSecurityLevelForWebContents(webContents);
43 * Initialize the native counterpart of this model.
44 * @param delegate The delegate that will be used by the model.
46 public void initialize(ToolbarModelDelegate delegate) {
47 mNativeToolbarModelAndroid = nativeInit(delegate);
51 * Destroys the native ToolbarModel.
53 public void destroy() {
54 if (mNativeToolbarModelAndroid == 0) return;
55 nativeDestroy(mNativeToolbarModelAndroid);
56 mNativeToolbarModelAndroid = 0;
59 /** @return The formatted text (URL or search terms) for display. */
60 public String getText() {
61 if (mNativeToolbarModelAndroid == 0) return null;
62 return nativeGetText(mNativeToolbarModelAndroid);
65 /** @return The parameter in the url that triggers query extraction. */
66 public String getQueryExtractionParam() {
67 if (mNativeToolbarModelAndroid == 0) return null;
68 return nativeGetQueryExtractionParam(mNativeToolbarModelAndroid);
71 /** @return The chip text from the search URL. */
72 public String getCorpusChipText() {
73 if (mNativeToolbarModelAndroid == 0) return null;
74 return nativeGetCorpusChipText(mNativeToolbarModelAndroid);
77 private static native int nativeGetSecurityLevelForWebContents(WebContents webContents);
79 private native long nativeInit(ToolbarModelDelegate delegate);
80 private native void nativeDestroy(long nativeToolbarModelAndroid);
81 private native String nativeGetText(long nativeToolbarModelAndroid);
82 private native String nativeGetQueryExtractionParam(long nativeToolbarModelAndroid);
83 private native String nativeGetCorpusChipText(long nativeToolbarModelAndroid);