| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 #include "modules/presentation/NavigatorPresentation.h" | 6 #include "modules/presentation/NavigatorPresentation.h" |
| 7 | 7 |
| 8 #include "core/dom/Document.h" | 8 #include "core/dom/Document.h" |
| 9 #include "core/frame/LocalFrame.h" | 9 #include "core/frame/LocalFrame.h" |
| 10 #include "core/frame/Navigator.h" | 10 #include "core/frame/Navigator.h" |
| 11 #include "modules/presentation/Presentation.h" | 11 #include "modules/presentation/Presentation.h" |
| 12 #include "platform/heap/Handle.h" | 12 #include "platform/heap/Handle.h" |
| 13 | 13 |
| 14 namespace blink { | 14 namespace blink { |
| 15 | 15 |
| 16 NavigatorPresentation::NavigatorPresentation(LocalFrame* frame) | 16 NavigatorPresentation::NavigatorPresentation() |
| 17 : DOMWindowProperty(frame) | |
| 18 { | 17 { |
| 19 } | 18 } |
| 20 | 19 |
| 21 NavigatorPresentation::~NavigatorPresentation() | 20 NavigatorPresentation::~NavigatorPresentation() |
| 22 { | 21 { |
| 23 } | 22 } |
| 24 | 23 |
| 25 // static | 24 // static |
| 26 const char* NavigatorPresentation::supplementName() | 25 const char* NavigatorPresentation::supplementName() |
| 27 { | 26 { |
| 28 return "NavigatorPresentation"; | 27 return "NavigatorPresentation"; |
| 29 } | 28 } |
| 30 | 29 |
| 31 // static | 30 // static |
| 32 NavigatorPresentation& NavigatorPresentation::from(Navigator& navigator) | 31 NavigatorPresentation& NavigatorPresentation::from(Navigator& navigator) |
| 33 { | 32 { |
| 34 NavigatorPresentation* supplement = static_cast<NavigatorPresentation*>(Will
BeHeapSupplement<Navigator>::from(navigator, supplementName())); | 33 NavigatorPresentation* supplement = static_cast<NavigatorPresentation*>(Will
BeHeapSupplement<Navigator>::from(navigator, supplementName())); |
| 35 if (!supplement) { | 34 if (!supplement) { |
| 36 supplement = new NavigatorPresentation(navigator.frame()); | 35 supplement = new NavigatorPresentation(); |
| 37 provideTo(navigator, supplementName(), adoptPtrWillBeNoop(supplement)); | 36 provideTo(navigator, supplementName(), adoptPtrWillBeNoop(supplement)); |
| 38 } | 37 } |
| 39 return *supplement; | 38 return *supplement; |
| 40 } | 39 } |
| 41 | 40 |
| 42 // static | 41 // static |
| 43 Presentation* NavigatorPresentation::presentation(Navigator& navigator) | 42 Presentation* NavigatorPresentation::presentation(Navigator& navigator) |
| 44 { | 43 { |
| 45 return NavigatorPresentation::from(navigator).presentation(); | 44 NavigatorPresentation& self = NavigatorPresentation::from(navigator); |
| 46 } | 45 if (!self.m_presentation) { |
| 47 | 46 if (!navigator.frame()) |
| 48 Presentation* NavigatorPresentation::presentation() | 47 return nullptr; |
| 49 { | 48 self.m_presentation = Presentation::create(navigator.frame()); |
| 50 if (!m_presentation) { | |
| 51 if (!frame()) | |
| 52 return 0; | |
| 53 m_presentation = Presentation::create(frame()->document()); | |
| 54 } | 49 } |
| 55 return m_presentation.get(); | 50 return self.m_presentation.get(); |
| 56 } | 51 } |
| 57 | 52 |
| 58 void NavigatorPresentation::trace(Visitor* visitor) | 53 void NavigatorPresentation::trace(Visitor* visitor) |
| 59 { | 54 { |
| 60 visitor->trace(m_presentation); | 55 visitor->trace(m_presentation); |
| 61 WillBeHeapSupplement<Navigator>::trace(visitor); | 56 WillBeHeapSupplement<Navigator>::trace(visitor); |
| 62 DOMWindowProperty::trace(visitor); | |
| 63 } | 57 } |
| 64 | 58 |
| 65 } // namespace blink | 59 } // namespace blink |
| OLD | NEW |