Bug 977188 - Report security errors separately in the Developer HUD. r=21
authorJan Keromnes <janx@linux.com>
Mon, 17 Mar 2014 10:43:33 -0400
changeset 192134 ef4ee2255eebe629dc932e62ee20f43c0714e86b
parent 192133 ec77797d0a47d48d85a11d90ebbb750e989ba860
child 192135 00e095a5bf18528b1dd8a836e8fd760e33c94a9c
push id474
push userasasaki@mozilla.com
push dateMon, 02 Jun 2014 21:01:02 +0000
treeherdermozilla-release@967f4cf1b31c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewers21
bugs977188
milestone30.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 977188 - Report security errors separately in the Developer HUD. r=21
b2g/chrome/content/devtools.js
--- a/b2g/chrome/content/devtools.js
+++ b/b2g/chrome/content/devtools.js
@@ -39,19 +39,20 @@ let developerHUD = {
   _frames: new Map(),
   _client: null,
   _webappsActor: null,
   _watchers: [],
   _logging: true,
 
   /**
    * This method registers a metric watcher that will watch one or more metrics
-   * of apps that are being tracked. A watcher must implement the trackApp(app)
-   * and untrackApp(app) methods, add entries to the app.metrics map, keep them
-   * up-to-date, and call app.display() when values were changed.
+   * on app frames that are being tracked. A watcher must implement the
+   * `trackTarget(target)` and `untrackTarget(target)` methods, register
+   * observed metrics with `target.register(metric)`, and keep them up-to-date
+   * with `target.update(metric, value, message)` when necessary.
    */
   registerWatcher: function dwp_registerWatcher(watcher) {
     this._watchers.unshift(watcher);
   },
 
   init: function dwp_init() {
     if (this._client)
       return;
@@ -82,17 +83,17 @@ let developerHUD = {
 
         let frames = systemapp.contentWindow.document.querySelectorAll('iframe[mozapp]');
         for (let frame of frames) {
           this.trackFrame(frame);
         }
       });
     });
 
-    SettingsListener.observe('hud.logging', enabled => {
+    SettingsListener.observe('hud.logging', this._logging, enabled => {
       this._logging = enabled;
     });
   },
 
   uninit: function dwp_uninit() {
     if (!this._client)
       return;
 
@@ -189,19 +190,19 @@ let developerHUD = {
       dump(DEVELOPER_HUD_LOG_PREFIX + ': ' + message + '\n');
     }
   }
 
 };
 
 
 /**
- * An App object represents all there is to know about a Firefox OS app that is
- * being tracked, e.g. its manifest information, current values of watched
- * metrics, and how to update these values on the front-end.
+ * A Target object represents all there is to know about a Firefox OS app frame
+ * that is being tracked, e.g. a pointer to the frame, current values of watched
+ * metrics, and how to notify the front-end when metrics have changed.
  */
 function Target(frame, actor) {
   this.frame = frame;
   this.actor = actor;
   this.metrics = new Map();
 }
 
 Target.prototype = {
@@ -271,37 +272,47 @@ Target.prototype = {
     shell.sendEvent(this.frame, 'developer-hud-update', Cu.cloneInto(data, this.frame));
   }
 
 };
 
 
 /**
  * The Console Watcher tracks the following metrics in apps: reflows, warnings,
- * and errors.
+ * and errors, with security errors reported separately.
  */
 let consoleWatcher = {
 
+  _client: null,
   _targets: new Map(),
   _watching: {
     reflows: false,
     warnings: false,
-    errors: false
+    errors: false,
+    security: false
   },
-  _client: null,
+  _security: [
+    'Mixed Content Blocker',
+    'Mixed Content Message',
+    'CSP',
+    'Invalid HSTS Headers',
+    'Insecure Password Field',
+    'SSL',
+    'CORS'
+  ],
 
   init: function cw_init(client) {
     this._client = client;
     this.consoleListener = this.consoleListener.bind(this);
 
     let watching = this._watching;
 
     for (let key in watching) {
       let metric = key;
-      SettingsListener.observe('hud.' + metric, false, watch => {
+      SettingsListener.observe('hud.' + metric, watching[metric], watch => {
         // Watch or unwatch the metric.
         if (watching[metric] = watch) {
           return;
         }
 
         // If unwatched, remove any existing widgets for that metric.
         for (let target of this._targets.values()) {
           target.clear(metric);
@@ -314,16 +325,17 @@ let consoleWatcher = {
     client.addListener('consoleAPICall', this.consoleListener);
     client.addListener('reflowActivity', this.consoleListener);
   },
 
   trackTarget: function cw_trackTarget(target) {
     target.register('reflows');
     target.register('warnings');
     target.register('errors');
+    target.register('security');
 
     this._client.request({
       to: target.actor.consoleActor,
       type: 'startListeners',
       listeners: ['LogMessage', 'PageError', 'ConsoleAPI', 'ReflowActivity']
     }, (res) => {
       this._targets.set(target.actor.consoleActor, target);
     });
@@ -352,23 +364,27 @@ let consoleWatcher = {
         if (pageError.warning || pageError.strict) {
           metric = 'warnings';
           output += 'warning (';
         } else {
           metric = 'errors';
           output += 'error (';
         }
 
+        if (this._security.indexOf(pageError.category) > -1) {
+          metric = 'security';
+        }
+
         let {errorMessage, sourceName, category, lineNumber, columnNumber} = pageError;
         output += category + '): "' + (errorMessage.initial || errorMessage) +
           '" in ' + sourceName + ':' + lineNumber + ':' + columnNumber;
         break;
 
       case 'consoleAPICall':
-        switch (packet.output.level) {
+        switch (packet.message.level) {
 
           case 'error':
             metric = 'errors';
             output += 'error (console)';
             break;
 
           case 'warn':
             metric = 'warnings';