Chromium Code Reviews| 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..8dd5a681b9ab89042a1d97c58b75a6ad5b142fc0 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/PtrUtil.h" |
| +#include "wtf/text/AtomicString.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( |
|
haraken
2016/10/20 15:51:23
Shall we rename this to createMojoBinding? In Blin
dominickn
2016/10/20 23:41:18
Renamed to bindMojoRequest, since that seems to be
|
| LocalFrame* frame, |
| - 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(wrapUnique(new AppBannerController(frame)), |
| + std::move(request)); |
| +} |
| + |
| +void AppBannerController::BannerPromptRequest( |
| + mojom::blink::AppBannerServicePtr servicePtr, |
| + mojom::blink::AppBannerEventRequest eventRequest, |
| + const Vector<String>& platforms, |
| + const BannerPromptRequestCallback& callback) { |
| + if (!m_frame) { |
|
haraken
2016/10/20 08:43:18
Who clears m_frame when the frame gets detached?
dominickn
2016/10/20 11:41:34
I don't think that's necessary. AppBannerControlle
haraken
2016/10/20 15:51:23
Thanks for the clarification. Makes sense.
|
| + 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 |