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..b9437c349036145eeafe9eae98d29e7ce01af335 |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/modules/ballista/Actions.cpp |
| @@ -0,0 +1,67 @@ |
| +// 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/Document.h" |
| +#include "core/dom/ExceptionCode.h" |
| +#include "core/frame/LocalFrame.h" |
| +#include "platform/MojoHelper.h" |
| +#include "public/platform/Platform.h" |
| +#include "public/platform/ServiceRegistry.h" |
| +#include "wtf/PassOwnPtr.h" |
| + |
| +namespace blink { |
| + |
| +Actions::BallistaClientImpl::BallistaClientImpl(Actions* actions, ScriptPromiseResolver* resolver) |
| + : m_actions(actions) |
| + , m_resolver(resolver) |
| +{ |
| +} |
| + |
| +void Actions::BallistaClientImpl::callback(const String& error) |
| +{ |
| + if (m_actions && m_actions->m_clients.contains(this)) |
|
Sam McNally
2016/04/13 04:32:35
When would m_clients not contain this?
Matt Giuca
2016/04/13 05:43:02
Done.
|
| + m_actions->m_clients.remove(this); |
| + |
| + if (error.isNull()) |
| + m_resolver->resolve(); |
| + else |
| + m_resolver->reject(DOMException::create(AbortError, error)); |
| +} |
| + |
| +Actions::~Actions() = default; |
| + |
| +ScriptPromise Actions::share(ScriptState* scriptState, const String& title, const String& text) |
| +{ |
| + if (!m_service) |
| + frame(scriptState)->serviceRegistry()->connectToRemoteService(mojo::GetProxy(&m_service)); |
| + |
| + ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
| + BallistaClientImpl* client = new BallistaClientImpl(this, resolver); |
| + m_clients.add(client); |
| + ScriptPromise promise = resolver->promise(); |
| + |
| + m_service->Share(title, text, sameThreadBindForMojo(&BallistaClientImpl::callback, client)); |
| + |
| + return promise; |
| +} |
| + |
| +Actions::Actions() |
| +{ |
| +} |
| + |
| +Document* Actions::document(ScriptState* scriptState) const |
| +{ |
| + return toDocument(scriptState->getExecutionContext()); |
| +} |
| + |
| +LocalFrame* Actions::frame(ScriptState* scriptState) const |
| +{ |
| + Document* doc = document(scriptState); |
| + return doc ? doc->frame() : nullptr; |
| +} |
| + |
| +} // namespace blink |