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..0536b5d8e321e07779e7b63785f1f49def0670fc |
--- /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 0; |
haraken
2016/02/27 15:53:12
nullptr
Daniel Nishi
2016/02/29 18:38:39
Done.
|
+ 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()); |
haraken
2016/02/27 15:53:12
Use adoptPtr & release.
Daniel Nishi
2016/02/29 18:38:39
The rest of Blink uses regular pointers for Naviga
|
+ 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; |
dcheng
2016/02/27 18:30:37
What's the benefit to using a heap pointer here? W
Daniel Nishi
2016/02/29 18:38:39
I think when using CallbackPromiseAdapter in this
|
+ for (const auto webApplication : *webInfo) |
+ 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()), |
+ new CallbackPromiseAdapter<RelatedAppArray, void>(resolver)); |
haraken
2016/02/27 15:53:11
Can't we use adoptPtr(new ...)? We should avoid cr
Daniel Nishi
2016/02/29 18:38:39
I've changed it to use adoptWebPtr -- this bit cro
|
+ return promise; |
+} |
+ |
+InstalledAppController* NavigatorInstalledApp::controller() |
+{ |
+ if (!frame()) |
+ return 0; |
+ |
+ return InstalledAppController::from(*frame()); |
+} |
+ |
+const char* NavigatorInstalledApp::supplementName() |
+{ |
+ return "NavigatorInstalledApp"; |
+} |
+ |
+DEFINE_TRACE(NavigatorInstalledApp) |
+{ |
+ HeapSupplement<Navigator>::trace(visitor); |
+ DOMWindowProperty::trace(visitor); |
+} |
+ |
+} // namespace blink |