OLD | NEW |
---|---|
1 // Copyright 2011, Google Inc. | 1 // Copyright 2011, Google Inc. |
2 // All rights reserved. | 2 // 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 1076 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1087 { | 1087 { |
1088 static const uint8_t snapshotBuffer[] = { | 1088 static const uint8_t snapshotBuffer[] = { |
1089 // DartSnapshot.bytes is generated by build system. | 1089 // DartSnapshot.bytes is generated by build system. |
1090 #include "DartSnapshot.bytes" | 1090 #include "DartSnapshot.bytes" |
1091 }; | 1091 }; |
1092 return snapshotBuffer; | 1092 return snapshotBuffer; |
1093 } | 1093 } |
1094 | 1094 |
1095 Dart_Handle DartUtilities::canonicalizeUrl(Dart_Handle library, Dart_Handle urlH andle, String url) | 1095 Dart_Handle DartUtilities::canonicalizeUrl(Dart_Handle library, Dart_Handle urlH andle, String url) |
1096 { | 1096 { |
1097 if (url.startsWith("dart:") || url.startsWith("package:")) | 1097 DEFINE_STATIC_LOCAL(const char*, dartPrefix, ("dart:")); |
1098 DEFINE_STATIC_LOCAL(const char*, packagePrefix, ("package:")); | |
1099 | |
1100 if (url.startsWith(dartPrefix) || url.startsWith(packagePrefix)) | |
1101 // Not a relative URL. | |
1098 return urlHandle; | 1102 return urlHandle; |
1099 | 1103 |
1100 Dart_Handle libraryURLHandle = Dart_LibraryUrl(library); | 1104 Dart_Handle libraryURLHandle = Dart_LibraryUrl(library); |
1101 ASSERT(!Dart_IsError(libraryURLHandle)); | 1105 ASSERT(!Dart_IsError(libraryURLHandle)); |
1102 String libraryURL = DartUtilities::toString(libraryURLHandle); | 1106 String libraryURL = DartUtilities::toString(libraryURLHandle); |
1103 | 1107 |
1104 bool packageScheme = false; | 1108 String result; |
1109 if (libraryURL.startsWith(packagePrefix) && !libraryURL.startsWith("package: //")) { | |
1110 // KURL expects a URL with an authority. If the library URL is | |
1111 // "package:<path>", we convert to "package://_/<path>" for resolution a nd | |
Jacob
2014/06/23 16:42:27
nit: keep commend at 80 chars.
vsm
2014/06/24 07:16:28
Done.
| |
1112 // convert back. | |
ahe
2014/06/23 16:05:49
Interesting approach. As far as I can tell, Chrome
| |
1113 DEFINE_STATIC_LOCAL(const int, packagePrefixLength, (strlen(packagePrefi x))); | |
1114 DEFINE_STATIC_LOCAL(const char*, resolvePrefix, ("package://_/")); | |
1115 DEFINE_STATIC_LOCAL(const int, resolvePrefixLength, (strlen(resolvePrefi x))); | |
Jacob
2014/06/23 16:42:27
instead of defining static locals for the string a
vsm
2014/06/24 07:16:28
Done.
| |
1105 | 1116 |
1106 const char* kPackagePrefix = "package:"; | 1117 libraryURL = resolvePrefix + libraryURL.substring(packagePrefixLength); |
1107 const int kPackagePrefixLength = strlen(kPackagePrefix); | 1118 result = KURL(KURL(KURL(), libraryURL), url).string(); |
1108 | 1119 if (result.startsWith(resolvePrefix)) |
1109 const char* kHttpPrefix = "http://"; | 1120 result = packagePrefix + result.substring(resolvePrefixLength); |
1110 const int kHttpPrefixLength = strlen(kHttpPrefix); | 1121 } else { |
1111 | 1122 result = KURL(KURL(KURL(), libraryURL), url).string(); |
1112 if (libraryURL.startsWith(kPackagePrefix)) { | |
1113 // KURL has problems concating package:foo/bar (without slashes right af ter colon) | |
1114 // and relative urls. Therefore pretend to be a standard absolute URL. | |
1115 packageScheme = true; | |
1116 libraryURL = kHttpPrefix + libraryURL.substring(kPackagePrefixLength); | |
1117 } | 1123 } |
1118 | 1124 |
1119 const KURL canonical = KURL(KURL(KURL(), libraryURL), url); | |
1120 String result = canonical.string(); | |
1121 if (packageScheme) | |
1122 result = kPackagePrefix + result.substring(kHttpPrefixLength); | |
1123 return DartUtilities::stringToDartString(result); | 1125 return DartUtilities::stringToDartString(result); |
1124 } | 1126 } |
1125 | 1127 |
1126 void DartUtilities::reportProblem(ExecutionContext* context, const String& error , int line, int col) | 1128 void DartUtilities::reportProblem(ExecutionContext* context, const String& error , int line, int col) |
1127 { | 1129 { |
1128 String sourceURL = context->url().string(); | 1130 String sourceURL = context->url().string(); |
1129 // FIXME: Pass in stack trace. | 1131 // FIXME: Pass in stack trace. |
1130 if (context && context->isDocument()) { | 1132 if (context && context->isDocument()) { |
1131 static_cast<Document*>(context)->reportException(ErrorEvent::create(erro r, sourceURL, line, col, 0), nullptr, NotSharableCrossOrigin); | 1133 static_cast<Document*>(context)->reportException(ErrorEvent::create(erro r, sourceURL, line, col, 0), nullptr, NotSharableCrossOrigin); |
1132 } | 1134 } |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1208 if (!v) { | 1210 if (!v) { |
1209 return 0; | 1211 return 0; |
1210 } | 1212 } |
1211 ASSERT(valueLen > 0 && static_cast<size_t>(valueLen) > strlen(v)); | 1213 ASSERT(valueLen > 0 && static_cast<size_t>(valueLen) > strlen(v)); |
1212 strncpy(value, v, valueLen); | 1214 strncpy(value, v, valueLen); |
1213 value[valueLen - 1] = '\0'; | 1215 value[valueLen - 1] = '\0'; |
1214 return strlen(value); | 1216 return strlen(value); |
1215 #endif | 1217 #endif |
1216 } | 1218 } |
1217 } | 1219 } |
OLD | NEW |