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 <memory> |
8 #include <string> | 9 #include <string> |
| 10 #include <vector> |
9 | 11 |
10 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
11 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
| 14 #include "chrome/browser/ui/browser.h" |
| 15 #include "chrome/browser/ui/browser_dialogs.h" |
12 #include "mojo/public/cpp/bindings/interface_request.h" | 16 #include "mojo/public/cpp/bindings/interface_request.h" |
13 #include "third_party/WebKit/public/platform/modules/webshare/webshare.mojom.h" | 17 #include "third_party/WebKit/public/platform/modules/webshare/webshare.mojom.h" |
| 18 #include "third_party/WebKit/public/platform/site_engagement.mojom.h" |
14 | 19 |
| 20 class DictionaryValue; |
15 class GURL; | 21 class GURL; |
16 | 22 |
17 // Desktop implementation of the ShareService Mojo service. | 23 // Desktop implementation of the ShareService Mojo service. |
18 class ShareServiceImpl : public blink::mojom::ShareService { | 24 class ShareServiceImpl : public blink::mojom::ShareService { |
19 public: | 25 public: |
20 ShareServiceImpl() = default; | 26 ShareServiceImpl(); |
21 ~ShareServiceImpl() override = default; | 27 ~ShareServiceImpl() override; |
22 | 28 |
23 static void Create(mojo::InterfaceRequest<ShareService> request); | 29 static void Create(mojo::InterfaceRequest<ShareService> request); |
24 | 30 |
25 // blink::mojom::ShareService overrides: | 31 // blink::mojom::ShareService overrides: |
26 void Share(const std::string& title, | 32 void Share(const std::string& title, |
27 const std::string& text, | 33 const std::string& text, |
28 const GURL& share_url, | 34 const GURL& share_url, |
29 const ShareCallback& callback) override; | 35 const ShareCallback& callback) override; |
30 | 36 |
31 private: | 37 private: |
32 FRIEND_TEST_ALL_PREFIXES(ShareServiceImplUnittest, ReplacePlaceholders); | 38 FRIEND_TEST_ALL_PREFIXES(ShareServiceImplUnittest, ReplacePlaceholders); |
33 | 39 |
| 40 Browser* GetBrowser(); |
| 41 |
| 42 // Returns the URL template of the target identified by |target_url| |
| 43 std::string GetTargetTemplate( |
| 44 const std::string& target_url, |
| 45 const base::DictionaryValue& share_targets); |
| 46 |
| 47 // Virtual for testing purposes. |
| 48 virtual PrefService* GetPrefService(); |
| 49 |
| 50 // Returns the site engagement level of the site, |url|, with the user. |
| 51 // Virtual for testing purposes. |
| 52 virtual blink::mojom::EngagementLevel GetEngagementLevel(const GURL& url); |
| 53 |
34 // Shows the share picker dialog with |targets| as the list of applications | 54 // Shows the share picker dialog with |targets| as the list of applications |
35 // presented to the user. Passes the result to |callback|. If the user picks a | 55 // presented to the user. Passes the result to |callback|. If the user picks a |
36 // target, the result passed to |callback| is the manifest URL of the chosen | 56 // target, the result passed to |callback| is the manifest URL of the chosen |
37 // target, or is null if the user cancelled the share. Virtual for testing. | 57 // target, or is null if the user cancelled the share. Virtual for testing. |
38 virtual void ShowPickerDialog( | 58 virtual void ShowPickerDialog( |
39 const std::vector<std::pair<base::string16, GURL>>& targets, | 59 const std::vector<std::pair<base::string16, GURL>>& targets, |
40 const base::Callback<void(base::Optional<std::string>)>& callback); | 60 const base::Callback<void(base::Optional<std::string>)>& callback); |
41 | 61 |
42 // Opens a new tab and navigates to |target_url|. | 62 // Opens a new tab and navigates to |target_url|. |
43 // Virtual for testing purposes. | 63 // Virtual for testing purposes. |
44 virtual void OpenTargetURL(const GURL& target_url); | 64 virtual void OpenTargetURL(const GURL& target_url); |
45 | 65 |
| 66 // Returns all stored Share Targets that have a high enough engagement score |
| 67 // with the user. |
| 68 std::vector<std::pair<base::string16, GURL>> |
| 69 GetTargetsWithSufficientEngagement( |
| 70 const base::DictionaryValue& share_targets); |
| 71 |
46 // Writes to |url_template_filled|, a copy of |url_template| with all | 72 // Writes to |url_template_filled|, a copy of |url_template| with all |
47 // instances of "{title}", "{text}", and "{url}" replaced with | 73 // instances of "{title}", "{text}", and "{url}" replaced with |
48 // |title|, |text|, and |url| respectively. | 74 // |title|, |text|, and |url| respectively. |
49 // Replaces instances of "{X}" where "X" is any string besides "title", | 75 // Replaces instances of "{X}" where "X" is any string besides "title", |
50 // "text", and "url", with an empty string, for forwards compatibility. | 76 // "text", and "url", with an empty string, for forwards compatibility. |
51 // Returns false, if there are badly nested placeholders. | 77 // Returns false, if there are badly nested placeholders. |
52 // This includes any case in which two "{" occur before a "}", or a "}" | 78 // This includes any case in which two "{" occur before a "}", or a "}" |
53 // occurs with no preceding "{". | 79 // occurs with no preceding "{". |
54 static bool ReplacePlaceholders(base::StringPiece url_template, | 80 static bool ReplacePlaceholders(base::StringPiece url_template, |
55 base::StringPiece title, | 81 base::StringPiece title, |
56 base::StringPiece text, | 82 base::StringPiece text, |
57 const GURL& share_url, | 83 const GURL& share_url, |
58 std::string* url_template_filled); | 84 std::string* url_template_filled); |
59 | 85 |
60 void OnPickerClosed(const std::string& title, | 86 void OnPickerClosed(std::unique_ptr<base::DictionaryValue> share_targets, |
| 87 const std::string& title, |
61 const std::string& text, | 88 const std::string& text, |
62 const GURL& share_url, | 89 const GURL& share_url, |
63 const ShareCallback& callback, | 90 const ShareCallback& callback, |
64 base::Optional<std::string> result); | 91 base::Optional<std::string> result); |
65 | 92 |
66 DISALLOW_COPY_AND_ASSIGN(ShareServiceImpl); | 93 DISALLOW_COPY_AND_ASSIGN(ShareServiceImpl); |
67 }; | 94 }; |
68 | 95 |
69 #endif // CHROME_BROWSER_WEBSHARE_SHARE_SERVICE_IMPL_H_ | 96 #endif // CHROME_BROWSER_WEBSHARE_SHARE_SERVICE_IMPL_H_ |
OLD | NEW |