Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 /** | |
| 6 * @constructor | |
| 7 * @extends {WebInspector.VBox} | |
| 8 * @implements {WebInspector.TargetManager.Observer} | |
| 9 */ | |
| 10 WebInspector.AppManifestView = function() | |
| 11 { | |
| 12 WebInspector.VBox.call(this, true); | |
| 13 this.registerRequiredCSS("resources/appManifestView.css"); | |
| 14 | |
| 15 this._contentBox = this.contentElement.createChild("div", "app-content-box") ; | |
| 16 this._contentBox.createChild("div", "app-manifest-title").textContent = WebI nspector.UIString("App Manifest"); | |
| 17 this._urlElement = this._contentBox.createChild("div", "app-manifest-url lin k"); | |
| 18 this._identitySection = this._createSection(WebInspector.UIString("Identity" )); | |
| 19 this._presentationSection = this._createSection(WebInspector.UIString("Prese ntation")); | |
| 20 var iconsSection = this._createSection(WebInspector.UIString("Icons")); | |
| 21 this._iconsList = iconsSection.createChild("div", "app-manifest-icons"); | |
| 22 this._errorsSection = this._createSection(WebInspector.UIString("Errors and warnings")); | |
| 23 this._errorsList = this._errorsSection.createChild("div", "app-manifest-erro rs"); | |
| 24 | |
| 25 this._nameField = this._createField(this._identitySection, WebInspector.UISt ring("Name")); | |
| 26 this._shortNameField = this._createField(this._identitySection, WebInspector .UIString("Short name")); | |
| 27 | |
| 28 this._startURLField = this._createField(this._presentationSection, WebInspec tor.UIString("Start URL")); | |
| 29 | |
| 30 var themeColorField = this._createField(this._presentationSection, WebInspec tor.UIString("Theme color")); | |
| 31 this._themeColorSwatch = WebInspector.ColorSwatch.create(); | |
| 32 themeColorField.appendChild(this._themeColorSwatch); | |
| 33 | |
| 34 var backgroundColorField = this._createField(this._presentationSection, WebI nspector.UIString("Background color")); | |
| 35 this._backgroundColorSwatch = WebInspector.ColorSwatch.create(); | |
| 36 backgroundColorField.appendChild(this._backgroundColorSwatch); | |
| 37 | |
| 38 this._orientationField = this._createField(this._presentationSection, WebIns pector.UIString("Orientation")); | |
| 39 this._displayField = this._createField(this._presentationSection, WebInspect or.UIString("Display")); | |
| 40 | |
| 41 WebInspector.targetManager.observeTargets(this); | |
| 42 } | |
| 43 | |
| 44 WebInspector.AppManifestView.prototype = { | |
| 45 /** | |
| 46 * @param {string} title | |
| 47 * @return {!Element} | |
| 48 */ | |
| 49 _createSection: function(title) | |
| 50 { | |
| 51 var section = this._contentBox.createChild("div", "app-manifest-section" ) | |
|
dgozman
2016/04/30 00:38:19
style: semicolon missing
| |
| 52 section.createChild("div", "app-manifest-section-title").textContent = t itle; | |
| 53 return section; | |
| 54 }, | |
| 55 | |
| 56 /** | |
| 57 * @param {string} title | |
| 58 * @param {!Element} section | |
| 59 * @return {!Element} | |
| 60 */ | |
| 61 _createField: function(section, title) | |
| 62 { | |
| 63 var row = section.createChild("div", "app-manifest-field"); | |
| 64 row.createChild("div", "app-manifest-field-name").textContent = title; | |
| 65 return row.createChild("div", "app-manifest-field-value"); | |
| 66 }, | |
| 67 | |
| 68 /** | |
| 69 * @override | |
| 70 * @param {!WebInspector.Target} target | |
| 71 */ | |
| 72 targetAdded: function(target) | |
| 73 { | |
| 74 if (this._target) | |
| 75 return; | |
| 76 this._target = target; | |
| 77 | |
| 78 this._updateManifest(); | |
| 79 WebInspector.targetManager.addEventListener(WebInspector.TargetManager.E vents.MainFrameNavigated, this._updateManifest, this); | |
| 80 }, | |
| 81 | |
| 82 /** | |
| 83 * @override | |
| 84 * @param {!WebInspector.Target} target | |
| 85 */ | |
| 86 targetRemoved: function(target) | |
| 87 { | |
| 88 }, | |
| 89 | |
| 90 _updateManifest: function() | |
| 91 { | |
| 92 this._target.resourceTreeModel.fetchAppManifest(this._renderManifest.bin d(this)); | |
| 93 }, | |
| 94 | |
| 95 /** | |
| 96 * @param {string} url | |
| 97 * @param {?string} data | |
| 98 * @param {!Array<!PageAgent.AppManifestError>} errors | |
| 99 */ | |
| 100 _renderManifest: function(url, data, errors) | |
| 101 { | |
| 102 this._urlElement.removeChildren(); | |
| 103 if (url) | |
| 104 this._urlElement.appendChild(WebInspector.linkifyResourceAsNode(url, undefined, undefined, undefined, undefined, url)); | |
| 105 this._errorsList.removeChildren(); | |
| 106 this._errorsSection.classList.toggle("hidden", !errors.length); | |
| 107 for (var error of errors) | |
| 108 this._errorsList.appendChild(createLabel(error.message, error.critic al ? "error-icon" : "warning-icon")); | |
| 109 | |
| 110 if (!data) | |
| 111 data = "{}"; | |
| 112 | |
| 113 var parsedManifest = JSON.parse(data); | |
| 114 this._nameField.textContent = stringProperty("name"); | |
| 115 this._shortNameField.textContent = stringProperty("short_name"); | |
| 116 this._startURLField.removeChildren(); | |
| 117 var startURL = stringProperty("start_url"); | |
| 118 if (startURL) | |
| 119 this._startURLField.appendChild(WebInspector.linkifyResourceAsNode(/ ** @type {string} */(WebInspector.ParsedURL.completeURL(url, startURL)), undefin ed, undefined, undefined, undefined, startURL)); | |
| 120 | |
| 121 this._themeColorSwatch.classList.toggle("hidden", !stringProperty("theme _color")); | |
| 122 this._themeColorSwatch.setColorText(stringProperty("theme_color") || "wh ite"); | |
| 123 this._backgroundColorSwatch.classList.toggle("hidden", !stringProperty(" background_color")); | |
| 124 this._backgroundColorSwatch.setColorText(stringProperty("background_colo r") || "white"); | |
| 125 | |
| 126 this._orientationField.textContent = stringProperty("orientation"); | |
| 127 this._displayField.textContent = stringProperty("display"); | |
| 128 | |
| 129 var icons = parsedManifest["icons"] || []; | |
| 130 this._iconsList.removeChildren(); | |
| 131 for (var icon of icons) { | |
| 132 var title = (icon["sizes"] || "") + "\n" + (icon["type"] || ""); | |
| 133 var field = this._createField(this._iconsList, title); | |
| 134 var imageElement = field.createChild("img"); | |
|
dgozman
2016/04/30 00:38:19
Let's set style.width and style.height to not rely
pfeldman
2016/04/30 01:03:06
I'll use max-width and max-height.
| |
| 135 imageElement.src = WebInspector.ParsedURL.completeURL(url, icon["src "]); | |
|
dgozman
2016/04/30 00:38:19
Should we validate icon["src"] to disallow javascr
pfeldman
2016/04/30 01:03:06
We would not execute scripts here.
| |
| 136 } | |
| 137 | |
| 138 /** | |
| 139 * @param {string} name | |
| 140 * @return {string} | |
| 141 */ | |
| 142 function stringProperty(name) | |
| 143 { | |
| 144 var value = parsedManifest[name]; | |
| 145 if (typeof value !== "string") | |
| 146 return ""; | |
| 147 return value; | |
| 148 } | |
| 149 }, | |
| 150 | |
| 151 __proto__: WebInspector.VBox.prototype | |
| 152 } | |
| OLD | NEW |