| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "config.h" |
| 6 #include "core/experiments/APIKey.h" |
| 7 |
| 8 #include "core/dom/ElementTraversal.h" |
| 9 #include "core/dom/ExceptionCode.h" |
| 10 #include "core/frame/LocalDOMWindow.h" |
| 11 #include "core/html/HTMLHeadElement.h" |
| 12 #include "core/html/HTMLMetaElement.h" |
| 13 #include "platform/RuntimeEnabledFeatures.h" |
| 14 #include "platform/weborigin/SecurityOrigin.h" |
| 15 |
| 16 #include <string> |
| 17 |
| 18 namespace blink { |
| 19 |
| 20 PassRefPtrWillBeRawPtr<APIKey> APIKey::parse(const String& keyText) |
| 21 { |
| 22 if (keyText.isEmpty()) { |
| 23 return nullptr; |
| 24 } |
| 25 |
| 26 // API Key should resemble: |
| 27 // signature|origin|apiName|expiry |
| 28 Vector<String> parts; |
| 29 keyText.split('|', parts); |
| 30 if (parts.size() != 4) { |
| 31 return nullptr; |
| 32 } |
| 33 |
| 34 const String& signature = parts[0]; |
| 35 const String& originText = parts[1]; |
| 36 const String& apiName = parts[2]; |
| 37 const String& expiryText = parts[3]; |
| 38 |
| 39 // Expiry field must be an integer |
| 40 bool expiryIsValid = false; |
| 41 uint64_t expiry = expiryText.toUInt64Strict(&expiryIsValid); |
| 42 if (!expiryIsValid) { |
| 43 return nullptr; |
| 44 } |
| 45 |
| 46 // Origin field must be a valid URL |
| 47 KURL origin = KURL(KURL(), originText); |
| 48 if (!origin.isValid()) { |
| 49 return nullptr; |
| 50 } |
| 51 |
| 52 return adoptRefWillBeNoop(new APIKey(signature, origin, apiName, expiry)); |
| 53 } |
| 54 |
| 55 APIKey::APIKey(const String& signature, const KURL& origin, const String& apiNam
e, uint64_t expiry) |
| 56 : m_signature(signature) |
| 57 , m_origin(origin) |
| 58 , m_apiName(apiName) |
| 59 , m_expiry(expiry) |
| 60 { |
| 61 } |
| 62 |
| 63 bool APIKey::isValid(const String& origin, const String& apiName, uint64_t now)
const |
| 64 { |
| 65 return validateOrigin(origin) |
| 66 && validateApiName(apiName) |
| 67 && validateDate(now); |
| 68 } |
| 69 |
| 70 bool APIKey::validateOrigin(const String& originText) const |
| 71 { |
| 72 KURL origin = KURL(KURL(), originText); |
| 73 if (!origin.isValid()) { |
| 74 return false; |
| 75 } |
| 76 return origin == m_origin; |
| 77 } |
| 78 |
| 79 bool APIKey::validateApiName(const String& apiName) const |
| 80 { |
| 81 return equalIgnoringCase(m_apiName, apiName); |
| 82 } |
| 83 |
| 84 bool APIKey::validateDate(uint64_t now) const |
| 85 { |
| 86 return m_expiry > now; |
| 87 } |
| 88 |
| 89 } // namespace blink |
| OLD | NEW |