| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_WEBSHARE_SHARE_SERVICE_IMPL_H_ | 5 #ifndef CHROME_BROWSER_WEBSHARE_SHARE_SERVICE_IMPL_H_ |
| 6 #define CHROME_BROWSER_WEBSHARE_SHARE_SERVICE_IMPL_H_ | 6 #define CHROME_BROWSER_WEBSHARE_SHARE_SERVICE_IMPL_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/gtest_prod_util.h" | 10 #include "base/gtest_prod_util.h" |
| 11 #include "base/strings/string16.h" |
| 11 #include "mojo/public/cpp/bindings/interface_request.h" | 12 #include "mojo/public/cpp/bindings/interface_request.h" |
| 12 #include "third_party/WebKit/public/platform/modules/webshare/webshare.mojom.h" | 13 #include "third_party/WebKit/public/platform/modules/webshare/webshare.mojom.h" |
| 13 | 14 |
| 14 class GURL; | 15 class GURL; |
| 15 | 16 |
| 17 enum class SharePickerResult { |
| 18 CANCEL, |
| 19 SHARE |
| 20 }; |
| 21 |
| 16 // Desktop implementation of the ShareService Mojo service. | 22 // Desktop implementation of the ShareService Mojo service. |
| 17 class ShareServiceImpl : public blink::mojom::ShareService { | 23 class ShareServiceImpl : public blink::mojom::ShareService { |
| 18 public: | 24 public: |
| 19 ShareServiceImpl() = default; | 25 ShareServiceImpl() = default; |
| 20 ~ShareServiceImpl() override = default; | 26 ~ShareServiceImpl() override = default; |
| 21 | 27 |
| 22 static void Create(mojo::InterfaceRequest<ShareService> request); | 28 static void Create(mojo::InterfaceRequest<ShareService> request); |
| 23 | 29 |
| 24 // blink::mojom::ShareService overrides: | 30 // blink::mojom::ShareService overrides: |
| 25 void Share(const std::string& title, | 31 void Share(const std::string& title, |
| 26 const std::string& text, | 32 const std::string& text, |
| 27 const GURL& share_url, | 33 const GURL& share_url, |
| 28 const ShareCallback& callback) override; | 34 const ShareCallback& callback) override; |
| 29 | 35 |
| 30 private: | 36 private: |
| 31 FRIEND_TEST_ALL_PREFIXES(ShareServiceImplUnittest, ReplacePlaceholders); | 37 FRIEND_TEST_ALL_PREFIXES(ShareServiceImplUnittest, ReplacePlaceholders); |
| 32 | 38 |
| 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 |
| 33 // Opens a new tab and navigates to |target_url|. | 46 // Opens a new tab and navigates to |target_url|. |
| 34 // Virtual for testing purposes. | 47 // Virtual for testing purposes. |
| 35 virtual void OpenTargetURL(const GURL& target_url); | 48 virtual void OpenTargetURL(const GURL& target_url); |
| 36 | 49 |
| 37 // Writes to |url_template_filled|, a copy of |url_template| with all | 50 // Writes to |url_template_filled|, a copy of |url_template| with all |
| 38 // instances of "{title}", "{text}", and "{url}" replaced with | 51 // instances of "{title}", "{text}", and "{url}" replaced with |
| 39 // |title|, |text|, and |url| respectively. | 52 // |title|, |text|, and |url| respectively. |
| 40 // Replaces instances of "{X}" where "X" is any string besides "title", | 53 // Replaces instances of "{X}" where "X" is any string besides "title", |
| 41 // "text", and "url", with an empty string, for forwards compatibility. | 54 // "text", and "url", with an empty string, for forwards compatibility. |
| 42 // Returns false, if there are badly nested placeholders. | 55 // Returns false, if there are badly nested placeholders. |
| 43 // This includes any case in which two "{" occur before a "}", or a "}" | 56 // This includes any case in which two "{" occur before a "}", or a "}" |
| 44 // occurs with no preceding "{". | 57 // occurs with no preceding "{". |
| 45 static bool ReplacePlaceholders(base::StringPiece url_template, | 58 static bool ReplacePlaceholders(base::StringPiece url_template, |
| 46 base::StringPiece title, | 59 base::StringPiece title, |
| 47 base::StringPiece text, | 60 base::StringPiece text, |
| 48 const GURL& share_url, | 61 const GURL& share_url, |
| 49 std::string* url_template_filled); | 62 std::string* url_template_filled); |
| 50 | 63 |
| 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 |
| 51 DISALLOW_COPY_AND_ASSIGN(ShareServiceImpl); | 70 DISALLOW_COPY_AND_ASSIGN(ShareServiceImpl); |
| 52 }; | 71 }; |
| 53 | 72 |
| 54 #endif // CHROME_BROWSER_WEBSHARE_SHARE_SERVICE_IMPL_H_ | 73 #endif // CHROME_BROWSER_WEBSHARE_SHARE_SERVICE_IMPL_H_ |
| OLD | NEW |