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/presentation/NavigatorPresentation.h" 7 8 #include "core/dom/Document.h" 9 #include "core/frame/LocalFrame.h" 10 #include "core/frame/Navigator.h" 11 #include "modules/presentation/Presentation.h" 12 #include "platform/heap/Handle.h" 13 14 namespace blink { 15 16 NavigatorPresentation::NavigatorPresentation(LocalFrame* frame) 17 : DOMWindowProperty(frame) 18 { 19 } 20 21 NavigatorPresentation::~NavigatorPresentation() 22 { 23 } 24 25 // static 26 const char* NavigatorPresentation::supplementName() 27 { 28 return "NavigatorPresentation"; 29 } 30 31 // static 32 NavigatorPresentation& NavigatorPresentation::from(Navigator& navigator) 33 { 34 NavigatorPresentation* supplement = static_cast<NavigatorPresentation*>(WillBeHeapSupplement<Navigator>::from(navigator, supplementName())); 35 if (!supplement) { 36 supplement = new NavigatorPresentation(navigator.frame()); 37 provideTo(navigator, supplementName(), adoptPtrWillBeNoop(supplement)); 38 } 39 return *supplement; 40 } 41 42 // static 43 Presentation* NavigatorPresentation::presentation(Navigator& navigator) 44 { 45 return NavigatorPresentation::from(navigator).presentation(); 46 } 47 48 Presentation* NavigatorPresentation::presentation() 49 { 50 if (!m_presentation) { 51 if (!frame()) 52 return 0; 53 m_presentation = Presentation::create(frame()->document()); 54 } 55 return m_presentation.get(); 56 } 57 58 void NavigatorPresentation::trace(Visitor* visitor) 59 { 60 visitor->trace(m_presentation); 61 WillBeHeapSupplement<Navigator>::trace(visitor); 62 DOMWindowProperty::trace(visitor); 63 } 64 65 } // namespace blink 66