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(String, dartPrefix, ("dart:")); |
| 1098 DEFINE_STATIC_LOCAL(String, 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 |
| 1112 // and convert back. |
| 1113 DEFINE_STATIC_LOCAL(String, resolvePrefix, ("package://_/")); |
1105 | 1114 |
1106 const char* kPackagePrefix = "package:"; | 1115 libraryURL = resolvePrefix + libraryURL.substring(packagePrefix.length()
); |
1107 const int kPackagePrefixLength = strlen(kPackagePrefix); | 1116 result = KURL(KURL(KURL(), libraryURL), url).string(); |
1108 | 1117 if (result.startsWith(resolvePrefix)) |
1109 const char* kHttpPrefix = "http://"; | 1118 result = packagePrefix + result.substring(resolvePrefix.length()); |
1110 const int kHttpPrefixLength = strlen(kHttpPrefix); | 1119 } else { |
1111 | 1120 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 } | 1121 } |
1118 | 1122 |
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); | 1123 return DartUtilities::stringToDartString(result); |
1124 } | 1124 } |
1125 | 1125 |
1126 void DartUtilities::reportProblem(ExecutionContext* context, const String& error
, int line, int col) | 1126 void DartUtilities::reportProblem(ExecutionContext* context, const String& error
, int line, int col) |
1127 { | 1127 { |
1128 String sourceURL = context->url().string(); | 1128 String sourceURL = context->url().string(); |
1129 // FIXME: Pass in stack trace. | 1129 // FIXME: Pass in stack trace. |
1130 if (context && context->isDocument()) { | 1130 if (context && context->isDocument()) { |
1131 static_cast<Document*>(context)->reportException(ErrorEvent::create(erro
r, sourceURL, line, col, 0), nullptr, NotSharableCrossOrigin); | 1131 static_cast<Document*>(context)->reportException(ErrorEvent::create(erro
r, sourceURL, line, col, 0), nullptr, NotSharableCrossOrigin); |
1132 } | 1132 } |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1208 if (!v) { | 1208 if (!v) { |
1209 return 0; | 1209 return 0; |
1210 } | 1210 } |
1211 ASSERT(valueLen > 0 && static_cast<size_t>(valueLen) > strlen(v)); | 1211 ASSERT(valueLen > 0 && static_cast<size_t>(valueLen) > strlen(v)); |
1212 strncpy(value, v, valueLen); | 1212 strncpy(value, v, valueLen); |
1213 value[valueLen - 1] = '\0'; | 1213 value[valueLen - 1] = '\0'; |
1214 return strlen(value); | 1214 return strlen(value); |
1215 #endif | 1215 #endif |
1216 } | 1216 } |
1217 } | 1217 } |
OLD | NEW |