Chromium Code Reviews| Index: third_party/WebKit/Source/core/css/FontFaceSet.cpp |
| diff --git a/third_party/WebKit/Source/core/css/FontFaceSet.cpp b/third_party/WebKit/Source/core/css/FontFaceSet.cpp |
| index 7b435591e68a841519c2bf7780fbeeffc6b40d14..1a2c68025199e9b752aa48822e470abd52ec4dfa 100644 |
| --- a/third_party/WebKit/Source/core/css/FontFaceSet.cpp |
| +++ b/third_party/WebKit/Source/core/css/FontFaceSet.cpp |
| @@ -25,13 +25,16 @@ |
| #include "core/css/FontFaceSet.h" |
| +#include "bindings/core/v8/CallbackPromiseAdapter.h" |
| #include "bindings/core/v8/Dictionary.h" |
| #include "bindings/core/v8/ScriptPromiseResolver.h" |
| #include "bindings/core/v8/ScriptState.h" |
| #include "core/css/CSSFontSelector.h" |
| #include "core/css/CSSSegmentedFontFace.h" |
| #include "core/css/FontFaceCache.h" |
| +#include "core/css/FontFaceDescriptors.h" |
| #include "core/css/FontFaceSetLoadEvent.h" |
| +#include "core/css/LocalFontFace.h" |
| #include "core/css/StylePropertySet.h" |
| #include "core/css/parser/CSSParser.h" |
| #include "core/css/resolver/StyleResolver.h" |
| @@ -41,6 +44,8 @@ |
| #include "core/frame/LocalFrame.h" |
| #include "core/style/StyleInheritedData.h" |
| #include "public/platform/Platform.h" |
| +#include "public/platform/modules/font_access/WebFontAccess.h" |
| +#include "public/platform/modules/font_access/WebFontAccessDescription.h" |
| namespace blink { |
| @@ -534,6 +539,54 @@ bool FontFaceSet::IterationSource::next(ScriptState*, RefPtrWillBeMember<FontFac |
| return true; |
| } |
| +class FontAccessDescriptionCallback : public FontAccessCallbacks { |
|
esprehn
2016/02/09 19:29:56
final
Daniel Nishi
2016/02/11 00:23:51
Done.
|
| +public: |
| + FontAccessDescriptionCallback(ScriptPromiseResolver* resolver, ScriptState* scriptState) |
| + : m_resolver(resolver) |
| + , m_executionContext(scriptState->executionContext()) |
| + { |
| + } |
| + |
| + void onSuccess(WebPassOwnPtr<WebVector<WebFontAccessDescription>> description) override |
| + { |
| + WillBeHeapVector<RefPtrWillBeMember<FontFace>> fonts; |
| + OwnPtr<WebVector<WebFontAccessDescription>> webFonts = description.release(); |
| + blink::FontFaceDescriptors faceDecsription; |
| + for (const auto webFont : *webFonts) { |
| + StringOrArrayBufferOrArrayBufferView cssString; |
| + StringBuilder result; |
| + result.append("local('"); |
| + result.append(webFont.fullName); |
| + result.append(')'); |
| + cssString.setString(result.toString()); |
| + RefPtrWillBeMember<LocalFontFace> ff = LocalFontFace::createLocalFontFace(m_executionContext.get(), webFont.family, webFont.style, webFont.fullName, cssString, faceDecsription); |
| + fonts.append(ff); |
| + } |
| + |
| + m_resolver->resolve(fonts); |
| + } |
| + void onError() override |
| + { |
| + } |
| + |
| +private: |
| + Persistent<ScriptPromiseResolver> m_resolver; |
| + RefPtrWillBePersistent<ExecutionContext> m_executionContext; |
| +}; |
| + |
| +ScriptPromise FontFaceSet::systemFonts(ScriptState* scriptState) |
| +{ |
| + WebFontAccess* webfontaccess = Platform::current()->fontAccess(); |
| + if (!webfontaccess) |
| + return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(NotSupportedError)); |
| + |
| + ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
| + ScriptPromise promise = resolver->promise(); |
| + |
| + webfontaccess->getFonts(new FontAccessDescriptionCallback(resolver, scriptState)); |
| + return promise; |
| +} |
| + |
| DEFINE_TRACE(FontFaceSet) |
| { |
| #if ENABLE(OILPAN) |