Web Inspector: register context menu providers for lazily loaded panels.
[WebKit-https.git] / Source / WebCore / inspector / compile-front-end.py
1 #!/usr/bin/env python
2 # Copyright (c) 2012 Google Inc. All rights reserved.
3 #
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are
6 # met:
7 #
8 #     * Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
10 #     * Redistributions in binary form must reproduce the above
11 # copyright notice, this list of conditions and the following disclaimer
12 # in the documentation and/or other materials provided with the
13 # distribution.
14 #     * Neither the name of Google Inc. nor the names of its
15 # contributors may be used to endorse or promote products derived from
16 # this software without specific prior written permission.
17 #
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30 import os
31 import os.path
32 import generate_protocol_externs
33 import sys
34
35 inspector_path = "Source/WebCore/inspector"
36 inspector_frontend_path = inspector_path + "/front-end"
37
38 generate_protocol_externs.generate_protocol_externs(inspector_frontend_path + "/protocol-externs.js", inspector_path + "/Inspector.json")
39
40 jsmodule_name_prefix = "jsmodule_"
41 modules = [
42     {
43         "name": "common",
44         "dependencies": [],
45         "sources": [
46             "Color.js",
47             "Object.js",
48             "Settings.js",
49             "UIString.js",
50             "UserMetrics.js",
51             "utilities.js",
52         ]
53     },
54     {
55         "name": "sdk",
56         "dependencies": ["common"],
57         "sources": [
58             "ApplicationCacheModel.js",
59             "CompilerScriptMapping.js",
60             "ConsoleModel.js",
61             "ContentProvider.js",
62             "ContentProviders.js",
63             "CookieParser.js",
64             "CSSCompletions.js",
65             "CSSKeywordCompletions.js",
66             "CSSStyleModel.js",
67             "BreakpointManager.js",
68             "Database.js",
69             "DOMAgent.js",
70             "DOMStorage.js",
71             "DebuggerModel.js",
72             "DebuggerScriptMapping.js",
73             "FileManager.js",
74             "FileSystemModel.js",
75             "FileUtils.js",
76             "HAREntry.js",
77             "IndexedDBModel.js",
78             "InspectorBackend.js",
79             "JavaScriptSource.js",
80             "Linkifier.js",
81             "NetworkLog.js",
82             "PresentationConsoleMessageHelper.js",
83             "SASSSourceMapping.js",
84             "Script.js",
85             "ScriptFormatter.js",
86             "ScriptSnippetModel.js",
87             "SnippetStorage.js",
88             "SourceMapping.js",
89             "StyleSource.js",
90             "TimelineManager.js",
91             "RawSourceCode.js",
92             "RemoteObject.js",
93             "Resource.js",
94             "ResourceScriptMapping.js",
95             "ResourceTreeModel.js",
96             "ResourceType.js",
97             "ResourceUtils.js",
98             "NetworkManager.js",
99             "NetworkRequest.js",
100             "UISourceCode.js",
101             "UserAgentSupport.js",
102             "Workspace.js",
103             "protocol-externs.js",
104         ]
105     },
106     {
107         "name": "ui",
108         "dependencies": ["common"],
109         "sources": [
110             "Checkbox.js",
111             "ContextMenu.js",
112             "DOMExtension.js",
113             "DOMSyntaxHighlighter.js",
114             "DataGrid.js",
115             "DefaultTextEditor.js",
116             "Dialog.js",
117             "Drawer.js",
118             "EmptyView.js",
119             "GoToLineDialog.js",
120             "HelpScreen.js",
121             "InspectorView.js",
122             "KeyboardShortcut.js",
123             "Panel.js",
124             "PanelEnablerView.js",
125             "Placard.js",
126             "Popover.js",
127             "ProgressBar.js",
128             "PropertiesSection.js",
129             "SearchController.js",
130             "Section.js",
131             "SidebarPane.js",
132             "SidebarTreeElement.js",
133             "ShortcutsScreen.js",
134             "ShowMoreDataGridNode.js",
135             "SidebarOverlay.js",
136             "SoftContextMenu.js",
137             "SourceTokenizer.js",
138             "Spectrum.js",
139             "SplitView.js",
140             "StatusBarButton.js",
141             "TabbedPane.js",
142             "TextEditor.js",
143             "TextEditorHighlighter.js",
144             "TextEditorModel.js",
145             "TextPrompt.js",
146             "TimelineGrid.js",
147             "Toolbar.js",
148             "UIUtils.js",
149             "View.js",
150             "treeoutline.js",
151         ]
152     },
153     {
154         "name": "components",
155         "dependencies": ["sdk", "ui"],
156         "sources": [
157             "AdvancedSearchController.js",
158             "HandlerRegistry.js",
159             "ConsoleMessage.js",
160             "CookiesTable.js",
161             "DOMBreakpointsSidebarPane.js",
162             "DOMPresentationUtils.js",
163             "ElementsTreeOutline.js",
164             "NativeBreakpointsSidebarPane.js",
165             "JavaScriptContextManager.js",
166             "ObjectPopoverHelper.js",
167             "ObjectPropertiesSection.js",
168             "SourceFrame.js",
169         ]
170     },
171     {
172         "name": "elements",
173         "dependencies": ["components"],
174         "sources": [
175             "ElementsPanel.js",
176             "EventListenersSidebarPane.js",
177             "MetricsSidebarPane.js",
178             "PropertiesSidebarPane.js",
179             "StylesSidebarPane.js",
180         ]
181     },
182     {
183         "name": "network",
184         "dependencies": ["components"],
185         "sources": [
186             "FontView.js",
187             "ImageView.js",
188             "NetworkItemView.js",
189             "RequestCookiesView.js",
190             "RequestHeadersView.js",
191             "RequestHTMLView.js",
192             "RequestJSONView.js",
193             "RequestPreviewView.js",
194             "RequestResponseView.js",
195             "RequestTimingView.js",
196             "RequestView.js",
197             "ResourceView.js",
198             "ResourceWebSocketFrameView.js",
199             "NetworkPanel.js",
200             "NetworkPanelDescriptor.js",
201         ]
202     },
203     {
204         "name": "resources",
205         "dependencies": ["components"],
206         "sources": [
207             "ApplicationCacheItemsView.js",
208             "CookieItemsView.js",
209             "DatabaseQueryView.js",
210             "DatabaseTableView.js",
211             "DirectoryContentView.js",
212             "DOMStorageItemsView.js",
213             "FileContentView.js",
214             "FileSystemView.js",
215             "IndexedDBViews.js",
216             "ResourcesPanel.js",
217         ]
218     },
219     {
220         "name": "scripts",
221         "dependencies": ["components"],
222         "sources": [
223             "BreakpointsSidebarPane.js",
224             "CallStackSidebarPane.js",
225             "FilteredItemSelectionDialog.js",
226             "JavaScriptSourceFrame.js",
227             "NavigatorOverlayController.js",
228             "NavigatorView.js",
229             "RevisionHistoryView.js",
230             "ScopeChainSidebarPane.js",
231             "ScriptsNavigator.js",
232             "ScriptsPanel.js",
233             "ScriptsPanelDescriptor.js",
234             "ScriptsSearchScope.js",
235             "SnippetJavaScriptSourceFrame.js",
236             "StyleSheetOutlineDialog.js",
237             "TabbedEditorContainer.js",
238             "UISourceCodeFrame.js",
239             "WatchExpressionsSidebarPane.js",
240             "WorkersSidebarPane.js",
241         ]
242     },
243     {
244         "name": "console",
245         "dependencies": ["components"],
246         "sources": [
247             "ConsoleView.js",
248             "ConsolePanel.js",
249         ]
250     },
251     {
252         "name": "timeline",
253         "dependencies": ["components"],
254         "sources": [
255             "MemoryStatistics.js",
256             "TimelineModel.js",
257             "TimelineOverviewPane.js",
258             "TimelinePanel.js",
259             "TimelinePresentationModel.js",
260             "TimelineFrameController.js"
261         ]
262     },
263     {
264         "name": "audits",
265         "dependencies": ["components"],
266         "sources": [
267             "AuditCategories.js",
268             "AuditFormatters.js",
269             "AuditLauncherView.js",
270             "AuditResultView.js",
271             "AuditRules.js",
272             "AuditsPanel.js",
273         ]
274     },
275     {
276         "name": "extensions",
277         "dependencies": ["components"],
278         "sources": [
279             "ExtensionAPI.js",
280             "ExtensionAuditCategory.js",
281             "ExtensionPanel.js",
282             "ExtensionRegistryStub.js",
283             "ExtensionServer.js",
284             "ExtensionView.js",
285         ]
286     },
287     {
288         "name": "settings",
289         "dependencies": ["components", "extensions"],
290         "sources": [
291             "SettingsScreen.js",
292         ]
293     },
294     {
295         "name": "workers",
296         "dependencies": ["components"],
297         "sources": [
298             "WorkerManager.js",
299         ]
300     },
301     {
302         "name": "tests",
303         "dependencies": ["components"],
304         "sources": [
305             "TestController.js",
306         ]
307     },
308     {
309         "name": "profiler",
310         "dependencies": ["components"],
311         "sources": [
312             "BottomUpProfileDataGridTree.js",
313             "CPUProfileView.js",
314             "CSSSelectorProfileView.js",
315             "HeapSnapshot.js",
316             "HeapSnapshotDataGrids.js",
317             "HeapSnapshotGridNodes.js",
318             "HeapSnapshotLoader.js",
319             "HeapSnapshotProxy.js",
320             "HeapSnapshotView.js",
321             "HeapSnapshotWorker.js",
322             "HeapSnapshotWorkerDispatcher.js",
323             "NativeMemorySnapshotView.js",
324             "ProfileDataGridTree.js",
325             "ProfilesPanel.js",
326             "ProfileLauncherView.js",
327             "TopDownProfileDataGridTree.js",
328         ]
329     },
330     {
331         "name": "host_stub",
332         "dependencies": ["ui"],
333         "sources": [
334             "InspectorFrontendHostStub.js",
335         ]
336     },
337 ]
338
339 modules_by_name = {}
340 for module in modules:
341     modules_by_name[module["name"]] = module
342
343
344 def dump_module(name, recursively, processed_modules):
345     if name in processed_modules:
346         return ""
347     processed_modules[name] = True
348     module = modules_by_name[name]
349     command = ""
350     if recursively:
351         for dependency in module["dependencies"]:
352             command += dump_module(dependency, recursively, processed_modules)
353     command += " \\\n    --module " + jsmodule_name_prefix + module["name"] + ":"
354     command += str(len(module["sources"]))
355     firstDependency = True
356     for dependency in module["dependencies"]:
357         if firstDependency:
358             command += ":"
359         else:
360             command += ","
361         firstDependency = False
362         command += jsmodule_name_prefix + dependency
363     for script in module["sources"]:
364         command += " \\\n        --js " + inspector_frontend_path + "/" + script
365     return command
366
367 compiler_command = "java -jar ~/closure/compiler.jar --summary_detail_level 3 --compilation_level SIMPLE_OPTIMIZATIONS --warning_level VERBOSE --language_in ECMASCRIPT5 --accept_const_keyword \\\n"
368
369 process_recursively = len(sys.argv) == 2
370 if process_recursively:
371     module_name = sys.argv[1]
372     if module_name != "all":
373         modules = [modules_by_name[sys.argv[1]]]
374     for module in modules:
375         command = compiler_command
376         command += "    --externs " + inspector_frontend_path + "/externs.js"
377         command += dump_module(module["name"], True, {})
378         print "Compiling \"" + module["name"] + "\""
379         os.system(command)
380 else:
381     command = compiler_command
382     command += "    --externs " + inspector_frontend_path + "/externs.js"
383     for module in modules:
384         command += dump_module(module["name"], False, {})
385     os.system(command)
386
387 if not process_recursively:
388     print "Compiling InjectedScriptSource.js..."
389     os.system("echo \"var injectedScriptValue = \" > " + inspector_path + "/" + "InjectedScriptSourceTmp.js")
390     os.system("cat  " + inspector_path + "/" + "InjectedScriptSource.js" + " >> " + inspector_path + "/" + "InjectedScriptSourceTmp.js")
391     command = compiler_command
392     command += "    --externs " + inspector_path + "/" + "InjectedScriptExterns.js" + " \\\n"
393     command += "    --module " + jsmodule_name_prefix + "injected_script" + ":" + "1" + " \\\n"
394     command += "        --js " + inspector_path + "/" + "InjectedScriptSourceTmp.js" + " \\\n"
395     command += "\n"
396     os.system(command)
397     os.system("rm " + inspector_path + "/" + "InjectedScriptSourceTmp.js")
398
399     print "Compiling InjectedScriptWebGLModuleSource.js..."
400     os.system("echo \"var injectedScriptWebGLModuleValue = \" > " + inspector_path + "/" + "InjectedScriptWebGLModuleSourceTmp.js")
401     os.system("cat  " + inspector_path + "/" + "InjectedScriptWebGLModuleSource.js" + " >> " + inspector_path + "/" + "InjectedScriptWebGLModuleSourceTmp.js")
402     command = compiler_command
403     command += "    --externs " + inspector_path + "/" + "InjectedScriptExterns.js" + " \\\n"
404     command += "    --module " + jsmodule_name_prefix + "injected_script" + ":" + "1" + " \\\n"
405     command += "        --js " + inspector_path + "/" + "InjectedScriptWebGLModuleSourceTmp.js" + " \\\n"
406     command += "\n"
407     os.system(command)
408     os.system("rm " + inspector_path + "/" + "InjectedScriptWebGLModuleSourceTmp.js")