Upstream version 6.35.121.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / modules / serviceworkers / NavigatorServiceWorker.cpp
1 // Copyright 2014 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 "config.h"
6 #include "modules/serviceworkers/NavigatorServiceWorker.h"
7
8 #include "core/frame/Navigator.h"
9 #include "modules/serviceworkers/ServiceWorkerContainer.h"
10
11 namespace WebCore {
12
13 NavigatorServiceWorker::NavigatorServiceWorker(Navigator& navigator)
14     : DOMWindowProperty(navigator.frame())
15 {
16 }
17
18 NavigatorServiceWorker::~NavigatorServiceWorker()
19 {
20 }
21
22 NavigatorServiceWorker& NavigatorServiceWorker::from(Navigator& navigator)
23 {
24     NavigatorServiceWorker* supplement = toNavigatorServiceWorker(navigator);
25     if (!supplement) {
26         supplement = new NavigatorServiceWorker(navigator);
27         provideTo(navigator, supplementName(), adoptPtrWillBeNoop(supplement));
28     }
29     return *supplement;
30 }
31
32 NavigatorServiceWorker* NavigatorServiceWorker::toNavigatorServiceWorker(Navigator& navigator)
33 {
34     return static_cast<NavigatorServiceWorker*>(WillBeHeapSupplement<Navigator>::from(navigator, supplementName()));
35 }
36
37 const char* NavigatorServiceWorker::supplementName()
38 {
39     return "NavigatorServiceWorker";
40 }
41
42 ServiceWorkerContainer* NavigatorServiceWorker::serviceWorker(ExecutionContext* executionContext, Navigator& navigator)
43 {
44     return NavigatorServiceWorker::from(navigator).serviceWorker(executionContext);
45 }
46
47 ServiceWorkerContainer* NavigatorServiceWorker::serviceWorker(ExecutionContext* executionContext)
48 {
49     if (!m_serviceWorker && frame())
50         m_serviceWorker = ServiceWorkerContainer::create(executionContext);
51     return m_serviceWorker.get();
52 }
53
54 void NavigatorServiceWorker::willDetachGlobalObjectFromFrame()
55 {
56     m_serviceWorker->detachClient();
57     m_serviceWorker = nullptr;
58 }
59
60 } // namespace WebCore