Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1148)

Unified Diff: chrome/browser/android/service_tab_launcher.cc

Issue 904453002: Feed back to the ServiceTabLauncher when the tab has been created. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@a-open-window
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/android/service_tab_launcher.cc
diff --git a/chrome/browser/android/service_tab_launcher.cc b/chrome/browser/android/service_tab_launcher.cc
index 6b6f66b1021d5333a8a8bd79e750fb069df053b1..6adb679cb28e404e7594d4ac830ae7a9b68b12c5 100644
--- a/chrome/browser/android/service_tab_launcher.cc
+++ b/chrome/browser/android/service_tab_launcher.cc
@@ -7,12 +7,21 @@
#include "base/android/jni_string.h"
#include "base/callback.h"
#include "content/public/browser/page_navigator.h"
+#include "content/public/browser/web_contents.h"
#include "jni/ServiceTabLauncher_jni.h"
using base::android::AttachCurrentThread;
using base::android::ConvertUTF8ToJavaString;
using base::android::GetApplicationContext;
+// Called by Java when the WebContents instance for a request Id is available.
+void OnWebContentsForRequestAvailable(
+ JNIEnv* env, jclass clazz, jint request_id, jobject android_web_contents) {
+ chrome::android::ServiceTabLauncher::GetInstance()->OnTabLaunched(
+ request_id,
+ content::WebContents::FromJavaWebContents(android_web_contents));
+}
+
namespace chrome {
namespace android {
@@ -21,7 +30,8 @@ ServiceTabLauncher* ServiceTabLauncher::GetInstance() {
return Singleton<ServiceTabLauncher>::get();
}
-ServiceTabLauncher::ServiceTabLauncher() {
+ServiceTabLauncher::ServiceTabLauncher()
+ : last_request_id_(0) {
java_object_.Reset(
Java_ServiceTabLauncher_create(
AttachCurrentThread(),
@@ -39,12 +49,20 @@ void ServiceTabLauncher::LaunchTab(
ScopedJavaLocalRef<jstring> url = ConvertUTF8ToJavaString(
env, params.url.spec());
- Java_ServiceTabLauncher_launchTab(env, java_object_.obj(), url.obj());
+ tab_launched_callbacks_[++last_request_id_] = callback;
+ Java_ServiceTabLauncher_launchTab(env,
+ java_object_.obj(),
+ last_request_id_,
+ url.obj());
+}
+
+void ServiceTabLauncher::OnTabLaunched(int request_id,
+ content::WebContents* web_contents) {
Ted C 2015/02/06 01:18:18 +1 indent
Peter Beverloo 2015/02/19 16:03:06 Done.
+ DCHECK_EQ(tab_launched_callbacks_.count(request_id), 1u);
+ DCHECK(web_contents);
- // TODO(peter): We need to wait for the Android Activity to reply to the
- // launch intent with the ID of the launched Web Contents, so that the Java
- // side can invoke a method on the native side with the request id and the
- // WebContents enabling us to invoke |callback|. See https://crbug.com/454809.
+ tab_launched_callbacks_[request_id].Run(web_contents);
+ tab_launched_callbacks_.erase(request_id);
}
bool ServiceTabLauncher::RegisterServiceTabLauncher(JNIEnv* env) {

Powered by Google App Engine
This is Rietveld 408576698