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

Side by Side 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: Add file reading failure checking. Created 4 years, 10 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 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.
4
5 #include "content/renderer/font_access/web_font_access_impl.h"
6
7 #include "base/bind.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "content/renderer/render_thread_impl.h"
10 #include "mojo/public/cpp/bindings/lib/buffer.h"
11 #include "third_party/WebKit/public/platform/WebData.h"
12 #include "third_party/WebKit/public/platform/WebPassOwnPtr.h"
13 #include "third_party/WebKit/public/platform/modules/font_access/WebFontAccessDe scription.h"
14
15 using blink::WebFontAccessDescription;
16 using blink::WebVector;
esprehn 2016/02/09 19:29:56 using blink::WebString and cut some verbosity belo
Daniel Nishi 2016/02/11 00:23:50 Done.
17
18 namespace content {
19
20 WebFontAccessImpl::WebFontAccessImpl() {}
21
22 WebFontAccessImpl::~WebFontAccessImpl() {}
23
24 void WebFontAccessImpl::getFonts(blink::FontAccessCallbacks* raw_callbacks) {
25 scoped_ptr<blink::FontAccessCallbacks> callbacks(raw_callbacks);
26 GetService()->GetFontList(base::Bind(&WebFontAccessImpl::FontListHasLoaded,
27 base::Unretained(this),
28 base::Passed(&callbacks)));
29 }
30
31 void WebFontAccessImpl::getFontWebData(
32 const blink::WebString& family,
33 const blink::WebString& style,
34 blink::FontDataCallbacks* raw_callbacks) {
35 scoped_ptr<blink::FontDataCallbacks> callbacks(raw_callbacks);
36 GetService()->GetFontData(
37 family.utf8(), style.utf8(),
38 base::Bind(&WebFontAccessImpl::FontDataHasLoaded, base::Unretained(this),
39 base::Passed(&callbacks)));
40 }
41
42 void WebFontAccessImpl::FontListHasLoaded(
43 scoped_ptr<blink::FontAccessCallbacks> callbacks,
44 mojo::Array<FontDescriptionPtr> fonts) {
45 std::vector<WebFontAccessDescription> results;
46 for (size_t i = 0; i < fonts.size(); i++) {
47 results.push_back(WebFontAccessDescription(
48 blink::WebString::fromLatin1(fonts[i]->family.get()),
49 blink::WebString::fromLatin1(fonts[i]->style.get()),
50 blink::WebString::fromLatin1(fonts[i]->fullName.get())));
51 }
52 callbacks->onSuccess(
53 blink::adoptWebPtr(new WebVector<WebFontAccessDescription>(results)));
54 }
55
56 void WebFontAccessImpl::FontDataHasLoaded(
57 scoped_ptr<blink::FontDataCallbacks> callbacks,
58 mojo::ScopedSharedBufferHandle handle,
59 uint64_t size) {
60 if (size == 0) {
61 callbacks->onError();
62 }
63
64 void* data;
65 MojoResult success = mojo::MapBuffer(
66 handle.get(), 0, size, &data,
67 MOJO_READ_DATA_FLAG_ALL_OR_NONE);
68 if (success != MOJO_RESULT_OK) {
69 callbacks->onError();
70 }
71 blink::WebData* webData = new blink::WebData(static_cast<char*>(data), size);
72 callbacks->onSuccess(blink::adoptWebPtr(webData));
73 }
74
75 FontAccessServicePtr& WebFontAccessImpl::GetService() {
76 if (!provider_) {
77 RenderThread::Get()->GetServiceRegistry()->ConnectToRemoteService(
78 mojo::GetProxy(&provider_));
79 }
80 return provider_;
81 }
82
83 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698