Diff
Modified: trunk/Source/WTF/ChangeLog (120249 => 120250)
--- trunk/Source/WTF/ChangeLog 2012-06-13 21:35:31 UTC (rev 120249)
+++ trunk/Source/WTF/ChangeLog 2012-06-13 21:44:27 UTC (rev 120250)
@@ -1,3 +1,42 @@
+2012-06-13 Benjamin Poulain <[email protected]>
+
+ Implement the simple constructors WTFURL's KURL
+ https://bugs.webkit.org/show_bug.cgi?id=85724
+
+ Reviewed by Adam Barth.
+
+ This patch extends WTFURL with:
+ -support basic debugging using print() methods
+ -parsing in the incomming string character set (8bits or 16bits)
+ -add a function for parsing of relative URL (but no implementation yet)
+
+ * WTF.xcodeproj/project.pbxproj:
+ * wtf/text/WTFString.h:
+ (String):
+ * wtf/url/api/ParsedURL.cpp:
+ (WTF::ParsedURL::ParsedURL):
+ (WTF):
+ (WTF::ParsedURL::hasFragment): Add this method to query the framgent availability without
+ allocating a new String.
+ (WTF::ParsedURL::withoutFragment): This method is added to implement KURL::removeFragmentIdentifier() and
+ the parsing of empty relative URL (where we return the base without fragment).
+ (WTF::ParsedURL::print):
+ * wtf/url/api/ParsedURL.h:
+ (ParsedURL):
+ (WTF::ParsedURL::spec):
+ * wtf/url/api/URLString.h:
+ (URLString):
+ * wtf/url/src/URLParser.h:
+ (WTF):
+ (URLParser):
+ (WTF::URLParser::parseURLWithBase):
+ * wtf/url/src/URLSegments.cpp:
+ (WTF::URLSegments::length):
+ (WTF::URLSegments::charactersBefore):
+ * wtf/url/src/URLSegments.h:
+ (URLSegments):
+ Change the boolean argument includeDelimiter in favor of an enum to improve readability.
+
2012-06-13 Filip Pizlo <[email protected]>
DFG should be able to set watchpoints on global variables
Modified: trunk/Source/WTF/WTF.xcodeproj/project.pbxproj (120249 => 120250)
--- trunk/Source/WTF/WTF.xcodeproj/project.pbxproj 2012-06-13 21:35:31 UTC (rev 120249)
+++ trunk/Source/WTF/WTF.xcodeproj/project.pbxproj 2012-06-13 21:44:27 UTC (rev 120250)
@@ -10,6 +10,7 @@
143F611F1565F0F900DB514A /* RAMSize.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 143F611D1565F0F900DB514A /* RAMSize.cpp */; };
143F61201565F0F900DB514A /* RAMSize.h in Headers */ = {isa = PBXBuildFile; fileRef = 143F611E1565F0F900DB514A /* RAMSize.h */; settings = {ATTRIBUTES = (Private, ); }; };
0FD81AC5154FB22E00983E72 /* FastBitVector.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FD81AC4154FB22E00983E72 /* FastBitVector.h */; settings = {ATTRIBUTES = (); }; };
+ 4330F38F15745B0500AAFA8F /* URLString.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4330F38E15745B0500AAFA8F /* URLString.cpp */; };
4F0321BC156AA8D1006EBAF6 /* BitArray.h in Headers */ = {isa = PBXBuildFile; fileRef = 4F0321BB156AA8D1006EBAF6 /* BitArray.h */; };
A876DBD8151816E500DADB95 /* Platform.h in Headers */ = {isa = PBXBuildFile; fileRef = A876DBD7151816E500DADB95 /* Platform.h */; };
A8A4737F151A825B004123FF /* Alignment.h in Headers */ = {isa = PBXBuildFile; fileRef = A8A47254151A825A004123FF /* Alignment.h */; };
@@ -247,6 +248,7 @@
143F611D1565F0F900DB514A /* RAMSize.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RAMSize.cpp; sourceTree = "<group>"; };
143F611E1565F0F900DB514A /* RAMSize.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RAMSize.h; sourceTree = "<group>"; };
0FD81AC4154FB22E00983E72 /* FastBitVector.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FastBitVector.h; sourceTree = "<group>"; };
+ 4330F38E15745B0500AAFA8F /* URLString.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = URLString.cpp; sourceTree = "<group>"; };
4F0321BB156AA8D1006EBAF6 /* BitArray.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BitArray.h; sourceTree = "<group>"; };
5D247B6214689B8600E78B76 /* libWTF.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libWTF.a; sourceTree = BUILT_PRODUCTS_DIR; };
5D247B6E14689C4700E78B76 /* Base.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Base.xcconfig; sourceTree = "<group>"; };
@@ -832,6 +834,7 @@
children = (
A8A47360151A825B004123FF /* ParsedURL.cpp */,
A8A47361151A825B004123FF /* ParsedURL.h */,
+ 4330F38E15745B0500AAFA8F /* URLString.cpp */,
A8A47362151A825B004123FF /* URLString.h */,
);
path = api;
@@ -1169,6 +1172,7 @@
A8A4743C151A825B004123FF /* StringBuilder.cpp in Sources */,
A8A47440151A825B004123FF /* StringImpl.cpp in Sources */,
A8A47443151A825B004123FF /* StringStatics.cpp in Sources */,
+ 4330F38F15745B0500AAFA8F /* URLString.cpp in Sources */,
A8A47445151A825B004123FF /* WTFString.cpp in Sources */,
A8A47448151A825B004123FF /* ThreadIdentifierDataPthreads.cpp in Sources */,
A8A4744A151A825B004123FF /* Threading.cpp in Sources */,
Modified: trunk/Source/WTF/wtf/text/WTFString.h (120249 => 120250)
--- trunk/Source/WTF/wtf/text/WTFString.h 2012-06-13 21:35:31 UTC (rev 120249)
+++ trunk/Source/WTF/wtf/text/WTFString.h 2012-06-13 21:44:27 UTC (rev 120250)
@@ -415,7 +415,7 @@
bool isHashTableDeletedValue() const { return m_impl.isHashTableDeletedValue(); }
#ifndef NDEBUG
- void show() const;
+ WTF_EXPORT_PRIVATE void show() const;
#endif
private:
Modified: trunk/Source/WTF/wtf/url/api/ParsedURL.cpp (120249 => 120250)
--- trunk/Source/WTF/wtf/url/api/ParsedURL.cpp 2012-06-13 21:35:31 UTC (rev 120249)
+++ trunk/Source/WTF/wtf/url/api/ParsedURL.cpp 2012-06-13 21:44:27 UTC (rev 120250)
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2010 Google, Inc. All Rights Reserved.
+ * Copyright (C) 2012 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -28,20 +29,65 @@
#if USE(WTFURL)
-#include "URLComponent.h"
-#include "URLParser.h"
+#include <wtf/DataLog.h>
+#include <wtf/RawURLBuffer.h>
+#include <wtf/URLComponent.h>
+#include <wtf/URLParser.h>
namespace WTF {
ParsedURL::ParsedURL(const String& urlString)
- : m_spec(urlString)
{
- // FIXME: Handle non-standard URLs.
- if (urlString.isEmpty())
+ if (urlString.isEmpty()) {
+ m_spec = URLString();
return;
- URLParser<UChar>::parseStandardURL(urlString.characters(), urlString.length(), m_segments);
+ }
+
+ // FIXME: handle invalid urlString.
+ m_spec = URLString(urlString);
+ if (urlString.is8Bit())
+ URLParser<LChar>::parseStandardURL(urlString.characters8(), urlString.length(), m_segments);
+ else
+ URLParser<UChar>::parseStandardURL(urlString.characters16(), urlString.length(), m_segments);
}
+ParsedURL::ParsedURL(const ParsedURL& base, const String& relative)
+{
+ if (!base.isValid())
+ return;
+
+ if (relative.isEmpty()) {
+ *this = base.withoutFragment();
+ return;
+ }
+
+ // FIXME: handle invalid URLs.
+ const String& baseString = base.m_spec.string();
+ RawURLBuffer<char, 1024> outputBuffer;
+ if (relative.is8Bit()) {
+ if (baseString.is8Bit()) {
+ URLParser<LChar, LChar>::parseURLWithBase(relative.characters8(), relative.length(),
+ baseString.characters8(), baseString.length(), base.m_segments,
+ outputBuffer, m_segments);
+ } else {
+ URLParser<LChar, UChar>::parseURLWithBase(relative.characters8(), relative.length(),
+ baseString.characters16(), baseString.length(), base.m_segments,
+ outputBuffer, m_segments);
+ }
+ } else {
+ if (baseString.is8Bit()) {
+ URLParser<UChar, LChar>::parseURLWithBase(relative.characters16(), relative.length(),
+ baseString.characters8(), baseString.length(), base.m_segments,
+ outputBuffer, m_segments);
+ } else {
+ URLParser<UChar, UChar>::parseURLWithBase(relative.characters16(), relative.length(),
+ baseString.characters16(), baseString.length(), base.m_segments,
+ outputBuffer, m_segments);
+ }
+ }
+ m_spec = URLString(String(outputBuffer.data(), outputBuffer.length()));
+}
+
ParsedURL ParsedURL::isolatedCopy() const
{
ParsedURL copy;
@@ -85,11 +131,31 @@
return segment(m_segments.query);
}
+bool ParsedURL::hasFragment() const
+{
+ return m_segments.fragment.isValid();
+}
+
String ParsedURL::fragment() const
{
return segment(m_segments.fragment);
}
+ParsedURL ParsedURL::withoutFragment() const
+{
+ if (!hasFragment())
+ return *this;
+
+ ParsedURL newURL;
+
+ int charactersBeforeFragemnt = m_segments.charactersBefore(URLSegments::Fragment, URLSegments::DelimiterExcluded);
+ newURL.m_spec = URLString(m_spec.string().substringSharingImpl(0, charactersBeforeFragemnt));
+
+ newURL.m_segments = m_segments;
+ newURL.m_segments.fragment = URLComponent();
+ return newURL;
+}
+
String ParsedURL::baseAsString() const
{
// FIXME: Add WTFURL Implementation.
@@ -108,6 +174,36 @@
return segment;
}
+#ifndef NDEBUG
+
+#define SHOW_COMPONENT(parsedURL, componentName) \
+ if (!parsedURL->componentName().isNull()) { \
+ dataLog(" " #componentName " = "); \
+ parsedURL->componentName().show(); \
+ }
+
+void ParsedURL::print() const
+{
+ if (!isValid()) {
+ dataLog("Invalid ParsedURL.\n");
+ return;
+ }
+
+ dataLog("Valid ParsedURL with:\n");
+ dataLog(" m_spec = ");
+ m_spec.print();
+
+ SHOW_COMPONENT(this, scheme);
+ SHOW_COMPONENT(this, username);
+ SHOW_COMPONENT(this, password);
+ SHOW_COMPONENT(this, host);
+ SHOW_COMPONENT(this, port);
+ SHOW_COMPONENT(this, path);
+ SHOW_COMPONENT(this, query);
+ SHOW_COMPONENT(this, fragment);
}
+#endif
+}
+
#endif // USE(WTFURL)
Modified: trunk/Source/WTF/wtf/url/api/ParsedURL.h (120249 => 120250)
--- trunk/Source/WTF/wtf/url/api/ParsedURL.h 2012-06-13 21:35:31 UTC (rev 120249)
+++ trunk/Source/WTF/wtf/url/api/ParsedURL.h 2012-06-13 21:44:27 UTC (rev 120250)
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2010 Google, Inc. All Rights Reserved.
+ * Copyright (C) 2012 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -38,9 +39,9 @@
// ParsedURL represents a valid URL decomposed by components.
class ParsedURL {
public:
- // FIXME: Add a method for parsing non-canonicalized URLs.
ParsedURL() { };
WTF_EXPORT_PRIVATE explicit ParsedURL(const String&);
+ WTF_EXPORT_PRIVATE explicit ParsedURL(const ParsedURL& base, const String& relative);
WTF_EXPORT_PRIVATE ParsedURL isolatedCopy() const;
@@ -54,12 +55,19 @@
WTF_EXPORT_PRIVATE String port() const;
WTF_EXPORT_PRIVATE String path() const;
WTF_EXPORT_PRIVATE String query() const;
+
+ WTF_EXPORT_PRIVATE bool hasFragment() const;
WTF_EXPORT_PRIVATE String fragment() const;
+ WTF_EXPORT_PRIVATE ParsedURL withoutFragment() const;
WTF_EXPORT_PRIVATE String baseAsString() const;
- URLString spec() { return m_spec; }
+ const URLString& spec() { return m_spec; }
+#ifndef NDEBUG
+ WTF_EXPORT_PRIVATE void print() const;
+#endif
+
private:
inline String segment(const URLComponent&) const;
Added: trunk/Source/WTF/wtf/url/api/URLString.cpp (0 => 120250)
--- trunk/Source/WTF/wtf/url/api/URLString.cpp (rev 0)
+++ trunk/Source/WTF/wtf/url/api/URLString.cpp 2012-06-13 21:44:27 UTC (rev 120250)
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2012 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "URLString.h"
+
+#if USE(WTFURL)
+
+namespace WTF {
+
+#ifndef NDEBUG
+void URLString::print() const
+{
+ m_string.show();
+}
+#endif // ndef NDEBUG
+
+}
+
+#endif // USE(WTFURL)
Modified: trunk/Source/WTF/wtf/url/api/URLString.h (120249 => 120250)
--- trunk/Source/WTF/wtf/url/api/URLString.h 2012-06-13 21:35:31 UTC (rev 120249)
+++ trunk/Source/WTF/wtf/url/api/URLString.h 2012-06-13 21:44:27 UTC (rev 120250)
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2010 Google, Inc. All Rights Reserved.
+ * Copyright (C) 2012 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -39,6 +40,10 @@
const String& string() const { return m_string;}
+#ifndef NDEBUG
+ WTF_EXPORT_PRIVATE void print() const;
+#endif
+
private:
friend class ParsedURL;
Modified: trunk/Source/WTF/wtf/url/src/URLParser.h (120249 => 120250)
--- trunk/Source/WTF/wtf/url/src/URLParser.h 2012-06-13 21:35:31 UTC (rev 120249)
+++ trunk/Source/WTF/wtf/url/src/URLParser.h 2012-06-13 21:44:27 UTC (rev 120250)
@@ -1,6 +1,7 @@
/* Based on nsURLParsers.cc from Mozilla
* -------------------------------------
* Copyright (C) 1998 Netscape Communications Corporation.
+ * Copyright (C) 2012 Apple Inc. All rights reserved.
*
* Other contributors:
* Darin Fisher (original author)
@@ -39,12 +40,13 @@
#include "URLComponent.h"
#include "URLSegments.h"
+#include "UnusedParam.h"
#if USE(WTFURL)
namespace WTF {
-template<typename CharacterType>
+template<typename CharacterType, typename BaseCharacterType = CharacterType>
class URLParser {
public:
enum SpecialPort {
@@ -168,6 +170,21 @@
parseAfterScheme(spec, specLength, afterScheme, parsed);
}
+ // The main parsing function for (may be) relative URLs.
+ static void parseURLWithBase(const CharacterType* spec, int specLength,
+ const BaseCharacterType* baseStringSpec, int baseStringSpecLength, const URLSegments& baseStringSegments,
+ URLBuffer<char>&outputBuffer, URLSegments& parsed)
+ {
+ UNUSED_PARAM(baseStringSpec);
+ UNUSED_PARAM(baseStringSpecLength);
+ UNUSED_PARAM(baseStringSegments);
+ UNUSED_PARAM(spec);
+ UNUSED_PARAM(specLength);
+ UNUSED_PARAM(outputBuffer);
+ UNUSED_PARAM(parsed);
+ // FIXME: To implement.
+ }
+
static void parsePath(const CharacterType* spec, const URLComponent& path, URLComponent& filepath, URLComponent& query, URLComponent& fragment)
{
// path = [/]<segment1>/<segment2>/<...>/<segmentN>;<param>?<query>#<fragment>
Modified: trunk/Source/WTF/wtf/url/src/URLSegments.cpp (120249 => 120250)
--- trunk/Source/WTF/wtf/url/src/URLSegments.cpp 2012-06-13 21:35:31 UTC (rev 120249)
+++ trunk/Source/WTF/wtf/url/src/URLSegments.cpp 2012-06-13 21:44:27 UTC (rev 120250)
@@ -1,6 +1,7 @@
/* Based on nsURLParsers.cc from Mozilla
* -------------------------------------
* Copyright (C) 1998 Netscape Communications Corporation.
+ * Copyright (C) 2012 Apple Inc. All rights reserved.
*
* Other contributors:
* Darin Fisher (original author)
@@ -45,10 +46,10 @@
{
if (fragment.isValid())
return fragment.end();
- return charactersBefore(Fragment, false);
+ return charactersBefore(Fragment, DelimiterExcluded);
}
-int URLSegments::charactersBefore(ComponentType type, bool includeDelimiter) const
+int URLSegments::charactersBefore(ComponentType type, DelimiterInclusion includeDelimiter) const
{
if (type == Scheme)
return scheme.begin();
@@ -76,7 +77,7 @@
}
if (port.isValid()) {
- if (type < Port || (type == Port && includeDelimiter))
+ if (type < Port || (type == Port && includeDelimiter == DelimiterIncluded))
return port.begin() - 1; // Back over delimiter.
if (type == Port)
return port.begin(); // Don't want delimiter counted.
@@ -90,7 +91,7 @@
}
if (query.isValid()) {
- if (type < Query || (type == Query && includeDelimiter))
+ if (type < Query || (type == Query && includeDelimiter == DelimiterIncluded))
return query.begin() - 1; // Back over delimiter.
if (type == Query)
return query.begin(); // Don't want delimiter counted.
@@ -98,7 +99,7 @@
}
if (fragment.isValid()) {
- if (type == Fragment && !includeDelimiter)
+ if (type == Fragment && includeDelimiter == DelimiterExcluded)
return fragment.begin(); // Back over delimiter.
// When there is a fragment and we get here, the component we wanted was before
Modified: trunk/Source/WTF/wtf/url/src/URLSegments.h (120249 => 120250)
--- trunk/Source/WTF/wtf/url/src/URLSegments.h 2012-06-13 21:35:31 UTC (rev 120249)
+++ trunk/Source/WTF/wtf/url/src/URLSegments.h 2012-06-13 21:44:27 UTC (rev 120250)
@@ -1,4 +1,5 @@
// Copyright 2007, Google Inc. All rights reserved.
+// Copyright 2012 Apple Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
@@ -51,6 +52,10 @@
Query,
Fragment,
};
+ enum DelimiterInclusion {
+ DelimiterExcluded,
+ DelimiterIncluded
+ };
URLSegments() { }
@@ -88,7 +93,7 @@
// *Query: 14 15 <-
// *Fragment: 20 20
//
- int charactersBefore(ComponentType, bool includeDelimiter) const;
+ int charactersBefore(ComponentType, DelimiterInclusion) const;
// Each component excludes the related delimiters and has a length of -1
// if that component is absent but 0 if the component exists but is empty.
Modified: trunk/Source/WebCore/ChangeLog (120249 => 120250)
--- trunk/Source/WebCore/ChangeLog 2012-06-13 21:35:31 UTC (rev 120249)
+++ trunk/Source/WebCore/ChangeLog 2012-06-13 21:44:27 UTC (rev 120250)
@@ -1,3 +1,36 @@
+2012-06-13 Benjamin Poulain <[email protected]>
+
+ Implement the simple constructors WTFURL's KURL
+ https://bugs.webkit.org/show_bug.cgi?id=85724
+
+ Reviewed by Adam Barth.
+
+ This patch implement the correct initialization of KURL from an absolute URL.
+ The URL correctness is also relaxed in order to have KURLWTFURL works similarily to KURL.
+
+ * platform/KURLWTFURL.cpp:
+ (WebCore::KURL::KURL):
+ (WebCore::KURL::isValid):
+ (WebCore::KURL::string):
+ (WebCore::KURL::protocol):
+ (WebCore::KURL::host):
+ (WebCore::KURL::port): Fix a bug where invalidPortNumber was returned if no port was defined.
+ (WebCore::KURL::hasFragmentIdentifier):
+ (WebCore::KURL::fragmentIdentifier):
+ (WebCore::KURL::protocolIs):
+ (WebCore::KURL::removeFragmentIdentifier):
+ (WebCore):
+ (WebCore::KURL::print):
+ * platform/cf/KURLCFNet.cpp:
+ (WebCore::KURL::KURL):
+ (WebCore::KURL::createCFURL):
+ (WebCore):
+ * platform/mac/KURLMac.mm:
+ (WebCore::KURL::KURL):
+ (WebCore::KURL::createCFURL):
+ (WebCore):
+ Use the code of KURL to make the conversion from WTFURL to NSURL.
+
2012-06-12 Vincent Scheib <[email protected]>
Remove duplicate webkitpointerlockchange events when unlocking.
Modified: trunk/Source/WebCore/platform/KURLWTFURL.cpp (120249 => 120250)
--- trunk/Source/WebCore/platform/KURLWTFURL.cpp 2012-06-13 21:35:31 UTC (rev 120249)
+++ trunk/Source/WebCore/platform/KURLWTFURL.cpp 2012-06-13 21:44:27 UTC (rev 120250)
@@ -26,6 +26,8 @@
#include "config.h"
#include "KURL.h"
+#include <wtf/DataLog.h>
+
#if USE(WTFURL)
using namespace WTF;
@@ -50,12 +52,23 @@
: m_urlImpl(adoptRef(new KURLWTFURLImpl()))
{
m_urlImpl->m_parsedURL = ParsedURL(urlString);
- ASSERT(m_urlImpl->m_parsedURL.isValid());
+
+ // FIXME: Frame::init() actually create empty URL, investigate why not just null URL.
+ // ASSERT(m_urlImpl->m_parsedURL.isValid());
}
-KURL::KURL(const KURL&, const String&)
+KURL::KURL(const KURL& baseURL, const String& relative)
+ : m_urlImpl(adoptRef(new KURLWTFURLImpl()))
{
- // FIXME: Add WTFURL Implementation.
+ // FIXME: the case with a null baseURL is common. We should have a separate constructor in KURL.
+ // FIXME: the case of an empty Base is useless, we should get rid of empty URLs.
+ if (baseURL.isEmpty())
+ m_urlImpl->m_parsedURL = ParsedURL(relative);
+ else
+ m_urlImpl->m_parsedURL = ParsedURL(baseURL.m_urlImpl->m_parsedURL, relative);
+
+ if (!m_urlImpl->m_parsedURL.isValid())
+ m_urlImpl->m_invalidUrlString = relative;
}
KURL::KURL(const KURL&, const String&, const TextEncoding&)
@@ -92,7 +105,7 @@
bool isParsedURLValid = m_urlImpl->m_parsedURL.isValid();
#ifndef NDEBUG
if (isParsedURLValid)
- ASSERT_WITH_MESSAGE(m_urlImpl->m_invalidUrlString.isNull(), "A valid URL should never have a valid invalidUrlString.");
+ ASSERT_WITH_MESSAGE(m_urlImpl->m_invalidUrlString.isNull(), "A valid URL must have a null invalidUrlString.");
#endif
return isParsedURLValid;
}
@@ -104,24 +117,27 @@
return nullString;
}
- if (!m_urlImpl->m_invalidUrlString.isNull()) {
- ASSERT(!isValid());
- return m_urlImpl->m_invalidUrlString;
- }
+ if (isValid())
+ return m_urlImpl->m_parsedURL.spec().string();
- ASSERT(isValid());
- return m_urlImpl->m_parsedURL.spec().string();
+ return m_urlImpl->m_invalidUrlString;
}
String KURL::protocol() const
{
- ASSERT(isValid());
+ // Skip the ASSERT for now, SubframeLoader::requestFrame() does not check the validity of URLs.
+ // ASSERT(isValid());
+ if (!isValid())
+ return String();
return m_urlImpl->m_parsedURL.scheme();
}
String KURL::host() const
{
- ASSERT(isValid());
+ // Skip the ASSERT for now, HTMLAnchorElement::parseAttribute() does not check the validity of URLs.
+ // ASSERT(isValid());
+ if (!isValid())
+ return String();
return m_urlImpl->m_parsedURL.host();
}
@@ -136,6 +152,9 @@
ASSERT(isValid());
String portString = m_urlImpl->m_parsedURL.port();
+ if (portString.isNull())
+ return 0;
+
bool ok = false;
unsigned portValue = portString.toUIntStrict(&ok);
@@ -190,13 +209,20 @@
bool KURL::hasFragmentIdentifier() const
{
- ASSERT(isValid());
- return !fragmentIdentifier().isNull();
+ // Skip the ASSERT for now, ScriptElement::requestScript() create requests for invalid URLs.
+ // ASSERT(isValid());
+ if (!isValid())
+ return false;
+
+ return m_urlImpl->m_parsedURL.hasFragment();
}
String KURL::fragmentIdentifier() const
{
- ASSERT(isValid());
+ // Skip the ASSERT for now, ScriptElement::requestScript() create requests for invalid URLs.
+ // ASSERT(isValid());
+ if (!isValid())
+ return String();
return m_urlImpl->m_parsedURL.fragment();
}
@@ -215,7 +241,8 @@
bool KURL::protocolIs(const char* testProtocol) const
{
- ASSERT(isValid());
+ if (!isValid())
+ return false;
return WebCore::protocolIs(protocol(), testProtocol);
}
@@ -287,8 +314,11 @@
void KURL::removeFragmentIdentifier()
{
+ if (!hasFragmentIdentifier())
+ return;
+
detach(m_urlImpl);
- // FIXME: Add WTFURL Implementation.
+ m_urlImpl->m_parsedURL = m_urlImpl->m_parsedURL.withoutFragment();
}
unsigned KURL::hostStart() const
@@ -321,6 +351,24 @@
return 0;
}
+#ifndef NDEBUG
+void KURL::print() const
+{
+ if (isValid())
+ m_urlImpl->m_parsedURL.print();
+ else {
+ if (isNull())
+ dataLog("Null KURL");
+ else if (isEmpty())
+ dataLog("Empty KURL");
+ else {
+ dataLog("Invalid KURL from string =");
+ m_urlImpl->m_invalidUrlString.show();
+ }
+ }
+}
+#endif
+
void KURL::invalidate()
{
m_urlImpl = nullptr;
Modified: trunk/Source/WebCore/platform/cf/KURLCFNet.cpp (120249 => 120250)
--- trunk/Source/WebCore/platform/cf/KURLCFNet.cpp 2012-06-13 21:35:31 UTC (rev 120249)
+++ trunk/Source/WebCore/platform/cf/KURLCFNet.cpp 2012-06-13 21:44:27 UTC (rev 120250)
@@ -33,8 +33,6 @@
namespace WebCore {
-#if !USE(WTFURL)
-
typedef Vector<char, 512> CharBuffer;
CFURLRef createCFURLFromBuffer(const CharBuffer&);
@@ -42,7 +40,7 @@
KURL::KURL(CFURLRef url)
{
if (!url) {
- parse(0);
+ invalidate();
return;
}
@@ -51,7 +49,13 @@
char* bytes = &buffer[0];
CFURLGetBytes(url, reinterpret_cast<UInt8*>(bytes), bytesLength);
bytes[bytesLength] = '\0';
+#if !USE(WTFURL)
parse(bytes);
+#else
+ // FIXME: Add WTFURL Implementation.
+ UNUSED_PARAM(url);
+ invalidate();
+#endif // USE(WTFURL)
}
CFURLRef createCFURLFromBuffer(const CharBuffer& buffer)
@@ -69,16 +73,21 @@
#if !PLATFORM(MAC) && !(PLATFORM(QT) && USE(QTKIT))
CFURLRef KURL::createCFURL() const
{
+#if !USE(WTFURL)
// FIXME: What should this return for invalid URLs?
// Currently it throws away the high bytes of the characters in the string in that case,
// which is clearly wrong.
CharBuffer buffer;
copyToBuffer(buffer);
return createCFURLFromBuffer(buffer);
+#else // USE(WTFURL)
+ // FIXME: Add WTFURL Implementation.
+ return 0;
+#endif
}
#endif
-#if !(PLATFORM(QT) && USE(QTKIT))
+#if !USE(WTFURL) && !(PLATFORM(QT) && USE(QTKIT))
String KURL::fileSystemPath() const
{
RetainPtr<CFURLRef> cfURL(AdoptCF, createCFURL());
@@ -94,20 +103,4 @@
}
#endif
-#else // USE(WTFURL)
-
-KURL::KURL(CFURLRef)
-{
- // FIXME: Add WTFURL Implementation.
- invalidate();
}
-
-CFURLRef KURL::createCFURL() const
-{
- // FIXME: Add WTFURL Implementation.
- return 0;
-}
-
-#endif // USE(WTFURL)
-
-}
Modified: trunk/Source/WebCore/platform/mac/KURLMac.mm (120249 => 120250)
--- trunk/Source/WebCore/platform/mac/KURLMac.mm 2012-06-13 21:35:31 UTC (rev 120249)
+++ trunk/Source/WebCore/platform/mac/KURLMac.mm 2012-06-13 21:44:27 UTC (rev 120250)
@@ -29,17 +29,17 @@
#import "FoundationExtras.h"
#import <CoreFoundation/CFURL.h>
+using namespace WTF;
+
namespace WebCore {
-#if !USE(WTFURL)
-
typedef Vector<char, 512> CharBuffer;
extern CFURLRef createCFURLFromBuffer(const CharBuffer& buffer);
KURL::KURL(NSURL *url)
{
if (!url) {
- parse(0);
+ invalidate();
return;
}
@@ -48,7 +48,15 @@
char* bytes = &buffer[0];
CFURLGetBytes(reinterpret_cast<CFURLRef>(url), reinterpret_cast<UInt8*>(bytes), bytesLength);
bytes[bytesLength] = '\0';
+#if !USE(WTFURL)
parse(bytes);
+#else
+ m_urlImpl = adoptRef(new KURLWTFURLImpl());
+ String urlString(bytes, bytesLength);
+ m_urlImpl->m_parsedURL = ParsedURL(urlString);
+ if (!m_urlImpl->m_parsedURL.isValid())
+ m_urlImpl->m_invalidUrlString = urlString;
+#endif // USE(WTFURL)
}
KURL::operator NSURL *() const
@@ -67,24 +75,18 @@
return reinterpret_cast<CFURLRef>([[NSURL alloc] initWithString:@""]);
CharBuffer buffer;
+#if !USE(WTFURL)
copyToBuffer(buffer);
+#else
+ String urlString = string();
+ buffer.resize(urlString.length());
+ size_t length = urlString.length();
+ for (size_t i = 0; i < length; i++)
+ buffer[i] = static_cast<char>(urlString[i]);
+#endif
return createCFURLFromBuffer(buffer);
}
-#else
-KURL::KURL(NSURL *)
-{
- // FIXME: Add WTFURL Implementation.
- invalidate();
-}
-KURL::operator NSURL *() const
-{
- // FIXME: Add WTFURL Implementation.
- return nil;
}
-
-#endif
-
-}