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.
6 #include "modules/credentialmanager/Credential.h"
8 #include "bindings/core/v8/ExceptionState.h"
9 #include "core/dom/ExceptionCode.h"
13 Credential* Credential::create(const String& id, const String& name, const KURL& avatar)
15 return new Credential(id, name, avatar);
18 Credential* Credential::create(const String& id, const String& name, const String& avatar, ExceptionState& exceptionState)
20 KURL avatarURL = parseStringAsURL(avatar, exceptionState);
21 if (exceptionState.hadException())
23 return new Credential(id, name, avatarURL);
26 Credential::Credential(PlatformCredential* credential)
27 : m_platformCredential(credential)
31 Credential::Credential(const String& id, const String& name, const KURL& avatar)
32 : m_platformCredential(PlatformCredential::create(id, name, avatar))
34 ScriptWrappable::init(this);
37 KURL Credential::parseStringAsURL(const String& url, ExceptionState& exceptionState)
39 KURL parsedURL = KURL(KURL(), url);
40 if (!parsedURL.isValid())
41 exceptionState.throwDOMException(SyntaxError, "'" + url + "' is not a valid URL.");
45 void Credential::trace(Visitor* visitor)
47 visitor->trace(m_platformCredential);