Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / dom_distiller / tab_utils_android.cc
blob83598cbe5bbbc90baa77c4a624117607c26604d7
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 "content/public/browser/web_contents.h"
16 #include "content/public/common/content_constants.h"
17 #include "jni/DomDistillerTabUtils_jni.h"
18 #include "net/base/net_util.h"
19 #include "url/gurl.h"
21 namespace android {
23 void DistillCurrentPageAndView(JNIEnv* env,
24 jclass clazz,
25 jobject j_web_contents) {
26 content::WebContents* web_contents =
27 content::WebContents::FromJavaWebContents(j_web_contents);
28 ::DistillCurrentPageAndView(web_contents);
31 void DistillAndView(JNIEnv* env,
32 jclass clazz,
33 jobject j_source_web_contents,
34 jobject j_destination_web_contents) {
35 content::WebContents* source_web_contents =
36 content::WebContents::FromJavaWebContents(j_source_web_contents);
37 content::WebContents* destination_web_contents =
38 content::WebContents::FromJavaWebContents(j_destination_web_contents);
39 ::DistillAndView(source_web_contents, destination_web_contents);
42 jstring GetFormattedUrlFromOriginalDistillerUrl(JNIEnv* env,
43 jclass clazz,
44 jstring j_url) {
45 GURL url(base::android::ConvertJavaStringToUTF8(env, j_url));
46 Profile* profile = ProfileManager::GetLastUsedProfile();
47 std::string languages; // Empty if Profile cannot be retrieved.
48 if (profile) {
49 languages = profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
52 if (url.spec().length() > content::kMaxURLDisplayChars)
53 url = url.IsStandard() ? url.GetOrigin() : GURL(url.scheme() + ":");
55 // Note that we can't unescape spaces here, because if the user copies this
56 // and pastes it into another program, that program may think the URL ends at
57 // the space.
58 return base::android::ConvertUTF16ToJavaString(
59 env,
60 net::FormatUrl(url,
61 languages,
62 net::kFormatUrlOmitAll,
63 net::UnescapeRule::NORMAL,
64 NULL,
65 NULL,
66 NULL)).Release();
69 } // namespace android
71 bool RegisterDomDistillerTabUtils(JNIEnv* env) {
72 return android::RegisterNativesImpl(env);