| OLD | NEW |
| 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.customtabs; | 5 package org.chromium.chrome.browser.customtabs; |
| 6 | 6 |
| 7 import android.content.Intent; | 7 import android.content.Intent; |
| 8 import android.content.pm.PackageManager; | 8 import android.content.pm.PackageManager; |
| 9 import android.content.pm.ResolveInfo; | 9 import android.content.pm.ResolveInfo; |
| 10 import android.net.Uri; | 10 import android.net.Uri; |
| 11 import android.os.AsyncTask; | 11 import android.os.AsyncTask; |
| 12 import android.view.Menu; | 12 import android.view.Menu; |
| 13 import android.view.MenuItem; | 13 import android.view.MenuItem; |
| 14 | 14 |
| 15 import org.chromium.base.BuildInfo; | 15 import org.chromium.base.BuildInfo; |
| 16 import org.chromium.base.VisibleForTesting; | 16 import org.chromium.base.VisibleForTesting; |
| 17 import org.chromium.chrome.R; | 17 import org.chromium.chrome.R; |
| 18 import org.chromium.chrome.browser.ChromeActivity; | 18 import org.chromium.chrome.browser.ChromeActivity; |
| 19 import org.chromium.chrome.browser.ChromeFeatureList; |
| 19 import org.chromium.chrome.browser.appmenu.AppMenuPropertiesDelegate; | 20 import org.chromium.chrome.browser.appmenu.AppMenuPropertiesDelegate; |
| 20 import org.chromium.chrome.browser.share.ShareHelper; | 21 import org.chromium.chrome.browser.share.ShareHelper; |
| 21 import org.chromium.chrome.browser.tab.Tab; | 22 import org.chromium.chrome.browser.tab.Tab; |
| 22 | 23 |
| 23 import java.util.HashMap; | 24 import java.util.HashMap; |
| 24 import java.util.List; | 25 import java.util.List; |
| 25 import java.util.Map; | 26 import java.util.Map; |
| 26 import java.util.concurrent.ExecutionException; | 27 import java.util.concurrent.ExecutionException; |
| 27 | 28 |
| 28 /** | 29 /** |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 MenuItem bookmarkItem = menu.findItem(R.id.bookmark_this_page_id
); | 98 MenuItem bookmarkItem = menu.findItem(R.id.bookmark_this_page_id
); |
| 98 updateBookmarkMenuItem(bookmarkItem, currentTab); | 99 updateBookmarkMenuItem(bookmarkItem, currentTab); |
| 99 } else { | 100 } else { |
| 100 // Because we have custom logic for laying out the icon row, the
bookmark icon must | 101 // Because we have custom logic for laying out the icon row, the
bookmark icon must |
| 101 // be explicitly removed instead of just made invisible. | 102 // be explicitly removed instead of just made invisible. |
| 102 menu.findItem(R.id.icon_row_menu_id).getSubMenu().removeItem( | 103 menu.findItem(R.id.icon_row_menu_id).getSubMenu().removeItem( |
| 103 R.id.bookmark_this_page_id); | 104 R.id.bookmark_this_page_id); |
| 104 } | 105 } |
| 105 | 106 |
| 106 MenuItem openInChromeItem = menu.findItem(R.id.open_in_browser_id); | 107 MenuItem openInChromeItem = menu.findItem(R.id.open_in_browser_id); |
| 107 try { | 108 MenuItem readItLaterItem = menu.findItem(R.id.read_it_later_id); |
| 108 openInChromeItem.setTitle(mDefaultBrowserFetcher.get()); | 109 if (ChromeFeatureList.isEnabled("ReadItLaterInMenu")) { |
| 109 } catch (InterruptedException | ExecutionException e) { | 110 // In the read-it-later experiment, Chrome will be the only brow
ser to open the link |
| 110 openInChromeItem.setTitle( | 111 openInChromeItem.setTitle(R.string.menu_open_in_chrome); |
| 111 mActivity.getString(R.string.menu_open_in_product_defaul
t)); | 112 } else { |
| 113 readItLaterItem.setVisible(false); |
| 114 try { |
| 115 openInChromeItem.setTitle(mDefaultBrowserFetcher.get()); |
| 116 } catch (InterruptedException | ExecutionException e) { |
| 117 openInChromeItem.setTitle( |
| 118 mActivity.getString(R.string.menu_open_in_product_de
fault)); |
| 119 } |
| 112 } | 120 } |
| 113 | 121 |
| 114 // Add custom menu items. Make sure they are only added once. | 122 // Add custom menu items. Make sure they are only added once. |
| 115 if (!mIsCustomEntryAdded) { | 123 if (!mIsCustomEntryAdded) { |
| 116 mIsCustomEntryAdded = true; | 124 mIsCustomEntryAdded = true; |
| 117 for (int i = 0; i < mMenuEntries.size(); i++) { | 125 for (int i = 0; i < mMenuEntries.size(); i++) { |
| 118 MenuItem item = menu.add(0, 0, 1, mMenuEntries.get(i)); | 126 MenuItem item = menu.add(0, 0, 1, mMenuEntries.get(i)); |
| 119 mItemToIndexMap.put(item, i); | 127 mItemToIndexMap.put(item, i); |
| 120 } | 128 } |
| 121 } | 129 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 143 * the same title, a random one will be returned. This method is for testing
purpose _only_. | 151 * the same title, a random one will be returned. This method is for testing
purpose _only_. |
| 144 */ | 152 */ |
| 145 @VisibleForTesting | 153 @VisibleForTesting |
| 146 MenuItem getMenuItemForTitle(String title) { | 154 MenuItem getMenuItemForTitle(String title) { |
| 147 for (MenuItem item : mItemToIndexMap.keySet()) { | 155 for (MenuItem item : mItemToIndexMap.keySet()) { |
| 148 if (item.getTitle().equals(title)) return item; | 156 if (item.getTitle().equals(title)) return item; |
| 149 } | 157 } |
| 150 return null; | 158 return null; |
| 151 } | 159 } |
| 152 } | 160 } |
| OLD | NEW |