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
26InspectorFrontendAPI = {
27    _loaded: false,
28
29    _pendingCommands: [],
30
31    savedURL: function(url)
32    {
33        // FIXME: Not implemented.
34    },
35
36    appendedToURL: function(url)
37    {
38        // FIXME: Not implemented.
39    },
40
41    isDebuggingEnabled: function()
42    {
43        // FIXME: Not implemented.
44        return false;
45    },
46
47    setDebuggingEnabled: function(enabled)
48    {
49        // FIXME: Not implemented.
50    },
51
52    isTimelineProfilingEnabled: function()
53    {
54        return WebInspector.timelineManager.isCapturing();
55    },
56
57    setTimelineProfilingEnabled: function(enabled)
58    {
59        if (enabled) {
60            WebInspector.navigationSidebar.selectedSidebarPanel = WebInspector.timelineSidebarPanel;
61            WebInspector.timelineSidebarPanel.showTimelineOverview();
62            WebInspector.timelineManager.startCapturing();
63        } else {
64            WebInspector.timelineManager.stopCapturing();
65        }
66    },
67
68    isProfilingJavaScript: function()
69    {
70        return WebInspector.legacyProfileManager.isProfilingJavaScript();
71    },
72
73    startProfilingJavaScript: function()
74    {
75        WebInspector.legacyProfileManager.startProfilingJavaScript();
76    },
77
78    stopProfilingJavaScript: function()
79    {
80        WebInspector.timelineSidebarPanel.show();
81        WebInspector.legacyProfileManager.stopProfilingJavaScript();
82    },
83
84    setDockSide: function(side)
85    {
86        WebInspector.updateDockedState(side);
87    },
88
89    showConsole: function()
90    {
91        WebInspector.showConsoleView();
92
93        WebInspector.quickConsole.prompt.focus();
94
95        // If the page is still loading, focus the quick console again after tabindex autofocus.
96        if (document.readyState !== "complete")
97            document.addEventListener("readystatechange", this);
98    },
99
100    handleEvent: function(event)
101    {
102        console.assert(event.type === "readystatechange");
103
104        if (document.readyState === "complete") {
105            WebInspector.quickConsole.prompt.focus();
106            document.removeEventListener("readystatechange", this);
107        }
108    },
109
110    showResources: function()
111    {
112        WebInspector.ignoreLastContentCookie = true;
113        WebInspector.navigationSidebar.selectedSidebarPanel = WebInspector.resourceSidebarPanel;
114        WebInspector.navigationSidebar.collapsed = false;
115    },
116
117    showMainResourceForFrame: function(frameIdentifier)
118    {
119        WebInspector.ignoreLastContentCookie = true;
120        WebInspector.navigationSidebar.selectedSidebarPanel = WebInspector.resourceSidebarPanel;
121        WebInspector.resourceSidebarPanel.showSourceCodeForFrame(frameIdentifier, true);
122    },
123
124    setDockingUnavailable: function(unavailable)
125    {
126        // Not used.
127    },
128
129    contextMenuItemSelected: function(id)
130    {
131        WebInspector.contextMenuItemSelected(id);
132    },
133
134    contextMenuCleared: function()
135    {
136        WebInspector.contextMenuCleared();
137    },
138
139    dispatchMessageAsync: function(messageObject)
140    {
141        WebInspector.dispatchMessageFromBackend(messageObject);
142    },
143
144    dispatchMessage: function(messageObject)
145    {
146        InspectorBackend.dispatch(messageObject);
147    },
148
149    dispatch: function(signature)
150    {
151        if (!InspectorFrontendAPI._loaded) {
152            InspectorFrontendAPI._pendingCommands.push(signature);
153            return null;
154        }
155
156        var methodName = signature.shift();
157        return InspectorFrontendAPI[methodName].apply(InspectorFrontendAPI, signature);
158    },
159
160    loadCompleted: function()
161    {
162        InspectorFrontendAPI._loaded = true;
163
164        for (var i = 0; i < InspectorFrontendAPI._pendingCommands.length; ++i)
165            InspectorFrontendAPI.dispatch(InspectorFrontendAPI._pendingCommands[i]);
166
167        InspectorFrontendAPI._pendingCommands = [];
168    }
169};
170