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

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: 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;
17 using blink::WebString;
18
19 namespace content {
20
21 WebFontAccessImpl::WebFontAccessImpl() {}
22
23 WebFontAccessImpl::~WebFontAccessImpl() {}
24
25 void WebFontAccessImpl::getFonts(blink::FontAccessCallbacks* raw_callbacks) {
26 scoped_ptr<blink::FontAccessCallbacks> callbacks(raw_callbacks);
27 GetService()->GetFontList(base::Bind(&WebFontAccessImpl::FontListHasLoaded,
28 base::Unretained(this),
nasko 2016/02/12 22:05:19 Why is it safe to pass base::Unretained(this)? Ple
Daniel Nishi 2016/02/12 22:49:40 Done.
29 base::Passed(&callbacks)));
30 }
31
32 void WebFontAccessImpl::getFontWebData(
33 const WebString& family,
34 const WebString& style,
35 blink::FontDataCallbacks* raw_callbacks) {
36 scoped_ptr<blink::FontDataCallbacks> callbacks(raw_callbacks);
37 GetService()->GetFontData(
38 family.utf8(), style.utf8(),
39 base::Bind(&WebFontAccessImpl::FontDataHasLoaded, base::Unretained(this),
40 base::Passed(&callbacks)));
41 }
42
43 void WebFontAccessImpl::FontListHasLoaded(
44 scoped_ptr<blink::FontAccessCallbacks> callbacks,
45 mojo::Array<FontDescriptionPtr> fonts) {
46 std::vector<WebFontAccessDescription> results;
47 for (size_t i = 0; i < fonts.size(); i++) {
48 results.push_back(WebFontAccessDescription(
49 WebString::fromLatin1(fonts[i]->family.get()),
50 WebString::fromLatin1(fonts[i]->style.get()),
51 WebString::fromLatin1(fonts[i]->fullName.get())));
52 }
53 callbacks->onSuccess(
54 blink::adoptWebPtr(new WebVector<WebFontAccessDescription>(results)));
55 }
56
57 void WebFontAccessImpl::FontDataHasLoaded(
58 scoped_ptr<blink::FontDataCallbacks> callbacks,
59 mojo::ScopedSharedBufferHandle handle,
60 uint64_t size) {
61 if (size == 0) {
62 callbacks->onError();
63 }
64
65 void* data;
66 MojoResult success = mojo::MapBuffer(
67 handle.get(), 0, size, &data,
68 MOJO_READ_DATA_FLAG_ALL_OR_NONE);
69 if (success != MOJO_RESULT_OK) {
nasko 2016/02/12 22:05:19 style: Single line if statements don't need {}.
Daniel Nishi 2016/02/12 22:49:40 Done.
70 callbacks->onError();
71 }
72 blink::WebData* webData = new blink::WebData(static_cast<char*>(data), size);
nasko 2016/02/12 22:05:19 web_data
Daniel Nishi 2016/02/12 22:49:40 Done.
73 callbacks->onSuccess(blink::adoptWebPtr(webData));
74 }
75
76 FontAccessServicePtr& WebFontAccessImpl::GetService() {
77 if (!provider_) {
78 RenderThread::Get()->GetServiceRegistry()->ConnectToRemoteService(
79 mojo::GetProxy(&provider_));
80 }
81 return provider_;
82 }
83
84 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698