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

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

Issue 2393513004: Convert app banners to use Mojo. (Closed)
Patch Set: Rebase 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..4e51d7bc09bf1e80593a18b8a1702bed65d5b6d9 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/WebString.h"
esprehn 2016/10/07 00:39:51 it's very strange to use WebString inside modules
dominickn 2016/10/13 00:18:15 Done.
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(
esprehn 2016/10/07 00:39:51 Nothing uses mojo::MakeProxy inside blink today, w
+ std::move(serviceHandle),
+ mojom::blink::AppBannerService::Version_))),
esprehn 2016/10/07 00:39:51 We never pass a Version_ anywhere else in blink, w
dcheng 2016/10/07 07:03:16 Before we get here, is it possible to turn it back
+ 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_bannerService.reset();
+ m_binding.Close();
+}
+
Vector<String> BeforeInstallPromptEvent::platforms() const {
return m_platforms;
}
@@ -48,14 +56,10 @@ 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()));
- }
+ // |m_binding| must be bound to allow the AppBannerService to resolve the
+ // userChoice promise.
+ if (m_userChoice && m_binding.is_bound())
return m_userChoice->promise(scriptState->world());
- }
return ScriptPromise::rejectWithDOMException(
scriptState,
DOMException::create(InvalidStateError,
@@ -66,20 +70,17 @@ 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)
+ // |m_bannerService| must be bound to allow us to inform the AppBannerService
+ // to display the banner now.
+ 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 +94,16 @@ void BeforeInstallPromptEvent::preventDefault() {
UseCounter::BeforeInstallPromptEventPreventDefault);
}
+void BeforeInstallPromptEvent::BannerAccepted(const WTF::String& platform) {
esprehn 2016/10/07 00:39:51 Don't need the WTF:: on wtf things
dominickn 2016/10/13 00:18:15 Done.
+ 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);

Powered by Google App Engine
This is Rietveld 408576698