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

Unified Diff: third_party/WebKit/Source/modules/installedapp/InstalledAppController.cpp

Issue 2488573002: Refactor getInstalledRelatedApps code and add manifest logic and tests. (Closed)
Patch Set: Use SecurityOrigin, not WebSecurityOrigin. Created 3 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
Index: third_party/WebKit/Source/modules/installedapp/InstalledAppController.cpp
diff --git a/third_party/WebKit/Source/modules/installedapp/InstalledAppController.cpp b/third_party/WebKit/Source/modules/installedapp/InstalledAppController.cpp
index 2d06c5f3fdbdb7d656ee19d6344cb50835d32393..66ac9ff72ff4fa788e2cbf77050c09d5d9e58cb8 100644
--- a/third_party/WebKit/Source/modules/installedapp/InstalledAppController.cpp
+++ b/third_party/WebKit/Source/modules/installedapp/InstalledAppController.cpp
@@ -7,55 +7,106 @@
#include "core/dom/Document.h"
#include "core/frame/LocalFrame.h"
#include "platform/RuntimeEnabledFeatures.h"
-#include "public/platform/WebSecurityOrigin.h"
+#include "platform/weborigin/SecurityOrigin.h"
+#include "public/platform/InterfaceProvider.h"
+#include "wtf/Functional.h"
#include <utility>
namespace blink {
+// Callbacks for the result of
+// WebRelatedAppsFetcher::getManifestRelatedApplications. Calls
+// filterByInstalledApps upon receiving the list of related applications.
+class InstalledAppController::GetRelatedAppsCallbacks
+ : public AppInstalledCallbacks {
+ public:
+ GetRelatedAppsCallbacks(InstalledAppController* controller,
+ WTF::RefPtr<SecurityOrigin> url,
+ std::unique_ptr<AppInstalledCallbacks> callbacks)
+ : m_controller(controller),
+ m_url(url),
+ m_callbacks(std::move(callbacks)) {}
+
+ // AppInstalledCallbacks overrides:
+ void onSuccess(const WebVector<WebRelatedApplication>& relatedApps) override {
+ if (!m_controller)
+ return;
+
+ m_controller->filterByInstalledApps(m_url, relatedApps,
+ std::move(m_callbacks));
+ }
+ void onError() override { m_callbacks->onError(); }
+
+ private:
+ WeakPersistent<InstalledAppController> m_controller;
+ WTF::RefPtr<SecurityOrigin> m_url;
+ std::unique_ptr<AppInstalledCallbacks> m_callbacks;
+};
+
InstalledAppController::~InstalledAppController() {}
-void InstalledAppController::provideTo(LocalFrame& frame,
- WebInstalledAppClient* client) {
- ASSERT(RuntimeEnabledFeatures::installedAppEnabled());
+void InstalledAppController::getInstalledRelatedApps(
+ WTF::RefPtr<SecurityOrigin> url,
+ std::unique_ptr<AppInstalledCallbacks> callbacks) {
+ // When detached, the fetcher is no longer valid.
+ if (!m_relatedAppsFetcher) {
+ // TODO(mgiuca): AbortError rather than simply undefined.
+ // https://crbug.com/687846
+ callbacks->onError();
+ return;
+ }
+
+ // Get the list of related applications from the manifest. This requires a
+ // request to the content layer (because the manifest is not a Blink concept).
+ // Upon returning, filter the result list to those apps that are installed.
+ // TODO(mgiuca): This roundtrip to content could be eliminated if the Manifest
+ // class was moved from content into Blink.
+ m_relatedAppsFetcher->getManifestRelatedApplications(
+ WTF::makeUnique<GetRelatedAppsCallbacks>(this, url,
+ std::move(callbacks)));
+}
+
+void InstalledAppController::provideTo(
+ LocalFrame& frame,
+ WebRelatedAppsFetcher* relatedAppsFetcher) {
+ DCHECK(RuntimeEnabledFeatures::installedAppEnabled());
InstalledAppController* controller =
- new InstalledAppController(frame, client);
+ new InstalledAppController(frame, relatedAppsFetcher);
Supplement<LocalFrame>::provideTo(frame, supplementName(), controller);
}
InstalledAppController* InstalledAppController::from(LocalFrame& frame) {
InstalledAppController* controller = static_cast<InstalledAppController*>(
Supplement<LocalFrame>::from(frame, supplementName()));
- ASSERT(controller);
+ DCHECK(controller);
return controller;
}
-InstalledAppController::InstalledAppController(LocalFrame& frame,
- WebInstalledAppClient* client)
- : Supplement<LocalFrame>(frame),
- ContextLifecycleObserver(frame.document()),
- m_client(client) {}
-
const char* InstalledAppController::supplementName() {
return "InstalledAppController";
}
-void InstalledAppController::getInstalledApps(
- const WebSecurityOrigin& url,
- std::unique_ptr<AppInstalledCallbacks> callback) {
- // When detached, the client is no longer valid.
- if (!m_client) {
- callback.release()->onError();
- return;
- }
+InstalledAppController::InstalledAppController(
+ LocalFrame& frame,
+ WebRelatedAppsFetcher* relatedAppsFetcher)
+ : Supplement<LocalFrame>(frame),
+ ContextLifecycleObserver(frame.document()),
+ m_relatedAppsFetcher(relatedAppsFetcher) {}
- // Client is expected to take ownership of the callback
- m_client->getInstalledRelatedApps(url, std::move(callback));
+void InstalledAppController::contextDestroyed(ExecutionContext*) {
+ m_relatedAppsFetcher = nullptr;
}
-void InstalledAppController::contextDestroyed(ExecutionContext*) {
- m_client = nullptr;
+void InstalledAppController::filterByInstalledApps(
+ WTF::RefPtr<SecurityOrigin> /*origin*/,
+ const WebVector<WebRelatedApplication>& /*relatedApps*/,
+ std::unique_ptr<AppInstalledCallbacks> callbacks) {
+ // TODO(mgiuca): Call through to the browser to filter the list of
+ // applications down to just those that are installed on the device.
+ // For now, just return the empty list (no applications are installed).
+ callbacks->onSuccess(WebVector<WebRelatedApplication>());
}
DEFINE_TRACE(InstalledAppController) {

Powered by Google App Engine
This is Rietveld 408576698