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
3 // found in the LICENSE file.
5 #include "chrome/renderer/banners/app_banner_client.h"
7 #include "chrome/common/render_messages.h"
8 #include "ipc/ipc_message.h"
9 #include "third_party/WebKit/public/platform/WebString.h"
11 using blink::WebString
;
13 AppBannerClient::AppBannerClient(content::RenderFrame
* render_frame
)
14 : content::RenderFrameObserver(render_frame
) {
17 AppBannerClient::~AppBannerClient() {
20 bool AppBannerClient::OnMessageReceived(const IPC::Message
& message
) {
22 IPC_BEGIN_MESSAGE_MAP(AppBannerClient
, message
)
23 IPC_MESSAGE_HANDLER(ChromeViewMsg_AppBannerAccepted
, OnBannerAccepted
);
24 IPC_MESSAGE_HANDLER(ChromeViewMsg_AppBannerDismissed
, OnBannerDismissed
);
25 IPC_MESSAGE_UNHANDLED(handled
= false)
30 void AppBannerClient::registerBannerCallbacks(
32 blink::WebAppBannerCallbacks
* callbacks
) {
33 banner_callbacks_
.AddWithID(callbacks
, request_id
);
36 void AppBannerClient::showAppBanner(int request_id
) {
37 Send(new ChromeViewHostMsg_RequestShowAppBanner(routing_id(), request_id
));
40 void AppBannerClient::ResolveEvent(
42 const std::string
& platform
,
43 const blink::WebAppBannerPromptResult::Outcome
& outcome
) {
44 blink::WebAppBannerCallbacks
* callbacks
=
45 banner_callbacks_
.Lookup(request_id
);
49 scoped_ptr
<blink::WebAppBannerPromptResult
> result(
50 new blink::WebAppBannerPromptResult(
51 blink::WebString::fromUTF8(platform
),
53 callbacks
->onSuccess(result
.release());
54 banner_callbacks_
.Remove(request_id
);
57 void AppBannerClient::OnBannerAccepted(int request_id
,
58 const std::string
& platform
) {
59 ResolveEvent(request_id
, platform
,
60 blink::WebAppBannerPromptResult::Outcome::Accepted
);
63 void AppBannerClient::OnBannerDismissed(int request_id
) {
64 ResolveEvent(request_id
, "",
65 blink::WebAppBannerPromptResult::Outcome::Dismissed
);