Index: chrome/browser/android/service_tab_creator.cc |
diff --git a/chrome/browser/android/service_tab_creator.cc b/chrome/browser/android/service_tab_creator.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..8794a830d32236c237c4d5aa261e0fc45dae6001 |
--- /dev/null |
+++ b/chrome/browser/android/service_tab_creator.cc |
@@ -0,0 +1,49 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/android/service_tab_creator.h" |
+ |
+#include "base/android/jni_string.h" |
+#include "base/callback.h" |
+#include "content/public/browser/page_navigator.h" |
+#include "jni/ServiceTabCreator_jni.h" |
+ |
+using base::android::AttachCurrentThread; |
+using base::android::ConvertUTF8ToJavaString; |
+using base::android::GetApplicationContext; |
+ |
+// static |
+ServiceTabCreator* ServiceTabCreator::GetInstance() { |
+ return Singleton<ServiceTabCreator>::get(); |
+} |
+ |
+ServiceTabCreator::ServiceTabCreator() { |
+ java_object_.Reset( |
+ Java_ServiceTabCreator_create( |
+ AttachCurrentThread(), |
+ reinterpret_cast<intptr_t>(this), |
+ GetApplicationContext())); |
+} |
+ |
+ServiceTabCreator::~ServiceTabCreator() {} |
+ |
+void ServiceTabCreator::CreateTab( |
+ content::BrowserContext* browser_context, |
+ const content::OpenURLParams& params, |
+ base::Callback<void(content::WebContents*)> callback) { |
+ JNIEnv* env = AttachCurrentThread(); |
+ ScopedJavaLocalRef<jstring> url = ConvertUTF8ToJavaString( |
+ env, params.url.spec()); |
+ |
+ Java_ServiceTabCreator_createTab(env, java_object_.obj(), url.obj()); |
+ |
+ // 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. |
+} |
+ |
+bool ServiceTabCreator::RegisterServiceTabCreator(JNIEnv* env) { |
+ return RegisterNativesImpl(env); |
+} |