REGRESSION: Web Inspector: Start Timeline Recording in Develop menu broken
[WebKit-https.git] / Source / WebInspectorUI / UserInterface / Protocol / InspectorFrontendAPI.js
1 /*
2  * Copyright (C) 2013 Apple 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
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 InspectorFrontendAPI = {
27     _loaded: false,
28     _pendingCommands: [],
29
30     savedURL: function(url)
31     {
32         // Not used yet.
33     },
34
35     appendedToURL: function(url)
36     {
37         // Not used yet.
38     },
39
40     isTimelineProfilingEnabled: function()
41     {
42         return WebInspector.timelineManager.isCapturing();
43     },
44
45     setTimelineProfilingEnabled: function(enabled)
46     {
47         if (WebInspector.timelineManager.isCapturing() === enabled)
48             return;
49
50         if (enabled) {
51             WebInspector.navigationSidebar.selectedSidebarPanel = WebInspector.timelineSidebarPanel;
52             WebInspector.timelineSidebarPanel.showTimelineOverview();
53             WebInspector.timelineManager.startCapturing();
54         } else {
55             WebInspector.timelineManager.stopCapturing();
56         }
57     },
58
59     setDockSide: function(side)
60     {
61         WebInspector.updateDockedState(side);
62     },
63
64     showConsole: function()
65     {
66         WebInspector.showConsoleView();
67
68         WebInspector.quickConsole.prompt.focus();
69
70         // If the page is still loading, focus the quick console again after tabindex autofocus.
71         if (document.readyState !== "complete")
72             document.addEventListener("readystatechange", this);
73     },
74
75     handleEvent: function(event)
76     {
77         console.assert(event.type === "readystatechange");
78
79         if (document.readyState === "complete") {
80             WebInspector.quickConsole.prompt.focus();
81             document.removeEventListener("readystatechange", this);
82         }
83     },
84
85     showResources: function()
86     {
87         WebInspector.ignoreLastContentCookie = true;
88         WebInspector.navigationSidebar.selectedSidebarPanel = WebInspector.resourceSidebarPanel;
89         WebInspector.navigationSidebar.collapsed = false;
90     },
91
92     showMainResourceForFrame: function(frameIdentifier)
93     {
94         WebInspector.ignoreLastContentCookie = true;
95         WebInspector.navigationSidebar.selectedSidebarPanel = WebInspector.resourceSidebarPanel;
96         WebInspector.resourceSidebarPanel.showSourceCodeForFrame(frameIdentifier, true);
97     },
98
99     contextMenuItemSelected: function(id)
100     {
101         WebInspector.ContextMenu.contextMenuItemSelected(id);
102     },
103
104     contextMenuCleared: function()
105     {
106         WebInspector.ContextMenu.contextMenuCleared();
107     },
108
109     dispatchMessageAsync: function(messageObject)
110     {
111         WebInspector.dispatchMessageFromBackend(messageObject);
112     },
113
114     dispatchMessage: function(messageObject)
115     {
116         InspectorBackend.dispatch(messageObject);
117     },
118
119     dispatch: function(signature)
120     {
121         if (!InspectorFrontendAPI._loaded) {
122             InspectorFrontendAPI._pendingCommands.push(signature);
123             return null;
124         }
125
126         var methodName = signature.shift();
127         console.assert(InspectorFrontendAPI[methodName], "Unexpected InspectorFrontendAPI method name: " + methodName);
128         if (!InspectorFrontendAPI[methodName])
129             return;
130
131         return InspectorFrontendAPI[methodName].apply(InspectorFrontendAPI, signature);
132     },
133
134     loadCompleted: function()
135     {
136         InspectorFrontendAPI._loaded = true;
137
138         for (var i = 0; i < InspectorFrontendAPI._pendingCommands.length; ++i)
139             InspectorFrontendAPI.dispatch(InspectorFrontendAPI._pendingCommands[i]);
140
141         delete InspectorFrontendAPI._pendingCommands;
142     }
143 };