Chromium Code Reviews| Index: third_party/WebKit/Source/modules/ballista/Actions.cpp |
| diff --git a/third_party/WebKit/Source/modules/ballista/Actions.cpp b/third_party/WebKit/Source/modules/ballista/Actions.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..076eb74730321df67656bb430202b3ec61a6126d |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/modules/ballista/Actions.cpp |
| @@ -0,0 +1,55 @@ |
| +// 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 "modules/ballista/Actions.h" |
| + |
| +#include "core/dom/DOMException.h" |
| +#include "core/dom/ExceptionCode.h" |
| +#include "mojo/public/cpp/bindings/string.h" |
| +#include "public/platform/Platform.h" |
| +#include "wtf/PassOwnPtr.h" |
| + |
| +namespace blink { |
| + |
| +Actions::BallistaClientImpl::BallistaClientImpl(ScriptPromiseResolver* resolver) |
| + : m_resolver(resolver) |
| +{ |
| +} |
| + |
| +void Actions::BallistaClientImpl::bind(const mojo::String& error) { |
| + if (error.is_null()) |
| + m_resolver->resolve(); |
| + else |
| + m_resolver->reject(DOMException::create(AbortError, String::fromUTF8(error.data(), error.size()))); |
| +} |
| + |
| +Actions::~Actions() = default; |
| + |
| +ScriptPromise Actions::share(ScriptState* scriptState, const String& title, const String& text) |
| +{ |
| + if (!m_service) |
| + Platform::current()->connectToRemoteService(mojo::GetProxy(&m_service)); |
| + |
| + ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
| + BallistaClientImpl* client = new BallistaClientImpl(resolver); |
| + m_clients.add(client); |
| + ScriptPromise promise = resolver->promise(); |
| + |
| + mojo::String titleMojo(title.utf8().data()); |
| + mojo::String textMojo(text.utf8().data()); |
| + m_service->Share(titleMojo, textMojo, [this, client](const mojo::String& error) { |
|
Sam McNally
2016/04/01 02:51:25
Use sameThreadBindForMojo() to bind.
Matt Giuca
2016/04/12 06:12:21
Done.
|
| + if (m_clients.contains(client)) { |
| + client->bind(error); |
| + m_clients.remove(client); |
| + } |
| + }); |
| + |
| + return promise; |
| +} |
| + |
| +Actions::Actions() |
| +{ |
| +} |
| + |
| +} // namespace blink |