summaryrefslogtreecommitdiffstats
path: root/components/test_runner/app_banner_client.cc
blob: 6e3afbddf45e7d3245f0efc285144ee2b7e22f89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/test_runner/app_banner_client.h"

#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "third_party/WebKit/public/platform/modules/app_banner/WebAppBannerPromptResult.h"

namespace test_runner {

AppBannerClient::AppBannerClient() {
}

AppBannerClient::~AppBannerClient() {
}

void AppBannerClient::registerBannerCallbacks(
    int requestId,
    blink::WebAppBannerCallbacks* callbacks) {
  callbacks_map_.AddWithID(callbacks, requestId);
}

void AppBannerClient::ResolvePromise(int request_id,
                                     const std::string& resolve_platform) {
  blink::WebAppBannerCallbacks* callbacks = callbacks_map_.Lookup(request_id);
  if (!callbacks)
    return;

  scoped_ptr<blink::WebAppBannerPromptResult> result(
      new blink::WebAppBannerPromptResult(
          blink::WebString::fromUTF8(resolve_platform),
          blink::WebAppBannerPromptResult::Outcome::Accepted));

  // If no platform has been set, treat it as dismissal.
  if (resolve_platform.empty())
    result->outcome = blink::WebAppBannerPromptResult::Outcome::Dismissed;

  callbacks->onSuccess(result.release());
  callbacks_map_.Remove(request_id);
}

}  // namespace test_runner