Chromium Code Reviews| 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; | 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.Context; | 12 import android.content.Context; |
| 13 import android.content.Intent; | 13 import android.content.Intent; |
| 14 import android.content.res.Configuration; | 14 import android.content.res.Configuration; |
| 15 import android.graphics.Bitmap; | 15 import android.graphics.Bitmap; |
| 16 import android.graphics.Color; | 16 import android.graphics.Color; |
| 17 import android.graphics.Rect; | 17 import android.graphics.Rect; |
| 18 import android.graphics.drawable.ColorDrawable; | 18 import android.graphics.drawable.ColorDrawable; |
| 19 import android.graphics.drawable.Drawable; | 19 import android.graphics.drawable.Drawable; |
| 20 import android.net.Uri; | 20 import android.net.Uri; |
| 21 import android.os.AsyncTask; | |
| 21 import android.os.Build; | 22 import android.os.Build; |
| 22 import android.os.Bundle; | 23 import android.os.Bundle; |
| 23 import android.os.Looper; | 24 import android.os.Looper; |
| 24 import android.os.MessageQueue; | 25 import android.os.MessageQueue; |
| 25 import android.os.SystemClock; | 26 import android.os.SystemClock; |
| 26 import android.support.v7.app.AlertDialog; | 27 import android.support.v7.app.AlertDialog; |
| 27 import android.util.DisplayMetrics; | 28 import android.util.DisplayMetrics; |
| 28 import android.view.Menu; | 29 import android.view.Menu; |
| 29 import android.view.MenuItem; | 30 import android.view.MenuItem; |
| 30 import android.view.View; | 31 import android.view.View; |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 116 import org.chromium.chrome.browser.util.FeatureUtilities; | 117 import org.chromium.chrome.browser.util.FeatureUtilities; |
| 117 import org.chromium.chrome.browser.webapps.AddToHomescreenDialog; | 118 import org.chromium.chrome.browser.webapps.AddToHomescreenDialog; |
| 118 import org.chromium.chrome.browser.widget.ControlContainer; | 119 import org.chromium.chrome.browser.widget.ControlContainer; |
| 119 import org.chromium.components.bookmarks.BookmarkId; | 120 import org.chromium.components.bookmarks.BookmarkId; |
| 120 import org.chromium.content.browser.ContentVideoView; | 121 import org.chromium.content.browser.ContentVideoView; |
| 121 import org.chromium.content.browser.ContentViewCore; | 122 import org.chromium.content.browser.ContentViewCore; |
| 122 import org.chromium.content.common.ContentSwitches; | 123 import org.chromium.content.common.ContentSwitches; |
| 123 import org.chromium.content_public.browser.ContentBitmapCallback; | 124 import org.chromium.content_public.browser.ContentBitmapCallback; |
| 124 import org.chromium.content_public.browser.LoadUrlParams; | 125 import org.chromium.content_public.browser.LoadUrlParams; |
| 125 import org.chromium.content_public.browser.WebContents; | 126 import org.chromium.content_public.browser.WebContents; |
| 126 import org.chromium.content_public.browser.readback_types.ReadbackResponse; | |
| 127 import org.chromium.policy.CombinedPolicyProvider.PolicyChangeListener; | 127 import org.chromium.policy.CombinedPolicyProvider.PolicyChangeListener; |
| 128 import org.chromium.printing.PrintManagerDelegateImpl; | 128 import org.chromium.printing.PrintManagerDelegateImpl; |
| 129 import org.chromium.printing.PrintingController; | 129 import org.chromium.printing.PrintingController; |
| 130 import org.chromium.ui.base.ActivityWindowAndroid; | 130 import org.chromium.ui.base.ActivityWindowAndroid; |
| 131 import org.chromium.ui.base.DeviceFormFactor; | 131 import org.chromium.ui.base.DeviceFormFactor; |
| 132 import org.chromium.ui.base.PageTransition; | 132 import org.chromium.ui.base.PageTransition; |
| 133 import org.chromium.ui.base.WindowAndroid; | 133 import org.chromium.ui.base.WindowAndroid; |
| 134 | 134 |
| 135 import java.util.ArrayList; | 135 import java.util.ArrayList; |
| 136 import java.util.List; | 136 import java.util.List; |
| (...skipping 810 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 947 return super.onOptionsItemSelected(item); | 947 return super.onOptionsItemSelected(item); |
| 948 } | 948 } |
| 949 | 949 |
| 950 /** | 950 /** |
| 951 * Triggered when the share menu item is selected. | 951 * Triggered when the share menu item is selected. |
| 952 * This creates and shows a share intent picker dialog or starts a share int ent directly. | 952 * This creates and shows a share intent picker dialog or starts a share int ent directly. |
| 953 * @param shareDirectly Whether it should share directly with the activity t hat was most | 953 * @param shareDirectly Whether it should share directly with the activity t hat was most |
| 954 * recently used to share. | 954 * recently used to share. |
| 955 * @param isIncognito Whether currentTab is incognito. | 955 * @param isIncognito Whether currentTab is incognito. |
| 956 */ | 956 */ |
| 957 public void onShareMenuItemSelected(final boolean shareDirectly, boolean isI ncognito) { | 957 public void onShareMenuItemSelected(final boolean shareDirectly, boolean isI ncognito) { |
|
nyquist
2016/07/14 17:36:32
Was there no test you needed to update for this?
I
ssid
2016/07/19 18:32:57
Done.
| |
| 958 final Tab currentTab = getActivityTab(); | 958 final Tab currentTab = getActivityTab(); |
| 959 if (currentTab == null) return; | 959 if (currentTab == null) return; |
| 960 | 960 |
| 961 final Activity mainActivity = this; | 961 final Activity mainActivity = this; |
| 962 ContentBitmapCallback callback = new ContentBitmapCallback() { | |
| 963 @Override | |
| 964 public void onFinishGetBitmap(Bitmap bitmap, int response) { | |
| 965 // Check whether this page is an offline page, and use i ts online URL if so. | |
| 966 String url = currentTab.getOfflinePageOriginalUrl(); | |
| 967 RecordHistogram.recordBooleanHistogram( | |
| 968 "OfflinePages.SharedPageWasOffline", url != null ); | |
| 969 | 962 |
| 970 // If there is no entry in the offline pages DB for this tab, use the tab's | 963 // Check whether this page is an offline page, and use its online URL if so. |
| 971 // URL directly. | 964 String url = currentTab.getOfflinePageOriginalUrl(); |
| 972 if (url == null) url = currentTab.getUrl(); | 965 RecordHistogram.recordBooleanHistogram("OfflinePages.SharedPageWasOfflin e", url != null); |
| 966 // If there is no entry in the offline pages DB for this tab, use the ta b's URL directly. | |
| 967 if (url == null) url = currentTab.getUrl(); | |
| 973 | 968 |
| 974 ShareHelper.share( | 969 if (shareDirectly) { |
| 975 shareDirectly, mainActivity, currentTab.getTitle (), url, bitmap); | 970 RecordUserAction.record("MobileMenuDirectShare"); |
| 976 if (shareDirectly) { | 971 } else { |
| 977 RecordUserAction.record("MobileMenuDirectShare"); | 972 RecordUserAction.record("MobileMenuShare"); |
| 978 } else { | 973 } |
| 979 RecordUserAction.record("MobileMenuShare"); | 974 |
| 980 } | |
| 981 } | |
| 982 }; | |
| 983 if (isIncognito || currentTab.getWebContents() == null) { | 975 if (isIncognito || currentTab.getWebContents() == null) { |
| 984 callback.onFinishGetBitmap(null, ReadbackResponse.SURFACE_UNAVAILABL E); | 976 ShareHelper.share(shareDirectly, mainActivity, currentTab.getTitle() , url, null); |
| 985 } else { | 977 } else { |
| 986 currentTab.getWebContents().getContentBitmapAsync( | 978 // Share an empty uuid in place of screenshot file. |
| 987 Bitmap.Config.ARGB_8888, 1.f, EMPTY_RECT, callback); | 979 final String fileName = String.valueOf(System.currentTimeMillis()); |
|
nyquist
2016/07/14 17:36:32
Will the user ever see this filename? If not, mayb
ssid
2016/07/19 18:32:57
The uri wouldn't overlap with anything because the
nyquist
2016/07/29 23:45:27
That'd be OK too. I was just thinking about if you
ssid
2016/08/03 22:33:40
The description says it returns the difference bet
| |
| 980 final Uri uuid = BlockingFileProvider.getContentUriForFile(mainActiv ity, fileName); | |
| 981 ShareHelper.share(shareDirectly, mainActivity, currentTab.getTitle() , url, uuid); | |
| 982 | |
| 983 // Start screenshot capture async and notify the provider when it is ready. | |
| 984 final ContentBitmapCallback callback = new ContentBitmapCallback() { | |
| 985 @Override | |
| 986 public void onFinishGetBitmap(Bitmap bitmap, int response) { | |
| 987 ShareHelper.onScreenshotReady(fileName, bitmap, mainActivity ); | |
|
nyquist
2016/07/14 17:36:32
Is mainActivity guaranteed to be alive here, or wi
ssid
2016/07/19 18:32:57
The check at the end of onScreenshotready should t
| |
| 988 } | |
| 989 }; | |
| 990 new AsyncTask<Void, Void, Void>() { | |
| 991 @Override | |
| 992 protected Void doInBackground(Void... params) { | |
| 993 currentTab.getWebContents().getContentBitmapAsync( | |
|
nyquist
2016/07/14 17:36:32
Is it guaranteed that getWebContents() does not re
ssid
2016/07/19 18:32:57
added a check
| |
| 994 Bitmap.Config.ARGB_8888, 1.f, EMPTY_RECT, callback); | |
| 995 return null; | |
| 996 } | |
| 997 }.execute(); | |
| 988 } | 998 } |
| 989 } | 999 } |
| 990 | 1000 |
| 991 /** | 1001 /** |
| 992 * @return Whether the activity is in overview mode. | 1002 * @return Whether the activity is in overview mode. |
| 993 */ | 1003 */ |
| 994 public boolean isInOverviewMode() { | 1004 public boolean isInOverviewMode() { |
| 995 return false; | 1005 return false; |
| 996 } | 1006 } |
| 997 | 1007 |
| (...skipping 747 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1745 "Android.MultiWindowMode.IsTabletScreenWidthBelow600", | 1755 "Android.MultiWindowMode.IsTabletScreenWidthBelow600", |
| 1746 mScreenWidthDp < DeviceFormFactor.MINIMUM_TABLET_WIDTH_DP); | 1756 mScreenWidthDp < DeviceFormFactor.MINIMUM_TABLET_WIDTH_DP); |
| 1747 | 1757 |
| 1748 if (mScreenWidthDp < DeviceFormFactor.MINIMUM_TABLET_WIDTH_DP) { | 1758 if (mScreenWidthDp < DeviceFormFactor.MINIMUM_TABLET_WIDTH_DP) { |
| 1749 RecordHistogram.recordLinearCountHistogram( | 1759 RecordHistogram.recordLinearCountHistogram( |
| 1750 "Android.MultiWindowMode.TabletScreenWidth", mScreenWidthDp, 1, | 1760 "Android.MultiWindowMode.TabletScreenWidth", mScreenWidthDp, 1, |
| 1751 DeviceFormFactor.MINIMUM_TABLET_WIDTH_DP, 50); | 1761 DeviceFormFactor.MINIMUM_TABLET_WIDTH_DP, 50); |
| 1752 } | 1762 } |
| 1753 } | 1763 } |
| 1754 } | 1764 } |
| OLD | NEW |