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