Commit b225ae56 authored by mlamouri's avatar mlamouri Committed by Commit bot

Use Web Manifest when creating a shortcut on Chrome Android.

This is using the short_name and the name set in the Manifest.

BUG=366145

Review URL: https://codereview.chromium.org/573073002

Cr-Commit-Position: refs/heads/master@{#295256}
parent ed971f12
......@@ -23,6 +23,7 @@
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/common/frame_navigate_params.h"
#include "content/public/common/manifest.h"
#include "jni/ShortcutHelper_jni.h"
#include "ui/gfx/android/java_bitmap.h"
#include "ui/gfx/codec/png_codec.h"
......@@ -46,7 +47,8 @@ ShortcutHelper::ShortcutHelper(JNIEnv* env,
: WebContentsObserver(web_contents),
java_ref_(env, obj),
url_(web_contents->GetURL()),
web_app_capable_(WebApplicationInfo::MOBILE_CAPABLE_UNSPECIFIED) {
web_app_capable_(WebApplicationInfo::MOBILE_CAPABLE_UNSPECIFIED),
weak_ptr_factory_(this) {
}
void ShortcutHelper::Initialize() {
......@@ -71,6 +73,25 @@ void ShortcutHelper::OnDidGetWebApplicationInfo(
title_ = web_app_info.title.empty() ? web_contents()->GetTitle()
: web_app_info.title;
web_contents()->GetManifest(base::Bind(&ShortcutHelper::OnDidGetManifest,
weak_ptr_factory_.GetWeakPtr()));
}
void ShortcutHelper::OnDidGetManifest(const content::Manifest& manifest) {
// Set the title based on the manifest value, if any.
if (!manifest.short_name.is_null())
title_ = manifest.short_name.string();
else if (!manifest.name.is_null())
title_ = manifest.name.string();
// Set the url based on the manifest value, if any.
if (manifest.start_url.is_valid())
url_ = manifest.start_url;
// The ShortcutHelper is now able to notify its Java counterpart that it is
// initialized. OnInitialized method is not conceptually part of getting the
// manifest data but it happens that the initialization is finalized when
// these data are available.
JNIEnv* env = base::android::AttachCurrentThread();
ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env);
ScopedJavaLocalRef<jstring> j_title =
......
......@@ -16,6 +16,7 @@
namespace content {
class WebContents;
struct Manifest;
} // namespace content
namespace IPC {
......@@ -47,6 +48,9 @@ class ShortcutHelper : public content::WebContentsObserver {
// IPC message received when the initialization is finished.
void OnDidGetWebApplicationInfo(const WebApplicationInfo& web_app_info);
// Callback run when the Manifest is ready to be used.
void OnDidGetManifest(const content::Manifest& manifest);
// Adds a shortcut to the current URL to the Android home screen.
void AddShortcut(JNIEnv* env,
jobject obj,
......@@ -84,6 +88,8 @@ class ShortcutHelper : public content::WebContentsObserver {
favicon_base::FaviconRawBitmapResult icon_;
base::CancelableTaskTracker cancelable_task_tracker_;
base::WeakPtrFactory<ShortcutHelper> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(ShortcutHelper);
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment