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

Unified Diff: components/url_formatter/url_formatter_android.cc

Issue 2110543004: Move JNI bindings for url_formatter from chrome to //components/url_formatter (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/url_formatter/url_formatter_android.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/url_formatter/url_formatter_android.cc
diff --git a/components/url_formatter/url_formatter_android.cc b/components/url_formatter/url_formatter_android.cc
new file mode 100644
index 0000000000000000000000000000000000000000..bc2e16cb9f56a9e36196bdcd11e0494984078866
--- /dev/null
+++ b/components/url_formatter/url_formatter_android.cc
@@ -0,0 +1,77 @@
+// Copyright 2016 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 "components/url_formatter/url_formatter_android.h"
+
+#include <string>
+
+#include "base/android/jni_android.h"
+#include "base/android/jni_string.h"
+#include "components/url_formatter/elide_url.h"
+#include "components/url_formatter/url_fixer.h"
+#include "components/url_formatter/url_formatter.h"
+#include "jni/UrlFormatter_jni.h"
+#include "url/gurl.h"
+
+using base::android::JavaParamRef;
+using base::android::ScopedJavaLocalRef;
+
+namespace {
+
+GURL ConvertJavaStringToGURL(JNIEnv* env, jstring url) {
+ return url ? GURL(base::android::ConvertJavaStringToUTF8(env, url)) : GURL();
+}
+
+} // namespace
+
+namespace url_formatter {
+
+namespace android {
+
+static ScopedJavaLocalRef<jstring> FixupUrl(JNIEnv* env,
+ const JavaParamRef<jclass>& clazz,
+ const JavaParamRef<jstring>& url) {
+ DCHECK(url);
+ GURL fixed_url = url_formatter::FixupURL(
+ base::android::ConvertJavaStringToUTF8(env, url), std::string());
+
+ return fixed_url.is_valid()
+ ? base::android::ConvertUTF8ToJavaString(env, fixed_url.spec())
+ : ScopedJavaLocalRef<jstring>();
+}
+
+static ScopedJavaLocalRef<jstring> FormatUrlForDisplay(
+ JNIEnv* env,
+ const JavaParamRef<jclass>& clazz,
+ const JavaParamRef<jstring>& url) {
+ return base::android::ConvertUTF16ToJavaString(
+ env, url_formatter::FormatUrl(ConvertJavaStringToGURL(env, url)));
+}
+
+static ScopedJavaLocalRef<jstring> FormatUrlForSecurityDisplay(
+ JNIEnv* env,
+ const JavaParamRef<jclass>& clazz,
+ const JavaParamRef<jstring>& url) {
+ return base::android::ConvertUTF16ToJavaString(
+ env, url_formatter::FormatUrlForSecurityDisplay(
+ ConvertJavaStringToGURL(env, url)));
+}
+
+static ScopedJavaLocalRef<jstring> FormatUrlForSecurityDisplayOmitScheme(
+ JNIEnv* env,
+ const JavaParamRef<jclass>& clazz,
+ const JavaParamRef<jstring>& url) {
+ return base::android::ConvertUTF16ToJavaString(
+ env, url_formatter::FormatUrlForSecurityDisplay(
+ ConvertJavaStringToGURL(env, url),
+ url_formatter::SchemeDisplay::OMIT_HTTP_AND_HTTPS));
+}
+
+bool RegisterUrlFormatterNatives(JNIEnv* env) {
+ return RegisterNativesImpl(env);
+}
+
+} // namespace android
+
+} // namespace url_formatter
« no previous file with comments | « components/url_formatter/url_formatter_android.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698