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 blink::WebPassOwnPtr<blink::AppInstalledCallbacks> raw_callbacks) { |
| 28 scoped_ptr<blink::AppInstalledCallbacks> callback(raw_callbacks); |
| 29 RenderFrameImpl::FromRoutingID(routing_id()) |
| 30 ->manifest_manager() |
| 31 ->GetManifest(base::Bind(&InstalledAppDispatcher::OnGetManifest, |
| 32 base::Unretained(this), base::Passed(&callback), |
| 33 origin)); |
| 34 } |
| 35 |
| 36 content::InstalledAppProviderPtr& InstalledAppDispatcher::GetProvider() { |
| 37 if (!provider_) { |
| 38 RenderThread::Get()->GetServiceRegistry()->ConnectToRemoteService( |
| 39 mojo::GetProxy(&provider_)); |
| 40 } |
| 41 return provider_; |
| 42 } |
| 43 |
| 44 void InstalledAppDispatcher::OnGetManifest( |
| 45 scoped_ptr<blink::AppInstalledCallbacks> callbacks, |
| 46 const blink::WebSecurityOrigin& origin, |
| 47 const Manifest& manifest) { |
| 48 mojo::Array<RelatedApplicationPtr> related_apps; |
| 49 for (auto relatedApplication : manifest.related_applications) { |
| 50 RelatedApplicationPtr convertedApplication(RelatedApplication::New()); |
| 51 convertedApplication->platform = mojo::String::From( |
| 52 base::UTF16ToUTF8(relatedApplication.platform.string())); |
| 53 convertedApplication->id = |
| 54 mojo::String::From(base::UTF16ToUTF8(relatedApplication.id.string())); |
| 55 convertedApplication->url = |
| 56 mojo::String::From(relatedApplication.url.spec()); |
| 57 related_apps.push_back(std::move(convertedApplication)); |
| 58 } |
| 59 |
| 60 GetProvider()->FilterInstalledApps( |
| 61 std::move(related_apps), mojo::String(origin.toString().utf8()), |
| 62 base::Bind(&InstalledAppDispatcher::OnFilterInstalledApps, |
| 63 base::Unretained(this), base::Passed(&callbacks))); |
| 64 } |
| 65 |
| 66 void InstalledAppDispatcher::OnFilterInstalledApps( |
| 67 scoped_ptr<blink::AppInstalledCallbacks> callbacks, |
| 68 mojo::Array<RelatedApplicationPtr> result) { |
| 69 std::vector<blink::WebRelatedApplication> applications; |
| 70 if (result.size() > 0) { |
| 71 blink::WebRelatedApplication app; |
| 72 app.platform = blink::WebString::fromUTF8(result[0]->platform.get()); |
| 73 app.url = blink::WebString::fromUTF8(result[0]->url.get()); |
| 74 app.id = blink::WebString::fromUTF8(result[0]->id.get()); |
| 75 applications.push_back(app); |
| 76 } |
| 77 callbacks->onSuccess( |
| 78 blink::WebVector<blink::WebRelatedApplication>(applications)); |
| 79 } |
| 80 |
| 81 } // namespace content |
OLD | NEW |