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

Side by Side Diff: chrome/browser/dom_distiller/tab_utils_android.cc

Issue 1288183004: jni_generator: Make all object-returning natives return ScopedJavaLocalRef. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nontrivial cases Created 5 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 unified diff | Download patch
OLDNEW
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
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 jstring GetFormattedUrlFromOriginalDistillerUrl(JNIEnv* env, 43 ScopedJavaLocalRef<jstring> GetFormattedUrlFromOriginalDistillerUrl(
44 jclass clazz, 44 JNIEnv* env,
45 jstring j_url) { 45 jclass clazz,
46 jstring j_url) {
46 GURL url(base::android::ConvertJavaStringToUTF8(env, j_url)); 47 GURL url(base::android::ConvertJavaStringToUTF8(env, j_url));
47 Profile* profile = ProfileManager::GetLastUsedProfile(); 48 Profile* profile = ProfileManager::GetLastUsedProfile();
48 std::string languages; // Empty if Profile cannot be retrieved. 49 std::string languages; // Empty if Profile cannot be retrieved.
49 if (profile) { 50 if (profile) {
50 languages = profile->GetPrefs()->GetString(prefs::kAcceptLanguages); 51 languages = profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
51 } 52 }
52 53
53 if (url.spec().length() > content::kMaxURLDisplayChars) 54 if (url.spec().length() > content::kMaxURLDisplayChars)
54 url = url.IsStandard() ? url.GetOrigin() : GURL(url.scheme() + ":"); 55 url = url.IsStandard() ? url.GetOrigin() : GURL(url.scheme() + ":");
55 56
56 // Note that we can't unescape spaces here, because if the user copies this 57 // Note that we can't unescape spaces here, because if the user copies this
57 // and pastes it into another program, that program may think the URL ends at 58 // and pastes it into another program, that program may think the URL ends at
58 // the space. 59 // the space.
59 return base::android::ConvertUTF16ToJavaString( 60 return base::android::ConvertUTF16ToJavaString(
60 env, url_formatter::FormatUrl( 61 env, url_formatter::FormatUrl(
61 url, languages, url_formatter::kFormatUrlOmitAll, 62 url, languages, url_formatter::kFormatUrlOmitAll,
62 net::UnescapeRule::NORMAL, nullptr, nullptr, nullptr)) 63 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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698