• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2012 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.Object}
34 */
35WebInspector.FileManager = function()
36{
37    /** @type {!Object.<string, ?function(boolean)>} */
38    this._saveCallbacks = {};
39}
40
41WebInspector.FileManager.EventTypes = {
42    SavedURL: "SavedURL",
43    AppendedToURL: "AppendedToURL"
44}
45
46WebInspector.FileManager.prototype = {
47    /**
48     * @return {boolean}
49     */
50    canSave: function()
51    {
52        return true;
53    },
54
55    /**
56     * @param {string} url
57     * @param {string} content
58     * @param {boolean} forceSaveAs
59     * @param {function(boolean)=} callback
60     */
61    save: function(url, content, forceSaveAs, callback)
62    {
63        // Remove this url from the saved URLs while it is being saved.
64        var savedURLs = WebInspector.settings.savedURLs.get();
65        delete savedURLs[url];
66        WebInspector.settings.savedURLs.set(savedURLs);
67        this._saveCallbacks[url] = callback || null;
68        InspectorFrontendHost.save(url, content, forceSaveAs);
69    },
70
71    /**
72     * @param {string} url
73     */
74    savedURL: function(url)
75    {
76        var savedURLs = WebInspector.settings.savedURLs.get();
77        savedURLs[url] = true;
78        WebInspector.settings.savedURLs.set(savedURLs);
79        this.dispatchEventToListeners(WebInspector.FileManager.EventTypes.SavedURL, url);
80        this._invokeSaveCallback(url, true);
81    },
82
83    /**
84     * @param {string} url
85     * @param {boolean} accepted
86     */
87    _invokeSaveCallback: function(url, accepted)
88    {
89        var callback = this._saveCallbacks[url];
90        delete this._saveCallbacks[url];
91        if (callback)
92            callback(accepted);
93    },
94
95    /**
96     * @param {string} url
97     */
98    canceledSaveURL: function(url)
99    {
100        this._invokeSaveCallback(url, false);
101    },
102
103    /**
104     * @param {string} url
105     * @return {boolean}
106     */
107    isURLSaved: function(url)
108    {
109        var savedURLs = WebInspector.settings.savedURLs.get();
110        return savedURLs[url];
111    },
112
113    /**
114     * @param {string} url
115     * @param {string} content
116     */
117    append: function(url, content)
118    {
119        InspectorFrontendHost.append(url, content);
120    },
121
122    /**
123     * @param {string} url
124     */
125    close: function(url)
126    {
127        // Currently a no-op.
128    },
129
130    /**
131     * @param {string} url
132     */
133    appendedToURL: function(url)
134    {
135        this.dispatchEventToListeners(WebInspector.FileManager.EventTypes.AppendedToURL, url);
136    },
137
138    __proto__: WebInspector.Object.prototype
139}
140
141WebInspector.fileManager = new WebInspector.FileManager();
142