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. 4 5 package org.chromium.chrome.browser.toolbar; 6 7 import org.chromium.base.CalledByNative; 8 import org.chromium.content_public.browser.WebContents; 9 10 /** 11 * Provides a way of accessing toolbar data and state. 12 */ 13 public class ToolbarModel { 14 15 /** 16 * Delegate for providing additional information to the model. 17 */ 18 public interface ToolbarModelDelegate { 19 /** 20 * @return The currently active WebContents being used by the Toolbar. 21 */ 22 @CalledByNative("ToolbarModelDelegate") 23 WebContents getActiveWebContents(); 24 } 25 26 private long mNativeToolbarModelAndroid; 27 28 /** 29 * Initialize the native counterpart of this model. 30 * @param delegate The delegate that will be used by the model. 31 */ 32 public void initialize(ToolbarModelDelegate delegate) { 33 mNativeToolbarModelAndroid = nativeInit(delegate); 34 } 35 36 /** 37 * Destroys the native ToolbarModel. 38 */ 39 public void destroy() { 40 if (mNativeToolbarModelAndroid == 0) return; 41 nativeDestroy(mNativeToolbarModelAndroid); 42 mNativeToolbarModelAndroid = 0; 43 } 44 45 /** @return The formatted text (URL or search terms) for display. */ 46 public String getText() { 47 if (mNativeToolbarModelAndroid == 0) return null; 48 return nativeGetText(mNativeToolbarModelAndroid); 49 } 50 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); 55 } 56 57 /** @return The chip text from the search URL. */ 58 public String getCorpusChipText() { 59 if (mNativeToolbarModelAndroid == 0) return null; 60 return nativeGetCorpusChipText(mNativeToolbarModelAndroid); 61 } 62 63 private native long nativeInit(ToolbarModelDelegate delegate); 64 private native void nativeDestroy(long nativeToolbarModelAndroid); 65 private native String nativeGetText(long nativeToolbarModelAndroid); 66 private native String nativeGetQueryExtractionParam(long nativeToolbarModelAndroid); 67 private native String nativeGetCorpusChipText(long nativeToolbarModelAndroid); 68 } 69