OLD | NEW |
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/context_utils.h" | |
8 #include "base/android/jni_string.h" | 7 #include "base/android/jni_string.h" |
9 #include "base/callback.h" | 8 #include "base/callback.h" |
10 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
11 #include "content/public/browser/browser_context.h" | 10 #include "content/public/browser/browser_context.h" |
12 #include "content/public/browser/page_navigator.h" | 11 #include "content/public/browser/page_navigator.h" |
13 #include "content/public/browser/web_contents.h" | 12 #include "content/public/browser/web_contents.h" |
14 #include "jni/ServiceTabLauncher_jni.h" | 13 #include "jni/ServiceTabLauncher_jni.h" |
15 | 14 |
16 using base::android::AttachCurrentThread; | 15 using base::android::AttachCurrentThread; |
17 using base::android::ConvertUTF8ToJavaString; | 16 using base::android::ConvertUTF8ToJavaString; |
18 using base::android::GetApplicationContext; | |
19 using base::android::JavaParamRef; | 17 using base::android::JavaParamRef; |
20 using base::android::ScopedJavaLocalRef; | 18 using base::android::ScopedJavaLocalRef; |
21 | 19 |
22 // Called by Java when the WebContents instance for a request Id is available. | 20 // Called by Java when the WebContents instance for a request Id is available. |
23 void OnWebContentsForRequestAvailable( | 21 void OnWebContentsForRequestAvailable( |
24 JNIEnv* env, | 22 JNIEnv* env, |
25 const JavaParamRef<jclass>& clazz, | 23 const JavaParamRef<jclass>& clazz, |
26 jint request_id, | 24 jint request_id, |
27 const JavaParamRef<jobject>& android_web_contents) { | 25 const JavaParamRef<jobject>& android_web_contents) { |
28 ServiceTabLauncher::GetInstance()->OnTabLaunched( | 26 ServiceTabLauncher::GetInstance()->OnTabLaunched( |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 ConvertUTF8ToJavaString(env, params.referrer.url.spec()); | 58 ConvertUTF8ToJavaString(env, params.referrer.url.spec()); |
61 ScopedJavaLocalRef<jstring> headers = ConvertUTF8ToJavaString( | 59 ScopedJavaLocalRef<jstring> headers = ConvertUTF8ToJavaString( |
62 env, params.extra_headers); | 60 env, params.extra_headers); |
63 | 61 |
64 ScopedJavaLocalRef<jobject> post_data; | 62 ScopedJavaLocalRef<jobject> post_data; |
65 | 63 |
66 int request_id = tab_launched_callbacks_.Add( | 64 int request_id = tab_launched_callbacks_.Add( |
67 base::MakeUnique<TabLaunchedCallback>(callback)); | 65 base::MakeUnique<TabLaunchedCallback>(callback)); |
68 DCHECK_GE(request_id, 1); | 66 DCHECK_GE(request_id, 1); |
69 | 67 |
70 Java_ServiceTabLauncher_launchTab(env, GetApplicationContext(), request_id, | 68 Java_ServiceTabLauncher_launchTab(env, request_id, |
71 browser_context->IsOffTheRecord(), url, | 69 browser_context->IsOffTheRecord(), url, |
72 static_cast<int>(disposition), referrer_url, | 70 static_cast<int>(disposition), referrer_url, |
73 params.referrer.policy, headers, post_data); | 71 params.referrer.policy, headers, post_data); |
74 } | 72 } |
75 | 73 |
76 void ServiceTabLauncher::OnTabLaunched(int request_id, | 74 void ServiceTabLauncher::OnTabLaunched(int request_id, |
77 content::WebContents* web_contents) { | 75 content::WebContents* web_contents) { |
78 TabLaunchedCallback* callback = tab_launched_callbacks_.Lookup(request_id); | 76 TabLaunchedCallback* callback = tab_launched_callbacks_.Lookup(request_id); |
79 DCHECK(callback); | 77 DCHECK(callback); |
80 | 78 |
81 if (callback) | 79 if (callback) |
82 callback->Run(web_contents); | 80 callback->Run(web_contents); |
83 | 81 |
84 tab_launched_callbacks_.Remove(request_id); | 82 tab_launched_callbacks_.Remove(request_id); |
85 } | 83 } |
86 | 84 |
87 bool ServiceTabLauncher::Register(JNIEnv* env) { | 85 bool ServiceTabLauncher::Register(JNIEnv* env) { |
88 return RegisterNativesImpl(env); | 86 return RegisterNativesImpl(env); |
89 } | 87 } |
OLD | NEW |