Chromium Code Reviews| 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..4a03644c08c081af659e8e92b0a271fcb7e344e0 |
| --- /dev/null |
| +++ b/content/renderer/font_access/web_font_access_impl.cc |
| @@ -0,0 +1,83 @@ |
| +// 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; |
|
esprehn
2016/02/09 19:29:56
using blink::WebString and cut some verbosity belo
Daniel Nishi
2016/02/11 00:23:50
Done.
|
| + |
| +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(WebFontAccessDescription( |
| + blink::WebString::fromLatin1(fonts[i]->family.get()), |
| + blink::WebString::fromLatin1(fonts[i]->style.get()), |
| + blink::WebString::fromLatin1(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; |
| + MojoResult success = mojo::MapBuffer( |
| + handle.get(), 0, size, &data, |
| + MOJO_READ_DATA_FLAG_ALL_OR_NONE); |
| + if (success != MOJO_RESULT_OK) { |
| + callbacks->onError(); |
| + } |
| + blink::WebData* webData = new blink::WebData(static_cast<char*>(data), size); |
| + callbacks->onSuccess(blink::adoptWebPtr(webData)); |
| +} |
| + |
| +FontAccessServicePtr& WebFontAccessImpl::GetService() { |
| + if (!provider_) { |
| + RenderThread::Get()->GetServiceRegistry()->ConnectToRemoteService( |
| + mojo::GetProxy(&provider_)); |
| + } |
| + return provider_; |
| +} |
| + |
| +} // namespace content |