mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1035131 - Factor out methods to encode/decode user-entered:// URLs (r=mfinkle)
This commit is contained in:
parent
cd0884981b
commit
4d4b03e37f
@ -196,7 +196,7 @@ abstract class HomeFragment extends Fragment {
|
||||
|
||||
// Some pinned site items have "user-entered" urls. URLs entered in the PinSiteDialog are wrapped in
|
||||
// a special URI until we can get a valid URL. If the url is a user-entered url, decode the URL before loading it.
|
||||
final Tab newTab = Tabs.getInstance().loadUrl(decodeUserEnteredUrl(url), flags);
|
||||
final Tab newTab = Tabs.getInstance().loadUrl(StringUtils.decodeUserEnteredUrl(url), flags);
|
||||
final int newTabId = newTab.getId(); // We don't want to hold a reference to the Tab.
|
||||
|
||||
final String message = isPrivate ?
|
||||
@ -275,22 +275,6 @@ abstract class HomeFragment extends Fragment {
|
||||
return mCanLoadHint;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a url with a user-entered scheme, extract the
|
||||
* scheme-specific component. For e.g, given "user-entered://www.google.com",
|
||||
* this method returns "//www.google.com". If the passed url
|
||||
* does not have a user-entered scheme, the same url will be returned.
|
||||
*
|
||||
* @param url to be decoded
|
||||
* @return url component entered by user
|
||||
*/
|
||||
public static String decodeUserEnteredUrl(String url) {
|
||||
Uri uri = Uri.parse(url);
|
||||
if ("user-entered".equals(uri.getScheme())) {
|
||||
return uri.getSchemeSpecificPart();
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
protected abstract void load();
|
||||
|
||||
|
@ -10,6 +10,7 @@ import java.util.EnumSet;
|
||||
import org.mozilla.gecko.R;
|
||||
import org.mozilla.gecko.db.BrowserDB.FilterFlags;
|
||||
import org.mozilla.gecko.db.BrowserDB.URLColumns;
|
||||
import org.mozilla.gecko.util.StringUtils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
@ -114,7 +115,7 @@ class PinSiteDialog extends DialogFragment {
|
||||
// a special URI until we can get a valid URL for this bookmark.
|
||||
final String text = mSearch.getText().toString().trim();
|
||||
if (!TextUtils.isEmpty(text)) {
|
||||
final String url = TopSitesPanel.encodeUserEnteredUrl(text);
|
||||
final String url = StringUtils.encodeUserEnteredUrl(text);
|
||||
mOnSiteSelectedListener.onSiteSelected(url, text);
|
||||
dismiss();
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ import org.mozilla.gecko.ThumbnailHelper;
|
||||
import org.mozilla.gecko.db.BrowserContract.TopSites;
|
||||
import org.mozilla.gecko.db.TopSitesCursorWrapper;
|
||||
import org.mozilla.gecko.home.HomePager.OnUrlOpenListener;
|
||||
import org.mozilla.gecko.util.StringUtils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
@ -106,7 +107,7 @@ public class TopSitesGridView extends GridView {
|
||||
TopSitesGridItemView item = (TopSitesGridItemView) view;
|
||||
|
||||
// Decode "user-entered" URLs before loading them.
|
||||
String url = HomeFragment.decodeUserEnteredUrl(item.getUrl());
|
||||
String url = StringUtils.decodeUserEnteredUrl(item.getUrl());
|
||||
int type = item.getType();
|
||||
|
||||
// If the url is empty, the user can pin a site.
|
||||
|
@ -356,7 +356,8 @@ public class TopSitesPanel extends HomeFragment {
|
||||
|
||||
if (itemId == R.id.top_sites_edit) {
|
||||
// Decode "user-entered" URLs before showing them.
|
||||
mEditPinnedSiteListener.onEditPinnedSite(info.position, decodeUserEnteredUrl(info.url));
|
||||
mEditPinnedSiteListener.onEditPinnedSite(info.position,
|
||||
StringUtils.decodeUserEnteredUrl(info.url));
|
||||
|
||||
Telemetry.sendUIEvent(TelemetryContract.Event.EDIT);
|
||||
return true;
|
||||
@ -378,10 +379,6 @@ public class TopSitesPanel extends HomeFragment {
|
||||
ThreadUtils.reduceGeckoPriority(PRIORITY_RESET_TIMEOUT);
|
||||
}
|
||||
|
||||
static String encodeUserEnteredUrl(String url) {
|
||||
return Uri.fromParts("user-entered", url, null).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Listener for editing pinned sites.
|
||||
*/
|
||||
|
@ -160,4 +160,25 @@ public class StringUtils {
|
||||
return !("about".equals(scheme) || "chrome".equals(scheme) ||
|
||||
"file".equals(scheme) || "resource".equals(scheme));
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a url with a user-entered scheme, extract the
|
||||
* scheme-specific component. For e.g, given "user-entered://www.google.com",
|
||||
* this method returns "//www.google.com". If the passed url
|
||||
* does not have a user-entered scheme, the same url will be returned.
|
||||
*
|
||||
* @param url to be decoded
|
||||
* @return url component entered by user
|
||||
*/
|
||||
public static String decodeUserEnteredUrl(String url) {
|
||||
Uri uri = Uri.parse(url);
|
||||
if ("user-entered".equals(uri.getScheme())) {
|
||||
return uri.getSchemeSpecificPart();
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
public static String encodeUserEnteredUrl(String url) {
|
||||
return Uri.fromParts("user-entered", url, null).toString();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user