Chromium Code Reviews| Index: third_party/WebKit/Source/modules/installedapp/NavigatorInstalledApp.cpp |
| diff --git a/third_party/WebKit/Source/modules/installedapp/NavigatorInstalledApp.cpp b/third_party/WebKit/Source/modules/installedapp/NavigatorInstalledApp.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..4f625df586dddbc40fa849975120e893bb3d7f31 |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/modules/installedapp/NavigatorInstalledApp.cpp |
| @@ -0,0 +1,94 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "modules/installedapp/NavigatorInstalledApp.h" |
| + |
| +#include "bindings/core/v8/CallbackPromiseAdapter.h" |
| +#include "bindings/core/v8/ScriptPromise.h" |
| +#include "bindings/core/v8/ScriptPromiseResolver.h" |
| +#include "bindings/core/v8/ScriptState.h" |
| +#include "core/dom/Document.h" |
| +#include "core/frame/LocalDOMWindow.h" |
| +#include "core/frame/LocalFrame.h" |
| +#include "core/frame/Navigator.h" |
| +#include "modules/installedapp/InstalledAppController.h" |
| +#include "modules/installedapp/RelatedApplication.h" |
| +#include "public/platform/modules/installedapp/WebInstalledApp.h" |
| +#include "public/platform/modules/installedapp/WebRelatedApplication.h" |
| + |
| +namespace blink { |
| + |
| +NavigatorInstalledApp::NavigatorInstalledApp(LocalFrame* frame) |
| + : DOMWindowProperty(frame) |
| +{ |
| +} |
| + |
| +NavigatorInstalledApp* NavigatorInstalledApp::from(Document& document) |
| +{ |
| + if (!document.frame() || !document.frame()->domWindow()) |
| + return nullptr; |
| + Navigator& navigator = *document.frame()->domWindow()->navigator(); |
| + return &from(navigator); |
| +} |
| + |
| +NavigatorInstalledApp& NavigatorInstalledApp::from(Navigator& navigator) |
| +{ |
| + NavigatorInstalledApp* supplement = static_cast<NavigatorInstalledApp*>(HeapSupplement<Navigator>::from(navigator, supplementName())); |
| + if (!supplement) { |
| + supplement = new NavigatorInstalledApp(navigator.frame()); |
| + provideTo(navigator, supplementName(), supplement); |
| + } |
| + return *supplement; |
| +} |
| + |
| +ScriptPromise NavigatorInstalledApp::getInstalledRelatedApps(ScriptState* scriptState, Navigator& navigator) |
| +{ |
| + return NavigatorInstalledApp::from(navigator).getInstalledRelatedApps(scriptState); |
| +} |
| + |
| +class RelatedAppArray { |
| + STATIC_ONLY(RelatedAppArray); |
| + |
| +public: |
| + using WebType = OwnPtr<WebVector<WebRelatedApplication>>; |
| + |
| + static HeapVector<Member<RelatedApplication>> take(ScriptPromiseResolver*, PassOwnPtr<WebVector<WebRelatedApplication>> webInfo) |
| + { |
| + HeapVector<Member<RelatedApplication>> applications; |
| + for (const auto webApplication : *webInfo) |
|
dcheng
2016/03/01 20:03:03
const auto&, this copies WebRelatedApplication oth
Daniel Nishi
2016/03/01 20:46:20
Done.
|
| + applications.append(RelatedApplication::create(webApplication.platform, webApplication.url, webApplication.id)); |
| + return applications; |
| + } |
| +}; |
| + |
| +ScriptPromise NavigatorInstalledApp::getInstalledRelatedApps(ScriptState* scriptState) |
| +{ |
| + ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
| + ScriptPromise promise = resolver->promise(); |
| + controller()->getInstalledApps( |
| + WebSecurityOrigin(scriptState->executionContext()->securityOrigin()), |
| + adoptWebPtr(new CallbackPromiseAdapter<RelatedAppArray, void>(resolver))); |
| + return promise; |
| +} |
| + |
| +InstalledAppController* NavigatorInstalledApp::controller() |
| +{ |
| + if (!frame()) |
| + return nullptr; |
| + |
| + return InstalledAppController::from(*frame()); |
| +} |
| + |
| +const char* NavigatorInstalledApp::supplementName() |
| +{ |
| + return "NavigatorInstalledApp"; |
| +} |
| + |
| +DEFINE_TRACE(NavigatorInstalledApp) |
| +{ |
| + HeapSupplement<Navigator>::trace(visitor); |
| + DOMWindowProperty::trace(visitor); |
| +} |
| + |
| +} // namespace blink |