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

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

Issue 2610783004: Remove ContextClient from NavigatorInstalledApp (Closed)
Patch Set: temp Created 3 years, 11 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
« no previous file with comments | « third_party/WebKit/Source/modules/installedapp/NavigatorInstalledApp.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/NavigatorInstalledApp.h" 5 #include "modules/installedapp/NavigatorInstalledApp.h"
6 6
7 #include "bindings/core/v8/CallbackPromiseAdapter.h" 7 #include "bindings/core/v8/CallbackPromiseAdapter.h"
8 #include "bindings/core/v8/ScriptPromise.h" 8 #include "bindings/core/v8/ScriptPromise.h"
9 #include "bindings/core/v8/ScriptPromiseResolver.h" 9 #include "bindings/core/v8/ScriptPromiseResolver.h"
10 #include "bindings/core/v8/ScriptState.h" 10 #include "bindings/core/v8/ScriptState.h"
11 #include "core/dom/DOMException.h" 11 #include "core/dom/DOMException.h"
12 #include "core/dom/Document.h" 12 #include "core/dom/Document.h"
13 #include "core/dom/ExceptionCode.h" 13 #include "core/dom/ExceptionCode.h"
14 #include "core/frame/LocalDOMWindow.h" 14 #include "core/frame/LocalDOMWindow.h"
15 #include "core/frame/LocalFrame.h" 15 #include "core/frame/LocalFrame.h"
16 #include "core/frame/Navigator.h" 16 #include "core/frame/Navigator.h"
17 #include "modules/installedapp/InstalledAppController.h" 17 #include "modules/installedapp/InstalledAppController.h"
18 #include "modules/installedapp/RelatedApplication.h" 18 #include "modules/installedapp/RelatedApplication.h"
19 #include "public/platform/modules/installedapp/WebInstalledAppClient.h" 19 #include "public/platform/modules/installedapp/WebInstalledAppClient.h"
20 #include "public/platform/modules/installedapp/WebRelatedApplication.h" 20 #include "public/platform/modules/installedapp/WebRelatedApplication.h"
21 #include "wtf/PtrUtil.h" 21 #include "wtf/PtrUtil.h"
22 22
23 namespace blink { 23 namespace blink {
24 24
25 NavigatorInstalledApp::NavigatorInstalledApp(LocalFrame* frame) 25 NavigatorInstalledApp::NavigatorInstalledApp(Navigator& navigator)
26 : ContextClient(frame) {} 26 : Supplement<Navigator>(navigator) {}
27 27
28 NavigatorInstalledApp* NavigatorInstalledApp::from(Document& document) { 28 NavigatorInstalledApp* NavigatorInstalledApp::from(Document& document) {
29 if (!document.frame() || !document.frame()->domWindow()) 29 if (!document.frame() || !document.frame()->domWindow())
30 return nullptr; 30 return nullptr;
31 Navigator& navigator = *document.frame()->domWindow()->navigator(); 31 Navigator& navigator = *document.frame()->domWindow()->navigator();
32 return &from(navigator); 32 return &from(navigator);
33 } 33 }
34 34
35 NavigatorInstalledApp& NavigatorInstalledApp::from(Navigator& navigator) { 35 NavigatorInstalledApp& NavigatorInstalledApp::from(Navigator& navigator) {
36 NavigatorInstalledApp* supplement = static_cast<NavigatorInstalledApp*>( 36 NavigatorInstalledApp* supplement = static_cast<NavigatorInstalledApp*>(
37 Supplement<Navigator>::from(navigator, supplementName())); 37 Supplement<Navigator>::from(navigator, supplementName()));
38 if (!supplement) { 38 if (!supplement) {
39 supplement = new NavigatorInstalledApp(navigator.frame()); 39 supplement = new NavigatorInstalledApp(navigator);
40 provideTo(navigator, supplementName(), supplement); 40 provideTo(navigator, supplementName(), supplement);
41 } 41 }
42 return *supplement; 42 return *supplement;
43 } 43 }
44 44
45 ScriptPromise NavigatorInstalledApp::getInstalledRelatedApps( 45 ScriptPromise NavigatorInstalledApp::getInstalledRelatedApps(
46 ScriptState* scriptState, 46 ScriptState* scriptState,
47 Navigator& navigator) { 47 Navigator& navigator) {
48 return NavigatorInstalledApp::from(navigator).getInstalledRelatedApps( 48 return NavigatorInstalledApp::from(navigator).getInstalledRelatedApps(
49 scriptState); 49 scriptState);
(...skipping 14 matching lines...) Expand all
64 webApplication.platform, webApplication.url, webApplication.id)); 64 webApplication.platform, webApplication.url, webApplication.id));
65 return applications; 65 return applications;
66 } 66 }
67 }; 67 };
68 68
69 ScriptPromise NavigatorInstalledApp::getInstalledRelatedApps( 69 ScriptPromise NavigatorInstalledApp::getInstalledRelatedApps(
70 ScriptState* scriptState) { 70 ScriptState* scriptState) {
71 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); 71 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
72 ScriptPromise promise = resolver->promise(); 72 ScriptPromise promise = resolver->promise();
73 73
74 // Don't crash when called and unattached to document. 74 if (!controller()) { // If the associated frame is detached
sof 2017/01/05 12:30:56 Bind it to a local so as to only call controller()
75 Document* document = frame() ? frame()->document() : 0;
76
77 if (!document || !controller()) {
78 DOMException* exception = DOMException::create( 75 DOMException* exception = DOMException::create(
79 InvalidStateError, "The object is no longer associated to a document."); 76 InvalidStateError, "The object is no longer associated to a document.");
80 resolver->reject(exception); 77 resolver->reject(exception);
81 return promise; 78 return promise;
82 } 79 }
83 80
84 controller()->getInstalledApps( 81 controller()->getInstalledApps(
85 WebSecurityOrigin( 82 WebSecurityOrigin(
86 scriptState->getExecutionContext()->getSecurityOrigin()), 83 scriptState->getExecutionContext()->getSecurityOrigin()),
87 WTF::wrapUnique( 84 WTF::wrapUnique(
88 new CallbackPromiseAdapter<RelatedAppArray, void>(resolver))); 85 new CallbackPromiseAdapter<RelatedAppArray, void>(resolver)));
89 return promise; 86 return promise;
90 } 87 }
91 88
92 InstalledAppController* NavigatorInstalledApp::controller() { 89 InstalledAppController* NavigatorInstalledApp::controller() {
93 if (!frame()) 90 if (!host()->frame())
94 return nullptr; 91 return nullptr;
95 92
96 return InstalledAppController::from(*frame()); 93 return InstalledAppController::from(*host()->frame());
97 } 94 }
98 95
99 const char* NavigatorInstalledApp::supplementName() { 96 const char* NavigatorInstalledApp::supplementName() {
100 return "NavigatorInstalledApp"; 97 return "NavigatorInstalledApp";
101 } 98 }
102 99
103 DEFINE_TRACE(NavigatorInstalledApp) { 100 DEFINE_TRACE(NavigatorInstalledApp) {
104 Supplement<Navigator>::trace(visitor); 101 Supplement<Navigator>::trace(visitor);
105 ContextClient::trace(visitor);
106 } 102 }
107 103
108 } // namespace blink 104 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/installedapp/NavigatorInstalledApp.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698