OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "modules/installedapp/InstalledAppController.h" | 5 #include "modules/installedapp/InstalledAppController.h" |
6 | 6 |
7 #include "core/dom/Document.h" | 7 #include "core/dom/Document.h" |
8 #include "core/frame/LocalFrame.h" | 8 #include "core/frame/LocalFrame.h" |
9 #include "platform/RuntimeEnabledFeatures.h" | 9 #include "platform/RuntimeEnabledFeatures.h" |
10 #include "platform/weborigin/SecurityOrigin.h" | 10 #include "platform/weborigin/SecurityOrigin.h" |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 | 86 |
87 const char* InstalledAppController::supplementName() { | 87 const char* InstalledAppController::supplementName() { |
88 return "InstalledAppController"; | 88 return "InstalledAppController"; |
89 } | 89 } |
90 | 90 |
91 InstalledAppController::InstalledAppController( | 91 InstalledAppController::InstalledAppController( |
92 LocalFrame& frame, | 92 LocalFrame& frame, |
93 WebRelatedAppsFetcher* relatedAppsFetcher) | 93 WebRelatedAppsFetcher* relatedAppsFetcher) |
94 : Supplement<LocalFrame>(frame), | 94 : Supplement<LocalFrame>(frame), |
95 ContextLifecycleObserver(frame.document()), | 95 ContextLifecycleObserver(frame.document()), |
| 96 m_frame(&frame), |
96 m_relatedAppsFetcher(relatedAppsFetcher) {} | 97 m_relatedAppsFetcher(relatedAppsFetcher) {} |
97 | 98 |
98 void InstalledAppController::contextDestroyed(ExecutionContext*) { | 99 void InstalledAppController::contextDestroyed(ExecutionContext*) { |
99 m_relatedAppsFetcher = nullptr; | 100 m_relatedAppsFetcher = nullptr; |
100 } | 101 } |
101 | 102 |
102 void InstalledAppController::filterByInstalledApps( | 103 void InstalledAppController::filterByInstalledApps( |
103 WTF::RefPtr<SecurityOrigin> /*origin*/, | 104 WTF::RefPtr<SecurityOrigin> origin, |
104 const WebVector<WebRelatedApplication>& /*relatedApps*/, | 105 const blink::WebVector<blink::WebRelatedApplication>& relatedApps, |
105 std::unique_ptr<AppInstalledCallbacks> callbacks) { | 106 std::unique_ptr<blink::AppInstalledCallbacks> callbacks) { |
106 // TODO(mgiuca): Call through to the browser to filter the list of | 107 WTF::Vector<mojom::blink::RelatedApplicationPtr> mojoRelatedApps; |
107 // applications down to just those that are installed on the device. | 108 for (const auto& relatedApplication : relatedApps) { |
108 // For now, just return the empty list (no applications are installed). | 109 mojom::blink::RelatedApplicationPtr convertedApplication( |
109 callbacks->onSuccess(WebVector<WebRelatedApplication>()); | 110 mojom::blink::RelatedApplication::New()); |
| 111 DCHECK(!relatedApplication.platform.isEmpty()); |
| 112 convertedApplication->platform = relatedApplication.platform; |
| 113 convertedApplication->id = relatedApplication.id; |
| 114 convertedApplication->url = relatedApplication.url; |
| 115 mojoRelatedApps.push_back(std::move(convertedApplication)); |
| 116 } |
| 117 |
| 118 if (!m_provider) { |
| 119 DCHECK(m_frame); |
| 120 m_frame->interfaceProvider()->getInterface(mojo::MakeRequest(&m_provider)); |
| 121 // TODO(mgiuca): Set a connection error handler. This requires a refactor to |
| 122 // work like NavigatorShare.cpp (retain a persistent list of clients to |
| 123 // reject all of their promises). |
| 124 DCHECK(m_provider); |
| 125 } |
| 126 |
| 127 m_provider->FilterInstalledApps( |
| 128 std::move(mojoRelatedApps), origin->toString(), |
| 129 convertToBaseCallback( |
| 130 WTF::bind(&InstalledAppController::OnFilterInstalledApps, |
| 131 wrapPersistent(this), WTF::passed(std::move(callbacks))))); |
| 132 } |
| 133 |
| 134 void InstalledAppController::OnFilterInstalledApps( |
| 135 std::unique_ptr<blink::AppInstalledCallbacks> callbacks, |
| 136 WTF::Vector<mojom::blink::RelatedApplicationPtr> result) { |
| 137 std::vector<blink::WebRelatedApplication> applications; |
| 138 for (const auto& res : result) { |
| 139 blink::WebRelatedApplication app; |
| 140 app.platform = res->platform; |
| 141 app.url = res->url; |
| 142 app.id = res->id; |
| 143 applications.push_back(app); |
| 144 } |
| 145 callbacks->onSuccess( |
| 146 blink::WebVector<blink::WebRelatedApplication>(applications)); |
110 } | 147 } |
111 | 148 |
112 DEFINE_TRACE(InstalledAppController) { | 149 DEFINE_TRACE(InstalledAppController) { |
113 Supplement<LocalFrame>::trace(visitor); | 150 Supplement<LocalFrame>::trace(visitor); |
114 ContextLifecycleObserver::trace(visitor); | 151 ContextLifecycleObserver::trace(visitor); |
| 152 visitor->trace(m_frame); |
115 } | 153 } |
116 | 154 |
117 } // namespace blink | 155 } // namespace blink |
OLD | NEW |