Skip to content

Commit

Permalink
[DevTools] Make all SDKModels take a single argument in constructor.
Browse files Browse the repository at this point in the history
- NetworkLog is not an SDKModel anymore.
- Moved ApplicationCacheModel to Resources.

BUG=none

Review-Url: https://codereview.chromium.org/2654423003
Cr-Commit-Position: refs/heads/master@{#446893}
  • Loading branch information
dgozman authored and Commit bot committed Jan 28, 2017
1 parent 2429f0c commit ed6ef78
Show file tree
Hide file tree
Showing 29 changed files with 169 additions and 153 deletions.
2 changes: 1 addition & 1 deletion BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ all_devtools_files = [
"front_end/quick_open/filteredListWidget.css",
"front_end/quick_open/FilteredListWidget.js",
"front_end/quick_open/module.json",
"front_end/resources/ApplicationCacheModel.js",
"front_end/resources/ApplicationCacheItemsView.js",
"front_end/resources/appManifestView.css",
"front_end/resources/AppManifestView.js",
Expand Down Expand Up @@ -413,7 +414,6 @@ all_devtools_files = [
"front_end/screencast/ScreencastApp.js",
"front_end/screencast/screencastView.css",
"front_end/screencast/ScreencastView.js",
"front_end/sdk/ApplicationCacheModel.js",
"front_end/sdk/Connections.js",
"front_end/sdk/ConsoleModel.js",
"front_end/sdk/ContentProviders.js",
Expand Down
11 changes: 4 additions & 7 deletions front_end/accessibility/AccessibilityModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ Accessibility.AccessibilityModel = class extends SDK.SDKModel {
* @param {!SDK.Target} target
*/
constructor(target) {
super(Accessibility.AccessibilityModel, target);
super(target);
this._agent = target.accessibilityAgent();

/** @type {!Map<string, !Accessibility.AccessibilityNode>} */
Expand All @@ -225,13 +225,10 @@ Accessibility.AccessibilityModel = class extends SDK.SDKModel {

/**
* @param {!SDK.Target} target
* @return {!Accessibility.AccessibilityModel}
* @return {?Accessibility.AccessibilityModel}
*/
static fromTarget(target) {
if (!target[Accessibility.AccessibilityModel._symbol])
target[Accessibility.AccessibilityModel._symbol] = new Accessibility.AccessibilityModel(target);

return target[Accessibility.AccessibilityModel._symbol];
return target.model(Accessibility.AccessibilityModel);
}

clear() {
Expand Down Expand Up @@ -314,4 +311,4 @@ Accessibility.AccessibilityModel = class extends SDK.SDKModel {
}
};

Accessibility.AccessibilityModel._symbol = Symbol('AccessibilityModel');
SDK.SDKModel.register(Accessibility.AccessibilityModel, SDK.Target.Capability.DOM);
13 changes: 4 additions & 9 deletions front_end/animation/AnimationModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Animation.AnimationModel = class extends SDK.SDKModel {
* @param {!SDK.Target} target
*/
constructor(target) {
super(Animation.AnimationModel, target);
super(target);
this._agent = target.animationAgent();
target.registerAnimationDispatcher(new Animation.AnimationDispatcher(this));
/** @type {!Map.<string, !Animation.AnimationModel.Animation>} */
Expand All @@ -31,12 +31,7 @@ Animation.AnimationModel = class extends SDK.SDKModel {
* @return {?Animation.AnimationModel}
*/
static fromTarget(target) {
if (!target.hasDOMCapability())
return null;
if (!target[Animation.AnimationModel._symbol])
target[Animation.AnimationModel._symbol] = new Animation.AnimationModel(target);

return target[Animation.AnimationModel._symbol];
return target.model(Animation.AnimationModel);
}

_reset() {
Expand Down Expand Up @@ -191,14 +186,14 @@ Animation.AnimationModel = class extends SDK.SDKModel {
}
};

SDK.SDKModel.register(Animation.AnimationModel, SDK.Target.Capability.DOM);

/** @enum {symbol} */
Animation.AnimationModel.Events = {
AnimationGroupStarted: Symbol('AnimationGroupStarted'),
ModelReset: Symbol('ModelReset')
};

Animation.AnimationModel._symbol = Symbol('AnimationModel');


/**
* @unrestricted
Expand Down
12 changes: 4 additions & 8 deletions front_end/layers/LayerTreeModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
*/
Layers.LayerTreeModel = class extends SDK.SDKModel {
constructor(target) {
super(Layers.LayerTreeModel, target);
super(target);
target.registerLayerTreeDispatcher(new Layers.LayerTreeDispatcher(this));
SDK.targetManager.addEventListener(SDK.TargetManager.Events.MainFrameNavigated, this._onMainFrameNavigated, this);
/** @type {?SDK.LayerTreeBase} */
Expand All @@ -45,13 +45,7 @@ Layers.LayerTreeModel = class extends SDK.SDKModel {
* @return {?Layers.LayerTreeModel}
*/
static fromTarget(target) {
if (!target.hasDOMCapability())
return null;

var model = target.model(Layers.LayerTreeModel);
if (!model)
model = new Layers.LayerTreeModel(target);
return model;
return target.model(Layers.LayerTreeModel);
}

disable() {
Expand Down Expand Up @@ -131,6 +125,8 @@ Layers.LayerTreeModel = class extends SDK.SDKModel {
}
};

SDK.SDKModel.register(Layers.LayerTreeModel, SDK.Target.Capability.DOM);

/** @enum {symbol} */
Layers.LayerTreeModel.Events = {
LayerTreeChanged: Symbol('LayerTreeChanged'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@
/**
* @unrestricted
*/
SDK.ApplicationCacheModel = class extends SDK.SDKModel {
Resources.ApplicationCacheModel = class extends SDK.SDKModel {
/**
* @param {!SDK.Target} target
* @param {!SDK.ResourceTreeModel} resourceTreeModel
*/
constructor(target, resourceTreeModel) {
super(SDK.ApplicationCacheModel, target);
constructor(target) {
super(target);

target.registerApplicationCacheDispatcher(new SDK.ApplicationCacheDispatcher(this));
target.registerApplicationCacheDispatcher(new Resources.ApplicationCacheDispatcher(this));
this._agent = target.applicationCacheAgent();
this._agent.enable();

var resourceTreeModel = SDK.ResourceTreeModel.fromTarget(target);
resourceTreeModel.addEventListener(SDK.ResourceTreeModel.Events.FrameNavigated, this._frameNavigated, this);
resourceTreeModel.addEventListener(SDK.ResourceTreeModel.Events.FrameDetached, this._frameDetached, this);

Expand All @@ -53,10 +53,10 @@ SDK.ApplicationCacheModel = class extends SDK.SDKModel {

/**
* @param {!SDK.Target} target
* @return {?SDK.ApplicationCacheModel}
* @return {?Resources.ApplicationCacheModel}
*/
static fromTarget(target) {
return target.model(SDK.ApplicationCacheModel);
return target.model(Resources.ApplicationCacheModel);
}

_frameNavigated(event) {
Expand All @@ -80,7 +80,7 @@ SDK.ApplicationCacheModel = class extends SDK.SDKModel {
reset() {
this._statuses = {};
this._manifestURLsByFrame = {};
this.dispatchEventToListeners(SDK.ApplicationCacheModel.Events.FrameManifestsReset);
this.dispatchEventToListeners(Resources.ApplicationCacheModel.Events.FrameManifestsReset);
}

_mainFrameNavigated() {
Expand Down Expand Up @@ -140,11 +140,11 @@ SDK.ApplicationCacheModel = class extends SDK.SDKModel {

if (!this._manifestURLsByFrame[frameId]) {
this._manifestURLsByFrame[frameId] = manifestURL;
this.dispatchEventToListeners(SDK.ApplicationCacheModel.Events.FrameManifestAdded, frameId);
this.dispatchEventToListeners(Resources.ApplicationCacheModel.Events.FrameManifestAdded, frameId);
}

if (statusChanged)
this.dispatchEventToListeners(SDK.ApplicationCacheModel.Events.FrameManifestStatusUpdated, frameId);
this.dispatchEventToListeners(Resources.ApplicationCacheModel.Events.FrameManifestStatusUpdated, frameId);
}

/**
Expand All @@ -157,7 +157,7 @@ SDK.ApplicationCacheModel = class extends SDK.SDKModel {
delete this._manifestURLsByFrame[frameId];
delete this._statuses[frameId];

this.dispatchEventToListeners(SDK.ApplicationCacheModel.Events.FrameManifestRemoved, frameId);
this.dispatchEventToListeners(Resources.ApplicationCacheModel.Events.FrameManifestRemoved, frameId);
}

/**
Expand Down Expand Up @@ -219,12 +219,14 @@ SDK.ApplicationCacheModel = class extends SDK.SDKModel {
*/
_networkStateUpdated(isNowOnline) {
this._onLine = isNowOnline;
this.dispatchEventToListeners(SDK.ApplicationCacheModel.Events.NetworkStateChanged, isNowOnline);
this.dispatchEventToListeners(Resources.ApplicationCacheModel.Events.NetworkStateChanged, isNowOnline);
}
};

SDK.SDKModel.register(Resources.ApplicationCacheModel, SDK.Target.Capability.DOM);

/** @enum {symbol} */
SDK.ApplicationCacheModel.Events = {
Resources.ApplicationCacheModel.Events = {
FrameManifestStatusUpdated: Symbol('FrameManifestStatusUpdated'),
FrameManifestAdded: Symbol('FrameManifestAdded'),
FrameManifestRemoved: Symbol('FrameManifestRemoved'),
Expand All @@ -236,7 +238,7 @@ SDK.ApplicationCacheModel.Events = {
* @implements {Protocol.ApplicationCacheDispatcher}
* @unrestricted
*/
SDK.ApplicationCacheDispatcher = class {
Resources.ApplicationCacheDispatcher = class {
constructor(applicationCacheModel) {
this._applicationCacheModel = applicationCacheModel;
}
Expand Down
2 changes: 1 addition & 1 deletion front_end/resources/ClearStorageView.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ Resources.ClearStorageView = class extends UI.VBox {
}

if (set.has(Protocol.Storage.StorageType.Appcache) || hasAll) {
var appcacheModel = SDK.ApplicationCacheModel.fromTarget(this._target);
var appcacheModel = Resources.ApplicationCacheModel.fromTarget(this._target);
if (appcacheModel)
appcacheModel.reset();
}
Expand Down
15 changes: 6 additions & 9 deletions front_end/resources/DOMStorageModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,11 @@ Resources.DOMStorage.Events = {
Resources.DOMStorageModel = class extends SDK.SDKModel {
/**
* @param {!SDK.Target} target
* @param {!SDK.SecurityOriginManager} securityOriginManager
*/
constructor(target, securityOriginManager) {
super(Resources.DOMStorageModel, target);
constructor(target) {
super(target);

this._securityOriginManager = securityOriginManager;
this._securityOriginManager = SDK.SecurityOriginManager.fromTarget(target);
/** @type {!Object.<string, !Resources.DOMStorage>} */
this._storages = {};
this._agent = target.domstorageAgent();
Expand All @@ -125,11 +124,7 @@ Resources.DOMStorageModel = class extends SDK.SDKModel {
* @return {!Resources.DOMStorageModel}
*/
static fromTarget(target) {
var model = target.model(Resources.DOMStorageModel);
if (!model)
model = new Resources.DOMStorageModel(target, SDK.SecurityOriginManager.fromTarget(target));

return model;
return /** @type {!Resources.DOMStorageModel} */ (target.model(Resources.DOMStorageModel));
}

enable() {
Expand Down Expand Up @@ -289,6 +284,8 @@ Resources.DOMStorageModel = class extends SDK.SDKModel {
}
};

SDK.SDKModel.register(Resources.DOMStorageModel, SDK.Target.Capability.None);

/** @enum {symbol} */
Resources.DOMStorageModel.Events = {
DOMStorageAdded: Symbol('DOMStorageAdded'),
Expand Down
10 changes: 5 additions & 5 deletions front_end/resources/DatabaseModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ Resources.DatabaseModel = class extends SDK.SDKModel {
* @param {!SDK.Target} target
*/
constructor(target) {
super(Resources.DatabaseModel, target);
super(target);

this._databases = [];
this._agent = target.databaseAgent();
Expand All @@ -145,10 +145,7 @@ Resources.DatabaseModel = class extends SDK.SDKModel {
* @return {!Resources.DatabaseModel}
*/
static fromTarget(target) {
if (!target[Resources.DatabaseModel._symbol])
target[Resources.DatabaseModel._symbol] = new Resources.DatabaseModel(target);

return target[Resources.DatabaseModel._symbol];
return /** @type {!Resources.DatabaseModel} */ (target.model(Resources.DatabaseModel));
}

enable() {
Expand Down Expand Up @@ -186,6 +183,9 @@ Resources.DatabaseModel = class extends SDK.SDKModel {
}
};

SDK.SDKModel.register(Resources.DatabaseModel, SDK.Target.Capability.None);


/** @implements {Common.Emittable} */
Resources.DatabaseModel.DatabaseAddedEvent = class {
/**
Expand Down
14 changes: 6 additions & 8 deletions front_end/resources/IndexedDBModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,10 @@
Resources.IndexedDBModel = class extends SDK.SDKModel {
/**
* @param {!SDK.Target} target
* @param {!SDK.SecurityOriginManager} securityOriginManager
*/
constructor(target, securityOriginManager) {
super(Resources.IndexedDBModel, target);
this._securityOriginManager = securityOriginManager;
constructor(target) {
super(target);
this._securityOriginManager = SDK.SecurityOriginManager.fromTarget(target);
this._agent = target.indexedDBAgent();

/** @type {!Map.<!Resources.IndexedDBModel.DatabaseId, !Resources.IndexedDBModel.Database>} */
Expand Down Expand Up @@ -144,10 +143,7 @@ Resources.IndexedDBModel = class extends SDK.SDKModel {
* @return {!Resources.IndexedDBModel}
*/
static fromTarget(target) {
var model = target.model(Resources.IndexedDBModel);
if (!model)
model = new Resources.IndexedDBModel(target, SDK.SecurityOriginManager.fromTarget(target));
return model;
return /** @type {!Resources.IndexedDBModel} */ (target.model(Resources.IndexedDBModel));
}

enable() {
Expand Down Expand Up @@ -430,6 +426,8 @@ Resources.IndexedDBModel = class extends SDK.SDKModel {
}
};

SDK.SDKModel.register(Resources.IndexedDBModel, SDK.Target.Capability.None);

Resources.IndexedDBModel.KeyTypes = {
NumberType: 'number',
StringType: 'string',
Expand Down
14 changes: 7 additions & 7 deletions front_end/resources/ResourcesPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -700,24 +700,24 @@ Resources.ResourcesPanel = class extends UI.PanelWithSidebar {
* @param {!SDK.ResourceTreeModel} resourceTreeModel
*/
_populateApplicationCacheTree(resourceTreeModel) {
this._applicationCacheModel = new SDK.ApplicationCacheModel(this._target, resourceTreeModel);
this._applicationCacheModel = Resources.ApplicationCacheModel.fromTarget(this._target);

this._applicationCacheViews = {};
this._applicationCacheFrameElements = {};
this._applicationCacheManifestElements = {};

this._applicationCacheModel.addEventListener(
SDK.ApplicationCacheModel.Events.FrameManifestAdded, this._applicationCacheFrameManifestAdded, this);
Resources.ApplicationCacheModel.Events.FrameManifestAdded, this._applicationCacheFrameManifestAdded, this);
this._applicationCacheModel.addEventListener(
SDK.ApplicationCacheModel.Events.FrameManifestRemoved, this._applicationCacheFrameManifestRemoved, this);
Resources.ApplicationCacheModel.Events.FrameManifestRemoved, this._applicationCacheFrameManifestRemoved, this);
this._applicationCacheModel.addEventListener(
SDK.ApplicationCacheModel.Events.FrameManifestsReset, this._resetAppCache, this);
Resources.ApplicationCacheModel.Events.FrameManifestsReset, this._resetAppCache, this);

this._applicationCacheModel.addEventListener(
SDK.ApplicationCacheModel.Events.FrameManifestStatusUpdated, this._applicationCacheFrameManifestStatusChanged,
this);
Resources.ApplicationCacheModel.Events.FrameManifestStatusUpdated,
this._applicationCacheFrameManifestStatusChanged, this);
this._applicationCacheModel.addEventListener(
SDK.ApplicationCacheModel.Events.NetworkStateChanged, this._applicationCacheNetworkStateChanged, this);
Resources.ApplicationCacheModel.Events.NetworkStateChanged, this._applicationCacheNetworkStateChanged, this);
}

_applicationCacheFrameManifestAdded(event) {
Expand Down
1 change: 1 addition & 0 deletions front_end/resources/module.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"components"
],
"scripts": [
"ApplicationCacheModel.js",
"AppManifestView.js",
"ApplicationCacheItemsView.js",
"ClearStorageView.js",
Expand Down
5 changes: 4 additions & 1 deletion front_end/sdk/CPUProfilerModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ SDK.CPUProfilerModel = class extends SDK.SDKModel {
* @param {!SDK.Target} target
*/
constructor(target) {
super(SDK.CPUProfilerModel, target);
super(target);
this._isRecording = false;
target.registerProfilerDispatcher(this);
target.profilerAgent().enable();
Expand Down Expand Up @@ -129,6 +129,9 @@ SDK.CPUProfilerModel = class extends SDK.SDKModel {
}
};

// TODO(dgozman): should be JS.
SDK.SDKModel.register(SDK.CPUProfilerModel, SDK.Target.Capability.None);

/** @enum {symbol} */
SDK.CPUProfilerModel.Events = {
ConsoleProfileStarted: Symbol('ConsoleProfileStarted'),
Expand Down
Loading

0 comments on commit ed6ef78

Please sign in to comment.