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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/components/CustomPreviewSection.js

Issue 1992493002: [DevTools] Pass bindRemoteObject function to Custom Formatter directly (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 * @param {!WebInspector.RemoteObject} object 7 * @param {!WebInspector.RemoteObject} object
8 */ 8 */
9 WebInspector.CustomPreviewSection = function(object) 9 WebInspector.CustomPreviewSection = function(object)
10 { 10 {
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 this._cachedContent.classList.toggle("hidden", !this._expanded); 177 this._cachedContent.classList.toggle("hidden", !this._expanded);
178 }, 178 },
179 179
180 _loadBody: function() 180 _loadBody: function()
181 { 181 {
182 /** 182 /**
183 * @suppressReceiverCheck 183 * @suppressReceiverCheck
184 * @suppressGlobalPropertiesCheck 184 * @suppressGlobalPropertiesCheck
185 * @suppress {undefinedVars} 185 * @suppress {undefinedVars}
186 * @this {Object} 186 * @this {Object}
187 * @param {function(!Object, *):*} bindRemoteObject
187 * @param {*=} formatter 188 * @param {*=} formatter
188 * @param {*=} config 189 * @param {*=} config
189 */ 190 */
190 function load(formatter, config) 191 function load(bindRemoteObject, formatter, config)
191 { 192 {
192 /** 193 /**
193 * @param {*} jsonMLObject 194 * @param {*} jsonMLObject
194 * @throws {string} error message 195 * @throws {string} error message
195 */ 196 */
196 function substituteObjectTagsInCustomPreview(jsonMLObject) 197 function substituteObjectTagsInCustomPreview(jsonMLObject)
197 { 198 {
198 if (!jsonMLObject || (typeof jsonMLObject !== "object") || (type of jsonMLObject.splice !== "function")) 199 if (!jsonMLObject || (typeof jsonMLObject !== "object") || (type of jsonMLObject.splice !== "function"))
199 return; 200 return;
200 201
201 var obj = jsonMLObject.length; 202 var obj = jsonMLObject.length;
202 if (!(typeof obj === "number" && obj >>> 0 === obj && (obj > 0 | | 1 / obj > 0))) 203 if (!(typeof obj === "number" && obj >>> 0 === obj && (obj > 0 | | 1 / obj > 0)))
203 return; 204 return;
204 205
205 var startIndex = 1; 206 var startIndex = 1;
206 if (jsonMLObject[0] === "object") { 207 if (jsonMLObject[0] === "object") {
207 var attributes = jsonMLObject[1]; 208 var attributes = jsonMLObject[1];
208 var originObject = attributes["object"]; 209 var originObject = attributes["object"];
209 var config = attributes["config"]; 210 var config = attributes["config"];
210 if (typeof originObject === "undefined") 211 if (typeof originObject === "undefined")
211 throw "Illegal format: obligatory attribute \"object\" i sn't specified"; 212 throw "Illegal format: obligatory attribute \"object\" i sn't specified";
212 213
213 jsonMLObject[1] = bindRemoteObject(originObject, false, fals e, null, false, config); 214 jsonMLObject[1] = bindRemoteObject(originObject, config);
214 startIndex = 2; 215 startIndex = 2;
215 } 216 }
216 for (var i = startIndex; i < jsonMLObject.length; ++i) 217 for (var i = startIndex; i < jsonMLObject.length; ++i)
217 substituteObjectTagsInCustomPreview(jsonMLObject[i]); 218 substituteObjectTagsInCustomPreview(jsonMLObject[i]);
218 } 219 }
219 220
220 try { 221 try {
221 var body = formatter.body(this, config); 222 var body = formatter.body(this, config);
222 substituteObjectTagsInCustomPreview(body); 223 substituteObjectTagsInCustomPreview(body);
223 return body; 224 return body;
224 } catch (e) { 225 } catch (e) {
225 console.error("Custom Formatter Failed: " + e); 226 console.error("Custom Formatter Failed: " + e);
226 return null; 227 return null;
227 } 228 }
228 } 229 }
229 230
230 var customPreview = this._object.customPreview(); 231 var customPreview = this._object.customPreview();
231 var args = [{objectId: customPreview.formatterObjectId}]; 232 var args = [{objectId: customPreview.bindRemoteObjectFunctionId}, {objec tId: customPreview.formatterObjectId}];
232 if (customPreview.configObjectId) 233 if (customPreview.configObjectId)
233 args.push({objectId: customPreview.configObjectId}); 234 args.push({objectId: customPreview.configObjectId});
234 this._object.callFunctionJSON(load, args, onBodyLoaded.bind(this)); 235 this._object.callFunctionJSON(load, args, onBodyLoaded.bind(this));
235 236
236 /** 237 /**
237 * @param {*} bodyJsonML 238 * @param {*} bodyJsonML
238 * @this {WebInspector.CustomPreviewSection} 239 * @this {WebInspector.CustomPreviewSection}
239 */ 240 */
240 function onBodyLoaded(bodyJsonML) 241 function onBodyLoaded(bodyJsonML)
241 { 242 {
242 if (!bodyJsonML) 243 if (!bodyJsonML)
243 return; 244 return;
244 245
245 this._cachedContent = this._renderJSONMLTag(bodyJsonML); 246 this._cachedContent = this._renderJSONMLTag(bodyJsonML);
246 this._sectionElement.appendChild(this._cachedContent); 247 this._sectionElement.appendChild(this._cachedContent);
247 this._toggleExpand(); 248 this._toggleExpand();
248 } 249 }
249 } 250 }
250 } 251 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698