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

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

Issue 2393513004: Convert app banners to use Mojo. (Closed)
Patch Set: Fix Win clang compile Created 4 years, 2 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: 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..b85517abf2d5479c206c2e896fe3c7e8b5be42a6 100644
--- a/third_party/WebKit/Source/modules/app_banner/BeforeInstallPromptEvent.cpp
+++ b/third_party/WebKit/Source/modules/app_banner/BeforeInstallPromptEvent.cpp
@@ -4,37 +4,42 @@
#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"
+#include "public/platform/modules/app_banner/WebAppBannerPromptResult.h"
namespace blink {
BeforeInstallPromptEvent::BeforeInstallPromptEvent(
const AtomicString& name,
- ExecutionContext* executionContext,
- const Vector<String>& platforms,
+ LocalFrame* frame,
int requestId,
- WebAppBannerClient* client)
+ const Vector<String>& platforms)
: Event(name, false, true),
- m_platforms(platforms),
+ m_binding(this),
m_requestId(requestId),
- m_client(client),
- m_userChoice(new UserChoiceProperty(executionContext,
+ m_platforms(platforms),
+ m_userChoice(new UserChoiceProperty(frame->document(),
this,
UserChoiceProperty::UserChoice)),
- m_registered(false) {
- UseCounter::count(executionContext, UseCounter::BeforeInstallPromptEvent);
+ m_promptCalled(false) {
+ UseCounter::count(frame, UseCounter::BeforeInstallPromptEvent);
+ frame->interfaceProvider()->getInterface(mojo::GetProxy(&m_bannerService));
+ m_bannerService->SetEvent(m_binding.CreateInterfacePtrAndBind());
}
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_requestId(-1),
+ m_promptCalled(false) {
if (init.hasPlatforms())
m_platforms = init.platforms();
}
@@ -48,14 +53,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_requestId != -1)
return m_userChoice->promise(scriptState->world());
- }
return ScriptPromise::rejectWithDOMException(
scriptState,
DOMException::create(InvalidStateError,
@@ -66,20 +65,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_requestId == -1)
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(m_requestId);
return ScriptPromise::castUndefined(scriptState);
}
@@ -93,6 +87,21 @@ void BeforeInstallPromptEvent::preventDefault() {
UseCounter::BeforeInstallPromptEventPreventDefault);
}
+void BeforeInstallPromptEvent::BannerAccepted(int requestId,
+ const WTF::String& platform) {
+ if (requestId != m_requestId)
+ return;
+ m_userChoice->resolve(AppBannerPromptResult::create(
+ platform, WebAppBannerPromptResult::Outcome::Accepted));
+}
+
+void BeforeInstallPromptEvent::BannerDismissed(int requestId) {
+ if (requestId != m_requestId)
+ return;
+ m_userChoice->resolve(AppBannerPromptResult::create(
+ "", WebAppBannerPromptResult::Outcome::Dismissed));
+}
+
DEFINE_TRACE(BeforeInstallPromptEvent) {
visitor->trace(m_userChoice);
Event::trace(visitor);

Powered by Google App Engine
This is Rietveld 408576698