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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
93 WebRelatedAppsFetcher* relatedAppsFetcher) | 93 WebRelatedAppsFetcher* relatedAppsFetcher) |
94 : Supplement<LocalFrame>(frame), | 94 : Supplement<LocalFrame>(frame), |
95 ContextLifecycleObserver(frame.document()), | 95 ContextLifecycleObserver(frame.document()), |
96 m_relatedAppsFetcher(relatedAppsFetcher) {} | 96 m_relatedAppsFetcher(relatedAppsFetcher) {} |
97 | 97 |
98 void InstalledAppController::contextDestroyed(ExecutionContext*) { | 98 void InstalledAppController::contextDestroyed(ExecutionContext*) { |
99 m_relatedAppsFetcher = nullptr; | 99 m_relatedAppsFetcher = nullptr; |
100 } | 100 } |
101 | 101 |
102 void InstalledAppController::filterByInstalledApps( | 102 void InstalledAppController::filterByInstalledApps( |
103 WTF::RefPtr<SecurityOrigin> /*origin*/, | 103 WTF::RefPtr<SecurityOrigin> origin, |
104 const WebVector<WebRelatedApplication>& /*relatedApps*/, | 104 const blink::WebVector<blink::WebRelatedApplication>& relatedApps, |
105 std::unique_ptr<AppInstalledCallbacks> callbacks) { | 105 std::unique_ptr<blink::AppInstalledCallbacks> callbacks) { |
106 // TODO(mgiuca): Call through to the browser to filter the list of | 106 WTF::Vector<mojom::blink::RelatedApplicationPtr> mojoRelatedApps; |
107 // applications down to just those that are installed on the device. | 107 for (const auto& relatedApplication : relatedApps) { |
108 // For now, just return the empty list (no applications are installed). | 108 mojom::blink::RelatedApplicationPtr convertedApplication( |
109 callbacks->onSuccess(WebVector<WebRelatedApplication>()); | 109 mojom::blink::RelatedApplication::New()); |
110 DCHECK(!relatedApplication.platform.isEmpty()); | |
111 convertedApplication->platform = relatedApplication.platform; | |
112 convertedApplication->id = relatedApplication.id; | |
113 convertedApplication->url = relatedApplication.url; | |
114 mojoRelatedApps.push_back(std::move(convertedApplication)); | |
115 } | |
116 | |
117 if (!m_provider) { | |
118 supplementable()->interfaceProvider()->getInterface( | |
119 mojo::MakeRequest(&m_provider)); | |
dcheng
2017/03/02 07:41:51
We should close m_provider in contextDestroyed(),
Matt Giuca
2017/03/10 03:35:47
Done.
| |
120 // TODO(mgiuca): Set a connection error handler. This requires a refactor to | |
121 // work like NavigatorShare.cpp (retain a persistent list of clients to | |
122 // reject all of their promises). | |
123 DCHECK(m_provider); | |
124 } | |
125 | |
126 m_provider->FilterInstalledApps( | |
127 std::move(mojoRelatedApps), origin->toString(), | |
128 convertToBaseCallback( | |
129 WTF::bind(&InstalledAppController::OnFilterInstalledApps, | |
130 wrapPersistent(this), WTF::passed(std::move(callbacks))))); | |
dcheng
2017/03/02 07:41:51
Nit: WTF::passed(&callbacks)
Matt Giuca
2017/03/10 03:35:47
This doesn't work (no viable conversion from 'std:
| |
131 } | |
132 | |
133 void InstalledAppController::OnFilterInstalledApps( | |
134 std::unique_ptr<blink::AppInstalledCallbacks> callbacks, | |
135 WTF::Vector<mojom::blink::RelatedApplicationPtr> result) { | |
haraken
2017/03/02 07:33:28
dcheng@: Is there any way to type-map mojom::blink
dcheng
2017/03/02 07:41:51
Yeah, this should be pretty easy to typemap, and +
Matt Giuca
2017/03/10 03:35:47
This is all going to change... I'm planning to ref
dcheng
2017/03/13 06:16:51
Honestly, I'd prefer if the last step (mojom -> ID
Matt Giuca
2017/03/14 06:38:11
I'm happy to play with it after this feature is wo
dcheng
2017/03/14 06:41:53
I wouldn't really say 3 is not a high priority; ma
Matt Giuca
2017/03/14 06:53:57
Sure; but I'm going to prioritize it behind actual
| |
136 std::vector<blink::WebRelatedApplication> applications; | |
137 for (const auto& res : result) { | |
138 blink::WebRelatedApplication app; | |
139 app.platform = res->platform; | |
140 app.url = res->url; | |
141 app.id = res->id; | |
142 applications.push_back(app); | |
143 } | |
144 callbacks->onSuccess( | |
145 blink::WebVector<blink::WebRelatedApplication>(applications)); | |
110 } | 146 } |
111 | 147 |
112 DEFINE_TRACE(InstalledAppController) { | 148 DEFINE_TRACE(InstalledAppController) { |
113 Supplement<LocalFrame>::trace(visitor); | 149 Supplement<LocalFrame>::trace(visitor); |
114 ContextLifecycleObserver::trace(visitor); | 150 ContextLifecycleObserver::trace(visitor); |
115 } | 151 } |
116 | 152 |
117 } // namespace blink | 153 } // namespace blink |
OLD | NEW |