| Index: content/renderer/installedapp/installed_app_dispatcher.cc
|
| diff --git a/content/renderer/installedapp/installed_app_dispatcher.cc b/content/renderer/installedapp/installed_app_dispatcher.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..198438d609edceb55fcd567a7928f2dc9a66b5d7
|
| --- /dev/null
|
| +++ b/content/renderer/installedapp/installed_app_dispatcher.cc
|
| @@ -0,0 +1,80 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "content/renderer/installedapp/installed_app_dispatcher.h"
|
| +
|
| +#include "base/logging.h"
|
| +#include "base/strings/utf_string_conversions.h"
|
| +#include "content/public/common/service_registry.h"
|
| +#include "content/renderer/manifest/manifest_manager.h"
|
| +#include "content/renderer/render_frame_impl.h"
|
| +#include "content/renderer/render_thread_impl.h"
|
| +#include "third_party/WebKit/public/platform/WebString.h"
|
| +#include "third_party/WebKit/public/platform/modules/installedapp/WebRelatedApplication.h"
|
| +
|
| +namespace content {
|
| +
|
| +InstalledAppDispatcher::InstalledAppDispatcher(
|
| + RenderFrame* render_frame,
|
| + ServiceRegistry* service_registry)
|
| + : RenderFrameObserver(render_frame), service_registry_(service_registry) {}
|
| +
|
| +InstalledAppDispatcher::~InstalledAppDispatcher() {}
|
| +
|
| +void InstalledAppDispatcher::getInstalledRelatedApps(
|
| + const blink::WebSecurityOrigin& origin,
|
| + std::unique_ptr<blink::AppInstalledCallbacks> callbacks) {
|
| + RenderFrameImpl::FromRoutingID(routing_id())
|
| + ->manifest_manager()
|
| + ->GetManifest(base::Bind(&InstalledAppDispatcher::OnGetManifest,
|
| + base::Unretained(this), base::Passed(&callbacks),
|
| + origin));
|
| +}
|
| +
|
| +content::InstalledAppProviderPtr& InstalledAppDispatcher::GetProvider() {
|
| + if (!provider_) {
|
| + RenderThread::Get()->GetServiceRegistry()->ConnectToRemoteService(
|
| + mojo::GetProxy(&provider_));
|
| + }
|
| + return provider_;
|
| +}
|
| +
|
| +void InstalledAppDispatcher::OnGetManifest(
|
| + std::unique_ptr<blink::AppInstalledCallbacks> callbacks,
|
| + const blink::WebSecurityOrigin& origin,
|
| + const Manifest& manifest) {
|
| + mojo::Array<RelatedApplicationPtr> related_apps;
|
| + for (auto relatedApplication : manifest.related_applications) {
|
| + RelatedApplicationPtr convertedApplication(RelatedApplication::New());
|
| + convertedApplication->platform = mojo::String::From(
|
| + base::UTF16ToUTF8(relatedApplication.platform.string()));
|
| + convertedApplication->id =
|
| + mojo::String::From(base::UTF16ToUTF8(relatedApplication.id.string()));
|
| + convertedApplication->url =
|
| + mojo::String::From(relatedApplication.url.spec());
|
| + related_apps.push_back(std::move(convertedApplication));
|
| + }
|
| +
|
| + GetProvider()->FilterInstalledApps(
|
| + std::move(related_apps), mojo::String(origin.toString().utf8()),
|
| + base::Bind(&InstalledAppDispatcher::OnFilterInstalledApps,
|
| + base::Unretained(this), base::Passed(&callbacks)));
|
| +}
|
| +
|
| +void InstalledAppDispatcher::OnFilterInstalledApps(
|
| + std::unique_ptr<blink::AppInstalledCallbacks> callbacks,
|
| + mojo::Array<RelatedApplicationPtr> result) {
|
| + std::vector<blink::WebRelatedApplication> applications;
|
| + if (result.size() > 0) {
|
| + blink::WebRelatedApplication app;
|
| + app.platform = blink::WebString::fromUTF8(result[0]->platform.get());
|
| + app.url = blink::WebString::fromUTF8(result[0]->url.get());
|
| + app.id = blink::WebString::fromUTF8(result[0]->id.get());
|
| + applications.push_back(app);
|
| + }
|
| + callbacks->onSuccess(
|
| + blink::WebVector<blink::WebRelatedApplication>(applications));
|
| +}
|
| +
|
| +} // namespace content
|
|
|