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

Unified Diff: Source/platform/weborigin/SecurityOrigin.cpp

Issue 299253003: [webcrypto] Only allow crypto.subtle.* to be used from "secure origins". (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Add more tests Created 6 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/platform/weborigin/SecurityOrigin.h ('k') | Source/platform/weborigin/SecurityOriginTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/platform/weborigin/SecurityOrigin.cpp
diff --git a/Source/platform/weborigin/SecurityOrigin.cpp b/Source/platform/weborigin/SecurityOrigin.cpp
index 652560af325dcf8ba1f0ae4a4f97b609654b7ef5..1e14c98ae3eafcde3b6ec4cfc18e28a51d9bc40e 100644
--- a/Source/platform/weborigin/SecurityOrigin.cpp
+++ b/Source/platform/weborigin/SecurityOrigin.cpp
@@ -38,6 +38,7 @@
#include "wtf/MainThread.h"
#include "wtf/StdLibExtras.h"
#include "wtf/text/StringBuilder.h"
+#include <url/url_canon_ip.h>
abarth-chromium 2014/06/10 17:09:11 #include "url/url_canon_ip.h" You should probably
eroman 2014/06/10 18:47:26 Done.
namespace WebCore {
@@ -375,6 +376,12 @@ bool SecurityOrigin::canDisplay(const KURL& url) const
return true;
}
+bool SecurityOrigin::canAccessFeatureRequiringSecureOrigin() const
+{
+ ASSERT(m_protocol != "data");
+ return isLocal() || isLocalhost() || SchemeRegistry::shouldTreatURLSchemeAsSecure(m_protocol);
abarth-chromium 2014/06/10 17:09:11 We should move isLocalhost() to the end because it
eroman 2014/06/10 18:47:26 Good point! Done. Similarly, I moved the secure s
+}
+
SecurityOrigin::Policy SecurityOrigin::canShowNotifications() const
{
if (m_universalAccess)
@@ -409,6 +416,29 @@ bool SecurityOrigin::isLocal() const
return SchemeRegistry::shouldTreatURLSchemeAsLocal(m_protocol);
}
+bool SecurityOrigin::isLocalhost() const
+{
+ if (m_host == "localhost")
+ return true;
+
+ if (m_host == "[::1]")
+ return true;
+
+ // Test if m_host matches 127.0.0.1/8
+ ASSERT(m_host.containsOnlyASCII());
+ CString hostAscii = m_host.ascii();
+ Vector<uint8, 4> ipNumber;
+ ipNumber.resize(4);
+
+ int numComponents;
+ url::Component hostComponent(0, hostAscii.length());
+ url::CanonHostInfo::Family family = url::IPv4AddressToNumber(
+ hostAscii.data(), hostComponent, &(ipNumber)[0], &numComponents);
+ if (family != url::CanonHostInfo::IPV4)
+ return false;
+ return ipNumber[0] == 127;
+}
+
String SecurityOrigin::toString() const
{
if (isUnique())
« no previous file with comments | « Source/platform/weborigin/SecurityOrigin.h ('k') | Source/platform/weborigin/SecurityOriginTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698