| Index: third_party/WebKit/Source/core/css/LocalFontFace.cpp
|
| diff --git a/third_party/WebKit/Source/core/css/LocalFontFace.cpp b/third_party/WebKit/Source/core/css/LocalFontFace.cpp
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..e26b1a1be4e7c0c74fdbae82867d55b86c39fefb
|
| --- /dev/null
|
| +++ b/third_party/WebKit/Source/core/css/LocalFontFace.cpp
|
| @@ -0,0 +1,72 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "core/css/LocalFontFace.h"
|
| +
|
| +#include "bindings/core/v8/CallbackPromiseAdapter.h"
|
| +#include "bindings/core/v8/ScriptPromiseResolver.h"
|
| +#include "bindings/core/v8/ScriptState.h"
|
| +#include "core/CSSValueKeywords.h"
|
| +#include "core/css/FontFaceDescriptors.h"
|
| +#include "core/css/parser/CSSParser.h"
|
| +#include "core/dom/DOMArrayBuffer.h"
|
| +#include "core/dom/DOMException.h"
|
| +#include "core/dom/Document.h"
|
| +#include "core/dom/ExceptionCode.h"
|
| +#include "core/frame/UseCounter.h"
|
| +#include "public/platform/Platform.h"
|
| +#include "public/platform/modules/font_access/WebFontAccess.h"
|
| +
|
| +namespace blink {
|
| +PassRefPtrWillBeRawPtr<LocalFontFace> LocalFontFace::createLocalFontFace(ExecutionContext* context, const AtomicString& family, const AtomicString& styleName, const AtomicString& fullName, StringOrArrayBufferOrArrayBufferView& source, const FontFaceDescriptors& descriptors)
|
| +{
|
| + String sourceString = source.getAsString();
|
| + RefPtrWillBeRawPtr<LocalFontFace> fontFace = adoptRefWillBeNoop(new LocalFontFace(context, family, styleName, fullName, descriptors));
|
| +
|
| + Document* document = toDocument(context);
|
| + CSSParserContext parserContext(*document, UseCounter::getFrom(document));
|
| + RefPtrWillBeRawPtr<CSSValue> src = CSSParser::parseFontFaceDescriptor(CSSPropertySrc, sourceString, parserContext);
|
| + if (!src || !src->isValueList())
|
| + fontFace->setError(DOMException::create(SyntaxError, "The source provided ('" + sourceString + "') could not be parsed as a value list."));
|
| +
|
| + fontFace->initCSSFontFace(toDocument(context), src);
|
| + return fontFace.release();
|
| +}
|
| +
|
| +class FontBinaryResult {
|
| + WTF_MAKE_NONCOPYABLE(FontBinaryResult);
|
| +
|
| +public:
|
| + using WebType = OwnPtr<WebData>;
|
| +
|
| + static PassRefPtr<DOMArrayBuffer> take(ScriptPromiseResolver* resolver, PassOwnPtr<WebData> webBlob)
|
| + {
|
| + RefPtr<DOMArrayBuffer> domBuffer = DOMArrayBuffer::create(webBlob->data(), webBlob->size());
|
| + return domBuffer;
|
| + }
|
| +
|
| +private:
|
| + FontBinaryResult() = delete;
|
| +};
|
| +
|
| +ScriptPromise LocalFontFace::binaryData(ScriptState* scriptState) const
|
| +{
|
| + WebFontAccess* webfontaccess = Platform::current()->fontAccess();
|
| + if (!webfontaccess)
|
| + return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(NotSupportedError));
|
| + ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
|
| + ScriptPromise promise = resolver->promise();
|
| +
|
| + webfontaccess->getFontWebData(family(), styleName(), new CallbackPromiseAdapter<FontBinaryResult, void>(resolver));
|
| + return promise;
|
| +}
|
| +
|
| +LocalFontFace::LocalFontFace(ExecutionContext* context, const AtomicString& family, const AtomicString& styleName, const AtomicString& fullName, const FontFaceDescriptors& descriptor)
|
| + : FontFace(context, family, descriptor)
|
| + , m_style(styleName)
|
| + , m_fullName(fullName)
|
| +{
|
| +}
|
| +
|
| +} // namespace blink
|
|
|