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

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

Issue 454063003: Added GetFormattedUrlFromOriginalDistillerUrl to DomDistillerTabUtils (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: moved comment Created 6 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 | Annotate | Revision Log
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/dom_distiller/DomDistillerTabUtils.java ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
10 #include "base/prefs/pref_service.h"
9 #include "chrome/browser/dom_distiller/tab_utils.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"
10 #include "content/public/browser/web_contents.h" 15 #include "content/public/browser/web_contents.h"
16 #include "content/public/common/content_constants.h"
11 #include "jni/DomDistillerTabUtils_jni.h" 17 #include "jni/DomDistillerTabUtils_jni.h"
18 #include "net/base/net_util.h"
19 #include "url/gurl.h"
12 20
13 namespace android { 21 namespace android {
14 22
15 void DistillCurrentPageAndView(JNIEnv* env, 23 void DistillCurrentPageAndView(JNIEnv* env,
16 jclass clazz, 24 jclass clazz,
17 jobject j_web_contents) { 25 jobject j_web_contents) {
18 content::WebContents* web_contents = 26 content::WebContents* web_contents =
19 content::WebContents::FromJavaWebContents(j_web_contents); 27 content::WebContents::FromJavaWebContents(j_web_contents);
20 ::DistillCurrentPageAndView(web_contents); 28 ::DistillCurrentPageAndView(web_contents);
21 } 29 }
22 30
31 jstring GetFormattedUrlFromOriginalDistillerUrl(JNIEnv* env,
32 jclass clazz,
33 jstring j_url) {
34 GURL url(base::android::ConvertJavaStringToUTF8(env, j_url));
35 Profile* profile = ProfileManager::GetLastUsedProfile();
36 std::string languages; // Empty if Profile cannot be retrieved.
37 if (profile) {
38 languages = profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
39 }
40
41 // Note that we can't unescape spaces here, because if the user copies this
nyquist 2014/08/11 20:35:48 I believe this is about net::FormatUrl, not the pa
sunangel 2014/08/12 01:54:39 Done.
42 // and pastes it into another program, that program may think the URL ends at
43 // the space.
44 if (url.spec().length() > content::kMaxURLDisplayChars)
45 url = url.IsStandard() ? url.GetOrigin() : GURL(url.scheme() + ":");
46
47 base::string16 formatted_url = net::FormatUrl(url,
48 languages,
49 net::kFormatUrlOmitAll,
50 net::UnescapeRule::NORMAL,
51 NULL,
52 NULL,
53 NULL);
54 base::android::ScopedJavaLocalRef<jstring> j_formatted_url =
nyquist 2014/08/11 20:35:48 Is it possible to just return base::android::Conve
sunangel 2014/08/12 01:54:39 Done.
55 base::android::ConvertUTF16ToJavaString(env, formatted_url);
56 return j_formatted_url.Release();
57 }
58
23 } // namespace android 59 } // namespace android
24 60
25 bool RegisterDomDistillerTabUtils(JNIEnv* env) { 61 bool RegisterDomDistillerTabUtils(JNIEnv* env) {
26 return android::RegisterNativesImpl(env); 62 return android::RegisterNativesImpl(env);
27 } 63 }
OLDNEW
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/dom_distiller/DomDistillerTabUtils.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698