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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 const JavaParamRef<jobject>& obj, | 68 const JavaParamRef<jobject>& obj, |
69 const JavaParamRef<jobject>& jtab) { | 69 const JavaParamRef<jobject>& jtab) { |
70 // Tab#initialize() should have been called by now otherwise we can't push | 70 // Tab#initialize() should have been called by now otherwise we can't push |
71 // the window id. | 71 // the window id. |
72 TabAndroid* tab = TabAndroid::GetNativeTab(env, jtab); | 72 TabAndroid* tab = TabAndroid::GetNativeTab(env, jtab); |
73 if (tab) tab->SetWindowSessionID(GetSessionId()); | 73 if (tab) tab->SetWindowSessionID(GetSessionId()); |
74 } | 74 } |
75 | 75 |
76 int TabModelJniBridge::GetTabCount() const { | 76 int TabModelJniBridge::GetTabCount() const { |
77 JNIEnv* env = AttachCurrentThread(); | 77 JNIEnv* env = AttachCurrentThread(); |
78 return Java_TabModelJniBridge_getCount(env, java_object_.get(env).obj()); | 78 return Java_TabModelJniBridge_getCount(env, java_object_.get(env)); |
79 } | 79 } |
80 | 80 |
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).obj()); | 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).obj(), |
92 (parent ? parent->GetJavaObject().obj() : nullptr), | 92 (parent ? parent->GetJavaObject().obj() : nullptr), |
93 web_contents->GetBrowserContext()->IsOffTheRecord(), | 93 web_contents->GetBrowserContext()->IsOffTheRecord(), |
94 web_contents->GetJavaWebContents().obj(), | 94 web_contents->GetJavaWebContents(), parent_tab_id); |
95 parent_tab_id); | |
96 } | 95 } |
97 | 96 |
98 WebContents* TabModelJniBridge::GetWebContentsAt(int index) const { | 97 WebContents* TabModelJniBridge::GetWebContentsAt(int index) const { |
99 TabAndroid* tab = GetTabAt(index); | 98 TabAndroid* tab = GetTabAt(index); |
100 return tab == NULL ? NULL : tab->web_contents(); | 99 return tab == NULL ? NULL : tab->web_contents(); |
101 } | 100 } |
102 | 101 |
103 TabAndroid* TabModelJniBridge::GetTabAt(int index) const { | 102 TabAndroid* TabModelJniBridge::GetTabAt(int index) const { |
104 JNIEnv* env = AttachCurrentThread(); | 103 JNIEnv* env = AttachCurrentThread(); |
105 ScopedJavaLocalRef<jobject> jtab = | 104 ScopedJavaLocalRef<jobject> jtab = |
106 Java_TabModelJniBridge_getTabAt(env, | 105 Java_TabModelJniBridge_getTabAt(env, java_object_.get(env), index); |
107 java_object_.get(env).obj(), | |
108 index); | |
109 | 106 |
110 return jtab.is_null() ? | 107 return jtab.is_null() ? |
111 NULL : TabAndroid::GetNativeTab(env, jtab.obj()); | 108 NULL : TabAndroid::GetNativeTab(env, jtab.obj()); |
112 } | 109 } |
113 | 110 |
114 void TabModelJniBridge::SetActiveIndex(int index) { | 111 void TabModelJniBridge::SetActiveIndex(int index) { |
115 JNIEnv* env = AttachCurrentThread(); | 112 JNIEnv* env = AttachCurrentThread(); |
116 Java_TabModelJniBridge_setIndex(env, java_object_.get(env).obj(), index); | 113 Java_TabModelJniBridge_setIndex(env, java_object_.get(env), index); |
117 } | 114 } |
118 | 115 |
119 void TabModelJniBridge::CloseTabAt(int index) { | 116 void TabModelJniBridge::CloseTabAt(int index) { |
120 JNIEnv* env = AttachCurrentThread(); | 117 JNIEnv* env = AttachCurrentThread(); |
121 Java_TabModelJniBridge_closeTabAt(env, | 118 Java_TabModelJniBridge_closeTabAt(env, java_object_.get(env), index); |
122 java_object_.get(env).obj(), | |
123 index); | |
124 } | 119 } |
125 | 120 |
126 WebContents* TabModelJniBridge::CreateNewTabForDevTools( | 121 WebContents* TabModelJniBridge::CreateNewTabForDevTools( |
127 const GURL& url) { | 122 const GURL& url) { |
128 // TODO(dfalcantara): Change the Java side so that it creates and returns the | 123 // TODO(dfalcantara): Change the Java side so that it creates and returns the |
129 // WebContents, which we can load the URL on and return. | 124 // WebContents, which we can load the URL on and return. |
130 JNIEnv* env = AttachCurrentThread(); | 125 JNIEnv* env = AttachCurrentThread(); |
131 ScopedJavaLocalRef<jstring> jurl = ConvertUTF8ToJavaString(env, url.spec()); | 126 ScopedJavaLocalRef<jstring> jurl = ConvertUTF8ToJavaString(env, url.spec()); |
132 ScopedJavaLocalRef<jobject> obj = | 127 ScopedJavaLocalRef<jobject> obj = |
133 Java_TabModelJniBridge_createNewTabForDevTools( | 128 Java_TabModelJniBridge_createNewTabForDevTools(env, java_object_.get(env), |
134 env, | 129 jurl); |
135 java_object_.get(env).obj(), | |
136 jurl.obj()); | |
137 if (obj.is_null()) { | 130 if (obj.is_null()) { |
138 VLOG(0) << "Failed to create java tab"; | 131 VLOG(0) << "Failed to create java tab"; |
139 return NULL; | 132 return NULL; |
140 } | 133 } |
141 TabAndroid* tab = TabAndroid::GetNativeTab(env, obj.obj()); | 134 TabAndroid* tab = TabAndroid::GetNativeTab(env, obj.obj()); |
142 if (!tab) { | 135 if (!tab) { |
143 VLOG(0) << "Failed to create java tab"; | 136 VLOG(0) << "Failed to create java tab"; |
144 return NULL; | 137 return NULL; |
145 } | 138 } |
146 return tab->web_contents(); | 139 return tab->web_contents(); |
147 } | 140 } |
148 | 141 |
149 bool TabModelJniBridge::IsSessionRestoreInProgress() const { | 142 bool TabModelJniBridge::IsSessionRestoreInProgress() const { |
150 JNIEnv* env = AttachCurrentThread(); | 143 JNIEnv* env = AttachCurrentThread(); |
151 return Java_TabModelJniBridge_isSessionRestoreInProgress( | 144 return Java_TabModelJniBridge_isSessionRestoreInProgress( |
152 env, java_object_.get(env).obj()); | 145 env, java_object_.get(env)); |
153 } | 146 } |
154 | 147 |
155 void TabModelJniBridge::BroadcastSessionRestoreComplete( | 148 void TabModelJniBridge::BroadcastSessionRestoreComplete( |
156 JNIEnv* env, | 149 JNIEnv* env, |
157 const JavaParamRef<jobject>& obj) { | 150 const JavaParamRef<jobject>& obj) { |
158 TabModel::BroadcastSessionRestoreComplete(); | 151 TabModel::BroadcastSessionRestoreComplete(); |
159 } | 152 } |
160 | 153 |
161 inline static base::TimeDelta GetTimeDelta(jlong ms) { | 154 inline static base::TimeDelta GetTimeDelta(jlong ms) { |
162 return base::TimeDelta::FromMilliseconds(static_cast<int64_t>(ms)); | 155 return base::TimeDelta::FromMilliseconds(static_cast<int64_t>(ms)); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 bool TabModelJniBridge::Register(JNIEnv* env) { | 214 bool TabModelJniBridge::Register(JNIEnv* env) { |
222 return RegisterNativesImpl(env); | 215 return RegisterNativesImpl(env); |
223 } | 216 } |
224 | 217 |
225 static jlong Init(JNIEnv* env, | 218 static jlong Init(JNIEnv* env, |
226 const JavaParamRef<jobject>& obj, | 219 const JavaParamRef<jobject>& obj, |
227 jboolean is_incognito) { | 220 jboolean is_incognito) { |
228 TabModel* tab_model = new TabModelJniBridge(env, obj, is_incognito); | 221 TabModel* tab_model = new TabModelJniBridge(env, obj, is_incognito); |
229 return reinterpret_cast<intptr_t>(tab_model); | 222 return reinterpret_cast<intptr_t>(tab_model); |
230 } | 223 } |
OLD | NEW |