Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(668)

Side by Side Diff: third_party/WebKit/Source/core/inspector/ContentSearchUtils.cpp

Issue 1470323003: [DevTools] Removed support deprecated (//@|/*@) source(URL|MappingURL)= (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 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 * 1. Redistributions of source code must retain the above copyright 8 * 1. 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 * 10 *
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 100
101 OwnPtr<ScriptRegexp> regex = ContentSearchUtils::createSearchRegex(query, ca seSensitive, isRegex); 101 OwnPtr<ScriptRegexp> regex = ContentSearchUtils::createSearchRegex(query, ca seSensitive, isRegex);
102 Vector<std::pair<int, String>> matches = getScriptRegexpMatchesByLines(regex .get(), text); 102 Vector<std::pair<int, String>> matches = getScriptRegexpMatchesByLines(regex .get(), text);
103 103
104 for (const auto& match : matches) 104 for (const auto& match : matches)
105 result->addItem(buildObjectForSearchMatch(match.first, match.second)); 105 result->addItem(buildObjectForSearchMatch(match.first, match.second));
106 106
107 return result; 107 return result;
108 } 108 }
109 109
110 static String findMagicComment(const String& content, const String& name, MagicC ommentType commentType, bool* deprecated = 0) 110 static String findMagicComment(const String& content, const String& name, MagicC ommentType commentType)
111 { 111 {
112 ASSERT(name.find("=") == kNotFound); 112 ASSERT(name.find("=") == kNotFound);
113 if (deprecated)
114 *deprecated = false;
115 113
116 unsigned length = content.length(); 114 unsigned length = content.length();
117 unsigned nameLength = name.length(); 115 unsigned nameLength = name.length();
118 116
119 size_t pos = length; 117 size_t pos = length;
120 size_t equalSignPos = 0; 118 size_t equalSignPos = 0;
121 size_t closingCommentPos = 0; 119 size_t closingCommentPos = 0;
122 while (true) { 120 while (true) {
123 pos = content.reverseFind(name, pos); 121 pos = content.reverseFind(name, pos);
124 if (pos == kNotFound) 122 if (pos == kNotFound)
125 return String(); 123 return String();
126 124
127 // Check for a /\/[\/*][@#][ \t]/ regexp (length of 4) before found name . 125 // Check for a /\/[\/*][@#][ \t]/ regexp (length of 4) before found name .
128 if (pos < 4) 126 if (pos < 4)
129 return String(); 127 return String();
130 pos -= 4; 128 pos -= 4;
131 if (content[pos] != '/') 129 if (content[pos] != '/')
132 continue; 130 continue;
133 if ((content[pos + 1] != '/' || commentType != JavaScriptMagicComment) 131 if ((content[pos + 1] != '/' || commentType != JavaScriptMagicComment)
134 && (content[pos + 1] != '*' || commentType != CSSMagicComment)) 132 && (content[pos + 1] != '*' || commentType != CSSMagicComment))
135 continue; 133 continue;
136 if (content[pos + 2] != '#' && content[pos + 2] != '@') 134 if (content[pos + 2] != '#')
137 continue; 135 continue;
138 if (content[pos + 3] != ' ' && content[pos + 3] != '\t') 136 if (content[pos + 3] != ' ' && content[pos + 3] != '\t')
139 continue; 137 continue;
140 equalSignPos = pos + 4 + nameLength; 138 equalSignPos = pos + 4 + nameLength;
141 if (equalSignPos < length && content[equalSignPos] != '=') 139 if (equalSignPos < length && content[equalSignPos] != '=')
142 continue; 140 continue;
143 if (commentType == CSSMagicComment) { 141 if (commentType == CSSMagicComment) {
144 closingCommentPos = content.find("*/", equalSignPos + 1); 142 closingCommentPos = content.find("*/", equalSignPos + 1);
145 if (closingCommentPos == kNotFound) 143 if (closingCommentPos == kNotFound)
146 return String(); 144 return String();
147 } 145 }
148 146
149 break; 147 break;
150 } 148 }
151 149
152 if (deprecated && content[pos + 2] == '@')
153 *deprecated = true;
154
155 ASSERT(equalSignPos); 150 ASSERT(equalSignPos);
156 ASSERT(commentType != CSSMagicComment || closingCommentPos); 151 ASSERT(commentType != CSSMagicComment || closingCommentPos);
157 size_t urlPos = equalSignPos + 1; 152 size_t urlPos = equalSignPos + 1;
158 String match = commentType == CSSMagicComment 153 String match = commentType == CSSMagicComment
159 ? content.substring(urlPos, closingCommentPos - urlPos) 154 ? content.substring(urlPos, closingCommentPos - urlPos)
160 : content.substring(urlPos); 155 : content.substring(urlPos);
161 156
162 size_t newLine = match.find("\n"); 157 size_t newLine = match.find("\n");
163 if (newLine != kNotFound) 158 if (newLine != kNotFound)
164 match = match.substring(0, newLine); 159 match = match.substring(0, newLine);
165 match = match.stripWhiteSpace(); 160 match = match.stripWhiteSpace();
166 161
167 String disallowedChars("\"' \t"); 162 String disallowedChars("\"' \t");
168 for (unsigned i = 0; i < match.length(); ++i) { 163 for (unsigned i = 0; i < match.length(); ++i) {
169 if (disallowedChars.find(match[i]) != kNotFound) 164 if (disallowedChars.find(match[i]) != kNotFound)
170 return ""; 165 return "";
171 } 166 }
172 167
173 return match; 168 return match;
174 } 169 }
175 170
176 String findSourceURL(const String& content, MagicCommentType commentType, bool* deprecated) 171 String findSourceURL(const String& content, MagicCommentType commentType)
177 { 172 {
178 return findMagicComment(content, "sourceURL", commentType, deprecated); 173 return findMagicComment(content, "sourceURL", commentType);
179 } 174 }
180 175
181 String findSourceMapURL(const String& content, MagicCommentType commentType, boo l* deprecated) 176 String findSourceMapURL(const String& content, MagicCommentType commentType)
182 { 177 {
183 return findMagicComment(content, "sourceMappingURL", commentType, deprecated ); 178 return findMagicComment(content, "sourceMappingURL", commentType);
184 } 179 }
185 180
186 } // namespace ContentSearchUtils 181 } // namespace ContentSearchUtils
187 } // namespace blink 182 } // namespace blink
188 183
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698