Commit e33136ac authored by Evan Stade's avatar Evan Stade Committed by Chromium LUCI CQ

Remove some Chrome dependencies from AddToHomescreenInstaller.

Bug: 1164069
Change-Id: I0abf13d932f72f3ed2b3f387afe3edc5578c9c89
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2637930
Commit-Queue: Evan Stade <estade@chromium.org>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#846139}
parent ca0b40a8
...@@ -13,8 +13,8 @@ import org.chromium.base.Log; ...@@ -13,8 +13,8 @@ import org.chromium.base.Log;
import org.chromium.base.PackageUtils; import org.chromium.base.PackageUtils;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.chrome.browser.banners.AppData; import org.chromium.chrome.browser.banners.AppData;
import org.chromium.chrome.browser.tab.Tab; import org.chromium.content_public.browser.WebContents;
import org.chromium.chrome.browser.tab.TabUtils; import org.chromium.ui.base.WindowAndroid;
/** /**
* Provides functionality related to native Android apps for its C++ counterpart, * Provides functionality related to native Android apps for its C++ counterpart,
...@@ -24,7 +24,7 @@ class AddToHomescreenInstaller { ...@@ -24,7 +24,7 @@ class AddToHomescreenInstaller {
private static final String TAG = "AddToHomescreen"; private static final String TAG = "AddToHomescreen";
@CalledByNative @CalledByNative
private static boolean installOrOpenNativeApp(Tab tab, AppData appData) { private static boolean installOrOpenNativeApp(WebContents webContents, AppData appData) {
Context context = ContextUtils.getApplicationContext(); Context context = ContextUtils.getApplicationContext();
Intent launchIntent; Intent launchIntent;
if (PackageUtils.isPackageInstalled(context, appData.packageName())) { if (PackageUtils.isPackageInstalled(context, appData.packageName())) {
...@@ -33,14 +33,20 @@ class AddToHomescreenInstaller { ...@@ -33,14 +33,20 @@ class AddToHomescreenInstaller {
} else { } else {
launchIntent = appData.installIntent(); launchIntent = appData.installIntent();
} }
if (launchIntent != null && TabUtils.getActivity(tab) != null) {
if (launchIntent != null) {
WindowAndroid window = webContents.getTopLevelNativeWindow();
Context intentLauncher = window == null ? null : window.getActivity().get();
if (intentLauncher != null) {
try { try {
TabUtils.getActivity(tab).startActivity(launchIntent); intentLauncher.startActivity(launchIntent);
} catch (ActivityNotFoundException e) { } catch (ActivityNotFoundException e) {
Log.e(TAG, "Failed to install or open app : %s!", appData.packageName(), e); Log.e(TAG, "Failed to install or open app : %s!", appData.packageName(), e);
return false; return false;
} }
} }
}
return true; return true;
} }
} }
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include "base/callback.h" #include "base/callback.h"
#include "chrome/android/chrome_jni_headers/AddToHomescreenInstaller_jni.h" #include "chrome/android/chrome_jni_headers/AddToHomescreenInstaller_jni.h"
#include "chrome/browser/android/tab_android.h"
#include "components/webapps/browser/webapps_client.h" #include "components/webapps/browser/webapps_client.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
...@@ -47,15 +46,9 @@ void AddToHomescreenInstaller::InstallOrOpenNativeApp( ...@@ -47,15 +46,9 @@ void AddToHomescreenInstaller::InstallOrOpenNativeApp(
const base::RepeatingCallback<void(Event, const AddToHomescreenParams&)>& const base::RepeatingCallback<void(Event, const AddToHomescreenParams&)>&
event_callback) { event_callback) {
JNIEnv* env = base::android::AttachCurrentThread(); JNIEnv* env = base::android::AttachCurrentThread();
TabAndroid* tab = TabAndroid::FromWebContents(web_contents);
if (tab == nullptr) {
event_callback.Run(Event::INSTALL_FAILED, params);
return;
}
bool was_successful = Java_AddToHomescreenInstaller_installOrOpenNativeApp( bool was_successful = Java_AddToHomescreenInstaller_installOrOpenNativeApp(
env, tab->GetJavaObject(), params.native_app_data); env, web_contents->GetJavaWebContents(), params.native_app_data);
event_callback.Run(was_successful ? Event::NATIVE_INSTALL_OR_OPEN_SUCCEEDED event_callback.Run(was_successful ? Event::NATIVE_INSTALL_OR_OPEN_SUCCEEDED
: Event::NATIVE_INSTALL_OR_OPEN_FAILED, : Event::NATIVE_INSTALL_OR_OPEN_FAILED,
params); params);
......
...@@ -45,6 +45,8 @@ class AddToHomescreenInstaller { ...@@ -45,6 +45,8 @@ class AddToHomescreenInstaller {
const AddToHomescreenParams& params, const AddToHomescreenParams& params,
const base::RepeatingCallback<void(Event, const AddToHomescreenParams&)>& const base::RepeatingCallback<void(Event, const AddToHomescreenParams&)>&
event_callback); event_callback);
static void InstallShortcut(content::WebContents* web_contents,
const AddToHomescreenParams& params);
static void InstallWebApk(content::WebContents* web_contents, static void InstallWebApk(content::WebContents* web_contents,
const AddToHomescreenParams& params); const AddToHomescreenParams& params);
......
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