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.
6 #include "modules/netinfo/NavigatorNetworkInformation.h"
8 #include "core/frame/LocalDOMWindow.h"
9 #include "core/frame/LocalFrame.h"
10 #include "core/frame/Navigator.h"
11 #include "modules/netinfo/NetworkInformation.h"
15 NavigatorNetworkInformation::NavigatorNetworkInformation(Navigator& navigator)
16 : DOMWindowProperty(navigator.frame())
20 DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(NavigatorNetworkInformation);
22 NavigatorNetworkInformation& NavigatorNetworkInformation::from(Navigator& navigator)
24 NavigatorNetworkInformation* supplement = toNavigatorNetworkInformation(navigator);
26 supplement = new NavigatorNetworkInformation(navigator);
27 provideTo(navigator, supplementName(), adoptPtrWillBeNoop(supplement));
32 NavigatorNetworkInformation* NavigatorNetworkInformation::toNavigatorNetworkInformation(Navigator& navigator)
34 return static_cast<NavigatorNetworkInformation*>(WillBeHeapSupplement<Navigator>::from(navigator, supplementName()));
37 const char* NavigatorNetworkInformation::supplementName()
39 return "NavigatorNetworkInformation";
42 NetworkInformation* NavigatorNetworkInformation::connection(Navigator& navigator)
44 return NavigatorNetworkInformation::from(navigator).connection();
47 NetworkInformation* NavigatorNetworkInformation::connection()
49 if (!m_connection && frame()) {
50 ASSERT(frame()->domWindow());
51 m_connection = NetworkInformation::create(frame()->domWindow()->executionContext());
53 return m_connection.get();
56 void NavigatorNetworkInformation::trace(Visitor* visitor)
58 visitor->trace(m_connection);
59 WillBeHeapSupplement<Navigator>::trace(visitor);
60 DOMWindowProperty::trace(visitor);