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

Side by Side Diff: Source/devtools/front_end/CSSStyleModel.js

Issue 14320027: DevTools: Track CSSStyleSheetHeaders in the front-end real time (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 8 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 */ 66 */
67 WebInspector.CSSStyleModel.parseRuleMatchArrayPayload = function(matchArray) 67 WebInspector.CSSStyleModel.parseRuleMatchArrayPayload = function(matchArray)
68 { 68 {
69 var result = []; 69 var result = [];
70 for (var i = 0; i < matchArray.length; ++i) 70 for (var i = 0; i < matchArray.length; ++i)
71 result.push(WebInspector.CSSRule.parsePayload(matchArray[i].rule, matchA rray[i].matchingSelectors)); 71 result.push(WebInspector.CSSRule.parsePayload(matchArray[i].rule, matchA rray[i].matchingSelectors));
72 return result; 72 return result;
73 } 73 }
74 74
75 WebInspector.CSSStyleModel.Events = { 75 WebInspector.CSSStyleModel.Events = {
76 StyleSheetAdded: "StyleSheetAdded",
76 StyleSheetChanged: "StyleSheetChanged", 77 StyleSheetChanged: "StyleSheetChanged",
78 StyleSheetRemoved: "StyleSheetRemoved",
77 MediaQueryResultChanged: "MediaQueryResultChanged", 79 MediaQueryResultChanged: "MediaQueryResultChanged",
78 NamedFlowCreated: "NamedFlowCreated", 80 NamedFlowCreated: "NamedFlowCreated",
79 NamedFlowRemoved: "NamedFlowRemoved", 81 NamedFlowRemoved: "NamedFlowRemoved",
80 RegionLayoutUpdated: "RegionLayoutUpdated" 82 RegionLayoutUpdated: "RegionLayoutUpdated"
81 } 83 }
82 84
83 WebInspector.CSSStyleModel.MediaTypes = ["all", "braille", "embossed", "handheld ", "print", "projection", "screen", "speech", "tty", "tv"]; 85 WebInspector.CSSStyleModel.MediaTypes = ["all", "braille", "embossed", "handheld ", "print", "projection", "screen", "speech", "tty", "tv"];
84 86
85 WebInspector.CSSStyleModel.prototype = { 87 WebInspector.CSSStyleModel.prototype = {
86 /** 88 /**
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 this._pendingCommandsMajorState.push(true); 353 this._pendingCommandsMajorState.push(true);
352 CSSAgent.addRule(nodeId, selector, callback.bind(this, successCallback, failureCallback, selector)); 354 CSSAgent.addRule(nodeId, selector, callback.bind(this, successCallback, failureCallback, selector));
353 }, 355 },
354 356
355 mediaQueryResultChanged: function() 357 mediaQueryResultChanged: function()
356 { 358 {
357 this.dispatchEventToListeners(WebInspector.CSSStyleModel.Events.MediaQue ryResultChanged); 359 this.dispatchEventToListeners(WebInspector.CSSStyleModel.Events.MediaQue ryResultChanged);
358 }, 360 },
359 361
360 /** 362 /**
363 * @return {Array.<CSSAgent.CSSStyleSheetHeader>}
364 */
365 styleSheetHeaders: function()
366 {
367 return Object.values(this._resourceBinding._styleSheetIdToHeader);
368 },
369
370 /**
361 * @param {DOMAgent.NodeId} nodeId 371 * @param {DOMAgent.NodeId} nodeId
362 */ 372 */
363 _ownerDocumentId: function(nodeId) 373 _ownerDocumentId: function(nodeId)
364 { 374 {
365 var node = WebInspector.domAgent.nodeForId(nodeId); 375 var node = WebInspector.domAgent.nodeForId(nodeId);
366 if (!node) 376 if (!node)
367 return null; 377 return null;
368 return node.ownerDocument ? node.ownerDocument.id : null; 378 return node.ownerDocument ? node.ownerDocument.id : null;
369 }, 379 },
370 380
371 /** 381 /**
372 * @param {CSSAgent.StyleSheetId} styleSheetId 382 * @param {CSSAgent.StyleSheetId} styleSheetId
373 */ 383 */
374 _fireStyleSheetChanged: function(styleSheetId) 384 _fireStyleSheetChanged: function(styleSheetId)
375 { 385 {
376 if (!this._pendingCommandsMajorState.length) 386 if (!this._pendingCommandsMajorState.length)
377 return; 387 return;
378 388
379 var majorChange = this._pendingCommandsMajorState[this._pendingCommandsM ajorState.length - 1]; 389 var majorChange = this._pendingCommandsMajorState[this._pendingCommandsM ajorState.length - 1];
380 390
381 if (!majorChange || !styleSheetId || !this.hasEventListeners(WebInspecto r.CSSStyleModel.Events.StyleSheetChanged)) 391 if (!majorChange || !styleSheetId || !this.hasEventListeners(WebInspecto r.CSSStyleModel.Events.StyleSheetChanged))
382 return; 392 return;
383 393
384 this.dispatchEventToListeners(WebInspector.CSSStyleModel.Events.StyleShe etChanged, { styleSheetId: styleSheetId, majorChange: majorChange }); 394 this.dispatchEventToListeners(WebInspector.CSSStyleModel.Events.StyleShe etChanged, { styleSheetId: styleSheetId, majorChange: majorChange });
385 }, 395 },
386 396
397 _styleSheetAdded: function(header)
398 {
399 this._resourceBinding._setHeaderForStyleSheetId(header.styleSheetId, hea der);
400 this.dispatchEventToListeners(WebInspector.CSSStyleModel.Events.StyleShe etAdded, header);
401 },
402
403 _styleSheetRemoved: function(id)
404 {
405 var header = this._resourceBinding._styleSheetIdToHeader[id];
406 console.assert(header);
407 this._resourceBinding._setHeaderForStyleSheetId(id, null);
408 this.dispatchEventToListeners(WebInspector.CSSStyleModel.Events.StyleShe etRemoved, header);
409 },
410
387 /** 411 /**
388 * @param {CSSAgent.NamedFlow} namedFlowPayload 412 * @param {CSSAgent.NamedFlow} namedFlowPayload
389 */ 413 */
390 _namedFlowCreated: function(namedFlowPayload) 414 _namedFlowCreated: function(namedFlowPayload)
391 { 415 {
392 var namedFlow = WebInspector.NamedFlow.parsePayload(namedFlowPayload); 416 var namedFlow = WebInspector.NamedFlow.parsePayload(namedFlowPayload);
393 var namedFlowCollection = this._namedFlowCollections[namedFlow.documentN odeId]; 417 var namedFlowCollection = this._namedFlowCollections[namedFlow.documentN odeId];
394 418
395 if (!namedFlowCollection) 419 if (!namedFlowCollection)
396 return; 420 return;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 this._pendingCommandsMajorState.push(true); 479 this._pendingCommandsMajorState.push(true);
456 }, 480 },
457 481
458 _undoRedoCompleted: function() 482 _undoRedoCompleted: function()
459 { 483 {
460 this._pendingCommandsMajorState.pop(); 484 this._pendingCommandsMajorState.pop();
461 }, 485 },
462 486
463 /** 487 /**
464 * @param {WebInspector.CSSRule} rule 488 * @param {WebInspector.CSSRule} rule
465 * @param {function(?WebInspector.Resource)} callback 489 * @return {?WebInspector.Resource}
466 */ 490 */
467 getViaInspectorResourceForRule: function(rule, callback) 491 viaInspectorResourceForRule: function(rule)
apavlov 2013/04/19 15:50:19 I'm happy to retain the callbacks and convert thes
468 { 492 {
469 if (!rule.id) { 493 if (!rule.id)
470 callback(null); 494 return null;
471 return; 495 return this._resourceBinding._inspectorResource(rule.id.styleSheetId);
472 }
473 this._resourceBinding._requestViaInspectorResource(rule.id.styleSheetId, callback);
474 }, 496 },
475 497
476 /** 498 /**
477 * @return {WebInspector.CSSStyleModelResourceBinding} 499 * @return {WebInspector.CSSStyleModelResourceBinding}
478 */ 500 */
479 resourceBinding: function() 501 resourceBinding: function()
480 { 502 {
481 return this._resourceBinding; 503 return this._resourceBinding;
482 }, 504 },
483 505
(...skipping 767 matching lines...) Expand 10 before | Expand all | Expand 10 after
1251 /** 1273 /**
1252 * @constructor 1274 * @constructor
1253 */ 1275 */
1254 WebInspector.CSSStyleModelResourceBinding = function() 1276 WebInspector.CSSStyleModelResourceBinding = function()
1255 { 1277 {
1256 this._reset(); 1278 this._reset();
1257 } 1279 }
1258 1280
1259 WebInspector.CSSStyleModelResourceBinding.prototype = { 1281 WebInspector.CSSStyleModelResourceBinding.prototype = {
1260 /** 1282 /**
1261 * @param {WebInspector.Resource} resource 1283 * @param {CSSAgent.StyleSheetId} styleSheetId
1262 * @param {function(?CSSAgent.StyleSheetId)} callback 1284 * @param {CSSAgent.CSSStyleSheetHeader} header
1263 */ 1285 */
1264 requestStyleSheetIdForResource: function(resource, callback) 1286 _setHeaderForStyleSheetId: function(styleSheetId, header)
1265 { 1287 {
1266 function innerCallback() 1288 var oldHeader = this._styleSheetIdToHeader[styleSheetId];
1267 { 1289 if (oldHeader) {
1268 callback(this._styleSheetIdForResource(resource)); 1290 delete this._styleSheetIdToHeader[styleSheetId];
1291 delete this._frameAndURLToStyleSheetId[this._headerKey(oldHeader)];
1269 } 1292 }
1270 1293 if (header) {
1271 if (this._styleSheetIdForResource(resource)) 1294 this._styleSheetIdToHeader[styleSheetId] = header;
1272 innerCallback.call(this); 1295 if (header.origin === "inspector")
1273 else 1296 this._createInspectorResource(header);
1274 this._loadStyleSheetHeaders(innerCallback.bind(this)); 1297 else
1298 this._frameAndURLToStyleSheetId[this._headerKey(header)] = heade r.styleSheetId;
1299 }
1275 }, 1300 },
1276 1301
1277 /** 1302 /**
1278 * @param {CSSAgent.StyleSheetId} styleSheetId 1303 * @param {CSSAgent.StyleSheetId} styleSheetId
1279 * @param {function(?string)} callback 1304 * @return {?string}
1280 */ 1305 */
1281 requestResourceURLForStyleSheetId: function(styleSheetId, callback) 1306 resourceURLForStyleSheetId: function(styleSheetId)
1282 { 1307 {
1283 function innerCallback() 1308 var header = this._styleSheetIdToHeader[styleSheetId];
1284 { 1309 if (!header)
1285 var header = this._styleSheetIdToHeader[styleSheetId]; 1310 return null;
1286 if (!header) {
1287 callback(null);
1288 return;
1289 }
1290 1311
1291 var frame = WebInspector.resourceTreeModel.frameForId(header.frameId ); 1312 var frame = WebInspector.resourceTreeModel.frameForId(header.frameId);
1292 if (!frame) { 1313 if (!frame)
1293 callback(null); 1314 return null;
1294 return;
1295 }
1296 1315
1297 var styleSheetURL = header.origin === "inspector" ? this._viaInspect orResourceURL(header.sourceURL) : header.sourceURL; 1316 var styleSheetURL = header.origin === "inspector" ? this._viaInspectorRe sourceURL(header.sourceURL) : header.sourceURL;
1298 callback(styleSheetURL); 1317 return styleSheetURL;
1299 }
1300
1301 if (this._styleSheetIdToHeader[styleSheetId])
1302 innerCallback.call(this);
1303 else
1304 this._loadStyleSheetHeaders(innerCallback.bind(this));
1305 }, 1318 },
1306 1319
1307 /** 1320 /**
1308 * @param {WebInspector.Resource} resource 1321 * @param {WebInspector.Resource} resource
1309 * @return {CSSAgent.StyleSheetId} 1322 * @return {CSSAgent.StyleSheetId|undefined}
1310 */ 1323 */
1311 _styleSheetIdForResource: function(resource) 1324 styleSheetIdForResource: function(resource)
1312 { 1325 {
1313 return this._frameAndURLToStyleSheetId[resource.frameId + ":" + resource .url]; 1326 return this._frameAndURLToStyleSheetId[resource.frameId + ":" + resource .url];
1314 }, 1327 },
1315 1328
1316 /** 1329 /**
1317 * @param {function(?string)} callback 1330 * @param {!CSSAgent.CSSStyleSheetHeader} header
1331 * @return {string}
1318 */ 1332 */
1319 _loadStyleSheetHeaders: function(callback) 1333 _headerKey: function(header)
1320 { 1334 {
1321 /** 1335 return header.frameId + ":" + (header.origin === "inspector" ? this._via InspectorResourceURL(header.sourceURL) : header.sourceURL);
1322 * @param {?string} error
1323 * @param {Array.<CSSAgent.CSSStyleSheetHeader>} infos
1324 */
1325 function didGetAllStyleSheets(error, infos)
1326 {
1327 if (error) {
1328 callback(error);
1329 return;
1330 }
1331
1332 for (var i = 0; i < infos.length; ++i) {
1333 var info = infos[i];
1334 if (info.origin === "inspector") {
1335 this._getOrCreateInspectorResource(info);
1336 continue;
1337 }
1338 this._frameAndURLToStyleSheetId[info.frameId + ":" + info.source URL] = info.styleSheetId;
1339 this._styleSheetIdToHeader[info.styleSheetId] = info;
1340 }
1341 callback(null);
1342 }
1343 CSSAgent.getAllStyleSheets(didGetAllStyleSheets.bind(this));
1344 },
1345
1346 /**
1347 * @param {CSSAgent.StyleSheetId} styleSheetId
1348 * @param {function(?WebInspector.Resource)} callback
1349 */
1350 _requestViaInspectorResource: function(styleSheetId, callback)
1351 {
1352 var header = this._styleSheetIdToHeader[styleSheetId];
1353 if (header) {
1354 callback(this._getOrCreateInspectorResource(header));
1355 return;
1356 }
1357
1358 function headersLoaded()
1359 {
1360 var header = this._styleSheetIdToHeader[styleSheetId];
1361 if (header)
1362 callback(this._getOrCreateInspectorResource(header));
1363 else
1364 callback(null);
1365 }
1366 this._loadStyleSheetHeaders(headersLoaded.bind(this));
1367 }, 1336 },
1368 1337
1369 /** 1338 /**
1370 * @param {CSSAgent.CSSStyleSheetHeader} header 1339 * @param {CSSAgent.CSSStyleSheetHeader} header
1371 * @return {?WebInspector.Resource}
1372 */ 1340 */
1373 _getOrCreateInspectorResource: function(header) 1341 _createInspectorResource: function(header)
1374 { 1342 {
1375 var frame = WebInspector.resourceTreeModel.frameForId(header.frameId); 1343 var frame = WebInspector.resourceTreeModel.frameForId(header.frameId);
1376 if (!frame) 1344 if (!frame)
1377 return null; 1345 return;
1378 1346
1379 var viaInspectorURL = this._viaInspectorResourceURL(header.sourceURL); 1347 var viaInspectorURL = this._viaInspectorResourceURL(header.sourceURL);
1380 var inspectorResource = frame.resourceForURL(viaInspectorURL); 1348 console.assert(!frame.resourceForURL(viaInspectorURL));
1381 if (inspectorResource)
1382 return inspectorResource;
1383 1349
1384 var resource = frame.resourceForURL(header.sourceURL); 1350 var resource = frame.resourceForURL(header.sourceURL);
1385 if (!resource) 1351 if (!resource)
1386 return null; 1352 return;
1387 1353
1388 this._frameAndURLToStyleSheetId[header.frameId + ":" + viaInspectorURL] = header.styleSheetId; 1354 this._frameAndURLToStyleSheetId[this._headerKey(header)] = header.styleS heetId;
1389 this._styleSheetIdToHeader[header.styleSheetId] = header; 1355 var inspectorResource = new WebInspector.Resource(null, viaInspectorURL, resource.documentURL, resource.frameId, resource.loaderId, WebInspector.resourc eTypes.Stylesheet, "text/css", true);
1390 inspectorResource = new WebInspector.Resource(null, viaInspectorURL, res ource.documentURL, resource.frameId, resource.loaderId, WebInspector.resourceTyp es.Stylesheet, "text/css", true); 1356
1391 /** 1357 /**
1392 * @param {function(?string, boolean, string)} callback 1358 * @param {function(?string, boolean, string)} callback
1393 */ 1359 */
1394 function overrideRequestContent(callback) 1360 function overrideRequestContent(callback)
1395 { 1361 {
1396 function callbackWrapper(error, content) 1362 function callbackWrapper(error, content)
1397 { 1363 {
1398 callback(error ? "" : content, false, "text/css"); 1364 callback(error ? "" : content, false, "text/css");
1399 } 1365 }
1400 CSSAgent.getStyleSheetText(header.styleSheetId, callbackWrapper); 1366 CSSAgent.getStyleSheetText(header.styleSheetId, callbackWrapper);
1401 } 1367 }
1402 inspectorResource.requestContent = overrideRequestContent; 1368 inspectorResource.requestContent = overrideRequestContent;
1403 frame.addResource(inspectorResource); 1369 frame.addResource(inspectorResource);
1404 return inspectorResource;
1405 }, 1370 },
1406 1371
1407 /** 1372 /**
1373 * @param {CSSAgent.StyleSheetId} styleSheetId
1374 * @return {?WebInspector.Resource}
1375 */
1376 _inspectorResource: function(styleSheetId)
1377 {
1378 var header = this._styleSheetIdToHeader[styleSheetId];
1379 if (!header)
1380 return null;
1381 var frame = WebInspector.resourceTreeModel.frameForId(header.frameId);
1382 if (!frame)
1383 return null;
1384
1385 var viaInspectorURL = this._viaInspectorResourceURL(header.sourceURL);
1386 return frame.resourceForURL(viaInspectorURL);
1387 },
1388
1389 /**
1408 * @param {string} documentURL 1390 * @param {string} documentURL
1409 * @return {string} 1391 * @return {string}
1410 */ 1392 */
1411 _viaInspectorResourceURL: function(documentURL) 1393 _viaInspectorResourceURL: function(documentURL)
1412 { 1394 {
1413 var parsedURL = new WebInspector.ParsedURL(documentURL); 1395 var parsedURL = new WebInspector.ParsedURL(documentURL);
1414 var fakeURL = "inspector://" + parsedURL.host + parsedURL.folderPathComp onents; 1396 var fakeURL = "inspector://" + parsedURL.host + parsedURL.folderPathComp onents;
1415 if (!fakeURL.endsWith("/")) 1397 if (!fakeURL.endsWith("/"))
1416 fakeURL += "/"; 1398 fakeURL += "/";
1417 fakeURL += "inspector-stylesheet"; 1399 fakeURL += "inspector-stylesheet";
1418 return fakeURL; 1400 return fakeURL;
1419 }, 1401 },
1420 1402
1421 _reset: function() 1403 _reset: function()
1422 { 1404 {
1423 // Main frame navigation - clear history. 1405 // Main frame navigation - clear history.
1406 /** @type {!Object.<string, !CSSAgent.StyleSheetId>} */
1424 this._frameAndURLToStyleSheetId = {}; 1407 this._frameAndURLToStyleSheetId = {};
1408 /** @type {!Object.<CSSAgent.StyleSheetId, !CSSAgent.CSSStyleSheetHeader >} */
1425 this._styleSheetIdToHeader = {}; 1409 this._styleSheetIdToHeader = {};
1426 } 1410 }
1427 } 1411 }
1428 1412
1429 /** 1413 /**
1430 * @constructor 1414 * @constructor
1431 * @implements {CSSAgent.Dispatcher} 1415 * @implements {CSSAgent.Dispatcher}
1432 * @param {WebInspector.CSSStyleModel} cssModel 1416 * @param {WebInspector.CSSStyleModel} cssModel
1433 */ 1417 */
1434 WebInspector.CSSDispatcher = function(cssModel) 1418 WebInspector.CSSDispatcher = function(cssModel)
1435 { 1419 {
1436 this._cssModel = cssModel; 1420 this._cssModel = cssModel;
1437 } 1421 }
1438 1422
1439 WebInspector.CSSDispatcher.prototype = { 1423 WebInspector.CSSDispatcher.prototype = {
1440 mediaQueryResultChanged: function() 1424 mediaQueryResultChanged: function()
1441 { 1425 {
1442 this._cssModel.mediaQueryResultChanged(); 1426 this._cssModel.mediaQueryResultChanged();
1443 }, 1427 },
1444 1428
1445 /** 1429 /**
1446 * @param {CSSAgent.StyleSheetId} styleSheetId 1430 * @param {CSSAgent.StyleSheetId} styleSheetId
1447 */ 1431 */
1448 styleSheetChanged: function(styleSheetId) 1432 styleSheetChanged: function(styleSheetId)
1449 { 1433 {
1450 this._cssModel._fireStyleSheetChanged(styleSheetId); 1434 this._cssModel._fireStyleSheetChanged(styleSheetId);
1451 }, 1435 },
1452 1436
1453 /** 1437 /**
1438 * @param {CSSAgent.CSSStyleSheetHeader} header
1439 */
1440 styleSheetAdded: function(header)
1441 {
1442 this._cssModel._styleSheetAdded(header);
1443 },
1444
1445 /**
1446 * @param {CSSAgent.StyleSheetId} id
1447 */
1448 styleSheetRemoved: function(id)
1449 {
1450 this._cssModel._styleSheetRemoved(id);
1451 },
1452
1453 /**
1454 * @param {CSSAgent.NamedFlow} namedFlowPayload 1454 * @param {CSSAgent.NamedFlow} namedFlowPayload
1455 */ 1455 */
1456 namedFlowCreated: function(namedFlowPayload) 1456 namedFlowCreated: function(namedFlowPayload)
1457 { 1457 {
1458 this._cssModel._namedFlowCreated(namedFlowPayload); 1458 this._cssModel._namedFlowCreated(namedFlowPayload);
1459 }, 1459 },
1460 1460
1461 /** 1461 /**
1462 * @param {DOMAgent.NodeId} documentNodeId 1462 * @param {DOMAgent.NodeId} documentNodeId
1463 * @param {string} flowName 1463 * @param {string} flowName
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
1540 1540
1541 if (!namedFlow) 1541 if (!namedFlow)
1542 return null; 1542 return null;
1543 return namedFlow; 1543 return namedFlow;
1544 } 1544 }
1545 } 1545 }
1546 /** 1546 /**
1547 * @type {WebInspector.CSSStyleModel} 1547 * @type {WebInspector.CSSStyleModel}
1548 */ 1548 */
1549 WebInspector.cssModel = null; 1549 WebInspector.cssModel = null;
OLDNEW
« no previous file with comments | « Source/core/inspector/InspectorStyleSheet.h ('k') | Source/devtools/front_end/SASSSourceMapping.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698