constantina | c8b2173b | 2016-12-15 05:55:51 | [diff] [blame] | 1 | // 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 | |
constantina | 2cfa55e | 2017-01-13 06:36:55 | [diff] [blame] | 10 | #include "base/gtest_prod_util.h" |
mgiuca | 39e4067 | 2017-01-31 04:16:49 | [diff] [blame^] | 11 | #include "base/strings/string16.h" |
constantina | c8b2173b | 2016-12-15 05:55:51 | [diff] [blame] | 12 | #include "mojo/public/cpp/bindings/interface_request.h" |
| 13 | #include "third_party/WebKit/public/platform/modules/webshare/webshare.mojom.h" |
| 14 | |
| 15 | class GURL; |
| 16 | |
mgiuca | 39e4067 | 2017-01-31 04:16:49 | [diff] [blame^] | 17 | enum class SharePickerResult { |
| 18 | CANCEL, |
| 19 | SHARE |
| 20 | }; |
| 21 | |
constantina | c8b2173b | 2016-12-15 05:55:51 | [diff] [blame] | 22 | // Desktop implementation of the ShareService Mojo service. |
| 23 | class ShareServiceImpl : public blink::mojom::ShareService { |
| 24 | public: |
| 25 | ShareServiceImpl() = default; |
| 26 | ~ShareServiceImpl() override = default; |
| 27 | |
| 28 | static void Create(mojo::InterfaceRequest<ShareService> request); |
| 29 | |
constantina | 2cfa55e | 2017-01-13 06:36:55 | [diff] [blame] | 30 | // blink::mojom::ShareService overrides: |
constantina | c8b2173b | 2016-12-15 05:55:51 | [diff] [blame] | 31 | void Share(const std::string& title, |
| 32 | const std::string& text, |
constantina | 2cfa55e | 2017-01-13 06:36:55 | [diff] [blame] | 33 | const GURL& share_url, |
constantina | c8b2173b | 2016-12-15 05:55:51 | [diff] [blame] | 34 | const ShareCallback& callback) override; |
| 35 | |
| 36 | private: |
constantina | 2cfa55e | 2017-01-13 06:36:55 | [diff] [blame] | 37 | FRIEND_TEST_ALL_PREFIXES(ShareServiceImplUnittest, ReplacePlaceholders); |
| 38 | |
mgiuca | 39e4067 | 2017-01-31 04:16:49 | [diff] [blame^] | 39 | // Shows the share picker dialog with |targets| as the list of applications |
| 40 | // presented to the user. Passes the result to |callback|. Virtual for |
| 41 | // testing. |
| 42 | virtual void ShowPickerDialog( |
| 43 | const std::vector<base::string16>& targets, |
| 44 | const base::Callback<void(SharePickerResult)>& callback); |
| 45 | |
constantina | 2cfa55e | 2017-01-13 06:36:55 | [diff] [blame] | 46 | // Opens a new tab and navigates to |target_url|. |
| 47 | // Virtual for testing purposes. |
| 48 | virtual void OpenTargetURL(const GURL& target_url); |
| 49 | |
| 50 | // Writes to |url_template_filled|, a copy of |url_template| with all |
| 51 | // instances of "{title}", "{text}", and "{url}" replaced with |
| 52 | // |title|, |text|, and |url| respectively. |
| 53 | // Replaces instances of "{X}" where "X" is any string besides "title", |
| 54 | // "text", and "url", with an empty string, for forwards compatibility. |
| 55 | // Returns false, if there are badly nested placeholders. |
| 56 | // This includes any case in which two "{" occur before a "}", or a "}" |
| 57 | // occurs with no preceding "{". |
| 58 | static bool ReplacePlaceholders(base::StringPiece url_template, |
| 59 | base::StringPiece title, |
| 60 | base::StringPiece text, |
| 61 | const GURL& share_url, |
| 62 | std::string* url_template_filled); |
| 63 | |
mgiuca | 39e4067 | 2017-01-31 04:16:49 | [diff] [blame^] | 64 | void OnPickerClosed(const std::string& title, |
| 65 | const std::string& text, |
| 66 | const GURL& share_url, |
| 67 | const ShareCallback& callback, |
| 68 | SharePickerResult result); |
| 69 | |
constantina | c8b2173b | 2016-12-15 05:55:51 | [diff] [blame] | 70 | DISALLOW_COPY_AND_ASSIGN(ShareServiceImpl); |
| 71 | }; |
| 72 | |
| 73 | #endif // CHROME_BROWSER_WEBSHARE_SHARE_SERVICE_IMPL_H_ |