| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 // | 4 // |
| 5 // This is a port of ManifestParser.cc from WebKit/WebCore/loader/appcache. | 5 // This is a port of ManifestParser.cc from WebKit/WebCore/loader/appcache. |
| 6 | 6 |
| 7 /* | 7 /* |
| 8 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | 8 * Copyright (C) 2008 Apple Inc. All Rights Reserved. |
| 9 * | 9 * |
| 10 * Redistribution and use in source and binary forms, with or without | 10 * Redistribution and use in source and binary forms, with or without |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 ONLINE_WHITELIST, | 63 ONLINE_WHITELIST, |
| 64 UNKNOWN_MODE, | 64 UNKNOWN_MODE, |
| 65 }; | 65 }; |
| 66 | 66 |
| 67 enum InterceptVerb { | 67 enum InterceptVerb { |
| 68 RETURN, | 68 RETURN, |
| 69 EXECUTE, | 69 EXECUTE, |
| 70 UNKNOWN_VERB, | 70 UNKNOWN_VERB, |
| 71 }; | 71 }; |
| 72 | 72 |
| 73 Manifest::Manifest() : online_whitelist_all(false) {} | 73 Manifest::Manifest() |
| 74 : online_whitelist_all(false), |
| 75 did_ignore_intercept_namespaces(false) { |
| 76 } |
| 74 | 77 |
| 75 Manifest::~Manifest() {} | 78 Manifest::~Manifest() {} |
| 76 | 79 |
| 77 bool ParseManifest(const GURL& manifest_url, const char* data, int length, | 80 bool ParseManifest(const GURL& manifest_url, const char* data, int length, |
| 78 Manifest& manifest) { | 81 ParseMode parse_mode, Manifest& manifest) { |
| 79 // This is an implementation of the parsing algorithm specified in | 82 // This is an implementation of the parsing algorithm specified in |
| 80 // the HTML5 offline web application docs: | 83 // the HTML5 offline web application docs: |
| 81 // http://www.w3.org/TR/html5/offline.html | 84 // http://www.w3.org/TR/html5/offline.html |
| 82 // Do not modify it without consulting those docs. | 85 // Do not modify it without consulting those docs. |
| 83 // Though you might be tempted to convert these wstrings to UTF-8 or | 86 // Though you might be tempted to convert these wstrings to UTF-8 or |
| 84 // base::string16, this implementation seems simpler given the constraints. | 87 // base::string16, this implementation seems simpler given the constraints. |
| 85 | 88 |
| 86 const wchar_t kSignature[] = L"CACHE MANIFEST"; | 89 const wchar_t kSignature[] = L"CACHE MANIFEST"; |
| 87 const size_t kSignatureLength = arraysize(kSignature) - 1; | 90 const size_t kSignatureLength = arraysize(kSignature) - 1; |
| 88 const wchar_t kChromiumSignature[] = L"CHROMIUM CACHE MANIFEST"; | 91 const wchar_t kChromiumSignature[] = L"CHROMIUM CACHE MANIFEST"; |
| 89 const size_t kChromiumSignatureLength = arraysize(kChromiumSignature) - 1; | 92 const size_t kChromiumSignatureLength = arraysize(kChromiumSignature) - 1; |
| 90 | 93 |
| 91 DCHECK(manifest.explicit_urls.empty()); | 94 DCHECK(manifest.explicit_urls.empty()); |
| 92 DCHECK(manifest.fallback_namespaces.empty()); | 95 DCHECK(manifest.fallback_namespaces.empty()); |
| 93 DCHECK(manifest.online_whitelist_namespaces.empty()); | 96 DCHECK(manifest.online_whitelist_namespaces.empty()); |
| 94 DCHECK(!manifest.online_whitelist_all); | 97 DCHECK(!manifest.online_whitelist_all); |
| 98 DCHECK(!manifest.did_ignore_intercept_namespaces); |
| 95 | 99 |
| 96 Mode mode = EXPLICIT; | 100 Mode mode = EXPLICIT; |
| 97 | 101 |
| 98 std::wstring data_string; | 102 std::wstring data_string; |
| 99 // TODO(jennb): cannot do UTF8ToWide(data, length, &data_string); | 103 // TODO(jennb): cannot do UTF8ToWide(data, length, &data_string); |
| 100 // until UTF8ToWide uses 0xFFFD Unicode replacement character. | 104 // until UTF8ToWide uses 0xFFFD Unicode replacement character. |
| 101 base::CodepageToWide(std::string(data, length), base::kCodepageUTF8, | 105 base::CodepageToWide(std::string(data, length), base::kCodepageUTF8, |
| 102 base::OnStringConversionError::SUBSTITUTE, &data_string); | 106 base::OnStringConversionError::SUBSTITUTE, &data_string); |
| 103 const wchar_t* p = data_string.c_str(); | 107 const wchar_t* p = data_string.c_str(); |
| 104 const wchar_t* end = p + data_string.length(); | 108 const wchar_t* end = p + data_string.length(); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 // condition is enforced in AppCacheUpdateJob. | 215 // condition is enforced in AppCacheUpdateJob. |
| 212 | 216 |
| 213 if (mode == EXPLICIT) { | 217 if (mode == EXPLICIT) { |
| 214 manifest.explicit_urls.insert(url.spec()); | 218 manifest.explicit_urls.insert(url.spec()); |
| 215 } else { | 219 } else { |
| 216 bool is_pattern = HasPatternMatchingAnnotation(line_p, line_end); | 220 bool is_pattern = HasPatternMatchingAnnotation(line_p, line_end); |
| 217 manifest.online_whitelist_namespaces.push_back( | 221 manifest.online_whitelist_namespaces.push_back( |
| 218 Namespace(NETWORK_NAMESPACE, url, GURL(), is_pattern)); | 222 Namespace(NETWORK_NAMESPACE, url, GURL(), is_pattern)); |
| 219 } | 223 } |
| 220 } else if (mode == INTERCEPT) { | 224 } else if (mode == INTERCEPT) { |
| 225 if (parse_mode != PARSE_MANIFEST_ALLOWING_INTERCEPTS) { |
| 226 manifest.did_ignore_intercept_namespaces = true; |
| 227 continue; |
| 228 } |
| 229 |
| 221 // Lines of the form, | 230 // Lines of the form, |
| 222 // <urlnamespace> <intercept_type> <targeturl> | 231 // <urlnamespace> <intercept_type> <targeturl> |
| 223 const wchar_t* line_p = line.c_str(); | 232 const wchar_t* line_p = line.c_str(); |
| 224 const wchar_t* line_end = line_p + line.length(); | 233 const wchar_t* line_end = line_p + line.length(); |
| 225 | 234 |
| 226 // Look for first whitespace separating the url namespace from | 235 // Look for first whitespace separating the url namespace from |
| 227 // the intercept type. | 236 // the intercept type. |
| 228 while (line_p < line_end && *line_p != '\t' && *line_p != ' ') | 237 while (line_p < line_end && *line_p != '\t' && *line_p != ' ') |
| 229 ++line_p; | 238 ++line_p; |
| 230 | 239 |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 fallback_url, is_pattern)); | 372 fallback_url, is_pattern)); |
| 364 } else { | 373 } else { |
| 365 NOTREACHED(); | 374 NOTREACHED(); |
| 366 } | 375 } |
| 367 } | 376 } |
| 368 | 377 |
| 369 return true; | 378 return true; |
| 370 } | 379 } |
| 371 | 380 |
| 372 } // namespace appcache | 381 } // namespace appcache |
| OLD | NEW |