1 | /* |
2 | * Copyright (C) 2017 Apple Inc. All rights reserved. |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without |
5 | * modification, are permitted provided that the following conditions |
6 | * are met: |
7 | * 1. Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. |
9 | * 2. Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. |
12 | * |
13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
23 | * THE POSSIBILITY OF SUCH DAMAGE. |
24 | */ |
25 | |
26 | #include "config.h" |
27 | #include "ServiceWorkerProcessProxy.h" |
28 | |
29 | #if ENABLE(SERVICE_WORKER) |
30 | |
31 | #include "AuthenticationChallengeDisposition.h" |
32 | #include "AuthenticationChallengeProxy.h" |
33 | #include "AuthenticationDecisionListener.h" |
34 | #include "WebCredential.h" |
35 | #include "WebPageGroup.h" |
36 | #include "WebPreferencesStore.h" |
37 | #include "WebProcessMessages.h" |
38 | #include "WebProcessPool.h" |
39 | #include "WebSWContextManagerConnectionMessages.h" |
40 | #include <WebCore/NotImplemented.h> |
41 | #include <WebCore/RegistrationDatabase.h> |
42 | |
43 | namespace WebKit { |
44 | using namespace WebCore; |
45 | |
46 | Ref<ServiceWorkerProcessProxy> ServiceWorkerProcessProxy::create(WebProcessPool& pool, const RegistrableDomain& registrableDomain, WebsiteDataStore& store) |
47 | { |
48 | auto proxy = adoptRef(*new ServiceWorkerProcessProxy { pool, registrableDomain, store }); |
49 | proxy->connect(); |
50 | return proxy; |
51 | } |
52 | |
53 | ServiceWorkerProcessProxy::ServiceWorkerProcessProxy(WebProcessPool& pool, const RegistrableDomain& registrableDomain, WebsiteDataStore& store) |
54 | : WebProcessProxy { pool, &store, IsPrewarmed::No } |
55 | , m_registrableDomain(registrableDomain) |
56 | , m_serviceWorkerPageID(generatePageID()) |
57 | { |
58 | } |
59 | |
60 | ServiceWorkerProcessProxy::~ServiceWorkerProcessProxy() |
61 | { |
62 | } |
63 | |
64 | bool ServiceWorkerProcessProxy::hasRegisteredServiceWorkers(const String& serviceWorkerDirectory) |
65 | { |
66 | String registrationFile = WebCore::serviceWorkerRegistrationDatabaseFilename(serviceWorkerDirectory); |
67 | return FileSystem::fileExists(registrationFile); |
68 | } |
69 | |
70 | void ServiceWorkerProcessProxy::getLaunchOptions(ProcessLauncher::LaunchOptions& launchOptions) |
71 | { |
72 | WebProcessProxy::getLaunchOptions(launchOptions); |
73 | |
74 | launchOptions.extraInitializationData.add("service-worker-process"_s , "1"_s ); |
75 | launchOptions.extraInitializationData.add("registrable-domain"_s , registrableDomain().string()); |
76 | } |
77 | |
78 | void ServiceWorkerProcessProxy::start(const WebPreferencesStore& store, Optional<PAL::SessionID> initialSessionID) |
79 | { |
80 | send(Messages::WebProcess::EstablishWorkerContextConnectionToNetworkProcess { processPool().defaultPageGroup().pageGroupID(), m_serviceWorkerPageID, store, initialSessionID.valueOr(PAL::SessionID::defaultSessionID()) }, 0); |
81 | } |
82 | |
83 | void ServiceWorkerProcessProxy::setUserAgent(const String& userAgent) |
84 | { |
85 | send(Messages::WebSWContextManagerConnection::SetUserAgent { userAgent }, 0); |
86 | } |
87 | |
88 | void ServiceWorkerProcessProxy::updatePreferencesStore(const WebPreferencesStore& store) |
89 | { |
90 | send(Messages::WebSWContextManagerConnection::UpdatePreferencesStore { store }, 0); |
91 | } |
92 | |
93 | void ServiceWorkerProcessProxy::didReceiveAuthenticationChallenge(PageIdentifier pageID, uint64_t frameID, Ref<AuthenticationChallengeProxy>&& challenge) |
94 | { |
95 | UNUSED_PARAM(pageID); |
96 | UNUSED_PARAM(frameID); |
97 | |
98 | // FIXME: Expose an API to delegate the actual decision to the application layer. |
99 | auto& protectionSpace = challenge->core().protectionSpace(); |
100 | if (protectionSpace.authenticationScheme() == WebCore::ProtectionSpaceAuthenticationSchemeServerTrustEvaluationRequested && processPool().allowsAnySSLCertificateForServiceWorker()) { |
101 | auto credential = WebCore::Credential("accept server trust"_s , emptyString(), WebCore::CredentialPersistenceNone); |
102 | challenge->listener().completeChallenge(AuthenticationChallengeDisposition::UseCredential, credential); |
103 | return; |
104 | } |
105 | notImplemented(); |
106 | challenge->listener().completeChallenge(AuthenticationChallengeDisposition::PerformDefaultHandling); |
107 | } |
108 | |
109 | } // namespace WebKit |
110 | |
111 | #endif // ENABLE(SERVICE_WORKER) |
112 | |