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

Side by Side Diff: Source/devtools/front_end/emulation/EmulatedDevices.js

Issue 1160883011: [DevTools] Remove external device list update. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 6 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 // 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 */ 7 */
8 WebInspector.EmulatedDevice = function() 8 WebInspector.EmulatedDevice = function()
9 { 9 {
10 /** @type {string} */ 10 /** @type {string} */
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 * @constructor 380 * @constructor
381 * @extends {WebInspector.Object} 381 * @extends {WebInspector.Object}
382 */ 382 */
383 WebInspector.EmulatedDevice.Images = function() 383 WebInspector.EmulatedDevice.Images = function()
384 { 384 {
385 WebInspector.Object.call(this); 385 WebInspector.Object.call(this);
386 this._sources = []; 386 this._sources = [];
387 this._scales = []; 387 this._scales = [];
388 } 388 }
389 389
390 WebInspector.EmulatedDevice.Images.Events = {
391 Update: "Update"
392 }
393
394 WebInspector.EmulatedDevice.Images.prototype = { 390 WebInspector.EmulatedDevice.Images.prototype = {
395 /** 391 /**
396 * @return {*} 392 * @return {*}
397 */ 393 */
398 _toJSON: function() 394 _toJSON: function()
399 { 395 {
400 var result = []; 396 var result = [];
401 for (var i = 0; i < this._sources.length; ++i) 397 for (var i = 0; i < this._sources.length; ++i)
402 result.push({src: this._sources[i], scale: this._scales[i]}); 398 result.push({src: this._sources[i], scale: this._scales[i]});
403 return result; 399 return result;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 443
448 /** @type {!WebInspector.Setting} */ 444 /** @type {!WebInspector.Setting} */
449 this._standardSetting = WebInspector.settings.createSetting("standardEmulate dDeviceList", defaultValue); 445 this._standardSetting = WebInspector.settings.createSetting("standardEmulate dDeviceList", defaultValue);
450 /** @type {!Array.<!WebInspector.EmulatedDevice>} */ 446 /** @type {!Array.<!WebInspector.EmulatedDevice>} */
451 this._standard = this._listFromJSONV1(this._standardSetting.get()); 447 this._standard = this._listFromJSONV1(this._standardSetting.get());
452 448
453 /** @type {!WebInspector.Setting} */ 449 /** @type {!WebInspector.Setting} */
454 this._customSetting = WebInspector.settings.createSetting("customEmulatedDev iceList", []); 450 this._customSetting = WebInspector.settings.createSetting("customEmulatedDev iceList", []);
455 /** @type {!Array.<!WebInspector.EmulatedDevice>} */ 451 /** @type {!Array.<!WebInspector.EmulatedDevice>} */
456 this._custom = this._listFromJSONV1(this._customSetting.get()); 452 this._custom = this._listFromJSONV1(this._customSetting.get());
457
458 /** @type {!WebInspector.Setting} */
459 this._lastUpdatedSetting = WebInspector.settings.createSetting("lastUpdatedD eviceList", null);
460
461 /** @type {boolean} */
462 this._updating = false;
463 } 453 }
464 454
465 WebInspector.EmulatedDevicesList.Events = { 455 WebInspector.EmulatedDevicesList.Events = {
466 CustomDevicesUpdated: "CustomDevicesUpdated", 456 CustomDevicesUpdated: "CustomDevicesUpdated",
467 IsUpdatingChanged: "IsUpdatingChanged",
468 StandardDevicesUpdated: "StandardDevicesUpdated" 457 StandardDevicesUpdated: "StandardDevicesUpdated"
469 } 458 }
470 459
471 WebInspector.EmulatedDevicesList._DevicesJsonUrl = "https://api.github.com/repos /GoogleChrome/devtools-device-data/contents/devices.json?ref=release";
472 WebInspector.EmulatedDevicesList._UpdateIntervalMs = 24 * 60 * 60 * 1000;
473
474 WebInspector.EmulatedDevicesList.prototype = { 460 WebInspector.EmulatedDevicesList.prototype = {
475 /** 461 /**
476 * @param {!Array.<*>} jsonArray 462 * @param {!Array.<*>} jsonArray
477 * @return {!Array.<!WebInspector.EmulatedDevice>} 463 * @return {!Array.<!WebInspector.EmulatedDevice>}
478 */ 464 */
479 _listFromJSONV1: function(jsonArray) 465 _listFromJSONV1: function(jsonArray)
480 { 466 {
481 var result = []; 467 var result = [];
482 if (!Array.isArray(jsonArray)) 468 if (!Array.isArray(jsonArray))
483 return result; 469 return result;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 this.dispatchEventToListeners(WebInspector.EmulatedDevicesList.Events.Cu stomDevicesUpdated); 516 this.dispatchEventToListeners(WebInspector.EmulatedDevicesList.Events.Cu stomDevicesUpdated);
531 }, 517 },
532 518
533 saveStandardDevices: function() 519 saveStandardDevices: function()
534 { 520 {
535 var json = this._standard.map(/** @param {!WebInspector.EmulatedDevice} device */ function(device) { return device._toJSON(); }); 521 var json = this._standard.map(/** @param {!WebInspector.EmulatedDevice} device */ function(device) { return device._toJSON(); });
536 this._standardSetting.set(json); 522 this._standardSetting.set(json);
537 this.dispatchEventToListeners(WebInspector.EmulatedDevicesList.Events.St andardDevicesUpdated); 523 this.dispatchEventToListeners(WebInspector.EmulatedDevicesList.Events.St andardDevicesUpdated);
538 }, 524 },
539 525
540 update: function()
541 {
542 if (this._updating)
543 return;
544
545 this._updating = true;
546 this.dispatchEventToListeners(WebInspector.EmulatedDevicesList.Events.Is UpdatingChanged);
547
548 /**
549 * @param {*} json
550 * @return {!Promise.<string>}
551 */
552 function decodeBase64Content(json)
553 {
554 return loadXHR("data:application/json;charset=utf-8;base64," + json. content);
555 }
556
557 /**
558 * FIXME: promise chain below does not compile with JSON.parse.
559 * @return {*}
560 */
561 function myJsonParse(json)
562 {
563 return JSON.parse(json);
564 }
565
566 loadXHR(WebInspector.EmulatedDevicesList._DevicesJsonUrl)
567 .then(JSON.parse)
568 .then(decodeBase64Content)
569 .then(myJsonParse)
570 .then(this._parseUpdatedDevices.bind(this))
571 .then(this._updateFinished.bind(this))
572 .catch(this._updateFailed.bind(this));
573 },
574
575 maybeAutoUpdate: function()
576 {
577 if (!Runtime.experiments.isEnabled("externalDeviceList"))
578 return;
579 var lastUpdated = this._lastUpdatedSetting.get();
580 if (lastUpdated && (Date.now() - lastUpdated < WebInspector.EmulatedDevi cesList._UpdateIntervalMs))
581 return;
582 this.update();
583 },
584
585 /**
586 * @param {*} json
587 */
588 _parseUpdatedDevices: function(json)
589 {
590 if (!json || typeof json !== "object") {
591 WebInspector.console.error("Malfromed device list");
592 return;
593 }
594 if (!("version" in json) || typeof json["version"] !== "number") {
595 WebInspector.console.error("Device list does not specify version");
596 return;
597 }
598 var version = json["version"];
599 if (version === 1) {
600 this._parseDevicesV1(json);
601 return;
602 }
603 WebInspector.console.error("Unsupported device list version '" + version + "'");
604 },
605
606 /**
607 * @param {*} json
608 */
609 _parseDevicesV1: function(json)
610 {
611 if (!("devices" in json)) {
612 WebInspector.console.error("Malfromed device list");
613 return;
614 }
615 var devices = json["devices"];
616 if (!Array.isArray(devices)) {
617 WebInspector.console.error("Malfromed device list");
618 return;
619 }
620
621 devices = this._listFromJSONV1(devices);
622 this._copyShowValues(this._standard, devices);
623 this._standard = devices;
624 this.saveStandardDevices();
625 WebInspector.console.log("Device list updated successfully");
626 },
627
628 _updateFailed: function()
629 {
630 WebInspector.console.error("Cannot update device list");
631 this._updateFinished();
632 },
633
634 _updateFinished: function()
635 {
636 this._updating = false;
637 this._lastUpdatedSetting.set(Date.now());
638 this.dispatchEventToListeners(WebInspector.EmulatedDevicesList.Events.Is UpdatingChanged);
639 },
640
641 /** 526 /**
642 * @param {!Array.<!WebInspector.EmulatedDevice>} from 527 * @param {!Array.<!WebInspector.EmulatedDevice>} from
643 * @param {!Array.<!WebInspector.EmulatedDevice>} to 528 * @param {!Array.<!WebInspector.EmulatedDevice>} to
644 */ 529 */
645 _copyShowValues: function(from, to) 530 _copyShowValues: function(from, to)
646 { 531 {
647 var deviceById = new Map(); 532 var deviceById = new Map();
648 for (var i = 0; i < from.length; ++i) 533 for (var i = 0; i < from.length; ++i)
649 deviceById.set(from[i].title, from[i]); 534 deviceById.set(from[i].title, from[i]);
650 535
651 for (var i = 0; i < to.length; ++i) { 536 for (var i = 0; i < to.length; ++i) {
652 var title = to[i].title; 537 var title = to[i].title;
653 if (deviceById.has(title)) 538 if (deviceById.has(title))
654 to[i].copyShowFrom(/** @type {!WebInspector.EmulatedDevice} */ ( deviceById.get(title))); 539 to[i].copyShowFrom(/** @type {!WebInspector.EmulatedDevice} */ ( deviceById.get(title)));
655 } 540 }
656 }, 541 },
657 542
658 /**
659 * @return {boolean}
660 */
661 isUpdating: function()
662 {
663 return this._updating;
664 },
665
666 __proto__: WebInspector.Object.prototype 543 __proto__: WebInspector.Object.prototype
667 } 544 }
668 545
669 /** @type {!WebInspector.EmulatedDevicesList} */ 546 /** @type {!WebInspector.EmulatedDevicesList} */
670 WebInspector.emulatedDevicesList; 547 WebInspector.emulatedDevicesList;
OLDNEW
« no previous file with comments | « Source/devtools/front_end/emulation/DevicesSettingsTab.js ('k') | Source/devtools/front_end/emulation/OverridesUI.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698