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

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

Issue 2398493002: DevTools: [Persistence] split out WI.DefaultMapping (Closed)
Patch Set: Created 4 years, 2 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
(Empty)
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
3 // found in the LICENSE file.
4
5 /**
6 * @constructor
7 * @extends {WebInspector.Object}
8 * @param {!WebInspector.Workspace} workspace
9 * @param {!WebInspector.FileSystemMapping} fileSystemMapping
10 * @param {function(!WebInspector.PersistenceBinding)} onBindingCreated
11 * @param {function(!WebInspector.PersistenceBinding)} onBindingRemoved
12 */
13 WebInspector.DefaultMapping = function(workspace, fileSystemMapping, onBindingCr eated, onBindingRemoved)
14 {
15 WebInspector.Object.call(this);
dgozman 2016/10/05 02:25:24 No need to inherit from Object.
lushnikov 2016/10/05 03:55:25 Done.
16 this._workspace = workspace;
17 this._fileSystemMapping = fileSystemMapping;
18 /** @type {!Set<!WebInspector.PersistenceBinding>} */
19 this._bindings = new Set();
20 this._onBindingCreated = onBindingCreated;
21 this._onBindingRemoved = onBindingRemoved;
22
23 this._eventListeners = [
24 workspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeAdd ed, this._onUISourceCodeAdded, this),
25 workspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeRem oved, this._onUISourceCodeRemoved, this),
26 workspace.addEventListener(WebInspector.Workspace.Events.ProjectRemoved, this._onProjectRemoved, this),
27 this._fileSystemMapping.addEventListener(WebInspector.FileSystemMapping. Events.FileMappingAdded, this._remap, this),
28 this._fileSystemMapping.addEventListener(WebInspector.FileSystemMapping. Events.FileMappingRemoved, this._remap, this)
29 ];
30 this._remap();
31 }
32
33 WebInspector.DefaultMapping._binding = Symbol("DefaultMapping.Binding");
34
35 WebInspector.DefaultMapping.prototype = {
36 _remap: function()
37 {
38 for (var binding of this._bindings.valuesArray())
39 this._unbind(binding.network);
40 var networkProjects = this._workspace.projectsForType(WebInspector.proje ctTypes.Network);
41 for (var networkProject of networkProjects) {
42 for (var uiSourceCode of networkProject.uiSourceCodes())
43 this._bind(uiSourceCode);
44 }
45 },
46
47 /**
48 * @param {!WebInspector.Event} event
49 */
50 _onUISourceCodeAdded: function(event)
51 {
52 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */(event.data) ;
53 this._bind(uiSourceCode);
54 },
55
56 /**
57 * @param {!WebInspector.Event} event
58 */
59 _onUISourceCodeRemoved: function(event)
60 {
61 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */(event.data) ;
62 this._unbind(uiSourceCode);
63 },
64
65 /**
66 * @param {!WebInspector.Event} event
67 */
68 _onProjectRemoved: function(event)
69 {
70 var project = /** @type {!WebInspector.Project} */(event.data);
71 for (var uiSourceCode of project.uiSourceCodes())
72 this._unbind(uiSourceCode);
73 },
74
75 /**
76 * @param {!WebInspector.UISourceCode} uiSourceCode
77 * @return {?WebInspector.PersistenceBinding}
78 */
79 _createBinding: function(uiSourceCode)
80 {
81 if (uiSourceCode.project().type() === WebInspector.projectTypes.FileSyst em) {
82 var fileSystemPath = WebInspector.FileSystemWorkspaceBinding.fileSys temPath(uiSourceCode.project().id());
83 var networkURL = this._fileSystemMapping.networkURLForFileSystemURL( fileSystemPath, uiSourceCode.url());
84 var networkSourceCode = networkURL ? this._workspace.uiSourceCodeFor URL(networkURL) : null;
85 return networkSourceCode ? new WebInspector.PersistenceBinding(netwo rkSourceCode, uiSourceCode) : null;
86 }
87 if (uiSourceCode.project().type() === WebInspector.projectTypes.Network) {
88 var file = this._fileSystemMapping.fileForURL(uiSourceCode.url());
89 var projectId = file ? WebInspector.FileSystemWorkspaceBinding.proje ctId(file.fileSystemPath) : null;
90 var fileSourceCode = file && projectId ? this._workspace.uiSourceCod e(projectId, file.fileURL) : null;
91 return fileSourceCode ? new WebInspector.PersistenceBinding(uiSource Code, fileSourceCode) : null;
92 }
93 return null;
94 },
95
96 /**
97 * @param {!WebInspector.UISourceCode} uiSourceCode
98 */
99 _bind: function(uiSourceCode)
100 {
101 console.assert(!uiSourceCode[WebInspector.DefaultMapping._binding], "Can not bind already bound UISourceCode!");
102 var binding = this._createBinding(uiSourceCode);
103 if (!binding)
104 return;
105 this._bindings.add(binding);
106 binding.network[WebInspector.DefaultMapping._binding] = binding;
107 binding.fileSystem[WebInspector.DefaultMapping._binding] = binding;
108
109 binding.fileSystem.addEventListener(WebInspector.UISourceCode.Events.Tit leChanged, this._onFileSystemUISourceCodeRenamed, this);
110
111 this._onBindingCreated.call(null, binding);
112 },
113
114 /**
115 * @param {!WebInspector.UISourceCode} uiSourceCode
116 */
117 _unbind: function(uiSourceCode)
118 {
119 var binding = uiSourceCode[WebInspector.DefaultMapping._binding];
120 if (!binding)
121 return;
122 this._bindings.delete(binding);
123 binding.network[WebInspector.DefaultMapping._binding] = null;
124 binding.fileSystem[WebInspector.DefaultMapping._binding] = null;
125
126 binding.fileSystem.removeEventListener(WebInspector.UISourceCode.Events. TitleChanged, this._onFileSystemUISourceCodeRenamed, this);
127
128 this._onBindingRemoved.call(null, binding);
129 },
130
131 /**
132 * @param {!WebInspector.Event} event
133 */
134 _onFileSystemUISourceCodeRenamed: function(event)
135 {
136 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */(event.targe t);
137 var binding = uiSourceCode[WebInspector.DefaultMapping._binding];
138 this._unbind(binding.network);
139 this._bind(binding.network);
140 },
141
142 dispose: function()
143 {
144 WebInspector.EventTarget.removeEventListeners(this._eventListeners);
145 },
146
147 __proto__: WebInspector.Object.prototype
148 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698