Chromium Code Reviews| 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 #ifndef APIKey_h | |
| 6 #define APIKey_h | |
| 7 | |
| 8 #include "core/CoreExport.h" | |
| 9 #include "core/dom/DOMException.h" | |
| 10 #include "platform/heap/Handle.h" | |
| 11 #include "platform/weborigin/KURL.h" | |
| 12 #include "wtf/text/WTFString.h" | |
| 13 | |
| 14 | |
| 15 class APIKeyTest; | |
| 16 | |
| 17 namespace blink { | |
| 18 | |
| 19 // The Experimental Framework (EF) provides limited access to experimental APIs, | |
| 20 // on a per-origin basis. This class defines the API key data structure, used | |
| 21 // to securely provide access to an experimental API. | |
| 22 // | |
| 23 // Experimental APIs are defined by string names, provided by the implementers. | |
| 24 // The EF code does not maintain an enum or constant list for experiment names. | |
| 25 // Instead, the EF validates the name provided by the API implementation against | |
| 26 // any provided API keys. | |
| 27 // | |
| 28 // In the renderer, the EF is concerned with checking whether an API key claims | |
| 29 // to be valid for the current origin. It does not attempt to actually validate | |
| 30 // the signature on the key. | |
| 31 // | |
| 32 // TODO(chasej): Link to documentation, or provide more detail on keys, .etc | |
| 33 class CORE_EXPORT APIKey : public RefCountedWillBeGarbageCollected<APIKey> { | |
| 34 public: | |
| 35 // Returns an APIKey object if the string can be parsed correctly. (This | |
| 36 // does not mean that the key is valid for the current origin, just that it | |
| 37 // is well-formed.) If the string is not a well-formed key, then a null | |
| 38 // pointer is returned. | |
| 39 static PassRefPtrWillBeRawPtr<APIKey> parse(const String&); | |
| 40 | |
| 41 // Returns true if this API key was issued for the given origin and API | |
| 42 // combination. Returning true does not mean that the key is valid nor | |
|
chasej
2015/12/15 19:43:41
Should update comment to mention expiry date valid
iclelland
2015/12/15 21:22:24
Done.
| |
| 43 // is it a sufficient check to allow access to the API. | |
| 44 bool isValidNowForOrigin(const String& origin, const String& apiName, uint64 _t now) const; | |
|
chasej
2015/12/15 19:43:41
The naming for this method seems a little awkward.
iclelland
2015/12/15 21:22:24
Sounds good. Done.
| |
| 45 | |
| 46 protected: | |
| 47 friend class APIKeyTest; | |
| 48 | |
| 49 bool validateOrigin(const String& originText) const; | |
| 50 bool validateApiName(const String& apiName) const; | |
| 51 bool validateDate(uint64_t now) const; | |
| 52 | |
| 53 private: | |
| 54 APIKey(); | |
| 55 explicit APIKey(const String& m_signature, const KURL& origin, const String& apiName, uint64_t m_expiry); | |
| 56 | |
| 57 String m_signature; | |
| 58 KURL m_origin; | |
| 59 String m_apiName; | |
| 60 uint64_t m_expiry; | |
| 61 }; | |
| 62 | |
| 63 } // namespace blink | |
| 64 | |
| 65 #endif // APIKey_h | |
| OLD | NEW |