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

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

Issue 2393513004: Convert app banners to use Mojo. (Closed)
Patch Set: Rebase. init() can cause frames to detach 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/AppBannerController.cpp
diff --git a/third_party/WebKit/Source/modules/app_banner/AppBannerController.cpp b/third_party/WebKit/Source/modules/app_banner/AppBannerController.cpp
index 98efdd2747064feb0e1ea7107f522345c10b4685..ab79bbdaefd1c3a95b8facfb1858f2b1a8384920 100644
--- a/third_party/WebKit/Source/modules/app_banner/AppBannerController.cpp
+++ b/third_party/WebKit/Source/modules/app_banner/AppBannerController.cpp
@@ -9,31 +9,53 @@
#include "core/frame/DOMWindow.h"
#include "core/frame/LocalFrame.h"
#include "modules/app_banner/BeforeInstallPromptEvent.h"
-#include "public/platform/WebVector.h"
-#include "public/platform/modules/app_banner/WebAppBannerClient.h"
-#include "public/platform/modules/app_banner/WebAppBannerPromptReply.h"
+#include "mojo/public/cpp/bindings/strong_binding.h"
+#include "platform/weborigin/KURL.h"
+#include "platform/weborigin/Referrer.h"
+#include "platform/weborigin/SecurityPolicy.h"
+#include "wtf/text/WTFString.h"
+#include <memory>
+#include <utility>
namespace blink {
-// static
-void AppBannerController::willShowInstallBannerPrompt(
- int requestId,
- WebAppBannerClient* client,
+AppBannerController::AppBannerController(LocalFrame* frame) : m_frame(frame) {}
+
+void AppBannerController::create(
LocalFrame* frame,
dcheng 2016/10/19 06:15:58 I don't think we'll ever pass in a non-null |frame
dominickn 2016/10/19 08:16:59 This method is invoked by WTF::bind. Can it take a
- const WebVector<WebString>& platforms,
- WebAppBannerPromptReply* reply) {
- Vector<String> wtfPlatforms;
- for (const WebString& platform : platforms)
- wtfPlatforms.append(platform);
-
- // dispatchEvent() returns whether the default behavior can happen. In other
- // words, it returns false if preventDefault() was called.
- *reply =
- frame->domWindow()->dispatchEvent(BeforeInstallPromptEvent::create(
- EventTypeNames::beforeinstallprompt, frame->document(), wtfPlatforms,
- requestId, client)) == DispatchEventResult::NotCanceled
- ? WebAppBannerPromptReply::None
- : WebAppBannerPromptReply::Cancel;
+ mojom::blink::AppBannerControllerRequest request) {
+ if (!frame)
+ return;
+
+ mojo::MakeStrongBinding(
+ std::unique_ptr<AppBannerController>(new AppBannerController(frame)),
dcheng 2016/10/19 06:15:58 Nit: wrapUnique from wtf/PtrUtil.h
dominickn 2016/10/19 08:16:59 Done.
+ std::move(request));
+}
+
+void AppBannerController::BannerPromptRequest(
+ mojom::blink::AppBannerServicePtr servicePtr,
+ mojom::blink::AppBannerEventRequest eventRequest,
+ const Vector<String>& platforms,
+ const BannerPromptRequestCallback& callback) {
+ if (!m_frame) {
+ callback.Run(mojom::blink::AppBannerPromptReply::NONE, "");
+ return;
+ }
+
+ mojom::AppBannerPromptReply reply =
+ m_frame->domWindow()->dispatchEvent(BeforeInstallPromptEvent::create(
+ EventTypeNames::beforeinstallprompt, m_frame, std::move(servicePtr),
+ std::move(eventRequest), platforms)) ==
+ DispatchEventResult::NotCanceled
+ ? mojom::AppBannerPromptReply::NONE
+ : mojom::AppBannerPromptReply::CANCEL;
+
+ AtomicString referrer = SecurityPolicy::generateReferrer(
+ m_frame->document()->getReferrerPolicy(), KURL(),
+ m_frame->document()->outgoingReferrer())
+ .referrer;
+
+ callback.Run(reply, referrer.isNull() ? emptyString() : referrer);
}
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698