Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(25)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/resources/AppManifestView.js

Issue 2466123002: DevTools: reformat front-end code to match chromium style. (Closed)
Patch Set: all done Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 /**
5 * @implements {WebInspector.TargetManager.Observer}
6 * @unrestricted
7 */
8 WebInspector.AppManifestView = class extends WebInspector.VBox {
9 constructor() {
10 super(true);
11 this.registerRequiredCSS('resources/appManifestView.css');
4 12
5 /** 13 this._reportView = new WebInspector.ReportView(WebInspector.UIString('App Ma nifest'));
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._reportView = new WebInspector.ReportView(WebInspector.UIString("App Ma nifest"));
16 this._reportView.show(this.contentElement); 14 this._reportView.show(this.contentElement);
17 15
18 this._errorsSection = this._reportView.appendSection(WebInspector.UIString(" Errors and warnings")); 16 this._errorsSection = this._reportView.appendSection(WebInspector.UIString(' Errors and warnings'));
19 this._identitySection = this._reportView.appendSection(WebInspector.UIString ("Identity")); 17 this._identitySection = this._reportView.appendSection(WebInspector.UIString ('Identity'));
20 var toolbar = this._identitySection.createToolbar(); 18 var toolbar = this._identitySection.createToolbar();
21 toolbar.renderAsLinks(); 19 toolbar.renderAsLinks();
22 var addToHomeScreen = new WebInspector.ToolbarButton(WebInspector.UIString(" Add to homescreen"), undefined, WebInspector.UIString("Add to homescreen")); 20 var addToHomeScreen = new WebInspector.ToolbarButton(
23 addToHomeScreen.addEventListener("click", this._addToHomescreen.bind(this)); 21 WebInspector.UIString('Add to homescreen'), undefined, WebInspector.UISt ring('Add to homescreen'));
22 addToHomeScreen.addEventListener('click', this._addToHomescreen.bind(this));
24 toolbar.appendToolbarItem(addToHomeScreen); 23 toolbar.appendToolbarItem(addToHomeScreen);
25 24
26 this._presentationSection = this._reportView.appendSection(WebInspector.UISt ring("Presentation")); 25 this._presentationSection = this._reportView.appendSection(WebInspector.UISt ring('Presentation'));
27 this._iconsSection = this._reportView.appendSection(WebInspector.UIString("I cons")); 26 this._iconsSection = this._reportView.appendSection(WebInspector.UIString('I cons'));
28 27
29 this._nameField = this._identitySection.appendField(WebInspector.UIString("N ame")); 28 this._nameField = this._identitySection.appendField(WebInspector.UIString('N ame'));
30 this._shortNameField = this._identitySection.appendField(WebInspector.UIStri ng("Short name")); 29 this._shortNameField = this._identitySection.appendField(WebInspector.UIStri ng('Short name'));
31 30
32 this._startURLField = this._presentationSection.appendField(WebInspector.UIS tring("Start URL")); 31 this._startURLField = this._presentationSection.appendField(WebInspector.UIS tring('Start URL'));
33 32
34 var themeColorField = this._presentationSection.appendField(WebInspector.UIS tring("Theme color")); 33 var themeColorField = this._presentationSection.appendField(WebInspector.UIS tring('Theme color'));
35 this._themeColorSwatch = WebInspector.ColorSwatch.create(); 34 this._themeColorSwatch = WebInspector.ColorSwatch.create();
36 themeColorField.appendChild(this._themeColorSwatch); 35 themeColorField.appendChild(this._themeColorSwatch);
37 36
38 var backgroundColorField = this._presentationSection.appendField(WebInspecto r.UIString("Background color")); 37 var backgroundColorField = this._presentationSection.appendField(WebInspecto r.UIString('Background color'));
39 this._backgroundColorSwatch = WebInspector.ColorSwatch.create(); 38 this._backgroundColorSwatch = WebInspector.ColorSwatch.create();
40 backgroundColorField.appendChild(this._backgroundColorSwatch); 39 backgroundColorField.appendChild(this._backgroundColorSwatch);
41 40
42 this._orientationField = this._presentationSection.appendField(WebInspector. UIString("Orientation")); 41 this._orientationField = this._presentationSection.appendField(WebInspector. UIString('Orientation'));
43 this._displayField = this._presentationSection.appendField(WebInspector.UISt ring("Display")); 42 this._displayField = this._presentationSection.appendField(WebInspector.UISt ring('Display'));
44 43
45 WebInspector.targetManager.observeTargets(this, WebInspector.Target.Capabili ty.DOM); 44 WebInspector.targetManager.observeTargets(this, WebInspector.Target.Capabili ty.DOM);
46 }; 45 }
47 46
48 WebInspector.AppManifestView.prototype = { 47 /**
49 /** 48 * @override
50 * @override 49 * @param {!WebInspector.Target} target
51 * @param {!WebInspector.Target} target 50 */
52 */ 51 targetAdded(target) {
53 targetAdded: function(target) 52 if (this._resourceTreeModel)
54 { 53 return;
55 if (this._resourceTreeModel) 54 var resourceTreeModel = WebInspector.ResourceTreeModel.fromTarget(target);
56 return; 55 if (!resourceTreeModel)
57 var resourceTreeModel = WebInspector.ResourceTreeModel.fromTarget(target ); 56 return;
58 if (!resourceTreeModel) 57 this._resourceTreeModel = resourceTreeModel;
59 return; 58 this._updateManifest();
60 this._resourceTreeModel = resourceTreeModel; 59 resourceTreeModel.addEventListener(
61 this._updateManifest(); 60 WebInspector.ResourceTreeModel.Events.MainFrameNavigated, this._updateMa nifest, this);
62 resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.Events .MainFrameNavigated, this._updateManifest, this); 61 }
63 }, 62
63 /**
64 * @override
65 * @param {!WebInspector.Target} target
66 */
67 targetRemoved(target) {
68 var resourceTreeModel = WebInspector.ResourceTreeModel.fromTarget(target);
69 if (!this._resourceTreeModel || this._resourceTreeModel !== resourceTreeMode l)
70 return;
71 resourceTreeModel.removeEventListener(
72 WebInspector.ResourceTreeModel.Events.MainFrameNavigated, this._updateMa nifest, this);
73 delete this._resourceTreeModel;
74 }
75
76 _updateManifest() {
77 this._resourceTreeModel.fetchAppManifest(this._renderManifest.bind(this));
78 }
79
80 /**
81 * @param {string} url
82 * @param {?string} data
83 * @param {!Array<!PageAgent.AppManifestError>} errors
84 */
85 _renderManifest(url, data, errors) {
86 this._reportView.setURL(url);
87 this._errorsSection.clearContent();
88 this._errorsSection.element.classList.toggle('hidden', !errors.length);
89 for (var error of errors)
90 this._errorsSection.appendRow().appendChild(
91 createLabel(error.message, error.critical ? 'error-icon' : 'warning-ic on'));
92
93 if (!data)
94 data = '{}';
95
96 var parsedManifest = JSON.parse(data);
97 this._nameField.textContent = stringProperty('name');
98 this._shortNameField.textContent = stringProperty('short_name');
99 this._startURLField.removeChildren();
100 var startURL = stringProperty('start_url');
101 if (startURL)
102 this._startURLField.appendChild(WebInspector.linkifyResourceAsNode(
103 /** @type {string} */ (WebInspector.ParsedURL.completeURL(url, startUR L)), undefined, undefined, undefined,
104 undefined, startURL));
105
106 this._themeColorSwatch.classList.toggle('hidden', !stringProperty('theme_col or'));
107 var themeColor =
108 WebInspector.Color.parse(stringProperty('theme_color') || 'white') || We bInspector.Color.parse('white');
109 this._themeColorSwatch.setColor(/** @type {!WebInspector.Color} */ (themeCol or));
110 this._backgroundColorSwatch.classList.toggle('hidden', !stringProperty('back ground_color'));
111 var backgroundColor =
112 WebInspector.Color.parse(stringProperty('background_color') || 'white') || WebInspector.Color.parse('white');
113 this._backgroundColorSwatch.setColor(/** @type {!WebInspector.Color} */ (bac kgroundColor));
114
115 this._orientationField.textContent = stringProperty('orientation');
116 this._displayField.textContent = stringProperty('display');
117
118 var icons = parsedManifest['icons'] || [];
119 this._iconsSection.clearContent();
120 for (var icon of icons) {
121 var title = (icon['sizes'] || '') + '\n' + (icon['type'] || '');
122 var field = this._iconsSection.appendField(title);
123 var imageElement = field.createChild('img');
124 imageElement.style.maxWidth = '200px';
125 imageElement.style.maxHeight = '200px';
126 imageElement.src = WebInspector.ParsedURL.completeURL(url, icon['src']);
127 }
64 128
65 /** 129 /**
66 * @override 130 * @param {string} name
67 * @param {!WebInspector.Target} target 131 * @return {string}
68 */ 132 */
69 targetRemoved: function(target) 133 function stringProperty(name) {
70 { 134 var value = parsedManifest[name];
71 var resourceTreeModel = WebInspector.ResourceTreeModel.fromTarget(target ); 135 if (typeof value !== 'string')
72 if (!this._resourceTreeModel || this._resourceTreeModel !== resourceTree Model) 136 return '';
73 return; 137 return value;
74 resourceTreeModel.removeEventListener(WebInspector.ResourceTreeModel.Eve nts.MainFrameNavigated, this._updateManifest, this); 138 }
75 delete this._resourceTreeModel; 139 }
76 },
77 140
78 _updateManifest: function() 141 _addToHomescreen() {
79 { 142 var target = WebInspector.targetManager.mainTarget();
80 this._resourceTreeModel.fetchAppManifest(this._renderManifest.bind(this) ); 143 if (target && target.hasBrowserCapability()) {
81 }, 144 target.pageAgent().requestAppBanner();
82 145 WebInspector.console.show();
83 /** 146 }
84 * @param {string} url 147 }
85 * @param {?string} data
86 * @param {!Array<!PageAgent.AppManifestError>} errors
87 */
88 _renderManifest: function(url, data, errors)
89 {
90 this._reportView.setURL(url);
91 this._errorsSection.clearContent();
92 this._errorsSection.element.classList.toggle("hidden", !errors.length);
93 for (var error of errors)
94 this._errorsSection.appendRow().appendChild(createLabel(error.messag e, error.critical ? "error-icon" : "warning-icon"));
95
96 if (!data)
97 data = "{}";
98
99 var parsedManifest = JSON.parse(data);
100 this._nameField.textContent = stringProperty("name");
101 this._shortNameField.textContent = stringProperty("short_name");
102 this._startURLField.removeChildren();
103 var startURL = stringProperty("start_url");
104 if (startURL)
105 this._startURLField.appendChild(WebInspector.linkifyResourceAsNode(/ ** @type {string} */(WebInspector.ParsedURL.completeURL(url, startURL)), undefin ed, undefined, undefined, undefined, startURL));
106
107 this._themeColorSwatch.classList.toggle("hidden", !stringProperty("theme _color"));
108 var themeColor = WebInspector.Color.parse(stringProperty("theme_color") || "white") || WebInspector.Color.parse("white");
109 this._themeColorSwatch.setColor(/** @type {!WebInspector.Color} */ (them eColor));
110 this._backgroundColorSwatch.classList.toggle("hidden", !stringProperty(" background_color"));
111 var backgroundColor = WebInspector.Color.parse(stringProperty("backgroun d_color") || "white") || WebInspector.Color.parse("white");
112 this._backgroundColorSwatch.setColor(/** @type {!WebInspector.Color} */ (backgroundColor));
113
114 this._orientationField.textContent = stringProperty("orientation");
115 this._displayField.textContent = stringProperty("display");
116
117 var icons = parsedManifest["icons"] || [];
118 this._iconsSection.clearContent();
119 for (var icon of icons) {
120 var title = (icon["sizes"] || "") + "\n" + (icon["type"] || "");
121 var field = this._iconsSection.appendField(title);
122 var imageElement = field.createChild("img");
123 imageElement.style.maxWidth = "200px";
124 imageElement.style.maxHeight = "200px";
125 imageElement.src = WebInspector.ParsedURL.completeURL(url, icon["src "]);
126 }
127
128 /**
129 * @param {string} name
130 * @return {string}
131 */
132 function stringProperty(name)
133 {
134 var value = parsedManifest[name];
135 if (typeof value !== "string")
136 return "";
137 return value;
138 }
139 },
140
141 _addToHomescreen: function()
142 {
143 var target = WebInspector.targetManager.mainTarget();
144 if (target && target.hasBrowserCapability()) {
145 target.pageAgent().requestAppBanner();
146 WebInspector.console.show();
147 }
148 },
149
150 __proto__: WebInspector.VBox.prototype
151 }; 148 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698