| 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 "components/service_tab_launcher/browser/android/service_tab_launcher.h
" | 5 #include "chrome/browser/android/chrome_service_tab_launcher.h" |
| 6 | 6 |
| 7 #include "base/android/context_utils.h" | 7 #include "base/android/context_utils.h" |
| 8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "content/public/browser/browser_context.h" | 10 #include "content/public/browser/browser_context.h" |
| 11 #include "content/public/browser/page_navigator.h" | 11 #include "content/public/browser/page_navigator.h" |
| 12 #include "content/public/browser/web_contents.h" | 12 #include "content/public/browser/web_contents.h" |
| 13 #include "jni/ServiceTabLauncher_jni.h" | 13 #include "jni/ChromeServiceTabLauncher_jni.h" |
| 14 | 14 |
| 15 using base::android::AttachCurrentThread; | 15 using base::android::AttachCurrentThread; |
| 16 using base::android::ConvertUTF8ToJavaString; | 16 using base::android::ConvertUTF8ToJavaString; |
| 17 using base::android::GetApplicationContext; | 17 using base::android::GetApplicationContext; |
| 18 | 18 |
| 19 // Called by Java when the WebContents instance for a request Id is available. | 19 // Called by Java when the WebContents instance for a request Id is available. |
| 20 void OnWebContentsForRequestAvailable( | 20 void OnWebContentsForRequestAvailable( |
| 21 JNIEnv* env, | 21 JNIEnv* env, |
| 22 const JavaParamRef<jclass>& clazz, | 22 const JavaParamRef<jclass>& clazz, |
| 23 jint request_id, | 23 jint request_id, |
| 24 const JavaParamRef<jobject>& android_web_contents) { | 24 const JavaParamRef<jobject>& android_web_contents) { |
| 25 service_tab_launcher::ServiceTabLauncher::GetInstance()->OnTabLaunched( | 25 ChromeServiceTabLauncher::GetInstance()->OnTabLaunched( |
| 26 request_id, | 26 request_id, |
| 27 content::WebContents::FromJavaWebContents(android_web_contents)); | 27 content::WebContents::FromJavaWebContents(android_web_contents)); |
| 28 } | 28 } |
| 29 | 29 |
| 30 namespace service_tab_launcher { | |
| 31 | |
| 32 // static | 30 // static |
| 33 ServiceTabLauncher* ServiceTabLauncher::GetInstance() { | 31 ChromeServiceTabLauncher* ChromeServiceTabLauncher::GetInstance() { |
| 34 return base::Singleton<ServiceTabLauncher>::get(); | 32 return base::Singleton<ChromeServiceTabLauncher>::get(); |
| 35 } | 33 } |
| 36 | 34 |
| 37 ServiceTabLauncher::ServiceTabLauncher() { | 35 ChromeServiceTabLauncher::ChromeServiceTabLauncher() { |
| 38 java_object_.Reset( | 36 java_object_.Reset(Java_ChromeServiceTabLauncher_getInstance( |
| 39 Java_ServiceTabLauncher_getInstance(AttachCurrentThread(), | 37 AttachCurrentThread(), GetApplicationContext())); |
| 40 GetApplicationContext())); | |
| 41 } | 38 } |
| 42 | 39 |
| 43 ServiceTabLauncher::~ServiceTabLauncher() {} | 40 ChromeServiceTabLauncher::~ChromeServiceTabLauncher() {} |
| 44 | 41 |
| 45 void ServiceTabLauncher::LaunchTab( | 42 void ChromeServiceTabLauncher::LaunchTab( |
| 46 content::BrowserContext* browser_context, | 43 content::BrowserContext* browser_context, |
| 47 const content::OpenURLParams& params, | 44 const content::OpenURLParams& params, |
| 48 const TabLaunchedCallback& callback) { | 45 const TabLaunchedCallback& callback) { |
| 49 if (!java_object_.obj()) { | 46 if (!java_object_.obj()) { |
| 50 LOG(ERROR) << "No ServiceTabLauncher is available to launch a new tab."; | 47 LOG(ERROR) << "No ServiceTabLauncher is available to launch a new tab."; |
| 51 callback.Run(nullptr); | 48 callback.Run(nullptr); |
| 52 return; | 49 return; |
| 53 } | 50 } |
| 54 | 51 |
| 55 WindowOpenDisposition disposition = params.disposition; | 52 WindowOpenDisposition disposition = params.disposition; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 67 ConvertUTF8ToJavaString(env, params.referrer.url.spec()); | 64 ConvertUTF8ToJavaString(env, params.referrer.url.spec()); |
| 68 ScopedJavaLocalRef<jstring> headers = ConvertUTF8ToJavaString( | 65 ScopedJavaLocalRef<jstring> headers = ConvertUTF8ToJavaString( |
| 69 env, params.extra_headers); | 66 env, params.extra_headers); |
| 70 | 67 |
| 71 ScopedJavaLocalRef<jobject> post_data; | 68 ScopedJavaLocalRef<jobject> post_data; |
| 72 | 69 |
| 73 int request_id = tab_launched_callbacks_.Add( | 70 int request_id = tab_launched_callbacks_.Add( |
| 74 new TabLaunchedCallback(callback)); | 71 new TabLaunchedCallback(callback)); |
| 75 DCHECK_GE(request_id, 1); | 72 DCHECK_GE(request_id, 1); |
| 76 | 73 |
| 77 Java_ServiceTabLauncher_launchTab(env, | 74 Java_ChromeServiceTabLauncher_launchTab(env, |
| 78 java_object_.obj(), | 75 java_object_.obj(), |
| 79 GetApplicationContext(), | 76 GetApplicationContext(), |
| 80 request_id, | 77 request_id, |
| 81 browser_context->IsOffTheRecord(), | 78 browser_context->IsOffTheRecord(), |
| 82 url.obj(), | 79 url.obj(), |
| 83 disposition, | 80 disposition, |
| 84 referrer_url.obj(), | 81 referrer_url.obj(), |
| 85 params.referrer.policy, | 82 params.referrer.policy, |
| 86 headers.obj(), | 83 headers.obj(), |
| 87 post_data.obj()); | 84 post_data.obj()); |
| 88 } | 85 } |
| 89 | 86 |
| 90 void ServiceTabLauncher::OnTabLaunched(int request_id, | 87 void ChromeServiceTabLauncher::OnTabLaunched( |
| 91 content::WebContents* web_contents) { | 88 int request_id, |
| 89 content::WebContents* web_contents) { |
| 92 TabLaunchedCallback* callback = tab_launched_callbacks_.Lookup(request_id); | 90 TabLaunchedCallback* callback = tab_launched_callbacks_.Lookup(request_id); |
| 93 DCHECK(callback); | 91 DCHECK(callback); |
| 94 | 92 |
| 95 if (callback) | 93 if (callback) |
| 96 callback->Run(web_contents); | 94 callback->Run(web_contents); |
| 97 | 95 |
| 98 tab_launched_callbacks_.Remove(request_id); | 96 tab_launched_callbacks_.Remove(request_id); |
| 99 } | 97 } |
| 100 | 98 |
| 101 bool ServiceTabLauncher::RegisterServiceTabLauncher(JNIEnv* env) { | 99 bool ChromeServiceTabLauncher::Register(JNIEnv* env) { |
| 102 return RegisterNativesImpl(env); | 100 return RegisterNativesImpl(env); |
| 103 } | 101 } |
| 104 | |
| 105 } // namespace service_tab_launcher | |
| OLD | NEW |