This repository has been archived by the owner on Nov 3, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16220 from KevinGrandon/bug_971483_devtools_layer_v2
Bug 971483 - [System2] Instantiable DevToolsLayer r=alive
- Loading branch information
Showing
8 changed files
with
135 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
'use strict'; | ||
|
||
(function(exports) { | ||
|
||
/** | ||
* DevtoolsView displays metrics as an overlay on top of mozapps. | ||
* @param {Object} data The data to update the devtools view with. | ||
* @class DevtoolsView | ||
*/ | ||
function DevtoolsView() { | ||
window.addEventListener('widget-panel-update', function updateHandler(e){ | ||
this.display(e.detail); | ||
e.preventDefault(); | ||
}.bind(this)); | ||
} | ||
|
||
DevtoolsView.prototype = { | ||
|
||
/** | ||
* Displays the devtools view if it does not exist and updates with data. | ||
* Currently we measure errors, warnings, and reflows. | ||
* @memberof DevtoolsView.prototype | ||
* @param {Object} data The data to update the devtools view with. | ||
*/ | ||
display: function(data) { | ||
var target = 'iframe[mozapp="' + data.manifestURL + '"]'; | ||
var iframe = document.querySelector(target); | ||
if (!iframe) { | ||
return; | ||
} | ||
|
||
var appwindow = iframe.parentElement; | ||
var overlay = appwindow.querySelector('.devtools-view'); | ||
|
||
if (!overlay) { | ||
overlay = document.createElement('div'); | ||
overlay.classList.add('devtools-view'); | ||
appwindow.appendChild(overlay); | ||
} | ||
|
||
if (!data.metrics || data.metrics.length < 1) { | ||
overlay.remove(); | ||
return; | ||
} | ||
|
||
var html = ''; | ||
|
||
data.metrics.forEach(function(metric) { | ||
html += this.widget(metric); | ||
}, this); | ||
|
||
overlay.innerHTML = html; | ||
}, | ||
|
||
/** | ||
* Updates a single metric to be displayed. | ||
* @memberof DevtoolsView.prototype | ||
* @param {Object} metric The metric to be updated. | ||
*/ | ||
widget: function(metric) { | ||
var value = metric.value; | ||
if (!value) { | ||
return ''; | ||
} | ||
|
||
var color; | ||
switch(metric.name) { | ||
case 'errors': | ||
color = 'red'; | ||
break; | ||
|
||
case 'warnings': | ||
color = 'orange'; | ||
break; | ||
|
||
case 'reflows': | ||
color = 'purple'; | ||
break; | ||
|
||
default: | ||
color = this.colorHash(metric.name); | ||
break; | ||
} | ||
|
||
return '<div class=widget style="background-color: ' + color + '">' + | ||
value + '</div>'; | ||
}, | ||
|
||
/** | ||
* Given a color name, returns a styled CSS background value. | ||
* @memberof DevtoolsView.prototype | ||
* @param {String} name The name of the color. | ||
*/ | ||
colorHash: function(name) { | ||
var hue = 0; | ||
for (var i = 0; i < name.length; i++) { | ||
hue += name.charCodeAt(i); | ||
} | ||
return 'hsl(' + (hue % 360) + ', 75%, 50%)'; | ||
} | ||
}; | ||
|
||
exports.DevtoolsView = DevtoolsView; | ||
|
||
}(window)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/* exported MockDevtoolsView */ | ||
|
||
'use strict'; | ||
|
||
function MockDevtoolsView() { | ||
} |