OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 13 matching lines...) Expand all Loading... |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 /** | 31 /** |
32 * @interface | 32 * @interface |
33 */ | 33 */ |
34 WebInspector.ContentProvider = function() { } | 34 WebInspector.ContentProvider = function() { }; |
35 | 35 |
36 WebInspector.ContentProvider.prototype = { | 36 WebInspector.ContentProvider.prototype = { |
37 /** | 37 /** |
38 * @return {string} | 38 * @return {string} |
39 */ | 39 */ |
40 contentURL: function() { }, | 40 contentURL: function() { }, |
41 | 41 |
42 /** | 42 /** |
43 * @return {!WebInspector.ResourceType} | 43 * @return {!WebInspector.ResourceType} |
44 */ | 44 */ |
45 contentType: function() { }, | 45 contentType: function() { }, |
46 | 46 |
47 /** | 47 /** |
48 * @return {!Promise<?string>} | 48 * @return {!Promise<?string>} |
49 */ | 49 */ |
50 requestContent: function() { }, | 50 requestContent: function() { }, |
51 | 51 |
52 /** | 52 /** |
53 * @param {string} query | 53 * @param {string} query |
54 * @param {boolean} caseSensitive | 54 * @param {boolean} caseSensitive |
55 * @param {boolean} isRegex | 55 * @param {boolean} isRegex |
56 * @param {function(!Array.<!WebInspector.ContentProvider.SearchMatch>)} cal
lback | 56 * @param {function(!Array.<!WebInspector.ContentProvider.SearchMatch>)} cal
lback |
57 */ | 57 */ |
58 searchInContent: function(query, caseSensitive, isRegex, callback) { } | 58 searchInContent: function(query, caseSensitive, isRegex, callback) { } |
59 } | 59 }; |
60 | 60 |
61 /** | 61 /** |
62 * @constructor | 62 * @constructor |
63 * @param {number} lineNumber | 63 * @param {number} lineNumber |
64 * @param {string} lineContent | 64 * @param {string} lineContent |
65 */ | 65 */ |
66 WebInspector.ContentProvider.SearchMatch = function(lineNumber, lineContent) { | 66 WebInspector.ContentProvider.SearchMatch = function(lineNumber, lineContent) { |
67 this.lineNumber = lineNumber; | 67 this.lineNumber = lineNumber; |
68 this.lineContent = lineContent; | 68 this.lineContent = lineContent; |
69 } | 69 }; |
70 | 70 |
71 /** | 71 /** |
72 * @param {string} content | 72 * @param {string} content |
73 * @param {string} query | 73 * @param {string} query |
74 * @param {boolean} caseSensitive | 74 * @param {boolean} caseSensitive |
75 * @param {boolean} isRegex | 75 * @param {boolean} isRegex |
76 * @return {!Array.<!WebInspector.ContentProvider.SearchMatch>} | 76 * @return {!Array.<!WebInspector.ContentProvider.SearchMatch>} |
77 */ | 77 */ |
78 WebInspector.ContentProvider.performSearchInContent = function(content, query, c
aseSensitive, isRegex) | 78 WebInspector.ContentProvider.performSearchInContent = function(content, query, c
aseSensitive, isRegex) |
79 { | 79 { |
80 var regex = createSearchRegex(query, caseSensitive, isRegex); | 80 var regex = createSearchRegex(query, caseSensitive, isRegex); |
81 | 81 |
82 var text = new WebInspector.Text(content); | 82 var text = new WebInspector.Text(content); |
83 var result = []; | 83 var result = []; |
84 for (var i = 0; i < text.lineCount(); ++i) { | 84 for (var i = 0; i < text.lineCount(); ++i) { |
85 var lineContent = text.lineAt(i); | 85 var lineContent = text.lineAt(i); |
86 regex.lastIndex = 0; | 86 regex.lastIndex = 0; |
87 if (regex.exec(lineContent)) | 87 if (regex.exec(lineContent)) |
88 result.push(new WebInspector.ContentProvider.SearchMatch(i, lineCont
ent)); | 88 result.push(new WebInspector.ContentProvider.SearchMatch(i, lineCont
ent)); |
89 } | 89 } |
90 return result; | 90 return result; |
91 } | 91 }; |
92 | 92 |
93 /** | 93 /** |
94 * @param {?string} content | 94 * @param {?string} content |
95 * @param {string} mimeType | 95 * @param {string} mimeType |
96 * @param {boolean} contentEncoded | 96 * @param {boolean} contentEncoded |
97 * @param {?string=} charset | 97 * @param {?string=} charset |
98 * @return {?string} | 98 * @return {?string} |
99 */ | 99 */ |
100 WebInspector.ContentProvider.contentAsDataURL = function(content, mimeType, cont
entEncoded, charset) | 100 WebInspector.ContentProvider.contentAsDataURL = function(content, mimeType, cont
entEncoded, charset) |
101 { | 101 { |
102 const maxDataUrlSize = 1024 * 1024; | 102 const maxDataUrlSize = 1024 * 1024; |
103 if (content === null || content.length > maxDataUrlSize) | 103 if (content === null || content.length > maxDataUrlSize) |
104 return null; | 104 return null; |
105 | 105 |
106 return "data:" + mimeType + (charset ? ";charset=" + charset : "") + (conten
tEncoded ? ";base64" : "") + "," + content; | 106 return "data:" + mimeType + (charset ? ";charset=" + charset : "") + (conten
tEncoded ? ";base64" : "") + "," + content; |
107 } | 107 }; |
OLD | NEW |