OSDN Git Service

8cd0107f87426c72622024f4f69ad232bb110f75
[android-x86/external-webkit.git] / WebCore / inspector / front-end / FileSystemView.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.FileSystem = {}
32
33 // Keep in sync with Type in AsyncFileSystem.h
34 WebInspector.FileSystem.TEMPORARY = 0;
35 WebInspector.FileSystem.PERSISTENT = 1;
36
37 WebInspector.FileSystem.getFileSystemPathsAsync = function(origin)
38 {
39     InspectorBackend.getFileSystemPathAsync(WebInspector.FileSystem.PERSISTENT, origin);
40     InspectorBackend.getFileSystemPathAsync(WebInspector.FileSystem.TEMPORARY, origin);
41 }
42
43 WebInspector.FileSystemView = function(treeElement, fileSystemOrigin)
44 {
45     WebInspector.View.call(this);
46
47     this.element.addStyleClass("resource-view");
48     this._treeElement = treeElement;
49     this._origin = fileSystemOrigin;
50     this._tabbedPane = new WebInspector.TabbedPane(this.element);
51
52     this._persistentFileSystemElement = document.createElement("div");
53     this._persistentFileSystemElement.className = "resource-view-headers";
54     this._tabbedPane.appendTab("persistent", WebInspector.UIString("Persistent File System"), this._persistentFileSystemElement, this._selectFileSystemTab.bind(this, true));
55
56     this._tempFileSystemElement = document.createElement("div");
57     this._tempFileSystemElement.className = "resource-view-headers";
58     this._tabbedPane.appendTab("temp", WebInspector.UIString("Temporary File System"), this._tempFileSystemElement, this.selectTemporaryFileSystemTab.bind(this, true));
59
60     this._temporaryRoot = "";
61     this._persistentRoot = "";
62     this._isFileSystemDisabled = false;
63     this._persistentRootError = false;
64     this._temporaryRootError = false;
65     this.fileSystemVisible = true;
66     this._selectFileSystemTab();
67     this.refreshFileSystem();
68 }
69
70 WebInspector.FileSystemView.prototype = {
71     show: function(parentElement)
72     {
73         WebInspector.View.prototype.show.call(this, parentElement);
74         this._update();
75     },
76
77     set fileSystemVisible(x)
78     {
79         if (x === this._fileSystemVisible)
80             return;
81         this._fileSystemVisible = x;
82         if (x)
83             this.element.addStyleClass("headers-visible");
84         else
85             this.element.removeStyleClass("headers-visible"); 
86         this._selectFileSystemTab();
87     },
88
89     _update: function()
90     {
91         this._selectFileSystemTab();
92         WebInspector.FileSystem.getFileSystemPathsAsync(this._origin);
93     },
94
95     updateFileSystemPath: function(root, type, origin)
96     {
97         if (origin == this._origin && type == WebInspector.FileSystem.PERSISTENT) {
98             this._persistentRoot = root;
99             this._persistentRootError = false;
100         }
101         
102         if (origin == this._origin && type == WebInspector.FileSystem.TEMPORARY) {
103             this._temporaryRoot = root;
104             this._temporaryRootErrorError = false;
105         }
106
107         this.refreshFileSystem();
108     },
109     
110     updateFileSystemError: function(type, origin)
111     {
112         if (type == WebInspector.FileSystem.PERSISTENT)
113             this._persistentRootError = true;
114         
115         if (type == WebInspector.FileSystem.TEMPORARY)
116             this._temporaryRootError = true;
117
118         this.refreshFileSystem();
119     },
120     
121     setFileSystemDisabled: function()
122     {
123         this._isFileSystemDisabled = true;
124         this.refreshFileSystem();
125     },
126     _selectFileSystemTab: function()
127     {
128         this._tabbedPane.selectTab("persistent");
129     },
130     
131     selectTemporaryFileSystemTab: function()
132     {
133         this._tabbedPane.selectTab("temp");
134     },
135
136     _revealPersistentFolderInOS: function()
137     {
138         InspectorBackend.revealFolderInOS(this._persistentRoot);
139     },
140     
141     _revealTemporaryFolderInOS: function()
142     {
143         InspectorBackend.revealFolderInOS(this._temporaryRoot);
144     },
145     
146     _createTextAndButton: function(fileSystemElement, rootPathText, type, isError)
147     {
148         fileSystemElement.removeChildren();
149         var rootPath = WebInspector.UIString("File System root path not available.");
150         if (this._isFileSystemDisabled)
151             rootPath = WebInspector.UIString("File System is disabled.");
152         else if (isError)
153             rootPath = WebInspector.UIString("Error in fetching root path for file system.");
154         else if (rootPathText)
155             rootPath = rootPathText;
156
157         var rootTextNode = document.createTextNode("Root: " + rootPath.escapeHTML());
158         var rootSystemElement = document.createElement("div");
159         rootSystemElement.className = "header-value source-code";
160         rootSystemElement.appendChild(rootTextNode);
161         fileSystemElement.appendChild(rootSystemElement);
162             
163         if (!isError && rootPathText) {
164             // Append Browse button iff root path is available and it is not an error.
165             var contentElement = document.createElement("div");
166             contentElement.className = "panel-enabler-view-content";
167             fileSystemElement.appendChild(contentElement);
168             var choicesForm = document.createElement("form");
169             contentElement.appendChild(choicesForm);
170             var enableButton = document.createElement("button");
171             enableButton.setAttribute("type", "button");
172             enableButton.textContent = WebInspector.UIString("Reveal folder in OS");
173             // FIXME: Bind this directly to InspectorBackend.
174             if (type == WebInspector.FileSystem.PERSISTENT)
175                 enableButton.addEventListener("click", this._revealPersistentFolderInOS.bind(this), false);
176             if (type == WebInspector.FileSystem.TEMPORARY)
177                 enableButton.addEventListener("click", this._revealTemporaryFolderInOS.bind(this), false);
178             choicesForm.appendChild(enableButton);
179             fileSystemElement.appendChild(contentElement);
180         }
181     },
182     
183     refreshFileSystem: function()
184     {
185         this._createTextAndButton(this._persistentFileSystemElement, this._persistentRoot, WebInspector.FileSystem.PERSISTENT, this._persistentRootError);
186         this._createTextAndButton(this._tempFileSystemElement, this._temporaryRoot, WebInspector.FileSystem.TEMPORARY, this._temporaryRootError);
187     }, 
188 }
189
190 WebInspector.FileSystemView.prototype.__proto__ = WebInspector.View.prototype;