1/* 2 * Copyright (C) 2013 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 * @implements {WebInspector.ProjectDelegate} 34 * @extends {WebInspector.Object} 35 * @param {string} type 36 */ 37WebInspector.ContentProviderBasedProjectDelegate = function(type) 38{ 39 this._type = type; 40 /** @type {Object.<string, WebInspector.ContentProvider>} */ 41 this._contentProviders = {}; 42} 43 44WebInspector.ContentProviderBasedProjectDelegate.prototype = { 45 /** 46 * @return {string} 47 */ 48 id: function() 49 { 50 // Overriddden by subclasses 51 return ""; 52 }, 53 54 /** 55 * @return {string} 56 */ 57 type: function() 58 { 59 return this._type; 60 }, 61 62 /** 63 * @return {string} 64 */ 65 displayName: function() 66 { 67 // Overriddden by subclasses 68 return ""; 69 }, 70 71 /** 72 * @param {Array.<string>} path 73 * @param {function(?string,boolean,string)} callback 74 */ 75 requestFileContent: function(path, callback) 76 { 77 var contentProvider = this._contentProviders[path.join("/")]; 78 contentProvider.requestContent(callback); 79 }, 80 81 /** 82 * @return {boolean} 83 */ 84 canSetFileContent: function() 85 { 86 return false; 87 }, 88 89 /** 90 * @param {Array.<string>} path 91 * @param {string} newContent 92 * @param {function(?string)} callback 93 */ 94 setFileContent: function(path, newContent, callback) 95 { 96 callback(null); 97 }, 98 99 /** 100 * @param {Array.<string>} path 101 * @param {string} query 102 * @param {boolean} caseSensitive 103 * @param {boolean} isRegex 104 * @param {function(Array.<WebInspector.ContentProvider.SearchMatch>)} callback 105 */ 106 searchInFileContent: function(path, query, caseSensitive, isRegex, callback) 107 { 108 var contentProvider = this._contentProviders[path.join("/")]; 109 contentProvider.searchInContent(query, caseSensitive, isRegex, callback); 110 }, 111 112 /** 113 * @param {Array.<string>} path 114 * @param {string} url 115 * @param {WebInspector.ContentProvider} contentProvider 116 * @param {boolean} isEditable 117 * @param {boolean=} isContentScript 118 * @return {Array.<string>} 119 */ 120 addContentProvider: function(path, url, contentProvider, isEditable, isContentScript) 121 { 122 var fileDescriptor = new WebInspector.FileDescriptor(path, url, url, contentProvider.contentType(), isEditable, isContentScript); 123 this._contentProviders[path.join("/")] = contentProvider; 124 this.dispatchEventToListeners(WebInspector.ProjectDelegate.Events.FileAdded, fileDescriptor); 125 return path; 126 }, 127 128 /** 129 * @param {Array.<string>} path 130 */ 131 removeFile: function(path) 132 { 133 delete this._contentProviders[path.join("/")]; 134 this.dispatchEventToListeners(WebInspector.ProjectDelegate.Events.FileRemoved, path); 135 }, 136 137 /** 138 * @return {Object.<string, WebInspector.ContentProvider>} 139 */ 140 contentProviders: function() 141 { 142 return this._contentProviders; 143 }, 144 145 reset: function() 146 { 147 this._contentProviders = {}; 148 this.dispatchEventToListeners(WebInspector.ProjectDelegate.Events.Reset, null); 149 }, 150 151 __proto__: WebInspector.Object.prototype 152} 153