Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1057)

Unified Diff: Source/modules/app_banner/BeforeInstallPromptEvent.cpp

Issue 1247283004: Refactor BeforeInstallPromptEvent to use ScriptPromiseProperty (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Replace typedef with using as per style guide Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/modules/app_banner/BeforeInstallPromptEvent.cpp
diff --git a/Source/modules/app_banner/BeforeInstallPromptEvent.cpp b/Source/modules/app_banner/BeforeInstallPromptEvent.cpp
index c4d117dd853329d8168d27b16327fbb5f745a663..391f514ad1ad1cdb6b3445bda99372399496709c 100644
--- a/Source/modules/app_banner/BeforeInstallPromptEvent.cpp
+++ b/Source/modules/app_banner/BeforeInstallPromptEvent.cpp
@@ -5,12 +5,9 @@
#include "config.h"
#include "modules/app_banner/BeforeInstallPromptEvent.h"
-#include "bindings/core/v8/CallbackPromiseAdapter.h"
#include "bindings/core/v8/ScriptPromise.h"
-#include "bindings/core/v8/ScriptPromiseResolver.h"
#include "core/dom/DOMException.h"
#include "core/dom/ExceptionCode.h"
-#include "modules/app_banner/AppBannerPromptResult.h"
#include "modules/app_banner/BeforeInstallPromptEventInit.h"
#include "public/platform/modules/app_banner/WebAppBannerClient.h"
@@ -20,12 +17,14 @@ BeforeInstallPromptEvent::BeforeInstallPromptEvent()
{
}
-BeforeInstallPromptEvent::BeforeInstallPromptEvent(const AtomicString& name, const Vector<String>& platforms, int requestId, WebAppBannerClient* client)
+BeforeInstallPromptEvent::BeforeInstallPromptEvent(const AtomicString& name, ExecutionContext* executionContext, const Vector<String>& platforms, int requestId, WebAppBannerClient* client)
: Event(name, false, true)
, m_platforms(platforms)
, m_requestId(requestId)
, m_client(client)
, m_redispatched(false)
+ , m_userChoice(new UserChoiceProperty(executionContext, this, UserChoiceProperty::UserChoice))
+ , m_prompt(new PromptProperty(executionContext, this, PromptProperty::Prompt))
{
}
@@ -50,14 +49,9 @@ Vector<String> BeforeInstallPromptEvent::platforms() const
ScriptPromise BeforeInstallPromptEvent::userChoice(ScriptState* scriptState)
{
- if (m_userChoice.isEmpty() && m_client) {
- ASSERT(m_requestId != -1);
- RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scriptState);
- m_userChoice = resolver->promise();
- m_client->registerBannerCallbacks(m_requestId, new CallbackPromiseAdapter<AppBannerPromptResult, void>(resolver));
- }
-
- return m_userChoice;
+ if (m_userChoice)
+ return m_userChoice->promise(scriptState->world());
+ return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(InvalidStateError, "The prompt() method cannot be called on this event."));
}
const AtomicString& BeforeInstallPromptEvent::interfaceName() const
@@ -67,14 +61,27 @@ const AtomicString& BeforeInstallPromptEvent::interfaceName() const
ScriptPromise BeforeInstallPromptEvent::prompt(ScriptState* scriptState)
{
- if (m_client && defaultPrevented() && !m_redispatched) {
- ASSERT(m_requestId != -1);
- m_redispatched = true;
- m_client->showAppBanner(m_requestId);
- return ScriptPromise::cast(scriptState, v8::Undefined(scriptState->isolate()));
+ if (m_prompt) {
+ if (m_prompt->state() == PromptProperty::Pending) {
+ if (m_client && defaultPrevented() && !m_redispatched) {
+ ASSERT(m_requestId != -1);
+ m_redispatched = true;
+ m_prompt->resolve(ToV8UndefinedGenerator());
+ m_client->showAppBanner(m_requestId);
+ } else {
+ m_prompt->reject(DOMException::create(InvalidStateError, "The prompt() method may only be called once, following preventDefault()."));
+ }
+ }
+ return m_prompt->promise(scriptState->world());
}
+ return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(InvalidStateError, "The prompt() method cannot be called on this event."));
mlamouri (slow - plz ping) 2015/07/24 15:08:25 Linus Torvalds once said "If you need more than 3
dominickn 2015/07/24 23:53:36 Done, and I even removed m_redispatched because th
+}
- return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(InvalidStateError, "The prompt() method may only be called once, following preventDefault()."));
+DEFINE_TRACE(BeforeInstallPromptEvent)
+{
+ visitor->trace(m_userChoice);
+ visitor->trace(m_prompt);
+ Event::trace(visitor);
}
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698