OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/android/tab_model/tab_model_jni_bridge.h" | 5 #include "chrome/browser/ui/android/tab_model/tab_model_jni_bridge.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
10 #include "base/android/jni_string.h" | 10 #include "base/android/jni_string.h" |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 int TabModelJniBridge::GetActiveIndex() const { | 81 int TabModelJniBridge::GetActiveIndex() const { |
82 JNIEnv* env = AttachCurrentThread(); | 82 JNIEnv* env = AttachCurrentThread(); |
83 return Java_TabModelJniBridge_index(env, java_object_.get(env)); | 83 return Java_TabModelJniBridge_index(env, java_object_.get(env)); |
84 } | 84 } |
85 | 85 |
86 void TabModelJniBridge::CreateTab(TabAndroid* parent, | 86 void TabModelJniBridge::CreateTab(TabAndroid* parent, |
87 WebContents* web_contents, | 87 WebContents* web_contents, |
88 int parent_tab_id) { | 88 int parent_tab_id) { |
89 JNIEnv* env = AttachCurrentThread(); | 89 JNIEnv* env = AttachCurrentThread(); |
90 Java_TabModelJniBridge_createTabWithWebContents( | 90 Java_TabModelJniBridge_createTabWithWebContents( |
91 env, java_object_.get(env).obj(), | 91 env, java_object_.get(env), (parent ? parent->GetJavaObject() : nullptr), |
92 (parent ? parent->GetJavaObject().obj() : nullptr), | |
93 web_contents->GetBrowserContext()->IsOffTheRecord(), | 92 web_contents->GetBrowserContext()->IsOffTheRecord(), |
94 web_contents->GetJavaWebContents(), parent_tab_id); | 93 web_contents->GetJavaWebContents(), parent_tab_id); |
95 } | 94 } |
96 | 95 |
97 WebContents* TabModelJniBridge::GetWebContentsAt(int index) const { | 96 WebContents* TabModelJniBridge::GetWebContentsAt(int index) const { |
98 TabAndroid* tab = GetTabAt(index); | 97 TabAndroid* tab = GetTabAt(index); |
99 return tab == NULL ? NULL : tab->web_contents(); | 98 return tab == NULL ? NULL : tab->web_contents(); |
100 } | 99 } |
101 | 100 |
102 TabAndroid* TabModelJniBridge::GetTabAt(int index) const { | 101 TabAndroid* TabModelJniBridge::GetTabAt(int index) const { |
103 JNIEnv* env = AttachCurrentThread(); | 102 JNIEnv* env = AttachCurrentThread(); |
104 ScopedJavaLocalRef<jobject> jtab = | 103 ScopedJavaLocalRef<jobject> jtab = |
105 Java_TabModelJniBridge_getTabAt(env, java_object_.get(env), index); | 104 Java_TabModelJniBridge_getTabAt(env, java_object_.get(env), index); |
106 | 105 |
107 return jtab.is_null() ? | 106 return jtab.is_null() ? NULL : TabAndroid::GetNativeTab(env, jtab); |
108 NULL : TabAndroid::GetNativeTab(env, jtab.obj()); | |
109 } | 107 } |
110 | 108 |
111 void TabModelJniBridge::SetActiveIndex(int index) { | 109 void TabModelJniBridge::SetActiveIndex(int index) { |
112 JNIEnv* env = AttachCurrentThread(); | 110 JNIEnv* env = AttachCurrentThread(); |
113 Java_TabModelJniBridge_setIndex(env, java_object_.get(env), index); | 111 Java_TabModelJniBridge_setIndex(env, java_object_.get(env), index); |
114 } | 112 } |
115 | 113 |
116 void TabModelJniBridge::CloseTabAt(int index) { | 114 void TabModelJniBridge::CloseTabAt(int index) { |
117 JNIEnv* env = AttachCurrentThread(); | 115 JNIEnv* env = AttachCurrentThread(); |
118 Java_TabModelJniBridge_closeTabAt(env, java_object_.get(env), index); | 116 Java_TabModelJniBridge_closeTabAt(env, java_object_.get(env), index); |
119 } | 117 } |
120 | 118 |
121 WebContents* TabModelJniBridge::CreateNewTabForDevTools( | 119 WebContents* TabModelJniBridge::CreateNewTabForDevTools( |
122 const GURL& url) { | 120 const GURL& url) { |
123 // TODO(dfalcantara): Change the Java side so that it creates and returns the | 121 // TODO(dfalcantara): Change the Java side so that it creates and returns the |
124 // WebContents, which we can load the URL on and return. | 122 // WebContents, which we can load the URL on and return. |
125 JNIEnv* env = AttachCurrentThread(); | 123 JNIEnv* env = AttachCurrentThread(); |
126 ScopedJavaLocalRef<jstring> jurl = ConvertUTF8ToJavaString(env, url.spec()); | 124 ScopedJavaLocalRef<jstring> jurl = ConvertUTF8ToJavaString(env, url.spec()); |
127 ScopedJavaLocalRef<jobject> obj = | 125 ScopedJavaLocalRef<jobject> obj = |
128 Java_TabModelJniBridge_createNewTabForDevTools(env, java_object_.get(env), | 126 Java_TabModelJniBridge_createNewTabForDevTools(env, java_object_.get(env), |
129 jurl); | 127 jurl); |
130 if (obj.is_null()) { | 128 if (obj.is_null()) { |
131 VLOG(0) << "Failed to create java tab"; | 129 VLOG(0) << "Failed to create java tab"; |
132 return NULL; | 130 return NULL; |
133 } | 131 } |
134 TabAndroid* tab = TabAndroid::GetNativeTab(env, obj.obj()); | 132 TabAndroid* tab = TabAndroid::GetNativeTab(env, obj); |
135 if (!tab) { | 133 if (!tab) { |
136 VLOG(0) << "Failed to create java tab"; | 134 VLOG(0) << "Failed to create java tab"; |
137 return NULL; | 135 return NULL; |
138 } | 136 } |
139 return tab->web_contents(); | 137 return tab->web_contents(); |
140 } | 138 } |
141 | 139 |
142 bool TabModelJniBridge::IsSessionRestoreInProgress() const { | 140 bool TabModelJniBridge::IsSessionRestoreInProgress() const { |
143 JNIEnv* env = AttachCurrentThread(); | 141 JNIEnv* env = AttachCurrentThread(); |
144 return Java_TabModelJniBridge_isSessionRestoreInProgress( | 142 return Java_TabModelJniBridge_isSessionRestoreInProgress( |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 bool TabModelJniBridge::Register(JNIEnv* env) { | 212 bool TabModelJniBridge::Register(JNIEnv* env) { |
215 return RegisterNativesImpl(env); | 213 return RegisterNativesImpl(env); |
216 } | 214 } |
217 | 215 |
218 static jlong Init(JNIEnv* env, | 216 static jlong Init(JNIEnv* env, |
219 const JavaParamRef<jobject>& obj, | 217 const JavaParamRef<jobject>& obj, |
220 jboolean is_incognito) { | 218 jboolean is_incognito) { |
221 TabModel* tab_model = new TabModelJniBridge(env, obj, is_incognito); | 219 TabModel* tab_model = new TabModelJniBridge(env, obj, is_incognito); |
222 return reinterpret_cast<intptr_t>(tab_model); | 220 return reinterpret_cast<intptr_t>(tab_model); |
223 } | 221 } |
OLD | NEW |