Update To 11.40.268.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.resourceType() === 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.selectTab("headers");
96     },
97
98     _tabSelected: function(event)
99     {
100         if (!event.data.isUserGesture)
101             return;
102
103         WebInspector.settings.resourceViewTab.set(event.data.tabId);
104
105         WebInspector.notifications.dispatchEventToListeners(WebInspector.UserMetrics.UserAction, {
106             action: WebInspector.UserMetrics.UserActionNames.NetworkRequestTabSelected,
107             tab: event.data.tabId,
108             url: this._request.url
109         });
110     },
111
112     /**
113       * @return {!WebInspector.NetworkRequest}
114       */
115     request: function()
116     {
117         return this._request;
118     },
119
120     __proto__: WebInspector.TabbedPane.prototype
121 }
122
123 /**
124  * @constructor
125  * @extends {WebInspector.RequestView}
126  * @param {!WebInspector.NetworkRequest} request
127  */
128 WebInspector.RequestContentView = function(request)
129 {
130     WebInspector.RequestView.call(this, request);
131 }
132
133 WebInspector.RequestContentView.prototype = {
134     /**
135      * @return {!WebInspector.View}
136      */
137     get innerView()
138     {
139         return this._innerView;
140     },
141
142     set innerView(innerView)
143     {
144         this._innerView = innerView;
145     },
146
147     wasShown: function()
148     {
149         this._ensureInnerViewShown();
150     },
151
152     _ensureInnerViewShown: function()
153     {
154         if (this._innerViewShowRequested)
155             return;
156         this._innerViewShowRequested = true;
157
158         /**
159          * @param {?string} content
160          * @this {WebInspector.RequestContentView}
161          */
162         function callback(content)
163         {
164             this._innerViewShowRequested = false;
165             this.contentLoaded();
166         }
167
168         this.request.requestContent(callback.bind(this));
169     },
170
171     contentLoaded: function()
172     {
173         // Should be implemented by subclasses.
174     },
175
176     __proto__: WebInspector.RequestView.prototype
177 }