OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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/dom_distiller/tab_utils_android.h" | 5 #include "chrome/browser/dom_distiller/tab_utils_android.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/android/jni_string.h" | 9 #include "base/android/jni_string.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 jclass clazz, | 33 jclass clazz, |
34 jobject j_source_web_contents, | 34 jobject j_source_web_contents, |
35 jobject j_destination_web_contents) { | 35 jobject j_destination_web_contents) { |
36 content::WebContents* source_web_contents = | 36 content::WebContents* source_web_contents = |
37 content::WebContents::FromJavaWebContents(j_source_web_contents); | 37 content::WebContents::FromJavaWebContents(j_source_web_contents); |
38 content::WebContents* destination_web_contents = | 38 content::WebContents* destination_web_contents = |
39 content::WebContents::FromJavaWebContents(j_destination_web_contents); | 39 content::WebContents::FromJavaWebContents(j_destination_web_contents); |
40 ::DistillAndView(source_web_contents, destination_web_contents); | 40 ::DistillAndView(source_web_contents, destination_web_contents); |
41 } | 41 } |
42 | 42 |
43 ScopedJavaLocalRef<jstring> GetFormattedUrlFromOriginalDistillerUrl( | 43 jstring GetFormattedUrlFromOriginalDistillerUrl(JNIEnv* env, |
44 JNIEnv* env, | 44 jclass clazz, |
45 jclass clazz, | 45 jstring j_url) { |
46 jstring j_url) { | |
47 GURL url(base::android::ConvertJavaStringToUTF8(env, j_url)); | 46 GURL url(base::android::ConvertJavaStringToUTF8(env, j_url)); |
48 Profile* profile = ProfileManager::GetLastUsedProfile(); | 47 Profile* profile = ProfileManager::GetLastUsedProfile(); |
49 std::string languages; // Empty if Profile cannot be retrieved. | 48 std::string languages; // Empty if Profile cannot be retrieved. |
50 if (profile) { | 49 if (profile) { |
51 languages = profile->GetPrefs()->GetString(prefs::kAcceptLanguages); | 50 languages = profile->GetPrefs()->GetString(prefs::kAcceptLanguages); |
52 } | 51 } |
53 | 52 |
54 if (url.spec().length() > content::kMaxURLDisplayChars) | 53 if (url.spec().length() > content::kMaxURLDisplayChars) |
55 url = url.IsStandard() ? url.GetOrigin() : GURL(url.scheme() + ":"); | 54 url = url.IsStandard() ? url.GetOrigin() : GURL(url.scheme() + ":"); |
56 | 55 |
57 // Note that we can't unescape spaces here, because if the user copies this | 56 // 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 | 57 // and pastes it into another program, that program may think the URL ends at |
59 // the space. | 58 // the space. |
60 return base::android::ConvertUTF16ToJavaString( | 59 return base::android::ConvertUTF16ToJavaString( |
61 env, url_formatter::FormatUrl( | 60 env, url_formatter::FormatUrl( |
62 url, languages, url_formatter::kFormatUrlOmitAll, | 61 url, languages, url_formatter::kFormatUrlOmitAll, |
63 net::UnescapeRule::NORMAL, nullptr, nullptr, nullptr)); | 62 net::UnescapeRule::NORMAL, nullptr, nullptr, nullptr)) |
| 63 .Release(); |
64 } | 64 } |
65 | 65 |
66 } // namespace android | 66 } // namespace android |
67 | 67 |
68 bool RegisterDomDistillerTabUtils(JNIEnv* env) { | 68 bool RegisterDomDistillerTabUtils(JNIEnv* env) { |
69 return android::RegisterNativesImpl(env); | 69 return android::RegisterNativesImpl(env); |
70 } | 70 } |
OLD | NEW |