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
) {
29 ScopedJavaLocalRef
<jstring
> ToolbarModelAndroid::GetText(JNIEnv
* env
,
31 return base::android::ConvertUTF16ToJavaString(env
,
32 toolbar_model_
->GetText());
35 ScopedJavaLocalRef
<jstring
> ToolbarModelAndroid::GetQueryExtractionParam(
38 content::WebContents
* web_contents
= GetActiveWebContents();
40 return ScopedJavaLocalRef
<jstring
>();
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(
51 return base::android::ConvertUTF16ToJavaString(
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
);
61 ScopedJavaLocalRef
<jobject
> jweb_contents
=
62 Java_ToolbarModelDelegate_getActiveWebContents(env
, jdelegate
.obj());
63 return content::WebContents::FromJavaWebContents(jweb_contents
.obj());
67 bool ToolbarModelAndroid::RegisterToolbarModelAndroid(JNIEnv
* env
) {
68 return RegisterNativesImpl(env
);
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
);
78 jint
GetSecurityLevelForWebContents(JNIEnv
* env
,
80 jobject jweb_contents
) {
81 content::WebContents
* web_contents
=
82 content::WebContents::FromJavaWebContents(jweb_contents
);
84 return ToolbarModelImpl::GetSecurityLevelForWebContents(web_contents
);