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|. If the user picks a |
41 // testing. | 36 // target, the result passed to |callback| is the manifest URL of the chosen |
37 // target, and is null if the user cancelled the share. Virtual for testing. | |
Matt Giuca
2017/02/01 07:04:33
s/and/or :)
constantina
2017/02/01 23:24:21
Done :)
| |
42 virtual void ShowPickerDialog( | 38 virtual void ShowPickerDialog( |
43 const std::vector<base::string16>& targets, | 39 const std::vector<base::string16>& targets, |
44 const base::Callback<void(SharePickerResult)>& callback); | 40 const base::Callback<void(base::Optional<base::string16>)>& callback); |
45 | 41 |
46 // Opens a new tab and navigates to |target_url|. | 42 // Opens a new tab and navigates to |target_url|. |
47 // Virtual for testing purposes. | 43 // Virtual for testing purposes. |
48 virtual void OpenTargetURL(const GURL& target_url); | 44 virtual void OpenTargetURL(const GURL& target_url); |
49 | 45 |
50 // Writes to |url_template_filled|, a copy of |url_template| with all | 46 // Writes to |url_template_filled|, a copy of |url_template| with all |
51 // instances of "{title}", "{text}", and "{url}" replaced with | 47 // instances of "{title}", "{text}", and "{url}" replaced with |
52 // |title|, |text|, and |url| respectively. | 48 // |title|, |text|, and |url| respectively. |
53 // Replaces instances of "{X}" where "X" is any string besides "title", | 49 // Replaces instances of "{X}" where "X" is any string besides "title", |
54 // "text", and "url", with an empty string, for forwards compatibility. | 50 // "text", and "url", with an empty string, for forwards compatibility. |
55 // Returns false, if there are badly nested placeholders. | 51 // Returns false, if there are badly nested placeholders. |
56 // This includes any case in which two "{" occur before a "}", or a "}" | 52 // This includes any case in which two "{" occur before a "}", or a "}" |
57 // occurs with no preceding "{". | 53 // occurs with no preceding "{". |
58 static bool ReplacePlaceholders(base::StringPiece url_template, | 54 static bool ReplacePlaceholders(base::StringPiece url_template, |
59 base::StringPiece title, | 55 base::StringPiece title, |
60 base::StringPiece text, | 56 base::StringPiece text, |
61 const GURL& share_url, | 57 const GURL& share_url, |
62 std::string* url_template_filled); | 58 std::string* url_template_filled); |
63 | 59 |
64 void OnPickerClosed(const std::string& title, | 60 void OnPickerClosed(const std::string& title, |
65 const std::string& text, | 61 const std::string& text, |
66 const GURL& share_url, | 62 const GURL& share_url, |
67 const ShareCallback& callback, | 63 const ShareCallback& callback, |
68 SharePickerResult result); | 64 base::Optional<base::string16> result); |
69 | 65 |
70 DISALLOW_COPY_AND_ASSIGN(ShareServiceImpl); | 66 DISALLOW_COPY_AND_ASSIGN(ShareServiceImpl); |
71 }; | 67 }; |
72 | 68 |
73 #endif // CHROME_BROWSER_WEBSHARE_SHARE_SERVICE_IMPL_H_ | 69 #endif // CHROME_BROWSER_WEBSHARE_SHARE_SERVICE_IMPL_H_ |
OLD | NEW |