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..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 |