Index: Source/bindings/dart/DartUtilities.cpp |
diff --git a/Source/bindings/dart/DartUtilities.cpp b/Source/bindings/dart/DartUtilities.cpp |
index dfa636ea1a4c963f4f3a190ae08181a1e34fbc6f..99508573306e3ed8719d254eee05ae6a70c5c86c 100644 |
--- a/Source/bindings/dart/DartUtilities.cpp |
+++ b/Source/bindings/dart/DartUtilities.cpp |
@@ -941,6 +941,46 @@ const uint8_t* DartUtilities::fullSnapshot(Frame* frame) |
return reinterpret_cast<uint8_t*>(snapshotData.data()); |
} |
+Dart_Handle DartUtilities::canonicalizeUrl(Dart_Handle library, Dart_Handle urlHandle, String url) |
+{ |
+ if (url.startsWith("dart:") || url.startsWith("package:")) |
+ return urlHandle; |
+ |
+ Dart_Handle libraryURLHandle = Dart_LibraryUrl(library); |
+ ASSERT(!Dart_IsError(libraryURLHandle)); |
+ String libraryURL = DartUtilities::toString(libraryURLHandle); |
+ |
+ bool packageScheme = false; |
+ |
+ const char* kPackagePrefix = "package:"; |
+ const int kPackagePrefixLength = strlen(kPackagePrefix); |
+ |
+ const char* kHttpPrefix = "http://"; |
+ const int kHttpPrefixLength = strlen(kHttpPrefix); |
+ |
+ if (libraryURL.startsWith(kPackagePrefix)) { |
+ // KURL has problems concating package:foo/bar (without slashes right after colon) |
+ // and relative urls. Therefore pretend to be a standard absolute URL. |
+ packageScheme = true; |
+ libraryURL = kHttpPrefix + libraryURL.substring(kPackagePrefixLength); |
+ } |
+ |
+ const KURL canonical = KURL(KURL(KURL(), libraryURL), url); |
+ String result = canonical.string(); |
+ if (packageScheme) |
+ result = kPackagePrefix + result.substring(kHttpPrefixLength); |
+ return DartUtilities::stringToDartString(result); |
+} |
+ |
+void DartUtilities::reportProblem(ScriptExecutionContext* context, const String& error) |
+{ |
+ String sourceURL = context->url().string(); |
+ // FIXME: Pass in line number and stack trace. |
+ if (context && context->isDocument()) { |
+ static_cast<Document*>(context)->reportException(ErrorEvent::create(error, sourceURL, 0, 0), 0, NotSharableCrossOrigin); |
+ } |
+} |
+ |
void DartUtilities::reportProblem(ScriptExecutionContext* context, Dart_Handle result) |
{ |
// FIXME: provide sourceURL. |