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