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..881760dce39c548e79459586b9e34728fd086d6c | 
| --- /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(WebFontAccessDescription( | 
| + 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.
 
 | 
| + 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 |