2 * Copyright (C) 2010 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
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
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.
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.
31 WebInspector.FileSystem = {}
33 // Keep in sync with Type in AsyncFileSystem.h
34 WebInspector.FileSystem.TEMPORARY = 0;
35 WebInspector.FileSystem.PERSISTENT = 1;
37 WebInspector.FileSystem.getFileSystemPathsAsync = function(origin)
39 InspectorBackend.getFileSystemPathAsync(WebInspector.FileSystem.PERSISTENT, origin);
40 InspectorBackend.getFileSystemPathAsync(WebInspector.FileSystem.TEMPORARY, origin);
43 WebInspector.FileSystemView = function(treeElement, fileSystemOrigin)
45 WebInspector.View.call(this);
47 this.element.addStyleClass("resource-view");
48 this._treeElement = treeElement;
49 this._origin = fileSystemOrigin;
50 this._tabbedPane = new WebInspector.TabbedPane(this.element);
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));
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));
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();
70 WebInspector.FileSystemView.prototype = {
71 show: function(parentElement)
73 WebInspector.View.prototype.show.call(this, parentElement);
77 set fileSystemVisible(x)
79 if (x === this._fileSystemVisible)
81 this._fileSystemVisible = x;
83 this.element.addStyleClass("headers-visible");
85 this.element.removeStyleClass("headers-visible");
86 this._selectFileSystemTab();
91 this._selectFileSystemTab();
92 WebInspector.FileSystem.getFileSystemPathsAsync(this._origin);
95 updateFileSystemPath: function(root, type, origin)
97 if (origin == this._origin && type == WebInspector.FileSystem.PERSISTENT) {
98 this._persistentRoot = root;
99 this._persistentRootError = false;
102 if (origin == this._origin && type == WebInspector.FileSystem.TEMPORARY) {
103 this._temporaryRoot = root;
104 this._temporaryRootErrorError = false;
107 this.refreshFileSystem();
110 updateFileSystemError: function(type, origin)
112 if (type == WebInspector.FileSystem.PERSISTENT)
113 this._persistentRootError = true;
115 if (type == WebInspector.FileSystem.TEMPORARY)
116 this._temporaryRootError = true;
118 this.refreshFileSystem();
121 setFileSystemDisabled: function()
123 this._isFileSystemDisabled = true;
124 this.refreshFileSystem();
126 _selectFileSystemTab: function()
128 this._tabbedPane.selectTab("persistent");
131 selectTemporaryFileSystemTab: function()
133 this._tabbedPane.selectTab("temp");
136 _revealPersistentFolderInOS: function()
138 InspectorBackend.revealFolderInOS(this._persistentRoot);
141 _revealTemporaryFolderInOS: function()
143 InspectorBackend.revealFolderInOS(this._temporaryRoot);
146 _createTextAndButton: function(fileSystemElement, rootPathText, type, isError)
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.");
153 rootPath = WebInspector.UIString("Error in fetching root path for file system.");
154 else if (rootPathText)
155 rootPath = rootPathText;
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);
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);
183 refreshFileSystem: function()
185 this._createTextAndButton(this._persistentFileSystemElement, this._persistentRoot, WebInspector.FileSystem.PERSISTENT, this._persistentRootError);
186 this._createTextAndButton(this._tempFileSystemElement, this._temporaryRoot, WebInspector.FileSystem.TEMPORARY, this._temporaryRootError);
190 WebInspector.FileSystemView.prototype.__proto__ = WebInspector.View.prototype;