1 | // Copyright 2013 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.omnibox; |
6 | |
7 | import org.chromium.chrome.browser.profiles.Profile; |
8 | |
9 | /** |
10 | * Java bridge to handle conditional prerendering using autocomplete results * as the user types |
11 | * into the Omnibox. |
12 | * |
13 | * OmniboxPrerender takes keystrokes, autocomplete results and navigation actions then feeds |
14 | * them to the (native) AutocompleteActionPredictor. The predictor uses this data to update its |
15 | * database and returns predictions on what page, if any, to pre-render or pre-connect. |
16 | * |
17 | */ |
18 | public class OmniboxPrerender { |
19 | private int mNativeOmniboxPrerender = 0; |
20 | |
21 | /** |
22 | * Constructor for creating a OmniboxPrerender instanace. |
23 | */ |
24 | public OmniboxPrerender() { |
25 | mNativeOmniboxPrerender = nativeInit(); |
26 | } |
27 | |
28 | /** |
29 | * Clears the transitional matches. This should be called when the user stops typing into |
30 | * the omnibox (e.g. when navigating away, closing the keyboard or changing tabs) |
31 | * |
32 | * @param profile profile instance corresponding to the active profile. |
33 | */ |
34 | public void clear(Profile profile) { |
35 | nativeClear(mNativeOmniboxPrerender, profile); |
36 | } |
37 | |
38 | /** |
39 | * Initializes the underlying action predictor for a given profile instance. This should be |
40 | * called as soon as possible as the predictor must register for certain notifications to |
41 | * properly initialize before providing predictions and updated its learning database. |
42 | * |
43 | * @param profile profile instance corresponding to active profile. |
44 | */ |
45 | public void initializeForProfile(Profile profile) { |
46 | nativeInitializeForProfile(mNativeOmniboxPrerender, profile); |
47 | } |
48 | |
49 | /** |
50 | * Potentailly invokes a pre-render or pre-connect given the url typed into the omnibox and |
51 | * a corresponding autocomplete result. This should be invoked everytime the omnibox changes |
52 | * (e.g. As the user types characters this method should be invoked at least once per character) |
53 | * |
54 | * @param url url in the omnibox. |
55 | * @param currentUrl url the current tab is displaying. |
56 | * @param nativeAutocompleteResult native pointer to an autocomplete result. |
57 | * @param profile profile instance corresponding to the active profile. |
58 | * @param nativeWebContents native pointer to a web contents instance. |
59 | */ |
60 | public void prerenderMaybe(String url, String currentUrl, int nativeAutocompleteResult, |
61 | Profile profile, int nativeWebContents) { |
62 | nativePrerenderMaybe(mNativeOmniboxPrerender, url, currentUrl, nativeAutocompleteResult, |
63 | profile, nativeWebContents); |
64 | } |
65 | |
66 | private native int nativeInit(); |
67 | private native void nativeClear(int nativeOmniboxPrerender, Profile profile); |
68 | private native void nativeInitializeForProfile( |
69 | int nativeOmniboxPrerender, |
70 | Profile profile); |
71 | private native void nativePrerenderMaybe(int nativeOmniboxPrerender, String url, |
72 | String currentUrl, int nativeAutocompleteResult, Profile profile, |
73 | int nativeWebContents); |
74 | } |