Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(260)

Unified Diff: third_party/WebKit/Source/core/css/FontFaceSet.cpp

Issue 1615133002: Implement API for accessing fonts installed locally on the system. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing Mounir's comments. Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..a720b297692a26da152014dc67e16a69413b8b33 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 {
+public:
+ FontAccessDescriptionCallback(ScriptPromiseResolver* resolver, ScriptState* scriptState)
+ : m_resolver(resolver)
+ , m_executionContext(scriptState->executionContext())
+ {
+ }
+
+ void onSuccess(WebPassOwnPtr<WebVector<WebFontAccessDescription*>> description) override
esprehn 2016/01/26 20:26:45 who own's the description objects? Why isn't this
Daniel Nishi 2016/01/26 23:49:26 I think the WebVector owns the Description objects
+ {
+ WillBeHeapVector<RefPtrWillBeMember<FontFace>> fonts;
+ OwnPtr<WebVector<WebFontAccessDescription*>> webFonts = description.release();
+ blink::FontFaceDescriptors faceDesc;
esprehn 2016/01/26 20:26:45 don't abbreviate
Daniel Nishi 2016/01/26 23:49:26 Done.
+ 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, faceDesc);
+ 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)

Powered by Google App Engine
This is Rietveld 408576698