OLD | NEW |
---|---|
(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 | |
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 base::ASCIIToUTF16(fonts[i]->family.get()), | |
esprehn
2016/01/31 00:54:46
you want to use WebString::fromLatin1 to avoid the
Daniel Nishi
2016/02/02 17:54:17
Done.
| |
49 base::ASCIIToUTF16(fonts[i]->style.get()), | |
50 base::ASCIIToUTF16(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 mojo::MapBuffer( | |
66 handle.get(), 0, size, &data, | |
67 MOJO_READ_DATA_FLAG_ALL_OR_NONE); | |
68 blink::WebData* webData = new blink::WebData(static_cast<char*>(data), size); | |
69 mojo::UnmapBuffer(webData); | |
70 callbacks->onSuccess(blink::adoptWebPtr(webData)); | |
71 } | |
72 | |
73 FontAccessServicePtr& WebFontAccessImpl::GetService() { | |
74 if (!provider_) { | |
75 RenderThread::Get()->GetServiceRegistry()->ConnectToRemoteService( | |
76 mojo::GetProxy(&provider_)); | |
77 } | |
78 return provider_; | |
79 } | |
80 | |
81 } // namespace content | |
OLD | NEW |