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

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

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

Powered by Google App Engine
This is Rietveld 408576698