Upstream version 7.35.144.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / devtools / front_end / network / NetworkItemView.js
1 /*
2  * Copyright (C) 2010 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
31 /**
32  * @constructor
33  * @extends {WebInspector.TabbedPane}
34  * @param {!WebInspector.NetworkRequest} request
35  */
36 WebInspector.NetworkItemView = function(request)
37 {
38     WebInspector.TabbedPane.call(this);
39     this.element.classList.add("network-item-view");
40
41     var headersView = new WebInspector.RequestHeadersView(request);
42     this.appendTab("headers", WebInspector.UIString("Headers"), headersView);
43
44     this.addEventListener(WebInspector.TabbedPane.EventTypes.TabSelected, this._tabSelected, this);
45
46     if (request.type === WebInspector.resourceTypes.WebSocket) {
47         var frameView = new WebInspector.ResourceWebSocketFrameView(request);
48         this.appendTab("webSocketFrames", WebInspector.UIString("Frames"), frameView);
49     } else {
50         var responseView = new WebInspector.RequestResponseView(request);
51         var previewView = new WebInspector.RequestPreviewView(request, responseView);
52         this.appendTab("preview", WebInspector.UIString("Preview"), previewView);
53         this.appendTab("response", WebInspector.UIString("Response"), responseView);
54     }
55
56     if (request.requestCookies || request.responseCookies) {
57         this._cookiesView = new WebInspector.RequestCookiesView(request);
58         this.appendTab("cookies", WebInspector.UIString("Cookies"), this._cookiesView);
59     }
60
61     if (request.timing) {
62         var timingView = new WebInspector.RequestTimingView(request);
63         this.appendTab("timing", WebInspector.UIString("Timing"), timingView);
64     }
65     this._request = request;
66 }
67
68 WebInspector.NetworkItemView.prototype = {
69     wasShown: function()
70     {
71         WebInspector.TabbedPane.prototype.wasShown.call(this);
72         this._selectTab();
73     },
74
75     /**
76      * @return {?WebInspector.SourceFrame}
77      */
78     currentSourceFrame: function()
79     {
80         var view = this.visibleView;
81         if (view && view instanceof WebInspector.SourceFrame)
82             return /** @type {!WebInspector.SourceFrame} */ (view);
83         return null;
84     },
85
86     /**
87      * @param {string=} tabId
88      */
89     _selectTab: function(tabId)
90     {
91         if (!tabId)
92             tabId = WebInspector.settings.resourceViewTab.get();
93
94         if (!this.selectTab(tabId)) {
95             this._isInFallbackSelection = true;
96             this.selectTab("headers");
97             delete this._isInFallbackSelection;
98         }
99     },
100
101     _tabSelected: function(event)
102     {
103         if (!event.data.isUserGesture)
104             return;
105
106         WebInspector.settings.resourceViewTab.set(event.data.tabId);
107
108         WebInspector.notifications.dispatchEventToListeners(WebInspector.UserMetrics.UserAction, {
109             action: WebInspector.UserMetrics.UserActionNames.NetworkRequestTabSelected,
110             tab: event.data.tabId,
111             url: this._request.url
112         });
113     },
114
115     /**
116       * @return {!WebInspector.NetworkRequest}
117       */
118     request: function()
119     {
120         return this._request;
121     },
122
123     __proto__: WebInspector.TabbedPane.prototype
124 }
125
126 /**
127  * @constructor
128  * @extends {WebInspector.RequestView}
129  * @param {!WebInspector.NetworkRequest} request
130  */
131 WebInspector.RequestContentView = function(request)
132 {
133     WebInspector.RequestView.call(this, request);
134 }
135
136 WebInspector.RequestContentView.prototype = {
137     /**
138      * @return {boolean}
139      */
140     hasContent: function()
141     {
142         return true;
143     },
144
145     /**
146      * @return {!WebInspector.View}
147      */
148     get innerView()
149     {
150         return this._innerView;
151     },
152
153     set innerView(innerView)
154     {
155         this._innerView = innerView;
156     },
157
158     wasShown: function()
159     {
160         this._ensureInnerViewShown();
161     },
162
163     _ensureInnerViewShown: function()
164     {
165         if (this._innerViewShowRequested)
166             return;
167         this._innerViewShowRequested = true;
168
169         /**
170          * @param {?string} content
171          * @this {WebInspector.RequestContentView}
172          */
173         function callback(content)
174         {
175             this._innerViewShowRequested = false;
176             this.contentLoaded();
177         }
178
179         this.request.requestContent(callback.bind(this));
180     },
181
182     contentLoaded: function()
183     {
184         // Should be implemented by subclasses.
185     },
186
187     __proto__: WebInspector.RequestView.prototype
188 }