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_engines/search_terms_data.h"
10 #include "chrome/browser/ui/toolbar/toolbar_model_impl.h"
11 #include "content/public/browser/web_contents.h"
12 #include "jni/ToolbarModel_jni.h"
14 using base::android::ScopedJavaLocalRef
;
16 ToolbarModelAndroid::ToolbarModelAndroid(JNIEnv
* env
, jobject jdelegate
)
17 : toolbar_model_(new ToolbarModelImpl(this)),
18 weak_java_delegate_(env
, jdelegate
) {
21 ToolbarModelAndroid::~ToolbarModelAndroid() {
24 void ToolbarModelAndroid::Destroy(JNIEnv
* env
, jobject obj
) {
28 ScopedJavaLocalRef
<jstring
> ToolbarModelAndroid::GetSearchTerms(JNIEnv
* env
,
30 return base::android::ConvertUTF16ToJavaString(env
,
31 toolbar_model_
->GetText());
34 ScopedJavaLocalRef
<jstring
> ToolbarModelAndroid::GetQueryExtractionParam(
37 content::WebContents
* web_contents
= GetActiveWebContents();
39 return ScopedJavaLocalRef
<jstring
>();
41 Profile::FromBrowserContext(web_contents
->GetBrowserContext());
42 UIThreadSearchTermsData
search_terms_data(profile
);
43 return base::android::ConvertUTF8ToJavaString(
45 search_terms_data
.InstantExtendedEnabledParam());
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
);