Bug 808636 - Make urltext red on about:blocked. r=margaret
authorWes Johnston <wjohnston@mozilla.com>
Mon, 19 Aug 2013 15:14:37 -0700
changeset 143194 2cd7f480d9977c91aa582ba84da046c01481b8c8
parent 143193 91ff451693eda2754b5d5da1aef3d6db65c35945
child 143195 94e951d972d31efe8808009142f6194dd85341f3
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersmargaret
bugs808636
milestone26.0a1
Bug 808636 - Make urltext red on about:blocked. r=margaret
mobile/android/base/BrowserToolbar.java
mobile/android/base/Tab.java
mobile/android/base/Tabs.java
mobile/android/base/resources/values/colors.xml
mobile/android/chrome/content/browser.js
--- a/mobile/android/base/BrowserToolbar.java
+++ b/mobile/android/base/BrowserToolbar.java
@@ -121,16 +121,17 @@ public class BrowserToolbar extends Geck
     private PropertyAnimator mVisibilityAnimator;
     private static final Interpolator sButtonsInterpolator = new AccelerateInterpolator();
 
     private static final int TABS_CONTRACTED = 1;
     private static final int TABS_EXPANDED = 2;
 
     private static final int FORWARD_ANIMATION_DURATION = 450;
     private final ForegroundColorSpan mUrlColor;
+    private final ForegroundColorSpan mBlockedColor;
     private final ForegroundColorSpan mDomainColor;
     private final ForegroundColorSpan mPrivateDomainColor;
 
     private boolean mShowUrl;
 
     private Integer mPrefObserverId;
 
     public BrowserToolbar(Context context) {
@@ -177,16 +178,17 @@ public class BrowserToolbar extends Geck
                 // We want to be notified of changes to be able to switch mode
                 // without restarting.
                 return true;
             }
         });
 
         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));
 
         registerEventListener("Reader:Click");
         registerEventListener("Reader:LongClick");
 
         mShowSiteSecurity = false;
         mShowReader = false;
@@ -464,16 +466,21 @@ public class BrowserToolbar extends Geck
                 if (Tabs.getInstance().isSelectedTab(tab)) {
                     updateBackButton(tab.canDoBack());
                     updateForwardButton(tab.canDoForward());
                     setProgressVisibility(false);
                     // Reset the title in case we haven't navigated to a new page yet.
                     updateTitle();
                 }
                 break;
+            case LOADED:
+                if (Tabs.getInstance().isSelectedTab(tab)) {
+                    updateTitle();
+                }
+                break;
             case RESTORED:
                 // TabCount fixup after OOM
             case SELECTED:
                 updateTabCount(Tabs.getInstance().getDisplayCount());
                 mSwitchingTabs = true;
                 // fall through
             case LOCATION_CHANGE:
             case LOAD_ERROR:
@@ -936,16 +943,25 @@ public class BrowserToolbar extends Geck
 
         String url = tab.getURL();
         // Setting a null title will ensure we just see the "Enter Search or Address" placeholder text.
         if ("about:home".equals(url) || "about:privatebrowsing".equals(url)) {
             setTitle(null);
             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());
             return;
         }
 
         url = StringUtils.stripScheme(url);
         CharSequence title = StringUtils.stripCommonSubdomains(url);
--- a/mobile/android/base/Tab.java
+++ b/mobile/android/base/Tab.java
@@ -48,36 +48,43 @@ public class Tab {
     private BitmapDrawable mThumbnail;
     private int mHistoryIndex;
     private int mHistorySize;
     private int mParentId;
     private boolean mExternal;
     private boolean mBookmark;
     private boolean mReadingListItem;
     private long mFaviconLoadId;
-    private String mDocumentURI;
     private String mContentType;
     private boolean mHasTouchListeners;
     private ZoomConstraints mZoomConstraints;
     private boolean mIsRTL;
     private ArrayList<View> mPluginViews;
     private HashMap<Object, Layer> mPluginLayers;
     private int mBackgroundColor;
     private int mState;
     private Bitmap mThumbnailBitmap;
     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;
     public static final int STATE_LOADING = 1;
     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;
         mLastUsed = 0;
         mUrl = url;
         mBaseDomain = "";
         mUserSearch = "";
         mExternal = external;
@@ -91,17 +98,16 @@ public class Tab {
         mReaderEnabled = false;
         mEnteringReaderMode = false;
         mThumbnail = null;
         mHistoryIndex = -1;
         mHistorySize = 0;
         mBookmark = false;
         mReadingListItem = false;
         mFaviconLoadId = 0;
-        mDocumentURI = "";
         mContentType = "";
         mZoomConstraints = new ZoomConstraints(false);
         mPluginViews = new ArrayList<View>();
         mPluginLayers = new HashMap<Object, Layer>();
         mState = shouldShowProgress(url) ? STATE_SUCCESS : STATE_LOADING;
 
         // At startup, the background is set to a color specified by LayerView
         // when the LayerView is created. Shortly after, this background color
@@ -255,22 +261,33 @@ public class Tab {
             updateBookmark();
         }
     }
 
     private synchronized void updateUserSearch(String userSearch) {
         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) {
         mContentType = (contentType == null) ? "" : contentType;
     }
 
     public String getContentType() {
         return mContentType;
@@ -569,17 +586,16 @@ public class Tab {
     }
 
     void handleLocationChange(JSONObject message) throws JSONException {
         final String uri = message.getString("uri");
         mEnteringReaderMode = ReaderModeUtils.isEnteringReaderMode(mUrl, uri);
         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
             // Notify listeners so that buttons like back or forward will update themselves
             Tabs.getInstance().notifyListeners(this, Tabs.TabEvents.LOCATION_CHANGE, uri);
             return;
         }
 
@@ -587,16 +603,17 @@ public class Tab {
         clearFavicon();
         setFeedsEnabled(false);
         updateTitle(null);
         updateIdentityData(null);
         setReaderEnabled(false);
         setZoomConstraints(new ZoomConstraints(true));
         setHasTouchListeners(false);
         setBackgroundColor(getBackgroundColorForUrl(uri));
+        setErrorType(ErrorType.NONE);
 
         Tabs.getInstance().notifyListeners(this, Tabs.TabEvents.LOCATION_CHANGE, uri);
     }
 
     private boolean shouldShowProgress(String url) {
         return "about:home".equals(url) || ReaderModeUtils.isAboutReader(url);
     }
 
--- a/mobile/android/base/Tabs.java
+++ b/mobile/android/base/Tabs.java
@@ -439,16 +439,17 @@ public class Tabs implements GeckoEventL
             } else if (event.equals("DOMContentLoaded")) {
                 String backgroundColor = message.getString("bgColor");
                 if (backgroundColor != null) {
                     tab.setBackgroundColor(backgroundColor);
                 } else {
                     // 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"));
             } else if (event.equals("Link:Favicon")) {
                 tab.updateFaviconURL(message.getString("href"), message.getInt("size"));
                 notifyListeners(tab, TabEvents.LINK_FAVICON);
             } else if (event.equals("Link:Feed")) {
                 tab.setFeedsEnabled(true);
--- a/mobile/android/base/resources/values/colors.xml
+++ b/mobile/android/base/resources/values/colors.xml
@@ -84,11 +84,12 @@
   <color name="textbox_background">#FFF</color>
   <color name="textbox_background_disabled">#DDD</color>
   <color name="textbox_stroke">#000</color>
   <color name="textbox_stroke_disabled">#666</color>
 
   <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>
 
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -3332,27 +3332,36 @@ Tab.prototype = {
         try {
           let { contentDocument, contentWindow } = this.browser;
           let computedStyle = contentWindow.getComputedStyle(contentDocument.body);
           backgroundColor = computedStyle.backgroundColor;
         } catch (e) {
           // 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() {
             this.browser.removeEventListener("click", ErrorPageEventHandler, true);
             this.browser.removeEventListener("pagehide", listener, true);
           }.bind(this);
 
           this.browser.addEventListener("pagehide", listener, true);
@@ -3626,33 +3635,33 @@ Tab.prototype = {
 
     this._hostChanged = true;
 
     let fixedURI = aLocationURI;
     try {
       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
     // change but rather a spurious addition like a wyciwyg URI prefix. See Bug 747883.
     // Note that we have to ensure fixedURI is not the same as aLocationURI so we
     // don't false-positive page reloads as spurious additions.
     let sameDocument = (aFlags & Ci.nsIWebProgressListener.LOCATION_CHANGE_SAME_DOCUMENT) != 0 ||
                        ((this.browser.lastURI != null) && fixedURI.equals(this.browser.lastURI) && !fixedURI.equals(aLocationURI));
     this.browser.lastURI = fixedURI;
 
     // Reset state of click-to-play plugin notifications.
     clearTimeout(this.pluginDoorhangerTimeout);
     this.pluginDoorhangerTimeout = null;
     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) {
       var domain = "";
       [, , domain] = matchedURL;
 
       try {
         baseDomain = Services.eTLD.getBaseDomainFromHost(domain);
@@ -3664,17 +3673,16 @@ Tab.prototype = {
       } catch (e) {}
     }
 
     let message = {
       type: "Content:LocationChange",
       tabID: this.id,
       uri: fixedURI.spec,
       userSearch: this.userSearch || "",
-      documentURI: documentURI,
       baseDomain: baseDomain,
       contentType: (contentType ? contentType : ""),
       sameDocument: sameDocument
     };
 
     sendMessageToJava(message);
 
     // The search term is only valid for this location change event, so reset it here.