Disable TabDragController tests that fail with a real compositor.
[chromium-blink-merge.git] / chrome / browser / ui / android / toolbar / toolbar_model_android.cc
blob84535271e46682e2acbbbadb7adab0a7a3d405c5
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) {
25 delete this;
28 ScopedJavaLocalRef<jstring> ToolbarModelAndroid::GetSearchTerms(JNIEnv* env,
29 jobject obj) {
30 return base::android::ConvertUTF16ToJavaString(env,
31 toolbar_model_->GetText());
34 ScopedJavaLocalRef<jstring> ToolbarModelAndroid::GetQueryExtractionParam(
35 JNIEnv* env,
36 jobject obj) {
37 content::WebContents* web_contents = GetActiveWebContents();
38 if (!web_contents)
39 return ScopedJavaLocalRef<jstring>();
40 Profile* profile =
41 Profile::FromBrowserContext(web_contents->GetBrowserContext());
42 UIThreadSearchTermsData search_terms_data(profile);
43 return base::android::ConvertUTF8ToJavaString(
44 env,
45 search_terms_data.InstantExtendedEnabledParam());
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);