Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / ui / android / toolbar / toolbar_model_android.cc
blob57f8637afa08e0a432f80eb6ebbc34f2fc3a0e72
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 #include "chrome/browser/ui/android/toolbar/toolbar_model_android.h"
7 #include "base/android/jni_string.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/search/search.h"
10 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h"
11 #include "chrome/browser/ui/toolbar/toolbar_model_impl.h"
12 #include "content/public/browser/web_contents.h"
13 #include "jni/ToolbarModel_jni.h"
15 using base::android::ScopedJavaLocalRef;
17 ToolbarModelAndroid::ToolbarModelAndroid(JNIEnv* env, jobject jdelegate)
18 : toolbar_model_(new ToolbarModelImpl(this)),
19 weak_java_delegate_(env, jdelegate) {
22 ToolbarModelAndroid::~ToolbarModelAndroid() {
25 void ToolbarModelAndroid::Destroy(JNIEnv* env, jobject obj) {
26 delete this;
29 ScopedJavaLocalRef<jstring> ToolbarModelAndroid::GetText(JNIEnv* env,
30 jobject obj) {
31 return base::android::ConvertUTF16ToJavaString(env,
32 toolbar_model_->GetText());
35 ScopedJavaLocalRef<jstring> ToolbarModelAndroid::GetQueryExtractionParam(
36 JNIEnv* env,
37 jobject obj) {
38 content::WebContents* web_contents = GetActiveWebContents();
39 if (!web_contents)
40 return ScopedJavaLocalRef<jstring>();
41 Profile* profile =
42 Profile::FromBrowserContext(web_contents->GetBrowserContext());
43 UIThreadSearchTermsData search_terms_data(profile);
44 return base::android::ConvertUTF8ToJavaString(
45 env, chrome::InstantExtendedEnabledParam(true));
48 ScopedJavaLocalRef<jstring> ToolbarModelAndroid::GetCorpusChipText(
49 JNIEnv* env,
50 jobject obj) {
51 return base::android::ConvertUTF16ToJavaString(
52 env,
53 toolbar_model_->GetCorpusNameForMobile());
56 content::WebContents* ToolbarModelAndroid::GetActiveWebContents() const {
57 JNIEnv* env = base::android::AttachCurrentThread();
58 ScopedJavaLocalRef<jobject> jdelegate = weak_java_delegate_.get(env);
59 if (!jdelegate.obj())
60 return NULL;
61 ScopedJavaLocalRef<jobject> jweb_contents =
62 Java_ToolbarModelDelegate_getActiveWebContents(env, jdelegate.obj());
63 return content::WebContents::FromJavaWebContents(jweb_contents.obj());
66 // static
67 bool ToolbarModelAndroid::RegisterToolbarModelAndroid(JNIEnv* env) {
68 return RegisterNativesImpl(env);
71 // static
72 jlong Init(JNIEnv* env, jobject obj, jobject delegate) {
73 ToolbarModelAndroid* toolbar_model = new ToolbarModelAndroid(env, delegate);
74 return reinterpret_cast<intptr_t>(toolbar_model);
77 // static
78 jint GetSecurityLevelForWebContents(JNIEnv* env,
79 jclass jcaller,
80 jobject jweb_contents) {
81 content::WebContents* web_contents =
82 content::WebContents::FromJavaWebContents(jweb_contents);
83 DCHECK(web_contents);
84 return ToolbarModelImpl::GetSecurityLevelForWebContents(web_contents);