Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / chrome / renderer / banners / app_banner_client.cc
blobdd0b07c89fb421e2c99e236caae464c32bb69699
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) {
21 bool handled = true;
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)
26 IPC_END_MESSAGE_MAP()
27 return handled;
30 void AppBannerClient::registerBannerCallbacks(
31 int request_id,
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(
41 int request_id,
42 const std::string& platform,
43 const blink::WebAppBannerPromptResult::Outcome& outcome) {
44 blink::WebAppBannerCallbacks* callbacks =
45 banner_callbacks_.Lookup(request_id);
46 if (!callbacks)
47 return;
49 scoped_ptr<blink::WebAppBannerPromptResult> result(
50 new blink::WebAppBannerPromptResult(
51 blink::WebString::fromUTF8(platform),
52 outcome));
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);