summaryrefslogtreecommitdiffstats
path: root/chrome/browser/dom_distiller
diff options
context:
space:
mode:
authorsunangel@chromium.org <sunangel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-08-13 03:03:57 +0000
committersunangel@chromium.org <sunangel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-08-13 03:07:17 +0000
commitd4b5ac067843e42204271de95b44ac03739c033a (patch)
treec47efa4c809d79ac81a2d054e31c953b51e6276d /chrome/browser/dom_distiller
parent4ea293f71923dd464e237f6ef581df22c625c695 (diff)
downloadchromium_src-d4b5ac067843e42204271de95b44ac03739c033a.zip
chromium_src-d4b5ac067843e42204271de95b44ac03739c033a.tar.gz
chromium_src-d4b5ac067843e42204271de95b44ac03739c033a.tar.bz2
Added GetFormattedUrlFromOriginalDistillerUrl to DomDistillerTabUtils
These changes create support for GetFormattedUrlFromOriginalDistillerUrl, which is necessary for reformatting the original distiller URL for display in the Location Bar. BUG=383630 Review URL: https://codereview.chromium.org/454063003 Cr-Commit-Position: refs/heads/master@{#289166} git-svn-id: svn://svn.chromium.org/chrome/trunk/src@289166 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/dom_distiller')
-rw-r--r--chrome/browser/dom_distiller/tab_utils_android.cc35
1 files changed, 35 insertions, 0 deletions
diff --git a/chrome/browser/dom_distiller/tab_utils_android.cc b/chrome/browser/dom_distiller/tab_utils_android.cc
index 805f7e36..855fba6 100644
--- a/chrome/browser/dom_distiller/tab_utils_android.cc
+++ b/chrome/browser/dom_distiller/tab_utils_android.cc
@@ -6,9 +6,17 @@
#include <string>
+#include "base/android/jni_string.h"
+#include "base/prefs/pref_service.h"
#include "chrome/browser/dom_distiller/tab_utils.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/profiles/profile_manager.h"
+#include "chrome/common/pref_names.h"
#include "content/public/browser/web_contents.h"
+#include "content/public/common/content_constants.h"
#include "jni/DomDistillerTabUtils_jni.h"
+#include "net/base/net_util.h"
+#include "url/gurl.h"
namespace android {
@@ -20,6 +28,33 @@ void DistillCurrentPageAndView(JNIEnv* env,
::DistillCurrentPageAndView(web_contents);
}
+jstring GetFormattedUrlFromOriginalDistillerUrl(JNIEnv* env,
+ jclass clazz,
+ jstring j_url) {
+ GURL url(base::android::ConvertJavaStringToUTF8(env, j_url));
+ Profile* profile = ProfileManager::GetLastUsedProfile();
+ std::string languages; // Empty if Profile cannot be retrieved.
+ if (profile) {
+ languages = profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
+ }
+
+ if (url.spec().length() > content::kMaxURLDisplayChars)
+ url = url.IsStandard() ? url.GetOrigin() : GURL(url.scheme() + ":");
+
+ // Note that we can't unescape spaces here, because if the user copies this
+ // and pastes it into another program, that program may think the URL ends at
+ // the space.
+ return base::android::ConvertUTF16ToJavaString(
+ env,
+ net::FormatUrl(url,
+ languages,
+ net::kFormatUrlOmitAll,
+ net::UnescapeRule::NORMAL,
+ NULL,
+ NULL,
+ NULL)).Release();
+}
+
} // namespace android
bool RegisterDomDistillerTabUtils(JNIEnv* env) {