Chromium Code Reviews| 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; | |
|
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 | |
| OLD | NEW |