initial import
[vuplus_webkit] / Source / WebCore / inspector / front-end / 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 WebInspector.NetworkItemView = function(resource)
32 {
33     WebInspector.TabbedPane.call(this);
34
35     this.element.addStyleClass("network-item-view");
36
37     var headersView = new WebInspector.ResourceHeadersView(resource);
38     this.appendTab("headers", WebInspector.UIString("Headers"), headersView);
39
40     var responseView = new WebInspector.ResourceResponseView(resource);
41     var previewView = new WebInspector.ResourcePreviewView(resource, responseView);
42
43     this.appendTab("preview", WebInspector.UIString("Preview"), previewView);
44     this.appendTab("response", WebInspector.UIString("Response"), responseView);
45
46     if (Preferences.showCookiesTab) {
47         this._cookiesView = new WebInspector.ResourceCookiesView(resource);
48         this.appendTab("cookies", WebInspector.UIString("Cookies"), this._cookiesView);
49     }
50
51     if (Preferences.showTimingTab) {
52         var timingView = new WebInspector.ResourceTimingView(resource);
53         this.appendTab("timing", WebInspector.UIString("Timing"), timingView);
54     }
55
56     this.addEventListener("tab-selected", this._tabSelected, this);
57 }
58
59 WebInspector.NetworkItemView.prototype = {
60     show: function(parentElement)
61     {
62         WebInspector.TabbedPane.prototype.show.call(this, parentElement);
63         this._selectTab();
64     },
65
66     _selectTab: function(tabId)
67     {
68         if (!tabId)
69             tabId = WebInspector.settings.resourceViewTab.get();
70
71         if (!this.selectTab(tabId)) {
72             this._isInFallbackSelection = true;
73             this.selectTab("headers");
74             delete this._isInFallbackSelection;
75         }
76     },
77
78     _tabSelected: function(event)
79     {
80         if (event.data.isUserGesture)
81             WebInspector.settings.resourceViewTab.set(event.data.tabId);
82         this._installHighlightSupport(event.data.view);
83     },
84
85     _installHighlightSupport: function(view)
86     {
87         if (typeof view.highlightLine === "function")
88             this.highlightLine = view.highlightLine.bind(view);
89         else
90             delete this.highlightLine;
91     }
92 }
93
94 WebInspector.NetworkItemView.prototype.__proto__ = WebInspector.TabbedPane.prototype;
95
96 WebInspector.ResourceContentView = function(resource)
97 {
98     WebInspector.ResourceView.call(this, resource);
99 }
100
101 WebInspector.ResourceContentView.prototype = {
102     hasContent: function()
103     {
104         return true;
105     },
106
107     get innerView()
108     {
109         return this._innerView;
110     },
111
112     set innerView(innerView)
113     {
114         this._innerView = innerView;
115     },
116
117     show: function(parentElement)
118     {
119         WebInspector.ResourceView.prototype.show.call(this, parentElement);
120         this._ensureInnerViewShown();
121     },
122
123     hide: function()
124     {
125         if (this._innerView)
126             this._innerView.hide();
127         WebInspector.ResourceView.prototype.hide.call(this);
128     },
129
130     _ensureInnerViewShown: function()
131     {
132         if (this._innerViewShowRequested)
133             return;
134         this._innerViewShowRequested = true;
135
136         function callback()
137         {
138             this._innerViewShowRequested = false;
139             this.contentLoaded();
140         }
141
142         this.resource.requestContent(callback.bind(this));
143     },
144
145     contentLoaded: function()
146     {
147         // Should be implemented by subclasses.
148     }
149 }
150
151 WebInspector.ResourceContentView.prototype.__proto__ = WebInspector.ResourceView.prototype;