Chromium Code Reviews| Index: third_party/WebKit/Source/modules/app_banner/BeforeInstallPromptEvent.cpp |
| diff --git a/third_party/WebKit/Source/modules/app_banner/BeforeInstallPromptEvent.cpp b/third_party/WebKit/Source/modules/app_banner/BeforeInstallPromptEvent.cpp |
| index 8c7d0e3a56a753581674b4ce98ef755d8ac84552..43843f4e76373b4d1a0d6f72930e98ee23756cb5 100644 |
| --- a/third_party/WebKit/Source/modules/app_banner/BeforeInstallPromptEvent.cpp |
| +++ b/third_party/WebKit/Source/modules/app_banner/BeforeInstallPromptEvent.cpp |
| @@ -4,43 +4,51 @@ |
| #include "modules/app_banner/BeforeInstallPromptEvent.h" |
| -#include "bindings/core/v8/ScriptPromise.h" |
| #include "core/dom/DOMException.h" |
| +#include "core/dom/Document.h" |
| #include "core/dom/ExceptionCode.h" |
| #include "core/frame/UseCounter.h" |
| -#include "modules/app_banner/AppBannerCallbacks.h" |
| #include "modules/app_banner/BeforeInstallPromptEventInit.h" |
| -#include "public/platform/modules/app_banner/WebAppBannerClient.h" |
| +#include "public/platform/InterfaceProvider.h" |
| +#include "public/platform/WebString.h" |
| namespace blink { |
| BeforeInstallPromptEvent::BeforeInstallPromptEvent( |
| const AtomicString& name, |
| - ExecutionContext* executionContext, |
| - const Vector<String>& platforms, |
| - int requestId, |
| - WebAppBannerClient* client) |
| + LocalFrame* frame, |
| + mojo::ScopedMessagePipeHandle serviceHandle, |
| + mojo::ScopedMessagePipeHandle eventHandle, |
| + const Vector<String>& platforms) |
| : Event(name, false, true), |
| + m_bannerService(mojo::MakeProxy(mojom::blink::AppBannerServicePtrInfo( |
| + std::move(serviceHandle), |
| + mojom::blink::AppBannerService::Version_))), |
| + m_binding(this, std::move(eventHandle)), |
| m_platforms(platforms), |
| - m_requestId(requestId), |
| - m_client(client), |
| - m_userChoice(new UserChoiceProperty(executionContext, |
| + m_userChoice(new UserChoiceProperty(frame->document(), |
| this, |
| UserChoiceProperty::UserChoice)), |
| - m_registered(false) { |
| - UseCounter::count(executionContext, UseCounter::BeforeInstallPromptEvent); |
| + m_promptCalled(false) { |
| + DCHECK(m_bannerService); |
| + DCHECK(m_binding.is_bound()); |
| + UseCounter::count(frame, UseCounter::BeforeInstallPromptEvent); |
| } |
| BeforeInstallPromptEvent::BeforeInstallPromptEvent( |
| const AtomicString& name, |
| const BeforeInstallPromptEventInit& init) |
| - : Event(name, false, true), m_requestId(-1), m_client(nullptr) { |
| + : Event(name, false, true), m_binding(this), m_promptCalled(false) { |
| if (init.hasPlatforms()) |
| m_platforms = init.platforms(); |
| } |
| BeforeInstallPromptEvent::~BeforeInstallPromptEvent() {} |
| +void BeforeInstallPromptEvent::dispose() { |
| + m_binding.Close(); |
|
Sam McNally
2016/10/06 22:48:48
Reset m_bannerService too.
dominickn
2016/10/06 23:38:10
Done.
|
| +} |
| + |
| Vector<String> BeforeInstallPromptEvent::platforms() const { |
| return m_platforms; |
| } |
| @@ -48,14 +56,8 @@ Vector<String> BeforeInstallPromptEvent::platforms() const { |
| ScriptPromise BeforeInstallPromptEvent::userChoice(ScriptState* scriptState) { |
| UseCounter::count(scriptState->getExecutionContext(), |
| UseCounter::BeforeInstallPromptEventUserChoice); |
| - if (m_userChoice && m_client && m_requestId != -1) { |
| - if (!m_registered) { |
| - m_registered = true; |
| - m_client->registerBannerCallbacks( |
| - m_requestId, new AppBannerCallbacks(m_userChoice.get())); |
| - } |
| + if (m_userChoice && m_binding.is_bound()) |
| return m_userChoice->promise(scriptState->world()); |
| - } |
| return ScriptPromise::rejectWithDOMException( |
| scriptState, |
| DOMException::create(InvalidStateError, |
| @@ -66,20 +68,15 @@ ScriptPromise BeforeInstallPromptEvent::prompt(ScriptState* scriptState) { |
| UseCounter::count(scriptState->getExecutionContext(), |
| UseCounter::BeforeInstallPromptEventPrompt); |
| - // |m_registered| will be true if userChoice has already been accessed |
| - // or prompt() has already been called. Return a rejected promise in both |
| - // these cases, as well as if we have a null client or invalid requestId. |
| - if (m_registered || !defaultPrevented() || !m_client || m_requestId == -1) |
| + if (!defaultPrevented() || m_promptCalled || !m_bannerService.is_bound()) |
| return ScriptPromise::rejectWithDOMException( |
| scriptState, |
| DOMException::create(InvalidStateError, |
| "The prompt() method may only be called once, " |
| "following preventDefault().")); |
| - m_registered = true; |
| - m_client->registerBannerCallbacks(m_requestId, |
| - new AppBannerCallbacks(m_userChoice.get())); |
| - m_client->showAppBanner(m_requestId); |
| + m_promptCalled = true; |
| + m_bannerService->DisplayAppBanner(); |
| return ScriptPromise::castUndefined(scriptState); |
| } |
| @@ -93,6 +90,16 @@ void BeforeInstallPromptEvent::preventDefault() { |
| UseCounter::BeforeInstallPromptEventPreventDefault); |
| } |
| +void BeforeInstallPromptEvent::BannerAccepted(const WTF::String& platform) { |
| + m_userChoice->resolve(AppBannerPromptResult::create( |
| + platform, AppBannerPromptResult::Outcome::Accepted)); |
| +} |
| + |
| +void BeforeInstallPromptEvent::BannerDismissed() { |
| + m_userChoice->resolve(AppBannerPromptResult::create( |
| + "", AppBannerPromptResult::Outcome::Dismissed)); |
| +} |
| + |
| DEFINE_TRACE(BeforeInstallPromptEvent) { |
| visitor->trace(m_userChoice); |
| Event::trace(visitor); |