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

Side by Side Diff: Source/modules/background_sync/PeriodicSyncManager.cpp

Issue 1309393003: [Background Sync] Allow sync manager access from uncontrolled clients (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fixing comment Created 5 years, 3 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "config.h" 5 #include "config.h"
6 #include "modules/background_sync/PeriodicSyncManager.h" 6 #include "modules/background_sync/PeriodicSyncManager.h"
7 7
8 #include "bindings/core/v8/CallbackPromiseAdapter.h" 8 #include "bindings/core/v8/CallbackPromiseAdapter.h"
9 #include "bindings/core/v8/ScriptPromise.h" 9 #include "bindings/core/v8/ScriptPromise.h"
10 #include "bindings/core/v8/ScriptPromiseResolver.h" 10 #include "bindings/core/v8/ScriptPromiseResolver.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 : m_registration(registration) 45 : m_registration(registration)
46 { 46 {
47 ASSERT(registration); 47 ASSERT(registration);
48 } 48 }
49 49
50 unsigned long PeriodicSyncManager::minPossiblePeriod() 50 unsigned long PeriodicSyncManager::minPossiblePeriod()
51 { 51 {
52 return kMinPossiblePeriod; 52 return kMinPossiblePeriod;
53 } 53 }
54 54
55 ScriptPromise PeriodicSyncManager::registerFunction(ScriptState* scriptState, co nst PeriodicSyncRegistrationOptions& options) 55 ScriptPromise PeriodicSyncManager::registerFunction(ScriptState* scriptState, Ex ecutionContext* context, const PeriodicSyncRegistrationOptions& options)
56 { 56 {
57 if (!m_registration->active())
58 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(AbortError, "Registration failed - no active Service Worker"));
59
60 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; 57 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
61 ScriptPromise promise = resolver->promise(); 58 ScriptPromise promise = resolver->promise();
62 59
63 WebSyncRegistration::NetworkState networkState; 60 WebSyncRegistration::NetworkState networkState;
64 String networkStateString = options.networkState(); 61 String networkStateString = options.networkState();
65 if (networkStateString == "any") { 62 if (networkStateString == "any") {
66 networkState = WebSyncRegistration::NetworkState::NetworkStateAny; 63 networkState = WebSyncRegistration::NetworkState::NetworkStateAny;
67 } else if (networkStateString == "avoid-cellular") { 64 } else if (networkStateString == "avoid-cellular") {
68 networkState = WebSyncRegistration::NetworkState::NetworkStateAvoidCellu lar; 65 networkState = WebSyncRegistration::NetworkState::NetworkStateAvoidCellu lar;
69 } else { 66 } else {
70 networkState = WebSyncRegistration::NetworkState::NetworkStateOnline; 67 networkState = WebSyncRegistration::NetworkState::NetworkStateOnline;
71 } 68 }
72 WebSyncRegistration::PowerState powerState; 69 WebSyncRegistration::PowerState powerState;
73 String powerStateString = options.powerState(); 70 String powerStateString = options.powerState();
74 if (powerStateString == "avoid-draining") { 71 if (powerStateString == "avoid-draining") {
75 powerState = WebSyncRegistration::PowerState::PowerStateAvoidDraining; 72 powerState = WebSyncRegistration::PowerState::PowerStateAvoidDraining;
76 } else { 73 } else {
77 powerState = WebSyncRegistration::PowerState::PowerStateAuto; 74 powerState = WebSyncRegistration::PowerState::PowerStateAuto;
78 } 75 }
79 WebSyncRegistration* webSyncRegistration = new WebSyncRegistration( 76 WebSyncRegistration* webSyncRegistration = new WebSyncRegistration(
80 WebSyncRegistration::UNREGISTERED_SYNC_ID, 77 WebSyncRegistration::UNREGISTERED_SYNC_ID,
81 WebSyncRegistration::PeriodicityPeriodic, 78 WebSyncRegistration::PeriodicityPeriodic,
82 options.tag(), 79 options.tag(),
83 options.minPeriod(), 80 options.minPeriod(),
84 networkState, 81 networkState,
85 powerState 82 powerState
86 ); 83 );
87 backgroundSyncProvider()->registerBackgroundSync(webSyncRegistration, m_regi stration->webRegistration(), new SyncRegistrationCallbacks(resolver, m_registrat ion)); 84 backgroundSyncProvider()->registerBackgroundSync(webSyncRegistration, m_regi stration->webRegistration(), context->isServiceWorkerGlobalScope(), new SyncRegi strationCallbacks(resolver, m_registration));
88 85
89 return promise; 86 return promise;
90 } 87 }
91 88
92 ScriptPromise PeriodicSyncManager::getRegistration(ScriptState* scriptState, con st String& syncRegistrationTag) 89 ScriptPromise PeriodicSyncManager::getRegistration(ScriptState* scriptState, con st String& syncRegistrationTag)
93 { 90 {
94 if (!m_registration->active())
95 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(AbortError, "Operation failed - no active Service Worker"));
96
97 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; 91 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
98 ScriptPromise promise = resolver->promise(); 92 ScriptPromise promise = resolver->promise();
99 93
100 backgroundSyncProvider()->getRegistration(WebSyncRegistration::PeriodicityPe riodic, syncRegistrationTag, m_registration->webRegistration(), new SyncRegistra tionCallbacks(resolver, m_registration)); 94 backgroundSyncProvider()->getRegistration(WebSyncRegistration::PeriodicityPe riodic, syncRegistrationTag, m_registration->webRegistration(), new SyncRegistra tionCallbacks(resolver, m_registration));
101 95
102 return promise; 96 return promise;
103 } 97 }
104 98
105 ScriptPromise PeriodicSyncManager::getRegistrations(ScriptState* scriptState) 99 ScriptPromise PeriodicSyncManager::getRegistrations(ScriptState* scriptState)
106 { 100 {
107 if (!m_registration->active())
108 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(AbortError, "Operation failed - no active Service Worker"));
109
110 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; 101 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
111 ScriptPromise promise = resolver->promise(); 102 ScriptPromise promise = resolver->promise();
112 103
113 backgroundSyncProvider()->getRegistrations(WebSyncRegistration::PeriodicityP eriodic, m_registration->webRegistration(), new SyncGetRegistrationsCallbacks(re solver, m_registration)); 104 backgroundSyncProvider()->getRegistrations(WebSyncRegistration::PeriodicityP eriodic, m_registration->webRegistration(), new SyncGetRegistrationsCallbacks(re solver, m_registration));
114 105
115 return promise; 106 return promise;
116 } 107 }
117 108
118 ScriptPromise PeriodicSyncManager::permissionState(ScriptState* scriptState) 109 ScriptPromise PeriodicSyncManager::permissionState(ScriptState* scriptState)
119 { 110 {
120 if (!m_registration->active())
121 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(AbortError, "Operation failed - no active Service Worker"));
122
123 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; 111 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
124 ScriptPromise promise = resolver->promise(); 112 ScriptPromise promise = resolver->promise();
125 113
126 backgroundSyncProvider()->getPermissionStatus(WebSyncRegistration::Periodici tyPeriodic, m_registration->webRegistration(), new SyncGetPermissionStatusCallba cks(resolver, m_registration)); 114 backgroundSyncProvider()->getPermissionStatus(WebSyncRegistration::Periodici tyPeriodic, m_registration->webRegistration(), new SyncGetPermissionStatusCallba cks(resolver, m_registration));
127 115
128 return promise; 116 return promise;
129 } 117 }
130 118
131 DEFINE_TRACE(PeriodicSyncManager) 119 DEFINE_TRACE(PeriodicSyncManager)
132 { 120 {
133 visitor->trace(m_registration); 121 visitor->trace(m_registration);
134 } 122 }
135 123
136 } // namespace blink 124 } // namespace blink
OLDNEW
« no previous file with comments | « Source/modules/background_sync/PeriodicSyncManager.h ('k') | Source/modules/background_sync/PeriodicSyncManager.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698