Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "modules/app_banner/AppBannerController.h" | 5 #include "modules/app_banner/AppBannerController.h" |
| 6 | 6 |
| 7 #include "core/EventTypeNames.h" | 7 #include "core/EventTypeNames.h" |
| 8 #include "core/dom/Document.h" | 8 #include "core/dom/Document.h" |
| 9 #include "core/frame/DOMWindow.h" | 9 #include "core/frame/DOMWindow.h" |
| 10 #include "core/frame/LocalFrame.h" | 10 #include "core/frame/LocalFrame.h" |
| 11 #include "modules/app_banner/BeforeInstallPromptEvent.h" | 11 #include "modules/app_banner/BeforeInstallPromptEvent.h" |
| 12 #include "public/platform/WebVector.h" | 12 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 13 #include "public/platform/modules/app_banner/WebAppBannerClient.h" | 13 #include "platform/weborigin/KURL.h" |
| 14 #include "public/platform/modules/app_banner/WebAppBannerPromptReply.h" | 14 #include "platform/weborigin/Referrer.h" |
| 15 #include "platform/weborigin/SecurityPolicy.h" | |
| 16 #include "wtf/PtrUtil.h" | |
| 17 #include "wtf/text/AtomicString.h" | |
| 18 #include <memory> | |
| 19 #include <utility> | |
| 15 | 20 |
| 16 namespace blink { | 21 namespace blink { |
| 17 | 22 |
| 18 // static | 23 AppBannerController::AppBannerController(LocalFrame* frame) : m_frame(frame) {} |
| 19 void AppBannerController::willShowInstallBannerPrompt( | 24 |
| 20 int requestId, | 25 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
| |
| 21 WebAppBannerClient* client, | |
| 22 LocalFrame* frame, | 26 LocalFrame* frame, |
| 23 const WebVector<WebString>& platforms, | 27 mojom::blink::AppBannerControllerRequest request) { |
| 24 WebAppBannerPromptReply* reply) { | 28 if (!frame) |
| 25 Vector<String> wtfPlatforms; | 29 return; |
| 26 for (const WebString& platform : platforms) | |
| 27 wtfPlatforms.append(platform); | |
| 28 | 30 |
| 29 // dispatchEvent() returns whether the default behavior can happen. In other | 31 mojo::MakeStrongBinding(wrapUnique(new AppBannerController(frame)), |
| 30 // words, it returns false if preventDefault() was called. | 32 std::move(request)); |
| 31 *reply = | 33 } |
| 32 frame->domWindow()->dispatchEvent(BeforeInstallPromptEvent::create( | 34 |
| 33 EventTypeNames::beforeinstallprompt, frame->document(), wtfPlatforms, | 35 void AppBannerController::BannerPromptRequest( |
| 34 requestId, client)) == DispatchEventResult::NotCanceled | 36 mojom::blink::AppBannerServicePtr servicePtr, |
| 35 ? WebAppBannerPromptReply::None | 37 mojom::blink::AppBannerEventRequest eventRequest, |
| 36 : WebAppBannerPromptReply::Cancel; | 38 const Vector<String>& platforms, |
| 39 const BannerPromptRequestCallback& callback) { | |
| 40 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.
| |
| 41 callback.Run(mojom::blink::AppBannerPromptReply::NONE, ""); | |
| 42 return; | |
| 43 } | |
| 44 | |
| 45 mojom::AppBannerPromptReply reply = | |
| 46 m_frame->domWindow()->dispatchEvent(BeforeInstallPromptEvent::create( | |
| 47 EventTypeNames::beforeinstallprompt, *m_frame, std::move(servicePtr), | |
| 48 std::move(eventRequest), platforms)) == | |
| 49 DispatchEventResult::NotCanceled | |
| 50 ? mojom::AppBannerPromptReply::NONE | |
| 51 : mojom::AppBannerPromptReply::CANCEL; | |
| 52 | |
| 53 AtomicString referrer = SecurityPolicy::generateReferrer( | |
| 54 m_frame->document()->getReferrerPolicy(), KURL(), | |
| 55 m_frame->document()->outgoingReferrer()) | |
| 56 .referrer; | |
| 57 | |
| 58 callback.Run(reply, referrer.isNull() ? emptyString() : referrer); | |
| 37 } | 59 } |
| 38 | 60 |
| 39 } // namespace blink | 61 } // namespace blink |
| OLD | NEW |