Upstream version 11.40.277.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / modules / netinfo / NavigatorNetworkInformation.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/netinfo/NavigatorNetworkInformation.h"
7
8 #include "core/frame/LocalDOMWindow.h"
9 #include "core/frame/LocalFrame.h"
10 #include "core/frame/Navigator.h"
11 #include "modules/netinfo/NetworkInformation.h"
12
13 namespace blink {
14
15 NavigatorNetworkInformation::NavigatorNetworkInformation(Navigator& navigator)
16     : DOMWindowProperty(navigator.frame())
17 {
18 }
19
20 DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(NavigatorNetworkInformation);
21
22 NavigatorNetworkInformation& NavigatorNetworkInformation::from(Navigator& navigator)
23 {
24     NavigatorNetworkInformation* supplement = toNavigatorNetworkInformation(navigator);
25     if (!supplement) {
26         supplement = new NavigatorNetworkInformation(navigator);
27         provideTo(navigator, supplementName(), adoptPtrWillBeNoop(supplement));
28     }
29     return *supplement;
30 }
31
32 NavigatorNetworkInformation* NavigatorNetworkInformation::toNavigatorNetworkInformation(Navigator& navigator)
33 {
34     return static_cast<NavigatorNetworkInformation*>(WillBeHeapSupplement<Navigator>::from(navigator, supplementName()));
35 }
36
37 const char* NavigatorNetworkInformation::supplementName()
38 {
39     return "NavigatorNetworkInformation";
40 }
41
42 NetworkInformation* NavigatorNetworkInformation::connection(Navigator& navigator)
43 {
44     return NavigatorNetworkInformation::from(navigator).connection();
45 }
46
47 NetworkInformation* NavigatorNetworkInformation::connection()
48 {
49     if (!m_connection && frame()) {
50         ASSERT(frame()->domWindow());
51         m_connection = NetworkInformation::create(frame()->domWindow()->executionContext());
52     }
53     return m_connection.get();
54 }
55
56 void NavigatorNetworkInformation::trace(Visitor* visitor)
57 {
58     visitor->trace(m_connection);
59     WillBeHeapSupplement<Navigator>::trace(visitor);
60     DOMWindowProperty::trace(visitor);
61 }
62
63 } // namespace blink