- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / android / omnibox / omnibox_prerender.h
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 #ifndef CHROME_BROWSER_ANDROID_OMNIBOX_OMNIBOX_PRERENDER_H_
6 #define CHROME_BROWSER_ANDROID_OMNIBOX_OMNIBOX_PRERENDER_H_
7
8 #include "base/android/jni_helper.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/strings/string16.h"
11
12 class AutocompleteResult;
13 class ProfielAndroid;
14 class Profile;
15 class TabAndroid;
16 struct AutocompleteMatch;
17
18 namespace content {
19 class WebContents;
20 }
21
22 // This class is responsible for taking the user's omnibox input text,
23 // AutocompleteResults and navigation actions and then feeding them to the
24 // AutocompleteActionPredictor. The predictor uses it to update its
25 // database and returns predictions on what page, if any, to pre-render
26 // or pre-connect. This class then takes the corresponding action.
27 class OmniboxPrerender {
28  public:
29   OmniboxPrerender(JNIEnv* env, jobject obj);
30   virtual ~OmniboxPrerender();
31
32   // Clears the transitional matches. This should be called when the user
33   // stops typing into the omnibox (e.g. when navigating away, closing the
34   // keyboard or changing tabs).
35   void Clear(JNIEnv* env, jobject obj, jobject j_profile_android);
36
37   // Initializes the underlying action predictor for a given profile instance.
38   // This should be called as soon as possible as the predictor must register
39   // for certain notifications to properly initialize before providing
40   // predictions and updated its learning database.
41   void InitializeForProfile(JNIEnv* env,
42                             jobject obj,
43                             jobject j_profile_android);
44
45   // Potentailly invokes a pre-render or pre-connect given the url typed into
46   // the omnibox and a corresponding autocomplete result. This should be
47   // invoked everytime the omnibox changes (e.g. As the user types characters
48   // this method should be invoked at least once per character).
49   void PrerenderMaybe(JNIEnv* env,
50                       jobject obj,
51                       jstring j_url,
52                       jstring j_current_url,
53                       jint jsource_match,
54                       jobject j_profile_android,
55                       jint native_web_contents);
56
57  private:
58
59   // Prerenders a given AutocompleteMatch's url.
60   void DoPrerender(const AutocompleteMatch& match,
61                    Profile* profile,
62                    content::WebContents* web_contents);
63   JavaObjectWeakGlobalRef weak_java_omnibox_;
64
65   DISALLOW_COPY_AND_ASSIGN(OmniboxPrerender);
66 };
67
68 bool RegisterOmniboxPrerender(JNIEnv* env);
69
70 #endif  // CHROME_BROWSER_ANDROID_OMNIBOX_OMNIBOX_PRERENDER_H_