Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / dom_distiller / tab_utils_android.cc
blobb54fc7561802e210c668d7c175b837822e3a4703
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/dom_distiller/tab_utils_android.h"
7 #include <string>
9 #include "base/android/jni_string.h"
10 #include "base/prefs/pref_service.h"
11 #include "chrome/browser/dom_distiller/tab_utils.h"
12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/profiles/profile_manager.h"
14 #include "chrome/common/pref_names.h"
15 #include "components/url_formatter/url_formatter.h"
16 #include "content/public/browser/web_contents.h"
17 #include "content/public/common/content_constants.h"
18 #include "jni/DomDistillerTabUtils_jni.h"
19 #include "net/base/net_util.h"
20 #include "url/gurl.h"
22 namespace android {
24 void DistillCurrentPageAndView(JNIEnv* env,
25 const JavaParamRef<jclass>& clazz,
26 const JavaParamRef<jobject>& j_web_contents) {
27 content::WebContents* web_contents =
28 content::WebContents::FromJavaWebContents(j_web_contents);
29 ::DistillCurrentPageAndView(web_contents);
32 void DistillAndView(JNIEnv* env,
33 const JavaParamRef<jclass>& clazz,
34 const JavaParamRef<jobject>& j_source_web_contents,
35 const JavaParamRef<jobject>& j_destination_web_contents) {
36 content::WebContents* source_web_contents =
37 content::WebContents::FromJavaWebContents(j_source_web_contents);
38 content::WebContents* destination_web_contents =
39 content::WebContents::FromJavaWebContents(j_destination_web_contents);
40 ::DistillAndView(source_web_contents, destination_web_contents);
43 ScopedJavaLocalRef<jstring> GetFormattedUrlFromOriginalDistillerUrl(
44 JNIEnv* env,
45 const JavaParamRef<jclass>& clazz,
46 const JavaParamRef<jstring>& j_url) {
47 GURL url(base::android::ConvertJavaStringToUTF8(env, j_url));
48 Profile* profile = ProfileManager::GetLastUsedProfile();
49 std::string languages; // Empty if Profile cannot be retrieved.
50 if (profile) {
51 languages = profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
54 if (url.spec().length() > content::kMaxURLDisplayChars)
55 url = url.IsStandard() ? url.GetOrigin() : GURL(url.scheme() + ":");
57 // Note that we can't unescape spaces here, because if the user copies this
58 // and pastes it into another program, that program may think the URL ends at
59 // the space.
60 return base::android::ConvertUTF16ToJavaString(
61 env, url_formatter::FormatUrl(
62 url, languages, url_formatter::kFormatUrlOmitAll,
63 net::UnescapeRule::NORMAL, nullptr, nullptr, nullptr));
66 } // namespace android
68 bool RegisterDomDistillerTabUtils(JNIEnv* env) {
69 return android::RegisterNativesImpl(env);