Need WebKit2 API to create a SecurityOrigin from protocol, host, and port
authorjberlin@webkit.org <jberlin@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 24 Dec 2010 01:16:19 +0000 (01:16 +0000)
committerjberlin@webkit.org <jberlin@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 24 Dec 2010 01:16:19 +0000 (01:16 +0000)
https://bugs.webkit.org/show_bug.cgi?id=51563

Reviewed by Sam Weinig.

WebCore:

Add SecurityOrigin::create(const String& protocol, const String& host, int port).

* WebCore.exp.in:
Export the symbols for WebCore::SecurityOrigin::create(String, String, int).

* page/SecurityOrigin.cpp:
(WebCore::SecurityOrigin::createFromDatabaseIdentifier):
Use the constant MaxAllowedPort.
(WebCore::SecurityOrigin::create):
Sanitizing based off of that done in createFromDatabaseIdentifier.
* page/SecurityOrigin.h:

WebKit2:

Add WKSecurityOriginCreate(WKStringRef protocol, WKStringRef host, int port).

* Shared/API/c/WKSecurityOrigin.cpp:
(WKSecurityOriginCreateFromIdentifier):
Renamed so as not to clash with the new WKSecurityOriginCreate.
(WKSecurityOriginCreate):
* Shared/API/c/WKSecurityOrigin.h:
* Shared/WebSecurityOrigin.h:
(WebKit::WebSecurityOrigin::create):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@74597 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog
WebCore/WebCore.exp.in
WebCore/page/SecurityOrigin.cpp
WebCore/page/SecurityOrigin.h
WebKit2/ChangeLog
WebKit2/Shared/API/c/WKSecurityOrigin.cpp
WebKit2/Shared/API/c/WKSecurityOrigin.h
WebKit2/Shared/WebSecurityOrigin.h

index 9a589a8..47d9081 100644 (file)
@@ -1,3 +1,22 @@
+2010-12-23  Jessie Berlin  <jberlin@apple.com>
+
+        Reviewed by Sam Weinig.
+
+        Need WebKit2 API to create a SecurityOrigin from protocol, host, and port
+        https://bugs.webkit.org/show_bug.cgi?id=51563
+
+        Add SecurityOrigin::create(const String& protocol, const String& host, int port).
+
+        * WebCore.exp.in:
+        Export the symbols for WebCore::SecurityOrigin::create(String, String, int).
+
+        * page/SecurityOrigin.cpp:
+        (WebCore::SecurityOrigin::createFromDatabaseIdentifier):
+        Use the constant MaxAllowedPort.
+        (WebCore::SecurityOrigin::create):
+        Sanitizing based off of that done in createFromDatabaseIdentifier.
+        * page/SecurityOrigin.h:
+
 2010-12-23  Patrick Gansterer  <paroga@webkit.org>
 
         Unreviewed build fix for WinCE after r73802.
index e959972..593bc60 100644 (file)
@@ -341,6 +341,7 @@ __ZN7WebCore14SecurityOrigin29addOriginAccessWhitelistEntryERKS0_RKN3WTF6StringE
 __ZN7WebCore14SecurityOrigin32removeOriginAccessWhitelistEntryERKS0_RKN3WTF6StringES6_b
 __ZN7WebCore14SecurityOrigin40setDomainRelaxationForbiddenForURLSchemeEbRKN3WTF6StringE
 __ZN7WebCore14SecurityOrigin6createERKNS_4KURLEi
+__ZN7WebCore14SecurityOrigin6createERKN3WTF6StringES4_i
 __ZN7WebCore15ArchiveResource6createEN3WTF10PassRefPtrINS_12SharedBufferEEERKNS_4KURLERKNS1_6StringESA_SA_RKNS_16ResourceResponseE
 __ZN7WebCore15DOMWrapperWorld15unregisterWorldEv
 __ZN7WebCore15DOMWrapperWorldD1Ev
index a753c6d..16de640 100644 (file)
@@ -40,6 +40,7 @@
 namespace WebCore {
 
 static SecurityOrigin::LocalLoadPolicy localLoadPolicy = SecurityOrigin::AllowLocalLoadsForLocalOnly;
+const int MaxAllowedPort = 65535;
 
 typedef Vector<OriginAccessEntry> OriginAccessWhiteList;
 typedef HashMap<String, OriginAccessWhiteList*> OriginAccessMap;
@@ -415,7 +416,7 @@ PassRefPtr<SecurityOrigin> SecurityOrigin::createFromDatabaseIdentifier(const St
     if (!(portOkay || portAbsent))
         return create(KURL());
     
-    if (port < 0 || port > 65535)
+    if (port < 0 || port > MaxAllowedPort)
         return create(KURL());
         
     // Split out the 3 sections of data
@@ -426,6 +427,14 @@ PassRefPtr<SecurityOrigin> SecurityOrigin::createFromDatabaseIdentifier(const St
     return create(KURL(KURL(), protocol + "://" + host + ":" + String::number(port)));
 }
 
+PassRefPtr<SecurityOrigin> SecurityOrigin::create(const String& protocol, const String& host, int port)
+{
+    if (port < 0 || port > MaxAllowedPort)
+        create(KURL());
+    String decodedHost = decodeURLEscapeSequences(host);
+    return create(KURL(KURL(), protocol + "://" + host + ":" + String::number(port)));
+}
+
 String SecurityOrigin::databaseIdentifier() const 
 {
     String separatorString(&SeparatorCharacter, 1);
index 6bdb28c..61f6ab8 100644 (file)
@@ -42,6 +42,7 @@ class SecurityOrigin : public ThreadSafeShared<SecurityOrigin> {
 public:
     static PassRefPtr<SecurityOrigin> createFromDatabaseIdentifier(const String&);
     static PassRefPtr<SecurityOrigin> createFromString(const String&);
+    static PassRefPtr<SecurityOrigin> create(const String& protocol, const String& host, int port);
     static PassRefPtr<SecurityOrigin> create(const KURL&, SandboxFlags = SandboxNone);
     static PassRefPtr<SecurityOrigin> createEmpty();
 
index 5e16028..380f3b4 100644 (file)
@@ -1,3 +1,20 @@
+2010-12-23  Jessie Berlin  <jberlin@apple.com>
+
+        Reviewed by Sam Weinig.
+
+        Need WebKit2 API to create a SecurityOrigin from protocol, host, and port
+        https://bugs.webkit.org/show_bug.cgi?id=51563
+
+        Add WKSecurityOriginCreate(WKStringRef protocol, WKStringRef host, int port).
+
+        * Shared/API/c/WKSecurityOrigin.cpp:
+        (WKSecurityOriginCreateFromIdentifier):
+        Renamed so as not to clash with the new WKSecurityOriginCreate.
+        (WKSecurityOriginCreate):
+        * Shared/API/c/WKSecurityOrigin.h:
+        * Shared/WebSecurityOrigin.h:
+        (WebKit::WebSecurityOrigin::create):
+
 2010-12-23  Anders Carlsson  <andersca@apple.com>
 
         Reviewed by Simon Fraser.
index 7765658..761cbf8 100644 (file)
@@ -35,12 +35,18 @@ WKTypeID WKSecurityOriginGetTypeID()
     return toAPI(WebSecurityOrigin::APIType);
 }
 
-WKSecurityOriginRef WKSecurityOriginCreate(WKStringRef identifier)
+WKSecurityOriginRef WKSecurityOriginCreateFromIdentifier(WKStringRef identifier)
 {
     RefPtr<WebSecurityOrigin> securityOrigin = WebSecurityOrigin::create(toImpl(identifier)->string());
     return toAPI(securityOrigin.release().leakRef());
 }
 
+WKSecurityOriginRef WKSecurityOriginCreate(WKStringRef protocol, WKStringRef host, int port)
+{
+    RefPtr<WebSecurityOrigin> securityOrigin = WebSecurityOrigin::create(toImpl(protocol)->string(), toImpl(host)->string(), port);
+    return toAPI(securityOrigin.release().leakRef());
+}
+
 WKStringRef WKSecurityOriginGetProtocol(WKSecurityOriginRef securityOrigin)
 {
     return toCopiedAPI(toImpl(securityOrigin)->protocol());
index a19a36c..9bffdd7 100644 (file)
@@ -34,7 +34,8 @@ extern "C" {
 
 WK_EXPORT WKTypeID WKSecurityOriginGetTypeID();
 
-WK_EXPORT WKSecurityOriginRef WKSecurityOriginCreate(WKStringRef identifier);
+WK_EXPORT WKSecurityOriginRef WKSecurityOriginCreateFromIdentifier(WKStringRef identifier);
+WK_EXPORT WKSecurityOriginRef WKSecurityOriginCreate(WKStringRef protocol, WKStringRef host, int port);
 
 WK_EXPORT WKStringRef WKSecurityOriginGetProtocol(WKSecurityOriginRef securityOrigin);
 WK_EXPORT WKStringRef WKSecurityOriginGetHost(WKSecurityOriginRef securityOrigin);
index f462d00..be684ab 100644 (file)
@@ -44,6 +44,14 @@ public:
         return adoptRef(new WebSecurityOrigin(securityOrigin.release()));
     }
 
+    static PassRefPtr<WebSecurityOrigin> create(const String& protocol, const String& host, int port)
+    {
+        RefPtr<WebCore::SecurityOrigin> securityOrigin = WebCore::SecurityOrigin::create(protocol, host, port);
+        if (!securityOrigin)
+            return 0;
+        return adoptRef(new WebSecurityOrigin(securityOrigin.release()));
+    }
+
     const String protocol() const { return m_securityOrigin->domain(); }
     const String host() const { return m_securityOrigin->host(); }
     unsigned short port() const { return m_securityOrigin->port(); }