| 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 f10f223f60d86a5e08908a137e02388485b3e9a7..d61ed06b15e5a749422bdb3eb25a038a54f19ec3 100644
|
| --- a/chrome/browser/android/service_tab_launcher.cc
|
| +++ b/chrome/browser/android/service_tab_launcher.cc
|
| @@ -8,12 +8,21 @@
|
| #include "base/callback.h"
|
| #include "content/public/browser/browser_context.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 {
|
|
|
| @@ -22,7 +31,8 @@ ServiceTabLauncher* ServiceTabLauncher::GetInstance() {
|
| return Singleton<ServiceTabLauncher>::get();
|
| }
|
|
|
| -ServiceTabLauncher::ServiceTabLauncher() {
|
| +ServiceTabLauncher::ServiceTabLauncher()
|
| + : last_request_id_(0) {
|
| java_object_.Reset(
|
| Java_ServiceTabLauncher_getInstance(AttachCurrentThread(),
|
| GetApplicationContext()));
|
| @@ -58,10 +68,11 @@ void ServiceTabLauncher::LaunchTab(
|
|
|
| ScopedJavaLocalRef<jbyteArray> post_data;
|
|
|
| + tab_launched_callbacks_[++last_request_id_] = callback;
|
| Java_ServiceTabLauncher_launchTab(env,
|
| java_object_.obj(),
|
| GetApplicationContext(),
|
| - 0 /* request_id */,
|
| + last_request_id_,
|
| browser_context->IsOffTheRecord(),
|
| url.obj(),
|
| disposition,
|
| @@ -69,11 +80,15 @@ void ServiceTabLauncher::LaunchTab(
|
| params.referrer.policy,
|
| headers.obj(),
|
| post_data.obj());
|
| +}
|
| +
|
| +void ServiceTabLauncher::OnTabLaunched(int request_id,
|
| + content::WebContents* web_contents) {
|
| + 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) {
|
|
|