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

Side by Side Diff: third_party/WebKit/Source/modules/installedapp/NavigatorInstalledApp.cpp

Issue 1735033004: Bindings and client interface for the IsAppInstalled API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add OWNERS., Created 4 years, 9 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 unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "modules/installedapp/NavigatorInstalledApp.h"
6
7 #include "bindings/core/v8/CallbackPromiseAdapter.h"
8 #include "bindings/core/v8/ScriptPromise.h"
9 #include "bindings/core/v8/ScriptPromiseResolver.h"
10 #include "bindings/core/v8/ScriptState.h"
11 #include "core/dom/Document.h"
12 #include "core/frame/LocalDOMWindow.h"
13 #include "core/frame/LocalFrame.h"
14 #include "core/frame/Navigator.h"
15 #include "modules/installedapp/InstalledAppController.h"
16 #include "modules/installedapp/RelatedApplication.h"
17 #include "public/platform/modules/installedapp/WebInstalledApp.h"
18 #include "public/platform/modules/installedapp/WebRelatedApplication.h"
19
20 namespace blink {
21
22 NavigatorInstalledApp::NavigatorInstalledApp(LocalFrame* frame)
23 : DOMWindowProperty(frame)
24 {
25 }
26
27 NavigatorInstalledApp* NavigatorInstalledApp::from(Document& document)
28 {
29 if (!document.frame() || !document.frame()->domWindow())
30 return 0;
haraken 2016/02/27 15:53:12 nullptr
Daniel Nishi 2016/02/29 18:38:39 Done.
31 Navigator& navigator = *document.frame()->domWindow()->navigator();
32 return &from(navigator);
33 }
34
35 NavigatorInstalledApp& NavigatorInstalledApp::from(Navigator& navigator)
36 {
37 NavigatorInstalledApp* supplement = static_cast<NavigatorInstalledApp*>(Heap Supplement<Navigator>::from(navigator, supplementName()));
38 if (!supplement) {
39 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
40 provideTo(navigator, supplementName(), supplement);
41 }
42 return *supplement;
43 }
44
45 ScriptPromise NavigatorInstalledApp::getInstalledRelatedApps(ScriptState* script State, Navigator& navigator)
46 {
47 return NavigatorInstalledApp::from(navigator).getInstalledRelatedApps(script State);
48 }
49
50 class RelatedAppArray {
51 STATIC_ONLY(RelatedAppArray);
52
53 public:
54 using WebType = OwnPtr<WebVector<WebRelatedApplication*>>;
55
56 static HeapVector<Member<RelatedApplication>> take(ScriptPromiseResolver*, P assOwnPtr<WebVector<WebRelatedApplication*>> webInfo)
57 {
58 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
59 for (const auto webApplication : *webInfo)
60 applications.append(RelatedApplication::create(webApplication->platf orm, webApplication->url, webApplication->id));
61 return applications;
62 }
63 };
64
65 ScriptPromise NavigatorInstalledApp::getInstalledRelatedApps(ScriptState* script State)
66 {
67 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
68 ScriptPromise promise = resolver->promise();
69 controller()->getInstalledApps(
70 WebSecurityOrigin(scriptState->executionContext()->securityOrigin()),
71 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
72 return promise;
73 }
74
75 InstalledAppController* NavigatorInstalledApp::controller()
76 {
77 if (!frame())
78 return 0;
79
80 return InstalledAppController::from(*frame());
81 }
82
83 const char* NavigatorInstalledApp::supplementName()
84 {
85 return "NavigatorInstalledApp";
86 }
87
88 DEFINE_TRACE(NavigatorInstalledApp)
89 {
90 HeapSupplement<Navigator>::trace(visitor);
91 DOMWindowProperty::trace(visitor);
92 }
93
94 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698