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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/android/service_tab_launcher.h" 5 #include "chrome/browser/android/service_tab_launcher.h"
6 6
7 #include "base/android/jni_string.h" 7 #include "base/android/jni_string.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "content/public/browser/browser_context.h" 9 #include "content/public/browser/browser_context.h"
10 #include "content/public/browser/page_navigator.h" 10 #include "content/public/browser/page_navigator.h"
11 #include "content/public/browser/web_contents.h"
11 #include "jni/ServiceTabLauncher_jni.h" 12 #include "jni/ServiceTabLauncher_jni.h"
12 13
13 using base::android::AttachCurrentThread; 14 using base::android::AttachCurrentThread;
14 using base::android::ConvertUTF8ToJavaString; 15 using base::android::ConvertUTF8ToJavaString;
15 using base::android::GetApplicationContext; 16 using base::android::GetApplicationContext;
16 17
18 // Called by Java when the WebContents instance for a request Id is available.
19 void OnWebContentsForRequestAvailable(
20 JNIEnv* env, jclass clazz, jint request_id, jobject android_web_contents) {
21 chrome::android::ServiceTabLauncher::GetInstance()->OnTabLaunched(
22 request_id,
23 content::WebContents::FromJavaWebContents(android_web_contents));
24 }
25
17 namespace chrome { 26 namespace chrome {
18 namespace android { 27 namespace android {
19 28
20 // static 29 // static
21 ServiceTabLauncher* ServiceTabLauncher::GetInstance() { 30 ServiceTabLauncher* ServiceTabLauncher::GetInstance() {
22 return Singleton<ServiceTabLauncher>::get(); 31 return Singleton<ServiceTabLauncher>::get();
23 } 32 }
24 33
25 ServiceTabLauncher::ServiceTabLauncher() { 34 ServiceTabLauncher::ServiceTabLauncher()
35 : last_request_id_(0) {
26 java_object_.Reset( 36 java_object_.Reset(
27 Java_ServiceTabLauncher_getInstance(AttachCurrentThread(), 37 Java_ServiceTabLauncher_getInstance(AttachCurrentThread(),
28 GetApplicationContext())); 38 GetApplicationContext()));
29 } 39 }
30 40
31 ServiceTabLauncher::~ServiceTabLauncher() {} 41 ServiceTabLauncher::~ServiceTabLauncher() {}
32 42
33 void ServiceTabLauncher::LaunchTab( 43 void ServiceTabLauncher::LaunchTab(
34 content::BrowserContext* browser_context, 44 content::BrowserContext* browser_context,
35 const content::OpenURLParams& params, 45 const content::OpenURLParams& params,
(...skipping 15 matching lines...) Expand all
51 JNIEnv* env = AttachCurrentThread(); 61 JNIEnv* env = AttachCurrentThread();
52 ScopedJavaLocalRef<jstring> url = ConvertUTF8ToJavaString( 62 ScopedJavaLocalRef<jstring> url = ConvertUTF8ToJavaString(
53 env, params.url.spec()); 63 env, params.url.spec());
54 ScopedJavaLocalRef<jstring> referrer_url = 64 ScopedJavaLocalRef<jstring> referrer_url =
55 ConvertUTF8ToJavaString(env, params.referrer.url.spec()); 65 ConvertUTF8ToJavaString(env, params.referrer.url.spec());
56 ScopedJavaLocalRef<jstring> headers = ConvertUTF8ToJavaString( 66 ScopedJavaLocalRef<jstring> headers = ConvertUTF8ToJavaString(
57 env, params.extra_headers); 67 env, params.extra_headers);
58 68
59 ScopedJavaLocalRef<jbyteArray> post_data; 69 ScopedJavaLocalRef<jbyteArray> post_data;
60 70
71 tab_launched_callbacks_[++last_request_id_] = callback;
61 Java_ServiceTabLauncher_launchTab(env, 72 Java_ServiceTabLauncher_launchTab(env,
62 java_object_.obj(), 73 java_object_.obj(),
63 GetApplicationContext(), 74 GetApplicationContext(),
64 0 /* request_id */, 75 last_request_id_,
65 browser_context->IsOffTheRecord(), 76 browser_context->IsOffTheRecord(),
66 url.obj(), 77 url.obj(),
67 disposition, 78 disposition,
68 referrer_url.obj(), 79 referrer_url.obj(),
69 params.referrer.policy, 80 params.referrer.policy,
70 headers.obj(), 81 headers.obj(),
71 post_data.obj()); 82 post_data.obj());
83 }
72 84
73 // TODO(peter): We need to wait for the Android Activity to reply to the 85 void ServiceTabLauncher::OnTabLaunched(int request_id,
74 // launch intent with the ID of the launched Web Contents, so that the Java 86 content::WebContents* web_contents) {
75 // side can invoke a method on the native side with the request id and the 87 DCHECK_EQ(tab_launched_callbacks_.count(request_id), 1u);
76 // WebContents enabling us to invoke |callback|. See https://crbug.com/454809. 88 DCHECK(web_contents);
89
90 tab_launched_callbacks_[request_id].Run(web_contents);
91 tab_launched_callbacks_.erase(request_id);
77 } 92 }
78 93
79 bool ServiceTabLauncher::RegisterServiceTabLauncher(JNIEnv* env) { 94 bool ServiceTabLauncher::RegisterServiceTabLauncher(JNIEnv* env) {
80 return RegisterNativesImpl(env); 95 return RegisterNativesImpl(env);
81 } 96 }
82 97
83 } // namespace android 98 } // namespace android
84 } // namespace chrome 99 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698