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

Side by Side Diff: DartApplicationLoader.cpp

Issue 18024004: Bugfix in DOM bindings: canonicalize URLs even if no ApplicationLoader is available (Closed) Base URL: http://src.chromium.org/multivm/trunk/webkit/Source/bindings/dart
Patch Set: Created 7 years, 5 months 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
« DartApplicationLoader.h ('K') | « DartApplicationLoader.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009, Google Inc. 1 // Copyright (c) 2009, 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 79
80 void DartApplicationLoader::reportDartError(Dart_Handle error) 80 void DartApplicationLoader::reportDartError(Dart_Handle error)
81 { 81 {
82 m_scriptHasError = true; 82 m_scriptHasError = true;
83 DartUtilities::reportProblem(m_originDocument, error, m_libraryUrl); 83 DartUtilities::reportProblem(m_originDocument, error, m_libraryUrl);
84 } 84 }
85 85
86 Dart_Handle DartApplicationLoader::libraryTagHandlerCallback(Dart_LibraryTag tag , Dart_Handle library, Dart_Handle urlHandle) 86 Dart_Handle DartApplicationLoader::libraryTagHandlerCallback(Dart_LibraryTag tag , Dart_Handle library, Dart_Handle urlHandle)
87 { 87 {
88 ASSERT(Dart_CurrentIsolate()); 88 ASSERT(Dart_CurrentIsolate());
89 ASSERT(DartDOMData::current()->applicationLoader());
90 return DartDOMData::current()->applicationLoader()->libraryTagHandler(tag, l ibrary, urlHandle);
91 }
92
93 Dart_Handle DartApplicationLoader::libraryTagHandler(Dart_LibraryTag tag, Dart_H andle library, Dart_Handle urlHandle)
94 {
95 ASSERT(Dart_IsLibrary(library)); 89 ASSERT(Dart_IsLibrary(library));
96 90
97 const String url = DartUtilities::toString(urlHandle); 91 const String url = DartUtilities::toString(urlHandle);
98 92
93 if (tag == Dart_kCanonicalizeUrl) {
94 // If a dart application calls spawnUri, the DartVM will call this
95 // libraryTagHandler to canonicalize the url.
96 // DartDOMData::current()->applicationLoader() may be 0 at this point.
97 return DartApplicationLoader::CanonicalizeUrl(library, urlHandle, url);
98 }
99
100 ASSERT(DartDOMData::current()->applicationLoader());
101 return DartDOMData::current()->applicationLoader()->libraryTagHandler(tag, l ibrary, urlHandle, url);
102 }
103
104 Dart_Handle DartApplicationLoader::CanonicalizeUrl(Dart_Handle library, Dart_Han dle urlHandle, String url)
105 {
106 if (url.startsWith("dart:") || url.startsWith("package:"))
107 return urlHandle;
108
99 Dart_Handle libraryURLHandle = Dart_LibraryUrl(library); 109 Dart_Handle libraryURLHandle = Dart_LibraryUrl(library);
100 ASSERT(!Dart_IsError(libraryURLHandle)); 110 ASSERT(!Dart_IsError(libraryURLHandle));
101 String libraryURL = DartUtilities::toString(libraryURLHandle); 111 String libraryURL = DartUtilities::toString(libraryURLHandle);
102 112
103 if (tag == Dart_kCanonicalizeUrl) { 113 bool packageScheme = false;
104 if (url.startsWith("dart:") || url.startsWith("package:"))
105 return urlHandle;
106 114
107 bool packageScheme = false; 115 const char* kPackagePrefix = "package:";
108 if (libraryURL.startsWith("package:")) { 116 const int kPackagePrefixLength = strlen(kPackagePrefix);
109 // KURL have problems concating package:foo/bar (without slashes rig ht after colon)
110 // and relative urls. Therefore pretend to be a standard absolute UR L.
111 packageScheme = true;
112 libraryURL = "http://" + libraryURL.substring(8);
113 }
114 117
115 const KURL canonical = KURL(KURL(KURL(), libraryURL), url); 118 const char* kHttpPrefix = "http://";
116 String result = canonical.string(); 119 const int kHttpPrefixLength = strlen(kHttpPrefix);
117 if (packageScheme) 120
118 result = "package:" + result.substring(7); 121 if (libraryURL.startsWith(kPackagePrefix)) {
119 return DartUtilities::stringToDartString(result); 122 // KURL has problems concating package:foo/bar (without slashes right af ter colon)
123 // and relative urls. Therefore pretend to be a standard absolute URL.
124 packageScheme = true;
125 libraryURL = kHttpPrefix + libraryURL.substring(kPackagePrefixLength);
120 } 126 }
121 127
128 const KURL canonical = KURL(KURL(KURL(), libraryURL), url);
129 String result = canonical.string();
130 if (packageScheme)
131 result = kPackagePrefix + result.substring(kHttpPrefixLength);
132 return DartUtilities::stringToDartString(result);
133 }
134
135 Dart_Handle DartApplicationLoader::libraryTagHandler(Dart_LibraryTag tag, Dart_H andle library, Dart_Handle urlHandle, String url)
136 {
122 ASSERT(url != "dart:html"); 137 ASSERT(url != "dart:html");
123 138
124 // Record the importer. 139 // Record the importer.
125 if (tag == Dart_kImportTag) 140 if (tag == Dart_kImportTag)
126 m_importedLibraries.add(url); 141 m_importedLibraries.add(url);
127 else if (tag == Dart_kSourceTag) 142 else if (tag == Dart_kSourceTag) {
143 Dart_Handle libraryURLHandle = Dart_LibraryUrl(library);
144 ASSERT(!Dart_IsError(libraryURLHandle));
145 String libraryURL = DartUtilities::toString(libraryURLHandle);
146
128 add(m_importersForSource, url, libraryURL); 147 add(m_importersForSource, url, libraryURL);
129 else 148 } else
130 ASSERT_NOT_REACHED(); 149 ASSERT_NOT_REACHED();
131 150
132 loadScriptResource(url); 151 loadScriptResource(url);
133 return Dart_NewBoolean(true); 152 return Dart_NewBoolean(true);
134 } 153 }
135 154
136 void DartApplicationLoader::load(const String& url, const String& source) 155 void DartApplicationLoader::load(const String& url, const String& source)
137 { 156 {
138 DartIsolateScope isolateScope(m_isolate); 157 DartIsolateScope isolateScope(m_isolate);
139 DartApiScope dartApiScope; 158 DartApiScope dartApiScope;
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 // We should never have a self dependence. 402 // We should never have a self dependence.
384 ASSERT(key != value); 403 ASSERT(key != value);
385 UrlMultiMap::iterator iter = map.find(key); 404 UrlMultiMap::iterator iter = map.find(key);
386 if (iter == map.end()) 405 if (iter == map.end())
387 iter = map.add(key, new UrlSet()).iterator; 406 iter = map.add(key, new UrlSet()).iterator;
388 UrlSet* set = iter->value; 407 UrlSet* set = iter->value;
389 set->add(value); 408 set->add(value);
390 } 409 }
391 410
392 } 411 }
OLDNEW
« DartApplicationLoader.h ('K') | « DartApplicationLoader.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698