This source file includes following definitions.
- createSecurityOriginFromDatabaseIdentifier
- createDatabaseIdentifierFromSecurityOrigin
#include "config.h"
#include "platform/weborigin/DatabaseIdentifier.h"
#include "platform/weborigin/KURL.h"
#include "platform/weborigin/KnownPorts.h"
#include "platform/weborigin/SchemeRegistry.h"
#include "platform/weborigin/SecurityOriginCache.h"
#include "platform/weborigin/SecurityPolicy.h"
#include "wtf/HexNumber.h"
#include "wtf/MainThread.h"
#include "wtf/StdLibExtras.h"
#include "wtf/text/StringBuilder.h"
namespace WebCore {
const int maxAllowedPort = 65535;
static const char separatorCharacter = '_';
PassRefPtr<SecurityOrigin> createSecurityOriginFromDatabaseIdentifier(const String& databaseIdentifier)
{
if (!databaseIdentifier.containsOnlyASCII())
return SecurityOrigin::createUnique();
size_t separator1 = databaseIdentifier.find(separatorCharacter);
if (separator1 == kNotFound)
return SecurityOrigin::createUnique();
size_t separator2 = databaseIdentifier.reverseFind(separatorCharacter);
if (separator2 == kNotFound)
return SecurityOrigin::createUnique();
if (separator1 == separator2)
return SecurityOrigin::createUnique();
bool portOkay;
int port = databaseIdentifier.right(databaseIdentifier.length() - separator2 - 1).toInt(&portOkay);
bool portAbsent = (separator2 == databaseIdentifier.length() - 1);
if (!(portOkay || portAbsent))
return SecurityOrigin::createUnique();
if (port < 0 || port > maxAllowedPort)
return SecurityOrigin::createUnique();
String protocol = databaseIdentifier.substring(0, separator1);
String host = databaseIdentifier.substring(separator1 + 1, separator2 - separator1 - 1);
KURL url(KURL(), protocol + "://" + host + ":" + String::number(port) + "/");
if (!url.isValid() || url.protocol() != protocol || url.host() != host)
return SecurityOrigin::createUnique();
return SecurityOrigin::create(url);
}
String createDatabaseIdentifierFromSecurityOrigin(const SecurityOrigin* securityOrigin)
{
if (securityOrigin->needsDatabaseIdentifierQuirkForFiles())
return "file__0";
String separatorString(&separatorCharacter, 1);
return securityOrigin->protocol() + separatorString + securityOrigin->host() + separatorString + String::number(securityOrigin->port());
}
}