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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/persistence/DefaultMapping.js

Issue 2466123002: DevTools: reformat front-end code to match chromium style. (Closed)
Patch Set: all done 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 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
5 /** 4 /**
6 * @constructor 5 * @unrestricted
7 * @param {!WebInspector.Workspace} workspace
8 * @param {!WebInspector.FileSystemMapping} fileSystemMapping
9 * @param {function(!WebInspector.PersistenceBinding)} onBindingCreated
10 * @param {function(!WebInspector.PersistenceBinding)} onBindingRemoved
11 */ 6 */
12 WebInspector.DefaultMapping = function(workspace, fileSystemMapping, onBindingCr eated, onBindingRemoved) 7 WebInspector.DefaultMapping = class {
13 { 8 /**
9 * @param {!WebInspector.Workspace} workspace
10 * @param {!WebInspector.FileSystemMapping} fileSystemMapping
11 * @param {function(!WebInspector.PersistenceBinding)} onBindingCreated
12 * @param {function(!WebInspector.PersistenceBinding)} onBindingRemoved
13 */
14 constructor(workspace, fileSystemMapping, onBindingCreated, onBindingRemoved) {
14 this._workspace = workspace; 15 this._workspace = workspace;
15 this._fileSystemMapping = fileSystemMapping; 16 this._fileSystemMapping = fileSystemMapping;
16 /** @type {!Set<!WebInspector.PersistenceBinding>} */ 17 /** @type {!Set<!WebInspector.PersistenceBinding>} */
17 this._bindings = new Set(); 18 this._bindings = new Set();
18 this._onBindingCreated = onBindingCreated; 19 this._onBindingCreated = onBindingCreated;
19 this._onBindingRemoved = onBindingRemoved; 20 this._onBindingRemoved = onBindingRemoved;
20 21
21 this._eventListeners = [ 22 this._eventListeners = [
22 workspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeAdd ed, this._onUISourceCodeAdded, this), 23 workspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeAdded , this._onUISourceCodeAdded, this),
23 workspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeRem oved, this._onUISourceCodeRemoved, this), 24 workspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeRemov ed, this._onUISourceCodeRemoved, this),
24 workspace.addEventListener(WebInspector.Workspace.Events.ProjectRemoved, this._onProjectRemoved, this), 25 workspace.addEventListener(WebInspector.Workspace.Events.ProjectRemoved, t his._onProjectRemoved, this),
25 this._fileSystemMapping.addEventListener(WebInspector.FileSystemMapping. Events.FileMappingAdded, this._remap, this), 26 this._fileSystemMapping.addEventListener(
26 this._fileSystemMapping.addEventListener(WebInspector.FileSystemMapping. Events.FileMappingRemoved, this._remap, this) 27 WebInspector.FileSystemMapping.Events.FileMappingAdded, this._remap, t his),
28 this._fileSystemMapping.addEventListener(
29 WebInspector.FileSystemMapping.Events.FileMappingRemoved, this._remap, this)
27 ]; 30 ];
28 this._remap(); 31 this._remap();
32 }
33
34 _remap() {
35 for (var binding of this._bindings.valuesArray())
36 this._unbind(binding.network);
37 var networkProjects = this._workspace.projectsForType(WebInspector.projectTy pes.Network);
38 for (var networkProject of networkProjects) {
39 for (var uiSourceCode of networkProject.uiSourceCodes())
40 this._bind(uiSourceCode);
41 }
42 }
43
44 /**
45 * @param {!WebInspector.Event} event
46 */
47 _onUISourceCodeAdded(event) {
48 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (event.data);
49 this._bind(uiSourceCode);
50 }
51
52 /**
53 * @param {!WebInspector.Event} event
54 */
55 _onUISourceCodeRemoved(event) {
56 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (event.data);
57 this._unbind(uiSourceCode);
58 }
59
60 /**
61 * @param {!WebInspector.Event} event
62 */
63 _onProjectRemoved(event) {
64 var project = /** @type {!WebInspector.Project} */ (event.data);
65 for (var uiSourceCode of project.uiSourceCodes())
66 this._unbind(uiSourceCode);
67 }
68
69 /**
70 * @param {!WebInspector.UISourceCode} uiSourceCode
71 * @return {?WebInspector.PersistenceBinding}
72 */
73 _createBinding(uiSourceCode) {
74 if (uiSourceCode.project().type() === WebInspector.projectTypes.FileSystem) {
75 var fileSystemPath = WebInspector.FileSystemWorkspaceBinding.fileSystemPat h(uiSourceCode.project().id());
76 var networkURL = this._fileSystemMapping.networkURLForFileSystemURL(fileSy stemPath, uiSourceCode.url());
77 var networkSourceCode = networkURL ? this._workspace.uiSourceCodeForURL(ne tworkURL) : null;
78 return networkSourceCode ? new WebInspector.PersistenceBinding(networkSour ceCode, uiSourceCode, false) : null;
79 }
80 if (uiSourceCode.project().type() === WebInspector.projectTypes.Network) {
81 var file = this._fileSystemMapping.fileForURL(uiSourceCode.url());
82 var projectId = file ? WebInspector.FileSystemWorkspaceBinding.projectId(f ile.fileSystemPath) : null;
83 var fileSourceCode = file && projectId ? this._workspace.uiSourceCode(proj ectId, file.fileURL) : null;
84 return fileSourceCode ? new WebInspector.PersistenceBinding(uiSourceCode, fileSourceCode, false) : null;
85 }
86 return null;
87 }
88
89 /**
90 * @param {!WebInspector.UISourceCode} uiSourceCode
91 */
92 _bind(uiSourceCode) {
93 console.assert(!uiSourceCode[WebInspector.DefaultMapping._binding], 'Cannot bind already bound UISourceCode!');
94 var binding = this._createBinding(uiSourceCode);
95 if (!binding)
96 return;
97 this._bindings.add(binding);
98 binding.network[WebInspector.DefaultMapping._binding] = binding;
99 binding.fileSystem[WebInspector.DefaultMapping._binding] = binding;
100
101 binding.fileSystem.addEventListener(
102 WebInspector.UISourceCode.Events.TitleChanged, this._onFileSystemUISourc eCodeRenamed, this);
103
104 this._onBindingCreated.call(null, binding);
105 }
106
107 /**
108 * @param {!WebInspector.UISourceCode} uiSourceCode
109 */
110 _unbind(uiSourceCode) {
111 var binding = uiSourceCode[WebInspector.DefaultMapping._binding];
112 if (!binding)
113 return;
114 this._bindings.delete(binding);
115 binding.network[WebInspector.DefaultMapping._binding] = null;
116 binding.fileSystem[WebInspector.DefaultMapping._binding] = null;
117
118 binding.fileSystem.removeEventListener(
119 WebInspector.UISourceCode.Events.TitleChanged, this._onFileSystemUISourc eCodeRenamed, this);
120
121 this._onBindingRemoved.call(null, binding);
122 }
123
124 /**
125 * @param {!WebInspector.Event} event
126 */
127 _onFileSystemUISourceCodeRenamed(event) {
128 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (event.target);
129 var binding = uiSourceCode[WebInspector.DefaultMapping._binding];
130 this._unbind(binding.network);
131 this._bind(binding.network);
132 }
133
134 dispose() {
135 WebInspector.EventTarget.removeEventListeners(this._eventListeners);
136 }
29 }; 137 };
30 138
31 WebInspector.DefaultMapping._binding = Symbol("DefaultMapping.Binding"); 139 WebInspector.DefaultMapping._binding = Symbol('DefaultMapping.Binding');
32
33 WebInspector.DefaultMapping.prototype = {
34 _remap: function()
35 {
36 for (var binding of this._bindings.valuesArray())
37 this._unbind(binding.network);
38 var networkProjects = this._workspace.projectsForType(WebInspector.proje ctTypes.Network);
39 for (var networkProject of networkProjects) {
40 for (var uiSourceCode of networkProject.uiSourceCodes())
41 this._bind(uiSourceCode);
42 }
43 },
44
45 /**
46 * @param {!WebInspector.Event} event
47 */
48 _onUISourceCodeAdded: function(event)
49 {
50 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */(event.data) ;
51 this._bind(uiSourceCode);
52 },
53
54 /**
55 * @param {!WebInspector.Event} event
56 */
57 _onUISourceCodeRemoved: function(event)
58 {
59 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */(event.data) ;
60 this._unbind(uiSourceCode);
61 },
62
63 /**
64 * @param {!WebInspector.Event} event
65 */
66 _onProjectRemoved: function(event)
67 {
68 var project = /** @type {!WebInspector.Project} */(event.data);
69 for (var uiSourceCode of project.uiSourceCodes())
70 this._unbind(uiSourceCode);
71 },
72
73 /**
74 * @param {!WebInspector.UISourceCode} uiSourceCode
75 * @return {?WebInspector.PersistenceBinding}
76 */
77 _createBinding: function(uiSourceCode)
78 {
79 if (uiSourceCode.project().type() === WebInspector.projectTypes.FileSyst em) {
80 var fileSystemPath = WebInspector.FileSystemWorkspaceBinding.fileSys temPath(uiSourceCode.project().id());
81 var networkURL = this._fileSystemMapping.networkURLForFileSystemURL( fileSystemPath, uiSourceCode.url());
82 var networkSourceCode = networkURL ? this._workspace.uiSourceCodeFor URL(networkURL) : null;
83 return networkSourceCode ? new WebInspector.PersistenceBinding(netwo rkSourceCode, uiSourceCode, false) : null;
84 }
85 if (uiSourceCode.project().type() === WebInspector.projectTypes.Network) {
86 var file = this._fileSystemMapping.fileForURL(uiSourceCode.url());
87 var projectId = file ? WebInspector.FileSystemWorkspaceBinding.proje ctId(file.fileSystemPath) : null;
88 var fileSourceCode = file && projectId ? this._workspace.uiSourceCod e(projectId, file.fileURL) : null;
89 return fileSourceCode ? new WebInspector.PersistenceBinding(uiSource Code, fileSourceCode, false) : null;
90 }
91 return null;
92 },
93
94 /**
95 * @param {!WebInspector.UISourceCode} uiSourceCode
96 */
97 _bind: function(uiSourceCode)
98 {
99 console.assert(!uiSourceCode[WebInspector.DefaultMapping._binding], "Can not bind already bound UISourceCode!");
100 var binding = this._createBinding(uiSourceCode);
101 if (!binding)
102 return;
103 this._bindings.add(binding);
104 binding.network[WebInspector.DefaultMapping._binding] = binding;
105 binding.fileSystem[WebInspector.DefaultMapping._binding] = binding;
106
107 binding.fileSystem.addEventListener(WebInspector.UISourceCode.Events.Tit leChanged, this._onFileSystemUISourceCodeRenamed, this);
108
109 this._onBindingCreated.call(null, binding);
110 },
111
112 /**
113 * @param {!WebInspector.UISourceCode} uiSourceCode
114 */
115 _unbind: function(uiSourceCode)
116 {
117 var binding = uiSourceCode[WebInspector.DefaultMapping._binding];
118 if (!binding)
119 return;
120 this._bindings.delete(binding);
121 binding.network[WebInspector.DefaultMapping._binding] = null;
122 binding.fileSystem[WebInspector.DefaultMapping._binding] = null;
123
124 binding.fileSystem.removeEventListener(WebInspector.UISourceCode.Events. TitleChanged, this._onFileSystemUISourceCodeRenamed, this);
125
126 this._onBindingRemoved.call(null, binding);
127 },
128
129 /**
130 * @param {!WebInspector.Event} event
131 */
132 _onFileSystemUISourceCodeRenamed: function(event)
133 {
134 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */(event.targe t);
135 var binding = uiSourceCode[WebInspector.DefaultMapping._binding];
136 this._unbind(binding.network);
137 this._bind(binding.network);
138 },
139
140 dispose: function()
141 {
142 WebInspector.EventTarget.removeEventListeners(this._eventListeners);
143 }
144 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698