Bug 808636 - Make urltext red on about:blocked. r=margaret

This commit is contained in:
Wes Johnston 2013-08-19 15:14:37 -07:00
parent b12bff2373
commit a4a77666a9
5 changed files with 54 additions and 11 deletions

View File

@ -126,6 +126,7 @@ public class BrowserToolbar extends GeckoRelativeLayout
private static final int FORWARD_ANIMATION_DURATION = 450;
private final ForegroundColorSpan mUrlColor;
private final ForegroundColorSpan mBlockedColor;
private final ForegroundColorSpan mDomainColor;
private final ForegroundColorSpan mPrivateDomainColor;
@ -182,6 +183,7 @@ public class BrowserToolbar extends GeckoRelativeLayout
Resources res = getResources();
mUrlColor = new ForegroundColorSpan(res.getColor(R.color.url_bar_urltext));
mBlockedColor = new ForegroundColorSpan(res.getColor(R.color.url_bar_blockedtext));
mDomainColor = new ForegroundColorSpan(res.getColor(R.color.url_bar_domaintext));
mPrivateDomainColor = new ForegroundColorSpan(res.getColor(R.color.url_bar_domaintext_private));
@ -469,6 +471,11 @@ public class BrowserToolbar extends GeckoRelativeLayout
updateTitle();
}
break;
case LOADED:
if (Tabs.getInstance().isSelectedTab(tab)) {
updateTitle();
}
break;
case RESTORED:
// TabCount fixup after OOM
case SELECTED:
@ -941,6 +948,15 @@ public class BrowserToolbar extends GeckoRelativeLayout
return;
}
// Show the about:blocked page title in red, regardless of prefs
if (tab.getErrorType() == Tab.ErrorType.BLOCKED) {
String title = tab.getDisplayTitle();
SpannableStringBuilder builder = new SpannableStringBuilder(title);
builder.setSpan(mBlockedColor, 0, title.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
setTitle(builder);
return;
}
// If the pref to show the URL isn't set, just use the tab's display title.
if (!mShowUrl || url == null) {
setTitle(tab.getDisplayTitle());

View File

@ -53,7 +53,6 @@ public class Tab {
private boolean mBookmark;
private boolean mReadingListItem;
private long mFaviconLoadId;
private String mDocumentURI;
private String mContentType;
private boolean mHasTouchListeners;
private ZoomConstraints mZoomConstraints;
@ -66,6 +65,7 @@ public class Tab {
private boolean mDesktopMode;
private boolean mEnteringReaderMode;
private Context mAppContext;
private ErrorType mErrorType = ErrorType.NONE;
private static final int MAX_HISTORY_LIST_SIZE = 50;
public static final int STATE_DELAYED = 0;
@ -73,6 +73,13 @@ public class Tab {
public static final int STATE_SUCCESS = 2;
public static final int STATE_ERROR = 3;
public enum ErrorType {
CERT_ERROR, // Pages with certificate problems
BLOCKED, // Pages blocked for phishing or malware warnings
NET_ERROR, // All other types of error
NONE // Non error pages
}
public Tab(Context context, int id, String url, boolean external, int parentId, String title) {
mAppContext = context.getApplicationContext();
mId = id;
@ -96,7 +103,6 @@ public class Tab {
mBookmark = false;
mReadingListItem = false;
mFaviconLoadId = 0;
mDocumentURI = "";
mContentType = "";
mZoomConstraints = new ZoomConstraints(false);
mPluginViews = new ArrayList<View>();
@ -260,12 +266,23 @@ public class Tab {
mUserSearch = userSearch;
}
public void setDocumentURI(String documentURI) {
mDocumentURI = documentURI;
public void setErrorType(String type) {
if ("blocked".equals(type))
setErrorType(ErrorType.BLOCKED);
else if ("certerror".equals(type))
setErrorType(ErrorType.CERT_ERROR);
else if ("neterror".equals(type))
setErrorType(ErrorType.NET_ERROR);
else
setErrorType(ErrorType.NONE);
}
public String getDocumentURI() {
return mDocumentURI;
public void setErrorType(ErrorType type) {
mErrorType = type;
}
public ErrorType getErrorType() {
return mErrorType;
}
public void setContentType(String contentType) {
@ -574,7 +591,6 @@ public class Tab {
updateURL(uri);
updateUserSearch(message.getString("userSearch"));
setDocumentURI(message.getString("documentURI"));
mBaseDomain = message.optString("baseDomain");
if (message.getBoolean("sameDocument")) {
// We can get a location change event for the same document with an anchor tag
@ -592,6 +608,7 @@ public class Tab {
setZoomConstraints(new ZoomConstraints(true));
setHasTouchListeners(false);
setBackgroundColor(getBackgroundColorForUrl(uri));
setErrorType(ErrorType.NONE);
Tabs.getInstance().notifyListeners(this, Tabs.TabEvents.LOCATION_CHANGE, uri);
}

View File

@ -444,6 +444,7 @@ public class Tabs implements GeckoEventListener {
// Default to white if no color is given
tab.setBackgroundColor(Color.WHITE);
}
tab.setErrorType(message.optString("errorType"));
notifyListeners(tab, Tabs.TabEvents.LOADED);
} else if (event.equals("DOMTitleChanged")) {
tab.updateTitle(message.getString("title"));

View File

@ -89,6 +89,7 @@
<color name="url_bar_urltext">#A6A6A6</color>
<color name="url_bar_domaintext">#000</color>
<color name="url_bar_domaintext_private">#FFF</color>
<color name="url_bar_blockedtext">#b14646</color>
</resources>

View File

@ -3337,17 +3337,26 @@ Tab.prototype = {
// Ignore. Catching and ignoring exceptions here ensures that Talos succeeds.
}
let docURI = target.documentURI;
let errorType = "";
if (docURI.startsWith("about:certerror"))
errorType = "certerror";
else if (docURI.startsWith("about:blocked"))
errorType = "blocked"
else if (docURI.startsWith("about:neterror"))
errorType = "neterror";
sendMessageToJava({
type: "DOMContentLoaded",
tabID: this.id,
bgColor: backgroundColor
bgColor: backgroundColor,
errorType: errorType
});
// Attach a listener to watch for "click" events bubbling up from error
// pages and other similar page. This lets us fix bugs like 401575 which
// require error page UI to do privileged things, without letting error
// pages have any privilege themselves.
let docURI = target.documentURI;
if (docURI.startsWith("about:certerror") || docURI.startsWith("about:blocked")) {
this.browser.addEventListener("click", ErrorPageEventHandler, true);
let listener = function() {
@ -3631,7 +3640,6 @@ Tab.prototype = {
fixedURI = URIFixup.createExposableURI(aLocationURI);
} catch (ex) { }
let documentURI = contentWin.document.documentURIObject.spec;
let contentType = contentWin.document.contentType;
// If fixedURI matches browser.lastURI, we assume this isn't a real location
@ -3648,6 +3656,7 @@ Tab.prototype = {
this.shouldShowPluginDoorhanger = true;
this.clickToPlayPluginsActivated = false;
// Borrowed from desktop Firefox: http://mxr.mozilla.org/mozilla-central/source/browser/base/content/urlbarBindings.xml#174
let documentURI = contentWin.document.documentURIObject.spec
let matchedURL = documentURI.match(/^((?:[a-z]+:\/\/)?(?:[^\/]+@)?)(.+?)(?::\d+)?(?:\/|$)/);
let baseDomain = "";
if (matchedURL) {
@ -3669,7 +3678,6 @@ Tab.prototype = {
tabID: this.id,
uri: fixedURI.spec,
userSearch: this.userSearch || "",
documentURI: documentURI,
baseDomain: baseDomain,
contentType: (contentType ? contentType : ""),
sameDocument: sameDocument