/*
* Copyright (C) 2011, Google Inc. All rights reserved.
- * Copyright (C) 2012, Samsung Electronics. All rights reserved.
+ * Copyright (C) 2014, Samsung Electronics. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
#include "config.h"
#include "modules/navigatorcontentutils/NavigatorContentUtils.h"
-#include "bindings/v8/ExceptionState.h"
+#include "bindings/core/v8/ExceptionState.h"
#include "core/dom/Document.h"
#include "core/dom/ExceptionCode.h"
#include "core/frame/LocalFrame.h"
#include "core/frame/Navigator.h"
#include "core/page/Page.h"
#include "wtf/HashSet.h"
+#include "wtf/text/StringBuilder.h"
-namespace WebCore {
+namespace blink {
-static HashSet<String>* protocolWhitelist;
+static HashSet<String>* schemeWhitelist;
-static void initProtocolHandlerWhitelist()
+static void initCustomSchemeHandlerWhitelist()
{
- protocolWhitelist = new HashSet<String>;
- static const char* const protocols[] = {
+ schemeWhitelist = new HashSet<String>;
+ static const char* const schemes[] = {
"bitcoin",
"geo",
"im",
"wtai",
"xmpp",
};
- for (size_t i = 0; i < WTF_ARRAY_LENGTH(protocols); ++i)
- protocolWhitelist->add(protocols[i]);
+ for (size_t i = 0; i < WTF_ARRAY_LENGTH(schemes); ++i)
+ schemeWhitelist->add(schemes[i]);
}
static bool verifyCustomHandlerURL(const KURL& baseURL, const String& url, ExceptionState& exceptionState)
return true;
}
-static bool isProtocolWhitelisted(const String& scheme)
+static bool isSchemeWhitelisted(const String& scheme)
{
- if (!protocolWhitelist)
- initProtocolHandlerWhitelist();
- return protocolWhitelist->contains(scheme);
+ if (!schemeWhitelist)
+ initCustomSchemeHandlerWhitelist();
+
+ StringBuilder builder;
+ unsigned length = scheme.length();
+ for (unsigned i = 0; i < length; ++i)
+ builder.append(toASCIILower(scheme[i]));
+
+ return schemeWhitelist->contains(builder.toString());
}
-static bool verifyProtocolHandlerScheme(const String& scheme, const String& method, ExceptionState& exceptionState)
+static bool verifyCustomHandlerScheme(const String& scheme, ExceptionState& exceptionState)
{
+ if (!isValidProtocol(scheme)) {
+ exceptionState.throwSecurityError("The scheme '" + scheme + "' is not valid protocol");
+ return false;
+ }
+
if (scheme.startsWith("web+")) {
// The specification requires that the length of scheme is at least five characteres (including 'web+' prefix).
- if (scheme.length() >= 5 && isValidProtocol(scheme))
+ if (scheme.length() >= 5)
return true;
- if (!isValidProtocol(scheme))
- exceptionState.throwSecurityError("The scheme '" + scheme + "' is not a valid protocol.");
- else
- exceptionState.throwSecurityError("The scheme '" + scheme + "' is less than five characters long.");
+
+ exceptionState.throwSecurityError("The scheme '" + scheme + "' is less than five characters long.");
return false;
}
- if (isProtocolWhitelisted(scheme))
+ if (isSchemeWhitelisted(scheme))
return true;
- exceptionState.throwSecurityError("The scheme '" + scheme + "' doesn't belong to the protocol whitelist. Please prefix non-whitelisted schemes with the string 'web+'.");
+
+ exceptionState.throwSecurityError("The scheme '" + scheme + "' doesn't belong to the scheme whitelist. Please prefix non-whitelisted schemes with the string 'web+'.");
return false;
}
if (!verifyCustomHandlerURL(baseURL, url, exceptionState))
return;
- if (!verifyProtocolHandlerScheme(scheme, "registerProtocolHandler", exceptionState))
+ if (!verifyCustomHandlerScheme(scheme, exceptionState))
return;
ASSERT(navigator.frame()->page());
if (!verifyCustomHandlerURL(baseURL, url, exceptionState))
return declined;
- if (!verifyProtocolHandlerScheme(scheme, "isProtocolHandlerRegistered", exceptionState))
+ if (!verifyCustomHandlerScheme(scheme, exceptionState))
return declined;
ASSERT(navigator.frame()->page());
if (!verifyCustomHandlerURL(baseURL, url, exceptionState))
return;
- if (!verifyProtocolHandlerScheme(scheme, "unregisterProtocolHandler", exceptionState))
+ if (!verifyCustomHandlerScheme(scheme, exceptionState))
return;
ASSERT(navigator.frame()->page());
NavigatorContentUtils::provideTo(page, NavigatorContentUtils::supplementName(), NavigatorContentUtils::create(client));
}
-} // namespace WebCore
+} // namespace blink