1 // Copyright 2014 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 "modules/credentialmanager/Credential.h"
7
8 #include "bindings/core/v8/ExceptionState.h"
9 #include "core/dom/ExceptionCode.h"
10
11 namespace blink {
12
create(const String & id,const String & name,const KURL & avatar)13 Credential* Credential::create(const String& id, const String& name, const KURL& avatar)
14 {
15 return new Credential(id, name, avatar);
16 }
17
create(const String & id,const String & name,const String & avatar,ExceptionState & exceptionState)18 Credential* Credential::create(const String& id, const String& name, const String& avatar, ExceptionState& exceptionState)
19 {
20 KURL avatarURL = parseStringAsURL(avatar, exceptionState);
21 if (exceptionState.hadException())
22 return nullptr;
23 return new Credential(id, name, avatarURL);
24 }
25
Credential(PlatformCredential * credential)26 Credential::Credential(PlatformCredential* credential)
27 : m_platformCredential(credential)
28 {
29 }
30
Credential(const String & id,const String & name,const KURL & avatar)31 Credential::Credential(const String& id, const String& name, const KURL& avatar)
32 : m_platformCredential(PlatformCredential::create(id, name, avatar))
33 {
34 }
35
parseStringAsURL(const String & url,ExceptionState & exceptionState)36 KURL Credential::parseStringAsURL(const String& url, ExceptionState& exceptionState)
37 {
38 KURL parsedURL = KURL(KURL(), url);
39 if (!parsedURL.isValid())
40 exceptionState.throwDOMException(SyntaxError, "'" + url + "' is not a valid URL.");
41 return parsedURL;
42 }
43
trace(Visitor * visitor)44 void Credential::trace(Visitor* visitor)
45 {
46 visitor->trace(m_platformCredential);
47 }
48
49 } // namespace blink
50