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" | 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" |
(...skipping 25 matching lines...) Expand all Loading... |
36 | 36 |
37 ServiceTabLauncher::ServiceTabLauncher() { | 37 ServiceTabLauncher::ServiceTabLauncher() { |
38 } | 38 } |
39 | 39 |
40 ServiceTabLauncher::~ServiceTabLauncher() {} | 40 ServiceTabLauncher::~ServiceTabLauncher() {} |
41 | 41 |
42 void ServiceTabLauncher::LaunchTab(content::BrowserContext* browser_context, | 42 void ServiceTabLauncher::LaunchTab(content::BrowserContext* browser_context, |
43 const content::OpenURLParams& params, | 43 const content::OpenURLParams& params, |
44 const TabLaunchedCallback& callback) { | 44 const TabLaunchedCallback& callback) { |
45 WindowOpenDisposition disposition = params.disposition; | 45 WindowOpenDisposition disposition = params.disposition; |
46 if (disposition != NEW_WINDOW && disposition != NEW_POPUP && | 46 if (disposition != WindowOpenDisposition::NEW_WINDOW && |
47 disposition != NEW_FOREGROUND_TAB && disposition != NEW_BACKGROUND_TAB) { | 47 disposition != WindowOpenDisposition::NEW_POPUP && |
| 48 disposition != WindowOpenDisposition::NEW_FOREGROUND_TAB && |
| 49 disposition != WindowOpenDisposition::NEW_BACKGROUND_TAB) { |
48 // ServiceTabLauncher can currently only launch new tabs. | 50 // ServiceTabLauncher can currently only launch new tabs. |
49 NOTIMPLEMENTED(); | 51 NOTIMPLEMENTED(); |
50 return; | 52 return; |
51 } | 53 } |
52 | 54 |
53 JNIEnv* env = AttachCurrentThread(); | 55 JNIEnv* env = AttachCurrentThread(); |
54 ScopedJavaLocalRef<jstring> url = ConvertUTF8ToJavaString( | 56 ScopedJavaLocalRef<jstring> url = ConvertUTF8ToJavaString( |
55 env, params.url.spec()); | 57 env, params.url.spec()); |
56 ScopedJavaLocalRef<jstring> referrer_url = | 58 ScopedJavaLocalRef<jstring> referrer_url = |
57 ConvertUTF8ToJavaString(env, params.referrer.url.spec()); | 59 ConvertUTF8ToJavaString(env, params.referrer.url.spec()); |
58 ScopedJavaLocalRef<jstring> headers = ConvertUTF8ToJavaString( | 60 ScopedJavaLocalRef<jstring> headers = ConvertUTF8ToJavaString( |
59 env, params.extra_headers); | 61 env, params.extra_headers); |
60 | 62 |
61 ScopedJavaLocalRef<jobject> post_data; | 63 ScopedJavaLocalRef<jobject> post_data; |
62 | 64 |
63 int request_id = tab_launched_callbacks_.Add( | 65 int request_id = tab_launched_callbacks_.Add( |
64 new TabLaunchedCallback(callback)); | 66 new TabLaunchedCallback(callback)); |
65 DCHECK_GE(request_id, 1); | 67 DCHECK_GE(request_id, 1); |
66 | 68 |
67 Java_ServiceTabLauncher_launchTab(env, GetApplicationContext(), request_id, | 69 Java_ServiceTabLauncher_launchTab(env, GetApplicationContext(), request_id, |
68 browser_context->IsOffTheRecord(), url, | 70 browser_context->IsOffTheRecord(), url, |
69 disposition, referrer_url, | 71 static_cast<int>(disposition), referrer_url, |
70 params.referrer.policy, headers, post_data); | 72 params.referrer.policy, headers, post_data); |
71 } | 73 } |
72 | 74 |
73 void ServiceTabLauncher::OnTabLaunched(int request_id, | 75 void ServiceTabLauncher::OnTabLaunched(int request_id, |
74 content::WebContents* web_contents) { | 76 content::WebContents* web_contents) { |
75 TabLaunchedCallback* callback = tab_launched_callbacks_.Lookup(request_id); | 77 TabLaunchedCallback* callback = tab_launched_callbacks_.Lookup(request_id); |
76 DCHECK(callback); | 78 DCHECK(callback); |
77 | 79 |
78 if (callback) | 80 if (callback) |
79 callback->Run(web_contents); | 81 callback->Run(web_contents); |
80 | 82 |
81 tab_launched_callbacks_.Remove(request_id); | 83 tab_launched_callbacks_.Remove(request_id); |
82 } | 84 } |
83 | 85 |
84 bool ServiceTabLauncher::Register(JNIEnv* env) { | 86 bool ServiceTabLauncher::Register(JNIEnv* env) { |
85 return RegisterNativesImpl(env); | 87 return RegisterNativesImpl(env); |
86 } | 88 } |
OLD | NEW |