diff --git a/embedding/android/BrowserToolbar.java b/embedding/android/BrowserToolbar.java index a8a9de8ff6d..4a4fe430acb 100644 --- a/embedding/android/BrowserToolbar.java +++ b/embedding/android/BrowserToolbar.java @@ -43,6 +43,7 @@ package org.mozilla.gecko; import android.content.Context; import android.graphics.drawable.AnimationDrawable; import android.graphics.drawable.Drawable; +import android.graphics.Color; import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; @@ -128,4 +129,13 @@ public class BrowserToolbar extends LinearLayout { else mFavicon.setImageResource(R.drawable.favicon); } + + public void setSecurityMode(String mode) { + if (mode.equals("identified")) + mFavicon.setBackgroundColor(Color.rgb(137, 215, 21)); + else if (mode.equals("verified")) + mFavicon.setBackgroundColor(Color.rgb(101, 121, 227)); + else + mFavicon.setBackgroundColor(Color.TRANSPARENT); + } } diff --git a/embedding/android/GeckoApp.java b/embedding/android/GeckoApp.java index 8605f1dd6f7..3b681d84d86 100644 --- a/embedding/android/GeckoApp.java +++ b/embedding/android/GeckoApp.java @@ -584,6 +584,7 @@ abstract public class GeckoApp return; tab.updateFavicon(null); + tab.updateSecurityMode("unknown"); mMainHandler.post(new Runnable() { public void run() { @@ -591,11 +592,27 @@ abstract public class GeckoApp if (Tabs.getInstance().isSelectedTab(tab)) { mBrowserToolbar.setTitle(uri); mBrowserToolbar.setFavicon(null); + mBrowserToolbar.setSecurityMode("unknown"); } } }); } + void handleSecurityChange(final int tabId, final String mode) { + final Tab tab = Tabs.getInstance().getTab(tabId); + if (tab == null) + return; + + tab.updateSecurityMode(mode); + + mMainHandler.post(new Runnable() { + public void run() { + if (Tabs.getInstance().isSelectedTab(tab)) + mBrowserToolbar.setSecurityMode(mode); + } + }); + } + void addTab() { Intent intent = new Intent(mAppContext, AwesomeBar.class); intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION | Intent.FLAG_ACTIVITY_NO_HISTORY); @@ -687,12 +704,17 @@ abstract public class GeckoApp // generic log listener final String msg = message.getString("msg"); Log.i(LOG_NAME, "Log: " + msg); - } else if (event.equals("onLocationChange")) { + } else if (event.equals("Content:LocationChange")) { final int tabId = message.getInt("tabID"); final String uri = message.getString("uri"); Log.i(LOG_NAME, "URI - " + uri); handleLocationChange(tabId, uri); - } else if (event.equals("onStateChange")) { + } else if (event.equals("Content:SecurityChange")) { + final int tabId = message.getInt("tabID"); + final String mode = message.getString("mode"); + Log.i(LOG_NAME, "Security Mode - " + mode); + handleSecurityChange(tabId, mode); + } else if (event.equals("Content:StateChange")) { final int tabId = message.getInt("tabID"); int state = message.getInt("state"); Log.i(LOG_NAME, "State - " + state); @@ -810,6 +832,7 @@ abstract public class GeckoApp if (Tabs.getInstance().isSelectedTab(tab)) { mBrowserToolbar.setTitle(tab.getDisplayTitle()); mBrowserToolbar.setFavicon(tab.getFavicon()); + mBrowserToolbar.setSecurityMode(tab.getSecurityMode()); mBrowserToolbar.setProgressVisibility(tab.isLoading()); mDoorHanger.updateForTab(tab.getId()); } @@ -823,11 +846,14 @@ abstract public class GeckoApp return; tab.setLoading(true); - + tab.updateSecurityMode("unknown"); + mMainHandler.post(new Runnable() { public void run() { - if (Tabs.getInstance().isSelectedTab(tab)) + if (Tabs.getInstance().isSelectedTab(tab)) { + mBrowserToolbar.setSecurityMode(tab.getSecurityMode()); mBrowserToolbar.setProgressVisibility(true); + } onTabsChanged(); } }); @@ -1034,8 +1060,9 @@ abstract public class GeckoApp GeckoAppShell.registerGeckoEventListener("DOMTitleChanged", GeckoApp.mAppContext); GeckoAppShell.registerGeckoEventListener("DOMLinkAdded", GeckoApp.mAppContext); GeckoAppShell.registerGeckoEventListener("log", GeckoApp.mAppContext); - GeckoAppShell.registerGeckoEventListener("onLocationChange", GeckoApp.mAppContext); - GeckoAppShell.registerGeckoEventListener("onStateChange", GeckoApp.mAppContext); + GeckoAppShell.registerGeckoEventListener("Content:LocationChange", GeckoApp.mAppContext); + GeckoAppShell.registerGeckoEventListener("Content:SecurityChange", GeckoApp.mAppContext); + GeckoAppShell.registerGeckoEventListener("Content:StateChange", GeckoApp.mAppContext); GeckoAppShell.registerGeckoEventListener("onCameraCapture", GeckoApp.mAppContext); GeckoAppShell.registerGeckoEventListener("Tab:Added", GeckoApp.mAppContext); GeckoAppShell.registerGeckoEventListener("Tab:Closed", GeckoApp.mAppContext); @@ -1217,8 +1244,9 @@ abstract public class GeckoApp GeckoAppShell.unregisterGeckoEventListener("DOMTitleChanged", GeckoApp.mAppContext); GeckoAppShell.unregisterGeckoEventListener("DOMLinkAdded", GeckoApp.mAppContext); GeckoAppShell.unregisterGeckoEventListener("log", GeckoApp.mAppContext); - GeckoAppShell.unregisterGeckoEventListener("onLocationChange", GeckoApp.mAppContext); - GeckoAppShell.unregisterGeckoEventListener("onStateChange", GeckoApp.mAppContext); + GeckoAppShell.unregisterGeckoEventListener("Content:LocationChange", GeckoApp.mAppContext); + GeckoAppShell.unregisterGeckoEventListener("Content:SecurityChange", GeckoApp.mAppContext); + GeckoAppShell.unregisterGeckoEventListener("Content:StateChange", GeckoApp.mAppContext); GeckoAppShell.unregisterGeckoEventListener("onCameraCapture", GeckoApp.mAppContext); GeckoAppShell.unregisterGeckoEventListener("Tab:Added", GeckoApp.mAppContext); GeckoAppShell.unregisterGeckoEventListener("Tab:Closed", GeckoApp.mAppContext); diff --git a/embedding/android/Tab.java b/embedding/android/Tab.java index 92b642abd4f..e8ef9c4ff9c 100644 --- a/embedding/android/Tab.java +++ b/embedding/android/Tab.java @@ -63,6 +63,7 @@ public class Tab { private String mUrl; private String mTitle; private Drawable mFavicon; + private String mSecurityMode; private Drawable mThumbnail; private List mHistory; private int mHistoryIndex; @@ -89,6 +90,7 @@ public class Tab { mUrl = url; mTitle = new String(); mFavicon = null; + mSecurityMode = "unknown"; mThumbnail = null; mHistory = new ArrayList(); mHistoryIndex = -1; @@ -119,6 +121,10 @@ public class Tab { return mFavicon; } + public String getSecurityMode() { + return mSecurityMode; + } + public boolean isLoading() { return mLoading; } @@ -176,6 +182,10 @@ public class Tab { Log.i(LOG_NAME, "Updated favicon for tab with id: " + mId); } + public void updateSecurityMode(String mode) { + mSecurityMode = mode; + } + private void updateBookmark() { new CheckBookmarkTask().execute(); } diff --git a/mobile/chrome/content/browser.js b/mobile/chrome/content/browser.js index 9b641408b28..f0e0309c438 100644 --- a/mobile/chrome/content/browser.js +++ b/mobile/chrome/content/browser.js @@ -879,7 +879,8 @@ Tab.prototype = { sendMessageToJava(message); let flags = Ci.nsIWebProgress.NOTIFY_STATE_ALL | - Ci.nsIWebProgress.NOTIFY_LOCATION; + Ci.nsIWebProgress.NOTIFY_LOCATION | + Ci.nsIWebProgress.NOTIFY_SECURITY; this.browser.addProgressListener(this, flags); this.browser.sessionHistory.addSHistoryListener(this); this.browser.loadURI(aURL); @@ -931,7 +932,7 @@ Tab.prototype = { let message = { gecko: { - type: "onStateChange", + type: "Content:StateChange", tabID: this.id, uri: uri, state: aStateFlags @@ -952,7 +953,7 @@ Tab.prototype = { let message = { gecko: { - type: "onLocationChange", + type: "Content:LocationChange", tabID: this.id, uri: uri } @@ -961,7 +962,26 @@ Tab.prototype = { sendMessageToJava(message); }, - onSecurityChange: function(aBrowser, aWebProgress, aRequest, aState) { + onSecurityChange: function(aWebProgress, aRequest, aState) { + let mode = "unknown"; + if (aState & Ci.nsIWebProgressListener.STATE_IDENTITY_EV_TOPLEVEL) + mode = "identified"; + else if (aState & Ci.nsIWebProgressListener.STATE_SECURE_HIGH) + mode = "verified"; + else if (aState & Ci.nsIWebProgressListener.STATE_IS_BROKEN) + mode = "mixed"; + else + mode = "unknown"; + + let message = { + gecko: { + type: "Content:SecurityChange", + tabID: this.id, + mode: mode + } + }; + + sendMessageToJava(message); }, onProgressChange: function(aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress, aCurTotalProgress, aMaxTotalProgress) {