OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/renderer/installedapp/related_apps_fetcher.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "content/public/common/manifest.h" |
| 9 #include "content/renderer/manifest/manifest_debug_info.h" |
| 10 #include "content/renderer/manifest/manifest_manager.h" |
| 11 #include "third_party/WebKit/public/platform/WebString.h" |
| 12 #include "third_party/WebKit/public/platform/modules/installedapp/WebRelatedAppl
ication.h" |
| 13 |
| 14 namespace content { |
| 15 |
| 16 RelatedAppsFetcher::RelatedAppsFetcher(ManifestManager* manifest_manager) |
| 17 : manifest_manager_(manifest_manager) {} |
| 18 |
| 19 RelatedAppsFetcher::~RelatedAppsFetcher() {} |
| 20 |
| 21 void RelatedAppsFetcher::getManifestRelatedApplications( |
| 22 std::unique_ptr<blink::WebCallbacks< |
| 23 const blink::WebVector<blink::WebRelatedApplication>&, |
| 24 void>> callbacks) { |
| 25 manifest_manager_->GetManifest( |
| 26 base::Bind(&RelatedAppsFetcher::OnGetManifestForRelatedApplications, |
| 27 base::Unretained(this), base::Passed(&callbacks))); |
| 28 } |
| 29 |
| 30 void RelatedAppsFetcher::OnGetManifestForRelatedApplications( |
| 31 std::unique_ptr<blink::WebCallbacks< |
| 32 const blink::WebVector<blink::WebRelatedApplication>&, |
| 33 void>> callbacks, |
| 34 const GURL& /*url*/, |
| 35 const Manifest& manifest, |
| 36 const ManifestDebugInfo& /*manifest_debug_info*/) { |
| 37 std::vector<blink::WebRelatedApplication> related_apps; |
| 38 for (const auto& relatedApplication : manifest.related_applications) { |
| 39 blink::WebRelatedApplication webRelatedApplication; |
| 40 webRelatedApplication.platform = |
| 41 blink::WebString::fromUTF16(relatedApplication.platform); |
| 42 webRelatedApplication.id = |
| 43 blink::WebString::fromUTF16(relatedApplication.id); |
| 44 if (!relatedApplication.url.is_empty()) { |
| 45 webRelatedApplication.url = |
| 46 blink::WebString::fromUTF8(relatedApplication.url.spec()); |
| 47 } |
| 48 related_apps.push_back(std::move(webRelatedApplication)); |
| 49 } |
| 50 callbacks->onSuccess(std::move(related_apps)); |
| 51 } |
| 52 |
| 53 } // namespace content |
OLD | NEW |