Commit e5d5eef4 authored by Xi Han's avatar Xi Han Committed by Commit Bot

New WebAPK Install UI: Add from menu shows the add-to-homescreen dialog.

[2/4]

This CL includes the following UI changes:
When add to homescreen from menu, the add-to-homescreen dialog will show
first.
If user clicks the "Add" button, it triggers the app banner infobar.

Bug: 752338
Change-Id: I93f2c974b20449638d671a963bab13dd3359102a
Reviewed-on: https://chromium-review.googlesource.com/611084
Commit-Queue: Xi Han <hanxi@chromium.org>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Reviewed-by: default avatarPeter Kotwicz <pkotwicz@chromium.org>
Reviewed-by: default avatarYaron Friedman <yfriedman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#496059}
parent dbb3de06
......@@ -127,7 +127,7 @@ public class AddToHomescreenDialog implements AddToHomescreenManager.Observer {
@Override
public void onDismiss(DialogInterface dialog) {
mDialog = null;
mManager.onFinished();
mManager.destroy();
}
});
......@@ -138,8 +138,8 @@ public class AddToHomescreenDialog implements AddToHomescreenManager.Observer {
* Called when the title of the page is available.
*/
@Override
public void onUserTitleAvailable(String title) {
mInput.setEnabled(true);
public void onUserTitleAvailable(String title, boolean isTitleEditable) {
mInput.setEnabled(isTitleEditable);
mInput.setText(title);
}
......
......@@ -20,7 +20,7 @@ public class AddToHomescreenManager {
/** Interface for tracking fetch of add-to-homescreen data. */
public interface Observer {
/** Called when the title of the page is available. */
void onUserTitleAvailable(String title);
void onUserTitleAvailable(String title, boolean isTitleEditable);
/**
* Called once native has finished fetching the homescreen shortcut's data (like the Web
......@@ -75,11 +75,6 @@ public class AddToHomescreenManager {
nativeAddShortcut(mNativeAddToHomescreenManager, userRequestedTitle);
}
@CalledByNative
public void onFinished() {
destroy();
}
/**
* Shows alert to prompt user for name of home screen shortcut.
*/
......@@ -91,8 +86,8 @@ public class AddToHomescreenManager {
}
@CalledByNative
private void onUserTitleAvailable(String title) {
mObserver.onUserTitleAvailable(title);
private void onUserTitleAvailable(String title, boolean isTitleEditable) {
mObserver.onUserTitleAvailable(title, isTitleEditable);
}
@CalledByNative
......
......@@ -49,8 +49,6 @@ public class AddToHomescreenDialogTest {
@Override
public void addShortcut(String userRequestedTitle) {}
@Override
public void onFinished() {}
}
@Before
......
......@@ -153,7 +153,7 @@ public class AddToHomescreenManagerTest {
public void showDialog() {
AddToHomescreenManager.Observer observer = new AddToHomescreenManager.Observer() {
@Override
public void onUserTitleAvailable(String title) {
public void onUserTitleAvailable(String title, boolean isTitleEditable) {
if (TextUtils.isEmpty(mTitle)) {
mTitle = title;
}
......
......@@ -72,6 +72,20 @@ void AddToHomescreenManager::AddShortcut(
data_fetcher_->shortcut_info().user_title = user_title;
RecordAddToHomescreen();
if (is_webapk_compatible_) {
WebApkInstallService* install_service =
WebApkInstallService::Get(web_contents->GetBrowserContext());
if (install_service->IsInstallInProgress(
data_fetcher_->shortcut_info().manifest_url)) {
ShortcutHelper::ShowWebApkInstallInProgressToast();
} else {
CreateInfoBarForWebApk(data_fetcher_->shortcut_info(),
data_fetcher_->primary_icon(),
data_fetcher_->badge_icon());
}
return;
}
ShortcutHelper::AddToLauncherWithSkBitmap(web_contents,
data_fetcher_->shortcut_info(),
data_fetcher_->primary_icon());
......@@ -90,10 +104,11 @@ void AddToHomescreenManager::Start(content::WebContents* web_contents) {
if (ChromeWebApkHost::CanInstallWebApk() &&
InstallableManager::IsContentSecure(web_contents)) {
check_webapk_compatible = true;
} else {
ShowDialog();
}
JNIEnv* env = base::android::AttachCurrentThread();
Java_AddToHomescreenManager_showDialog(env, java_ref_);
data_fetcher_ = base::MakeUnique<AddToHomescreenDataFetcher>(
web_contents, ShortcutHelper::GetIdealHomescreenIconSizeInPx(),
ShortcutHelper::GetMinimumHomescreenIconSizeInPx(),
......@@ -105,11 +120,6 @@ void AddToHomescreenManager::Start(content::WebContents* web_contents) {
AddToHomescreenManager::~AddToHomescreenManager() {}
void AddToHomescreenManager::ShowDialog() {
JNIEnv* env = base::android::AttachCurrentThread();
Java_AddToHomescreenManager_showDialog(env, java_ref_);
}
void AddToHomescreenManager::RecordAddToHomescreen() {
// Record that the shortcut has been added, so no banners will be shown
// for this app.
......@@ -127,39 +137,21 @@ void AddToHomescreenManager::RecordAddToHomescreen() {
void AddToHomescreenManager::OnDidDetermineWebApkCompatibility(
bool is_webapk_compatible) {
is_webapk_compatible_ = is_webapk_compatible;
if (!is_webapk_compatible)
ShowDialog();
}
void AddToHomescreenManager::OnUserTitleAvailable(
const base::string16& user_title) {
if (is_webapk_compatible_)
return;
JNIEnv* env = base::android::AttachCurrentThread();
ScopedJavaLocalRef<jstring> j_user_title =
base::android::ConvertUTF16ToJavaString(env, user_title);
Java_AddToHomescreenManager_onUserTitleAvailable(env,
java_ref_,
j_user_title);
Java_AddToHomescreenManager_onUserTitleAvailable(
env, java_ref_, j_user_title,
!is_webapk_compatible_ /* isTitleEditable */);
}
void AddToHomescreenManager::OnDataAvailable(const ShortcutInfo& info,
const SkBitmap& primary_icon,
const SkBitmap& badge_icon) {
if (is_webapk_compatible_) {
WebApkInstallService* install_service =
WebApkInstallService::Get(
data_fetcher_->web_contents()->GetBrowserContext());
if (install_service->IsInstallInProgress(info.manifest_url))
ShortcutHelper::ShowWebApkInstallInProgressToast();
else
CreateInfoBarForWebApk(info, primary_icon, badge_icon);
JNIEnv* env = base::android::AttachCurrentThread();
Java_AddToHomescreenManager_onFinished(env, java_ref_);
return;
}
ScopedJavaLocalRef<jobject> java_bitmap;
if (!primary_icon.drawsNothing())
java_bitmap = gfx::ConvertToJavaBitmap(&primary_icon);
......
......@@ -41,9 +41,6 @@ class AddToHomescreenManager : public AddToHomescreenDataFetcher::Observer {
private:
~AddToHomescreenManager() override;
// Shows alert to prompt user for name of home screen shortcut.
void ShowDialog();
// Called only when the AddToHomescreenDataFetcher has retrieved all of the
// data needed to install a WebAPK.
void CreateInfoBarForWebApk(const ShortcutInfo& info,
......
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