Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(48)

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/ChromeActivity.java

Issue 2707993003: [Android]: Hide add-to-homescreen app menu item when WebAPK is installed (Closed)
Patch Set: Add new state for 'Add to Homescreen' Menu item Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser; 5 package org.chromium.chrome.browser;
6 6
7 import android.annotation.SuppressLint; 7 import android.annotation.SuppressLint;
8 import android.annotation.TargetApi; 8 import android.annotation.TargetApi;
9 import android.app.Activity; 9 import android.app.Activity;
10 import android.app.SearchManager; 10 import android.app.SearchManager;
11 import android.app.assist.AssistContent; 11 import android.app.assist.AssistContent;
12 import android.content.ActivityNotFoundException;
12 import android.content.Context; 13 import android.content.Context;
13 import android.content.Intent; 14 import android.content.Intent;
14 import android.content.res.Configuration; 15 import android.content.res.Configuration;
15 import android.graphics.Bitmap; 16 import android.graphics.Bitmap;
16 import android.graphics.Color; 17 import android.graphics.Color;
17 import android.graphics.Rect; 18 import android.graphics.Rect;
18 import android.graphics.drawable.ColorDrawable; 19 import android.graphics.drawable.ColorDrawable;
19 import android.graphics.drawable.Drawable; 20 import android.graphics.drawable.Drawable;
20 import android.net.Uri; 21 import android.net.Uri;
21 import android.os.Build; 22 import android.os.Build;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 import org.chromium.chrome.browser.gsa.GSAAccountChangeListener; 81 import org.chromium.chrome.browser.gsa.GSAAccountChangeListener;
81 import org.chromium.chrome.browser.gsa.GSAState; 82 import org.chromium.chrome.browser.gsa.GSAState;
82 import org.chromium.chrome.browser.help.HelpAndFeedback; 83 import org.chromium.chrome.browser.help.HelpAndFeedback;
83 import org.chromium.chrome.browser.history.HistoryManagerUtils; 84 import org.chromium.chrome.browser.history.HistoryManagerUtils;
84 import org.chromium.chrome.browser.infobar.InfoBarContainer; 85 import org.chromium.chrome.browser.infobar.InfoBarContainer;
85 import org.chromium.chrome.browser.init.AsyncInitializationActivity; 86 import org.chromium.chrome.browser.init.AsyncInitializationActivity;
86 import org.chromium.chrome.browser.metrics.LaunchMetrics; 87 import org.chromium.chrome.browser.metrics.LaunchMetrics;
87 import org.chromium.chrome.browser.metrics.StartupMetrics; 88 import org.chromium.chrome.browser.metrics.StartupMetrics;
88 import org.chromium.chrome.browser.metrics.UmaSessionStats; 89 import org.chromium.chrome.browser.metrics.UmaSessionStats;
89 import org.chromium.chrome.browser.metrics.UmaUtils; 90 import org.chromium.chrome.browser.metrics.UmaUtils;
91 import org.chromium.chrome.browser.metrics.WebApkUma;
90 import org.chromium.chrome.browser.multiwindow.MultiWindowUtils; 92 import org.chromium.chrome.browser.multiwindow.MultiWindowUtils;
91 import org.chromium.chrome.browser.net.spdyproxy.DataReductionProxySettings; 93 import org.chromium.chrome.browser.net.spdyproxy.DataReductionProxySettings;
92 import org.chromium.chrome.browser.nfc.BeamController; 94 import org.chromium.chrome.browser.nfc.BeamController;
93 import org.chromium.chrome.browser.nfc.BeamProvider; 95 import org.chromium.chrome.browser.nfc.BeamProvider;
94 import org.chromium.chrome.browser.ntp.NewTabPage; 96 import org.chromium.chrome.browser.ntp.NewTabPage;
95 import org.chromium.chrome.browser.ntp.NewTabPageUma; 97 import org.chromium.chrome.browser.ntp.NewTabPageUma;
96 import org.chromium.chrome.browser.offlinepages.OfflinePageBridge; 98 import org.chromium.chrome.browser.offlinepages.OfflinePageBridge;
97 import org.chromium.chrome.browser.offlinepages.OfflinePageUtils; 99 import org.chromium.chrome.browser.offlinepages.OfflinePageUtils;
98 import org.chromium.chrome.browser.omaha.UpdateMenuItemHelper; 100 import org.chromium.chrome.browser.omaha.UpdateMenuItemHelper;
99 import org.chromium.chrome.browser.pageinfo.WebsiteSettingsPopup; 101 import org.chromium.chrome.browser.pageinfo.WebsiteSettingsPopup;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 import org.chromium.content_public.browser.readback_types.ReadbackResponse; 144 import org.chromium.content_public.browser.readback_types.ReadbackResponse;
143 import org.chromium.policy.CombinedPolicyProvider; 145 import org.chromium.policy.CombinedPolicyProvider;
144 import org.chromium.policy.CombinedPolicyProvider.PolicyChangeListener; 146 import org.chromium.policy.CombinedPolicyProvider.PolicyChangeListener;
145 import org.chromium.printing.PrintManagerDelegateImpl; 147 import org.chromium.printing.PrintManagerDelegateImpl;
146 import org.chromium.printing.PrintingController; 148 import org.chromium.printing.PrintingController;
147 import org.chromium.printing.PrintingControllerImpl; 149 import org.chromium.printing.PrintingControllerImpl;
148 import org.chromium.ui.base.ActivityWindowAndroid; 150 import org.chromium.ui.base.ActivityWindowAndroid;
149 import org.chromium.ui.base.DeviceFormFactor; 151 import org.chromium.ui.base.DeviceFormFactor;
150 import org.chromium.ui.base.PageTransition; 152 import org.chromium.ui.base.PageTransition;
151 import org.chromium.ui.base.WindowAndroid; 153 import org.chromium.ui.base.WindowAndroid;
154 import org.chromium.ui.widget.Toast;
155 import org.chromium.webapk.lib.client.WebApkValidator;
152 156
153 import java.util.ArrayList; 157 import java.util.ArrayList;
154 import java.util.HashSet; 158 import java.util.HashSet;
155 import java.util.List; 159 import java.util.List;
156 import java.util.Set; 160 import java.util.Set;
157 import java.util.concurrent.TimeUnit; 161 import java.util.concurrent.TimeUnit;
158 162
159 import javax.annotation.Nullable; 163 import javax.annotation.Nullable;
160 164
161 /** 165 /**
(...skipping 1607 matching lines...) Expand 10 before | Expand all | Expand 10 after
1769 && PrefServiceBridge.getInstance().isPrintingEnabled()) { 1773 && PrefServiceBridge.getInstance().isPrintingEnabled()) {
1770 printingController.startPrint(new TabPrinter(currentTab), 1774 printingController.startPrint(new TabPrinter(currentTab),
1771 new PrintManagerDelegateImpl(this)); 1775 new PrintManagerDelegateImpl(this));
1772 RecordUserAction.record("MobileMenuPrint"); 1776 RecordUserAction.record("MobileMenuPrint");
1773 } 1777 }
1774 } else if (id == R.id.add_to_homescreen_id) { 1778 } else if (id == R.id.add_to_homescreen_id) {
1775 AddToHomescreenManager addToHomescreenManager = 1779 AddToHomescreenManager addToHomescreenManager =
1776 new AddToHomescreenManager(this, currentTab); 1780 new AddToHomescreenManager(this, currentTab);
1777 addToHomescreenManager.start(); 1781 addToHomescreenManager.start();
1778 RecordUserAction.record("MobileMenuAddToHomescreen"); 1782 RecordUserAction.record("MobileMenuAddToHomescreen");
1783 } else if (id == R.id.open_webapk_id) {
1784 boolean launchSuccess = openWebApkFromUrl(currentTab.getUrl());
1785 if (!launchSuccess) {
1786 Toast.makeText(this, R.string.open_webapk_failed, Toast.LENGTH_S HORT).show();
1787 }
1779 } else if (id == R.id.request_desktop_site_id) { 1788 } else if (id == R.id.request_desktop_site_id) {
1780 final boolean reloadOnChange = !currentTab.isNativePage(); 1789 final boolean reloadOnChange = !currentTab.isNativePage();
1781 final boolean usingDesktopUserAgent = currentTab.getUseDesktopUserAg ent(); 1790 final boolean usingDesktopUserAgent = currentTab.getUseDesktopUserAg ent();
1782 currentTab.setUseDesktopUserAgent(!usingDesktopUserAgent, reloadOnCh ange); 1791 currentTab.setUseDesktopUserAgent(!usingDesktopUserAgent, reloadOnCh ange);
1783 RecordUserAction.record("MobileMenuRequestDesktopSite"); 1792 RecordUserAction.record("MobileMenuRequestDesktopSite");
1784 } else if (id == R.id.reader_mode_prefs_id) { 1793 } else if (id == R.id.reader_mode_prefs_id) {
1785 if (currentTab.getWebContents() != null) { 1794 if (currentTab.getWebContents() != null) {
1786 RecordUserAction.record("DomDistiller_DistilledPagePrefsOpened") ; 1795 RecordUserAction.record("DomDistiller_DistilledPagePrefsOpened") ;
1787 AlertDialog.Builder builder = 1796 AlertDialog.Builder builder =
1788 new AlertDialog.Builder(this, R.style.AlertDialogTheme); 1797 new AlertDialog.Builder(this, R.style.AlertDialogTheme);
1789 builder.setView(DistilledPagePrefsView.create(this)); 1798 builder.setView(DistilledPagePrefsView.create(this));
1790 builder.show(); 1799 builder.show();
1791 } 1800 }
1792 } else if (id == R.id.help_id) { 1801 } else if (id == R.id.help_id) {
1793 startHelpAndFeedback(currentTab, "MobileMenuFeedback"); 1802 startHelpAndFeedback(currentTab, "MobileMenuFeedback");
1794 } else { 1803 } else {
1795 return false; 1804 return false;
1796 } 1805 }
1797 return true; 1806 return true;
1798 } 1807 }
1799 1808
1800 /** 1809 /**
1810 * Tries to open the WebAPK related to the |url|. Returns true if successful .
1811 *
1812 * @param url The URL that
1813 * @return true if the WwbAPK was opened successfully.
1814 */
1815 private boolean openWebApkFromUrl(String url) {
1816 String packageName = WebApkValidator.queryWebApkPackage(this, url);
1817 Intent launchIntent = getPackageManager().getLaunchIntentForPackage(pack ageName);
1818 if (launchIntent != null) {
nyquist 2017/02/28 17:57:17 I think I'd flip this around (i.e. == null). That
gonzalon 2017/02/28 18:05:09 Done.
1819 try {
1820 startActivity(launchIntent);
1821 RecordUserAction.record("MobileMenuOpenWebApk");
1822 WebApkUma.recordWebApkOpenAttempt(WebApkUma.WEBAPK_OPEN_LAUNCH_S UCCESS);
1823 } catch (ActivityNotFoundException e) {
1824 WebApkUma.recordWebApkOpenAttempt(WebApkUma.WEBAPK_OPEN_ACTIVITY _NOT_FOUND);
1825 return false;
1826 }
1827 } else {
1828 WebApkUma.recordWebApkOpenAttempt(WebApkUma.WEBAPK_OPEN_NO_LAUNCH_IN TENT);
1829 return false;
1830 }
1831 return true;
nyquist 2017/02/28 17:57:17 I think I'd move this up to the end of the try-sta
gonzalon 2017/02/28 18:05:09 Done.
1832 }
1833
1834 /**
1801 * Shows HelpAndFeedback and records the user action as well. 1835 * Shows HelpAndFeedback and records the user action as well.
1802 * @param currentTab The tab that the user is currently on. 1836 * @param currentTab The tab that the user is currently on.
1803 * @param recordAction The user action to record. 1837 * @param recordAction The user action to record.
1804 */ 1838 */
1805 public void startHelpAndFeedback(Tab currentTab, String recordAction) { 1839 public void startHelpAndFeedback(Tab currentTab, String recordAction) {
1806 // Since reading back the compositor is asynchronous, we need to do the readback 1840 // Since reading back the compositor is asynchronous, we need to do the readback
1807 // before starting the GoogleHelp. 1841 // before starting the GoogleHelp.
1808 String helpContextId = HelpAndFeedback.getHelpContextIdFromUrl( 1842 String helpContextId = HelpAndFeedback.getHelpContextIdFromUrl(
1809 this, currentTab.getUrl(), getCurrentTabModel().isIncognito()); 1843 this, currentTab.getUrl(), getCurrentTabModel().isIncognito());
1810 HelpAndFeedback.getInstance(this) 1844 HelpAndFeedback.getInstance(this)
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
2020 "Android.MultiWindowMode.IsTabletScreenWidthBelow600", 2054 "Android.MultiWindowMode.IsTabletScreenWidthBelow600",
2021 mScreenWidthDp < DeviceFormFactor.MINIMUM_TABLET_WIDTH_DP); 2055 mScreenWidthDp < DeviceFormFactor.MINIMUM_TABLET_WIDTH_DP);
2022 2056
2023 if (mScreenWidthDp < DeviceFormFactor.MINIMUM_TABLET_WIDTH_DP) { 2057 if (mScreenWidthDp < DeviceFormFactor.MINIMUM_TABLET_WIDTH_DP) {
2024 RecordHistogram.recordLinearCountHistogram( 2058 RecordHistogram.recordLinearCountHistogram(
2025 "Android.MultiWindowMode.TabletScreenWidth", mScreenWidthDp, 1, 2059 "Android.MultiWindowMode.TabletScreenWidth", mScreenWidthDp, 1,
2026 DeviceFormFactor.MINIMUM_TABLET_WIDTH_DP, 50); 2060 DeviceFormFactor.MINIMUM_TABLET_WIDTH_DP, 50);
2027 } 2061 }
2028 } 2062 }
2029 } 2063 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698