Bug 932208 - Part 2: Do not allow non-shareable links to be shared. r=mfinkle

This commit is contained in:
Michael Comella 2014-06-09 09:58:35 -07:00
Родитель ad6d0c7ed7
Коммит 8944acbd6f
4 изменённых файлов: 20 добавлений и 6 удалений

Просмотреть файл

@ -2315,10 +2315,9 @@ abstract public class BrowserApp extends GeckoApp
}
// Disable share menuitem for about:, chrome:, file:, and resource: URIs
String scheme = Uri.parse(url).getScheme();
share.setVisible(!GeckoProfile.get(this).inGuestMode());
share.setEnabled(!(scheme.equals("about") || scheme.equals("chrome") ||
scheme.equals("file") || scheme.equals("resource")));
final boolean inGuestMode = GeckoProfile.get(this).inGuestMode();
share.setVisible(!inGuestMode);
share.setEnabled(StringUtils.isShareableUrl(url) && !inGuestMode);
// NOTE: Use MenuUtils.safeSetEnabled because some actions might
// be on the BrowserToolbar context menu

Просмотреть файл

@ -21,6 +21,7 @@ import org.mozilla.gecko.db.BrowserDB;
import org.mozilla.gecko.favicons.Favicons;
import org.mozilla.gecko.home.TopSitesGridView.TopSitesGridContextMenuInfo;
import org.mozilla.gecko.util.Clipboard;
import org.mozilla.gecko.util.StringUtils;
import org.mozilla.gecko.util.ThreadUtils;
import org.mozilla.gecko.util.UiAsyncTask;
import org.mozilla.gecko.widget.ButtonToast;
@ -42,7 +43,7 @@ import android.widget.Toast;
/**
* HomeFragment is an empty fragment that can be added to the HomePager.
* Subclasses can add their own views.
* Subclasses can add their own views.
*/
abstract class HomeFragment extends Fragment {
// Log Tag.
@ -110,7 +111,9 @@ abstract class HomeFragment extends Fragment {
menu.findItem(R.id.home_remove).setVisible(false);
}
menu.findItem(R.id.home_share).setVisible(!GeckoProfile.get(getActivity()).inGuestMode());
if (!StringUtils.isShareableUrl(info.url) || GeckoProfile.get(getActivity()).inGuestMode()) {
menu.findItem(R.id.home_share).setVisible(false);
}
final boolean canOpenInReader = (info.display == Combined.DISPLAY_READER);
menu.findItem(R.id.home_open_in_reader).setVisible(canOpenInReader);

Просмотреть файл

@ -10,6 +10,7 @@ import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
import org.mozilla.gecko.GeckoProfile;
import org.mozilla.gecko.R;
import org.mozilla.gecko.Telemetry;
import org.mozilla.gecko.TelemetryContract;
@ -23,6 +24,7 @@ import org.mozilla.gecko.home.HomePager.OnUrlOpenListener;
import org.mozilla.gecko.home.PinSiteDialog.OnSiteSelectedListener;
import org.mozilla.gecko.home.TopSitesGridView.OnEditPinnedSiteListener;
import org.mozilla.gecko.home.TopSitesGridView.TopSitesGridContextMenuInfo;
import org.mozilla.gecko.util.StringUtils;
import org.mozilla.gecko.util.ThreadUtils;
import android.app.Activity;
@ -296,6 +298,10 @@ public class TopSitesPanel extends HomeFragment {
menu.findItem(R.id.top_sites_pin).setVisible(false);
menu.findItem(R.id.top_sites_unpin).setVisible(false);
}
if (!StringUtils.isShareableUrl(info.url) || GeckoProfile.get(getActivity()).inGuestMode()) {
menu.findItem(R.id.home_share).setVisible(false);
}
}
@Override

Просмотреть файл

@ -154,4 +154,10 @@ public class StringUtils {
return url.substring(FILTER_URL_PREFIX.length());
}
public static boolean isShareableUrl(final String url) {
final String scheme = Uri.parse(url).getScheme();
return !(scheme.equals("about") || scheme.equals("chrome") ||
scheme.equals("file") || scheme.equals("resource"));
}
}