OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/renderer/installedapp/installed_app_dispatcher.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "content/public/common/service_registry.h" |
| 10 #include "content/renderer/manifest/manifest_manager.h" |
| 11 #include "content/renderer/render_frame_impl.h" |
| 12 #include "content/renderer/render_thread_impl.h" |
| 13 #include "third_party/WebKit/public/platform/WebString.h" |
| 14 #include "third_party/WebKit/public/platform/modules/installedapp/WebRelatedAppl
ication.h" |
| 15 |
| 16 namespace content { |
| 17 |
| 18 InstalledAppDispatcher::InstalledAppDispatcher( |
| 19 RenderFrame* render_frame, |
| 20 ServiceRegistry* service_registry) |
| 21 : RenderFrameObserver(render_frame), service_registry_(service_registry) {} |
| 22 |
| 23 InstalledAppDispatcher::~InstalledAppDispatcher() {} |
| 24 |
| 25 void InstalledAppDispatcher::getInstalledRelatedApps( |
| 26 const blink::WebSecurityOrigin& origin, |
| 27 std::unique_ptr<blink::AppInstalledCallbacks> callbacks) { |
| 28 RenderFrameImpl::FromRoutingID(routing_id()) |
| 29 ->manifest_manager() |
| 30 ->GetManifest(base::Bind(&InstalledAppDispatcher::OnGetManifest, |
| 31 base::Unretained(this), base::Passed(&callbacks), |
| 32 origin)); |
| 33 } |
| 34 |
| 35 content::InstalledAppProviderPtr& InstalledAppDispatcher::GetProvider() { |
| 36 if (!provider_) { |
| 37 RenderThread::Get()->GetServiceRegistry()->ConnectToRemoteService( |
| 38 mojo::GetProxy(&provider_)); |
| 39 } |
| 40 return provider_; |
| 41 } |
| 42 |
| 43 void InstalledAppDispatcher::OnGetManifest( |
| 44 std::unique_ptr<blink::AppInstalledCallbacks> callbacks, |
| 45 const blink::WebSecurityOrigin& origin, |
| 46 const Manifest& manifest) { |
| 47 mojo::Array<RelatedApplicationPtr> related_apps; |
| 48 for (auto relatedApplication : manifest.related_applications) { |
| 49 RelatedApplicationPtr convertedApplication(RelatedApplication::New()); |
| 50 convertedApplication->platform = mojo::String::From( |
| 51 base::UTF16ToUTF8(relatedApplication.platform.string())); |
| 52 convertedApplication->id = |
| 53 mojo::String::From(base::UTF16ToUTF8(relatedApplication.id.string())); |
| 54 convertedApplication->url = |
| 55 mojo::String::From(relatedApplication.url.spec()); |
| 56 related_apps.push_back(std::move(convertedApplication)); |
| 57 } |
| 58 |
| 59 GetProvider()->FilterInstalledApps( |
| 60 std::move(related_apps), mojo::String(origin.toString().utf8()), |
| 61 base::Bind(&InstalledAppDispatcher::OnFilterInstalledApps, |
| 62 base::Unretained(this), base::Passed(&callbacks))); |
| 63 } |
| 64 |
| 65 void InstalledAppDispatcher::OnFilterInstalledApps( |
| 66 std::unique_ptr<blink::AppInstalledCallbacks> callbacks, |
| 67 mojo::Array<RelatedApplicationPtr> result) { |
| 68 std::vector<blink::WebRelatedApplication> applications; |
| 69 if (result.size() > 0) { |
| 70 blink::WebRelatedApplication app; |
| 71 app.platform = blink::WebString::fromUTF8(result[0]->platform.get()); |
| 72 app.url = blink::WebString::fromUTF8(result[0]->url.get()); |
| 73 app.id = blink::WebString::fromUTF8(result[0]->id.get()); |
| 74 applications.push_back(app); |
| 75 } |
| 76 callbacks->onSuccess( |
| 77 blink::WebVector<blink::WebRelatedApplication>(applications)); |
| 78 } |
| 79 |
| 80 } // namespace content |
OLD | NEW |