ContentProviderBasedProjectDelegate.js 4.6 KB

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