Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1271)

Unified Diff: content/renderer/installedapp/installed_app_dispatcher.cc

Issue 1756793004: Chrome-side patch for IsAppInstalled. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@splitpatch2
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/renderer/installedapp/installed_app_dispatcher.h ('k') | content/renderer/render_frame_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..c56dd843deebb3cf13fb82d8032088fcd6b268a8
--- /dev/null
+++ b/content/renderer/installedapp/installed_app_dispatcher.cc
@@ -0,0 +1,81 @@
+// 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,
+ blink::WebPassOwnPtr<blink::AppInstalledCallbacks> raw_callbacks) {
+ scoped_ptr<blink::AppInstalledCallbacks> callback(raw_callbacks);
+ RenderFrameImpl::FromRoutingID(routing_id())
+ ->manifest_manager()
+ ->GetManifest(base::Bind(&InstalledAppDispatcher::OnGetManifest,
+ base::Unretained(this), base::Passed(&callback),
+ origin));
+}
+
+content::InstalledAppProviderPtr& InstalledAppDispatcher::GetProvider() {
+ if (!provider_) {
+ RenderThread::Get()->GetServiceRegistry()->ConnectToRemoteService(
+ mojo::GetProxy(&provider_));
+ }
+ return provider_;
+}
+
+void InstalledAppDispatcher::OnGetManifest(
+ scoped_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(
+ scoped_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
« no previous file with comments | « content/renderer/installedapp/installed_app_dispatcher.h ('k') | content/renderer/render_frame_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698