blob: 8bd381f7c97df971ee70604a7804d264e6aad7ef [file] [log] [blame]
constantinac8b2173b2016-12-15 05:55:511// Copyright 2016 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.
4
5#ifndef CHROME_BROWSER_WEBSHARE_SHARE_SERVICE_IMPL_H_
6#define CHROME_BROWSER_WEBSHARE_SHARE_SERVICE_IMPL_H_
7
8#include <string>
9
constantina2cfa55e2017-01-13 06:36:5510#include "base/gtest_prod_util.h"
constantinac8b2173b2016-12-15 05:55:5111#include "mojo/public/cpp/bindings/interface_request.h"
12#include "third_party/WebKit/public/platform/modules/webshare/webshare.mojom.h"
13
14class GURL;
15
16// Desktop implementation of the ShareService Mojo service.
17class ShareServiceImpl : public blink::mojom::ShareService {
18 public:
19 ShareServiceImpl() = default;
20 ~ShareServiceImpl() override = default;
21
22 static void Create(mojo::InterfaceRequest<ShareService> request);
23
constantina2cfa55e2017-01-13 06:36:5524 // blink::mojom::ShareService overrides:
constantinac8b2173b2016-12-15 05:55:5125 void Share(const std::string& title,
26 const std::string& text,
constantina2cfa55e2017-01-13 06:36:5527 const GURL& share_url,
constantinac8b2173b2016-12-15 05:55:5128 const ShareCallback& callback) override;
29
30 private:
constantina2cfa55e2017-01-13 06:36:5531 FRIEND_TEST_ALL_PREFIXES(ShareServiceImplUnittest, ReplacePlaceholders);
32
33 // Opens a new tab and navigates to |target_url|.
34 // Virtual for testing purposes.
35 virtual void OpenTargetURL(const GURL& target_url);
36
37 // Writes to |url_template_filled|, a copy of |url_template| with all
38 // instances of "{title}", "{text}", and "{url}" replaced with
39 // |title|, |text|, and |url| respectively.
40 // Replaces instances of "{X}" where "X" is any string besides "title",
41 // "text", and "url", with an empty string, for forwards compatibility.
42 // Returns false, if there are badly nested placeholders.
43 // This includes any case in which two "{" occur before a "}", or a "}"
44 // occurs with no preceding "{".
45 static bool ReplacePlaceholders(base::StringPiece url_template,
46 base::StringPiece title,
47 base::StringPiece text,
48 const GURL& share_url,
49 std::string* url_template_filled);
50
constantinac8b2173b2016-12-15 05:55:5151 DISALLOW_COPY_AND_ASSIGN(ShareServiceImpl);
52};
53
54#endif // CHROME_BROWSER_WEBSHARE_SHARE_SERVICE_IMPL_H_