• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
31WebInspector.NetworkItemView = function(resource)
32{
33    WebInspector.View.call(this);
34
35    this.element.addStyleClass("network-item-view");
36
37    this._headersView = new WebInspector.ResourceHeadersView(resource);
38    // Do not store reference to content view - it can be recreated.
39    var contentView = WebInspector.ResourceView.resourceViewForResource(resource);
40
41    this._tabbedPane = new WebInspector.TabbedPane(this.element);
42    this._tabbedPane.appendTab("headers", WebInspector.UIString("Headers"), this._headersView);
43
44    if (contentView.hasContent()) {
45        // Reusing this view, so hide it at first.
46        contentView.visible = false;
47        this._tabbedPane.appendTab("content", WebInspector.UIString("Content"), contentView);
48    }
49
50    if (resource.type === WebInspector.Resource.Type.XHR && resource.content) {
51        var parsedJSON = WebInspector.ResourceJSONView.parseJSON(resource.content);
52        if (parsedJSON) {
53            var jsonView = new WebInspector.ResourceJSONView(resource, parsedJSON);
54            this._tabbedPane.appendTab("json", WebInspector.UIString("JSON"), jsonView);
55        }
56    }
57
58    if (Preferences.showCookiesTab) {
59        this._cookiesView = new WebInspector.ResourceCookiesView(resource);
60        this._tabbedPane.appendTab("cookies", WebInspector.UIString("Cookies"), this._cookiesView);
61    }
62
63    if (Preferences.showTimingTab) {
64        var timingView = new WebInspector.ResourceTimingView(resource);
65        this._tabbedPane.appendTab("timing", WebInspector.UIString("Timing"), timingView);
66    }
67
68    this._tabbedPane.addEventListener("tab-selected", this._tabSelected, this);
69}
70
71WebInspector.NetworkItemView.prototype = {
72    show: function(parentElement)
73    {
74        WebInspector.View.prototype.show.call(this, parentElement);
75        this._selectTab();
76    },
77
78    _selectTab: function(tabId)
79    {
80        if (!tabId)
81            tabId = WebInspector.settings.resourceViewTab;
82
83        if (!this._tabbedPane.selectTab(tabId)) {
84            this._isInFallbackSelection = true;
85            this._tabbedPane.selectTab("headers");
86            delete this._isInFallbackSelection;
87        }
88    },
89
90    _tabSelected: function(event)
91    {
92        WebInspector.settings.resourceViewTab = event.data.tabId;
93    },
94
95    resize: function()
96    {
97        if (this._cookiesView && this._cookiesView.visible)
98            this._cookiesView.resize();
99    }
100}
101
102WebInspector.NetworkItemView.prototype.__proto__ = WebInspector.View.prototype;
103