| OLD | NEW |
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * @constructor | 6 * @constructor |
| 7 * @extends {WebInspector.VBox} | 7 * @extends {WebInspector.VBox} |
| 8 * @implements {WebInspector.TargetManager.Observer} | 8 * @implements {WebInspector.TargetManager.Observer} |
| 9 */ | 9 */ |
| 10 WebInspector.AppManifestView = function() | 10 WebInspector.AppManifestView = function() |
| 11 { | 11 { |
| 12 WebInspector.VBox.call(this, true); | 12 WebInspector.VBox.call(this, true); |
| 13 this.registerRequiredCSS("resources/appManifestView.css"); | 13 this.registerRequiredCSS("resources/appManifestView.css"); |
| 14 | 14 |
| 15 this._contentBox = this.contentElement.createChild("div", "app-content-box")
; | 15 this._reportView = new WebInspector.ReportView(WebInspector.UIString("App Ma
nifest")); |
| 16 this._contentBox.createChild("div", "app-manifest-title").textContent = WebI
nspector.UIString("App Manifest"); | 16 this._reportView.show(this.contentElement); |
| 17 this._urlElement = this._contentBox.createChild("div", "app-manifest-url lin
k"); | 17 this._errorsSection = this._reportView.appendSection(WebInspector.UIString("
Errors and warnings")); |
| 18 this._identitySection = this._createSection(WebInspector.UIString("Identity"
)); | 18 this._identitySection = this._reportView.appendSection(WebInspector.UIString
("Identity")); |
| 19 this._presentationSection = this._createSection(WebInspector.UIString("Prese
ntation")); | 19 this._presentationSection = this._reportView.appendSection(WebInspector.UISt
ring("Presentation")); |
| 20 var iconsSection = this._createSection(WebInspector.UIString("Icons")); | 20 this._iconsSection = this._reportView.appendSection(WebInspector.UIString("I
cons")); |
| 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 | 21 |
| 25 this._nameField = this._createField(this._identitySection, WebInspector.UISt
ring("Name")); | 22 this._nameField = this._identitySection.appendField(WebInspector.UIString("N
ame")); |
| 26 this._shortNameField = this._createField(this._identitySection, WebInspector
.UIString("Short name")); | 23 this._shortNameField = this._identitySection.appendField(WebInspector.UIStri
ng("Short name")); |
| 27 | 24 |
| 28 this._startURLField = this._createField(this._presentationSection, WebInspec
tor.UIString("Start URL")); | 25 this._startURLField = this._presentationSection.appendField(WebInspector.UIS
tring("Start URL")); |
| 29 | 26 |
| 30 var themeColorField = this._createField(this._presentationSection, WebInspec
tor.UIString("Theme color")); | 27 var themeColorField = this._presentationSection.appendField(WebInspector.UIS
tring("Theme color")); |
| 31 this._themeColorSwatch = WebInspector.ColorSwatch.create(); | 28 this._themeColorSwatch = WebInspector.ColorSwatch.create(); |
| 32 themeColorField.appendChild(this._themeColorSwatch); | 29 themeColorField.appendChild(this._themeColorSwatch); |
| 33 | 30 |
| 34 var backgroundColorField = this._createField(this._presentationSection, WebI
nspector.UIString("Background color")); | 31 var backgroundColorField = this._presentationSection.appendField(WebInspecto
r.UIString("Background color")); |
| 35 this._backgroundColorSwatch = WebInspector.ColorSwatch.create(); | 32 this._backgroundColorSwatch = WebInspector.ColorSwatch.create(); |
| 36 backgroundColorField.appendChild(this._backgroundColorSwatch); | 33 backgroundColorField.appendChild(this._backgroundColorSwatch); |
| 37 | 34 |
| 38 this._orientationField = this._createField(this._presentationSection, WebIns
pector.UIString("Orientation")); | 35 this._orientationField = this._presentationSection.appendField(WebInspector.
UIString("Orientation")); |
| 39 this._displayField = this._createField(this._presentationSection, WebInspect
or.UIString("Display")); | 36 this._displayField = this._presentationSection.appendField(WebInspector.UISt
ring("Display")); |
| 40 | 37 |
| 41 WebInspector.targetManager.observeTargets(this); | 38 WebInspector.targetManager.observeTargets(this); |
| 42 } | 39 } |
| 43 | 40 |
| 44 WebInspector.AppManifestView.prototype = { | 41 WebInspector.AppManifestView.prototype = { |
| 45 /** | 42 /** |
| 46 * @param {string} title | |
| 47 * @return {!Element} | |
| 48 */ | |
| 49 _createSection: function(title) | |
| 50 { | |
| 51 var section = this._contentBox.createChild("div", "app-manifest-section"
); | |
| 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 | 43 * @override |
| 70 * @param {!WebInspector.Target} target | 44 * @param {!WebInspector.Target} target |
| 71 */ | 45 */ |
| 72 targetAdded: function(target) | 46 targetAdded: function(target) |
| 73 { | 47 { |
| 74 if (this._target) | 48 if (this._target) |
| 75 return; | 49 return; |
| 76 this._target = target; | 50 this._target = target; |
| 77 | 51 |
| 78 this._updateManifest(); | 52 this._updateManifest(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 92 this._target.resourceTreeModel.fetchAppManifest(this._renderManifest.bin
d(this)); | 66 this._target.resourceTreeModel.fetchAppManifest(this._renderManifest.bin
d(this)); |
| 93 }, | 67 }, |
| 94 | 68 |
| 95 /** | 69 /** |
| 96 * @param {string} url | 70 * @param {string} url |
| 97 * @param {?string} data | 71 * @param {?string} data |
| 98 * @param {!Array<!PageAgent.AppManifestError>} errors | 72 * @param {!Array<!PageAgent.AppManifestError>} errors |
| 99 */ | 73 */ |
| 100 _renderManifest: function(url, data, errors) | 74 _renderManifest: function(url, data, errors) |
| 101 { | 75 { |
| 102 this._urlElement.removeChildren(); | 76 this._reportView.setURL(url); |
| 103 if (url) | 77 this._errorsSection.clearContent(); |
| 104 this._urlElement.appendChild(WebInspector.linkifyResourceAsNode(url,
undefined, undefined, undefined, undefined, url)); | 78 this._errorsSection.element.classList.toggle("hidden", !errors.length); |
| 105 this._errorsList.removeChildren(); | |
| 106 this._errorsSection.classList.toggle("hidden", !errors.length); | |
| 107 for (var error of errors) | 79 for (var error of errors) |
| 108 this._errorsList.appendChild(createLabel(error.message, error.critic
al ? "error-icon" : "warning-icon")); | 80 this._errorsSection.appendRow().appendChild(createLabel(error.messag
e, error.critical ? "error-icon" : "warning-icon")); |
| 109 | 81 |
| 110 if (!data) | 82 if (!data) |
| 111 data = "{}"; | 83 data = "{}"; |
| 112 | 84 |
| 113 var parsedManifest = JSON.parse(data); | 85 var parsedManifest = JSON.parse(data); |
| 114 this._nameField.textContent = stringProperty("name"); | 86 this._nameField.textContent = stringProperty("name"); |
| 115 this._shortNameField.textContent = stringProperty("short_name"); | 87 this._shortNameField.textContent = stringProperty("short_name"); |
| 116 this._startURLField.removeChildren(); | 88 this._startURLField.removeChildren(); |
| 117 var startURL = stringProperty("start_url"); | 89 var startURL = stringProperty("start_url"); |
| 118 if (startURL) | 90 if (startURL) |
| 119 this._startURLField.appendChild(WebInspector.linkifyResourceAsNode(/
** @type {string} */(WebInspector.ParsedURL.completeURL(url, startURL)), undefin
ed, undefined, undefined, undefined, startURL)); | 91 this._startURLField.appendChild(WebInspector.linkifyResourceAsNode(/
** @type {string} */(WebInspector.ParsedURL.completeURL(url, startURL)), undefin
ed, undefined, undefined, undefined, startURL)); |
| 120 | 92 |
| 121 this._themeColorSwatch.classList.toggle("hidden", !stringProperty("theme
_color")); | 93 this._themeColorSwatch.classList.toggle("hidden", !stringProperty("theme
_color")); |
| 122 this._themeColorSwatch.setColorText(stringProperty("theme_color") || "wh
ite"); | 94 this._themeColorSwatch.setColorText(stringProperty("theme_color") || "wh
ite"); |
| 123 this._backgroundColorSwatch.classList.toggle("hidden", !stringProperty("
background_color")); | 95 this._backgroundColorSwatch.classList.toggle("hidden", !stringProperty("
background_color")); |
| 124 this._backgroundColorSwatch.setColorText(stringProperty("background_colo
r") || "white"); | 96 this._backgroundColorSwatch.setColorText(stringProperty("background_colo
r") || "white"); |
| 125 | 97 |
| 126 this._orientationField.textContent = stringProperty("orientation"); | 98 this._orientationField.textContent = stringProperty("orientation"); |
| 127 this._displayField.textContent = stringProperty("display"); | 99 this._displayField.textContent = stringProperty("display"); |
| 128 | 100 |
| 129 var icons = parsedManifest["icons"] || []; | 101 var icons = parsedManifest["icons"] || []; |
| 130 this._iconsList.removeChildren(); | 102 this._iconsSection.clearContent(); |
| 131 for (var icon of icons) { | 103 for (var icon of icons) { |
| 132 var title = (icon["sizes"] || "") + "\n" + (icon["type"] || ""); | 104 var title = (icon["sizes"] || "") + "\n" + (icon["type"] || ""); |
| 133 var field = this._createField(this._iconsList, title); | 105 var field = this._iconsSection.appendField(title); |
| 134 var imageElement = field.createChild("img"); | 106 var imageElement = field.createChild("img"); |
| 107 imageElement.style.maxWidth = "200px"; |
| 108 imageElement.style.maxHeight = "200px"; |
| 135 imageElement.src = WebInspector.ParsedURL.completeURL(url, icon["src
"]); | 109 imageElement.src = WebInspector.ParsedURL.completeURL(url, icon["src
"]); |
| 136 } | 110 } |
| 137 | 111 |
| 138 /** | 112 /** |
| 139 * @param {string} name | 113 * @param {string} name |
| 140 * @return {string} | 114 * @return {string} |
| 141 */ | 115 */ |
| 142 function stringProperty(name) | 116 function stringProperty(name) |
| 143 { | 117 { |
| 144 var value = parsedManifest[name]; | 118 var value = parsedManifest[name]; |
| 145 if (typeof value !== "string") | 119 if (typeof value !== "string") |
| 146 return ""; | 120 return ""; |
| 147 return value; | 121 return value; |
| 148 } | 122 } |
| 149 }, | 123 }, |
| 150 | 124 |
| 151 __proto__: WebInspector.VBox.prototype | 125 __proto__: WebInspector.VBox.prototype |
| 152 } | 126 } |
| OLD | NEW |