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

Unified Diff: content/renderer/font_access/web_font_access_impl.cc

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: content/renderer/font_access/web_font_access_impl.cc
diff --git a/content/renderer/font_access/web_font_access_impl.cc b/content/renderer/font_access/web_font_access_impl.cc
new file mode 100644
index 0000000000000000000000000000000000000000..935e210fde4674e352cac103d610e8aac3c844cb
--- /dev/null
+++ b/content/renderer/font_access/web_font_access_impl.cc
@@ -0,0 +1,81 @@
+// 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 "content/renderer/font_access/web_font_access_impl.h"
+
+#include "base/bind.h"
+#include "base/strings/utf_string_conversions.h"
+#include "content/renderer/render_thread_impl.h"
+#include "mojo/public/cpp/bindings/lib/buffer.h"
+#include "third_party/WebKit/public/platform/WebData.h"
+#include "third_party/WebKit/public/platform/WebPassOwnPtr.h"
+#include "third_party/WebKit/public/platform/modules/font_access/WebFontAccessDescription.h"
+
+using blink::WebFontAccessDescription;
+using blink::WebVector;
+
+namespace content {
+
+WebFontAccessImpl::WebFontAccessImpl() {}
+
+WebFontAccessImpl::~WebFontAccessImpl() {}
+
+void WebFontAccessImpl::getFonts(blink::FontAccessCallbacks* raw_callbacks) {
+ scoped_ptr<blink::FontAccessCallbacks> callbacks(raw_callbacks);
+ GetService()->GetFontList(base::Bind(&WebFontAccessImpl::FontListHasLoaded,
+ base::Unretained(this),
+ base::Passed(&callbacks)));
+}
+
+void WebFontAccessImpl::getFontWebData(
+ const blink::WebString& family,
+ const blink::WebString& style,
+ blink::FontDataCallbacks* raw_callbacks) {
+ scoped_ptr<blink::FontDataCallbacks> callbacks(raw_callbacks);
+ GetService()->GetFontData(
+ family.utf8(), style.utf8(),
+ base::Bind(&WebFontAccessImpl::FontDataHasLoaded, base::Unretained(this),
+ base::Passed(&callbacks)));
+}
+
+void WebFontAccessImpl::FontListHasLoaded(
+ scoped_ptr<blink::FontAccessCallbacks> callbacks,
+ mojo::Array<FontDescriptionPtr> fonts) {
+ std::vector<WebFontAccessDescription*> results;
+ for (size_t i = 0; i < fonts.size(); i++) {
+ results.push_back(new WebFontAccessDescription(
+ base::ASCIIToUTF16(fonts[i]->family.get()),
esprehn 2016/01/26 20:08:18 All this code belongs in blink, please stop doing
Daniel Nishi 2016/01/26 23:49:26 In terms of moving the code from content to Blink,
+ base::ASCIIToUTF16(fonts[i]->style.get()),
+ base::ASCIIToUTF16(fonts[i]->fullName.get())));
+ }
+ callbacks->onSuccess(
+ blink::adoptWebPtr(new WebVector<WebFontAccessDescription*>(results)));
+}
+
+void WebFontAccessImpl::FontDataHasLoaded(
+ scoped_ptr<blink::FontDataCallbacks> callbacks,
+ mojo::ScopedSharedBufferHandle handle,
+ uint64_t size) {
+ if (size == 0) {
+ callbacks->onError();
+ }
+
+ void* data;
+ mojo::MapBuffer(
+ handle.get(), 0, size, &data,
+ MOJO_READ_DATA_FLAG_ALL_OR_NONE);
+ blink::WebData* webData = new blink::WebData(static_cast<char*>(data), size);
+ mojo::UnmapBuffer(webData);
+ callbacks->onSuccess(blink::adoptWebPtr(webData));
+}
+
+FontAccessServicePtr& WebFontAccessImpl::GetService() {
+ if (!provider_) {
+ RenderThread::Get()->GetServiceRegistry()->ConnectToRemoteService(
+ mojo::GetProxy(&provider_));
+ }
+ return provider_;
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698