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 <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(const std::string& target_url); | |
| 44 | |
| 45 // Virtual for testing purposes. | |
| 46 virtual PrefService* GetPrefService(); | |
| 47 | |
| 48 // Returns the site engagement level of the site, |url|, with the user. | |
| 49 // Virtual for testing purposes. | |
| 50 virtual blink::mojom::EngagementLevel GetEngagementLevel(const GURL& url); | |
| 51 | |
| 34 // Shows the share picker dialog with |targets| as the list of applications | 52 // 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 | 53 // 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 | 54 // 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. | 55 // target, or is null if the user cancelled the share. Virtual for testing. |
| 38 virtual void ShowPickerDialog( | 56 virtual void ShowPickerDialog( |
| 39 const std::vector<std::pair<base::string16, GURL>>& targets, | 57 const std::vector<std::pair<base::string16, GURL>>& targets, |
| 40 const base::Callback<void(base::Optional<std::string>)>& callback); | 58 const base::Callback<void(base::Optional<std::string>)>& callback); |
| 41 | 59 |
| 42 // Opens a new tab and navigates to |target_url|. | 60 // Opens a new tab and navigates to |target_url|. |
| 43 // Virtual for testing purposes. | 61 // Virtual for testing purposes. |
| 44 virtual void OpenTargetURL(const GURL& target_url); | 62 virtual void OpenTargetURL(const GURL& target_url); |
| 45 | 63 |
| 64 // Returns all stored Share Targets that have a high enough engagement score | |
| 65 // with the user. | |
| 66 std::vector<std::pair<base::string16, GURL>> | |
| 67 GetTargetsWithSufficientEngagement(); | |
| 68 | |
| 46 // Writes to |url_template_filled|, a copy of |url_template| with all | 69 // Writes to |url_template_filled|, a copy of |url_template| with all |
| 47 // instances of "{title}", "{text}", and "{url}" replaced with | 70 // instances of "{title}", "{text}", and "{url}" replaced with |
| 48 // |title|, |text|, and |url| respectively. | 71 // |title|, |text|, and |url| respectively. |
| 49 // Replaces instances of "{X}" where "X" is any string besides "title", | 72 // Replaces instances of "{X}" where "X" is any string besides "title", |
| 50 // "text", and "url", with an empty string, for forwards compatibility. | 73 // "text", and "url", with an empty string, for forwards compatibility. |
| 51 // Returns false, if there are badly nested placeholders. | 74 // Returns false, if there are badly nested placeholders. |
| 52 // This includes any case in which two "{" occur before a "}", or a "}" | 75 // This includes any case in which two "{" occur before a "}", or a "}" |
| 53 // occurs with no preceding "{". | 76 // occurs with no preceding "{". |
| 54 static bool ReplacePlaceholders(base::StringPiece url_template, | 77 static bool ReplacePlaceholders(base::StringPiece url_template, |
| 55 base::StringPiece title, | 78 base::StringPiece title, |
| 56 base::StringPiece text, | 79 base::StringPiece text, |
| 57 const GURL& share_url, | 80 const GURL& share_url, |
| 58 std::string* url_template_filled); | 81 std::string* url_template_filled); |
| 59 | 82 |
| 60 void OnPickerClosed(const std::string& title, | 83 void OnPickerClosed(const std::string& title, |
| 61 const std::string& text, | 84 const std::string& text, |
| 62 const GURL& share_url, | 85 const GURL& share_url, |
| 63 const ShareCallback& callback, | 86 const ShareCallback& callback, |
| 64 base::Optional<std::string> result); | 87 base::Optional<std::string> result); |
| 65 | 88 |
| 66 DISALLOW_COPY_AND_ASSIGN(ShareServiceImpl); | 89 DISALLOW_COPY_AND_ASSIGN(ShareServiceImpl); |
| 90 | |
| 91 std::unique_ptr<base::DictionaryValue> share_targets; | |
|
Matt Giuca
2017/02/09 05:47:16
share_targets_
Matt Giuca
2017/02/09 23:21:09
Actually, remove this and just make it a temporary
constantina
2017/02/10 00:43:09
Done.
| |
| 67 }; | 92 }; |
| 68 | 93 |
| 69 #endif // CHROME_BROWSER_WEBSHARE_SHARE_SERVICE_IMPL_H_ | 94 #endif // CHROME_BROWSER_WEBSHARE_SHARE_SERVICE_IMPL_H_ |
| OLD | NEW |