1591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch/*
2591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch * Copyright (C) 2008 Apple Inc. All Rights Reserved.
3591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch * Copyright (C) 2013 Google Inc. All Rights Reserved.
4591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch *
5591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch * Redistribution and use in source and binary forms, with or without
6591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch * modification, are permitted provided that the following conditions
7591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch * are met:
8591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch * 1. Redistributions of source code must retain the above copyright
9591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch *    notice, this list of conditions and the following disclaimer.
10591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch * 2. Redistributions in binary form must reproduce the above copyright
11591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch *    notice, this list of conditions and the following disclaimer in the
12591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch *    documentation and/or other materials provided with the distribution.
13591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch *
14591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
15591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
18591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch *
26591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch */
27591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch#ifndef ContextLifecycleNotifier_h
28591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch#define ContextLifecycleNotifier_h
29591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch
30591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch#include "core/dom/ActiveDOMObject.h"
31f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)#include "platform/LifecycleNotifier.h"
32591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch#include "wtf/HashSet.h"
33591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch#include "wtf/PassOwnPtr.h"
34591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch
35c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)namespace blink {
36591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch
37591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdochclass ActiveDOMObject;
381e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)class ExecutionContext;
39591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch
40f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)class ContextLifecycleNotifier : public LifecycleNotifier<ExecutionContext> {
41591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdochpublic:
421e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    static PassOwnPtr<ContextLifecycleNotifier> create(ExecutionContext*);
43591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch
44591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch    virtual ~ContextLifecycleNotifier();
45591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch
46591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch    typedef HashSet<ActiveDOMObject*> ActiveDOMObjectSet;
47591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch
48591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch    const ActiveDOMObjectSet& activeDOMObjects() const { return m_activeDOMObjects; }
49591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch
50f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)    virtual void addObserver(Observer*) OVERRIDE;
51f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)    virtual void removeObserver(Observer*) OVERRIDE;
52591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch
53591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch    void notifyResumingActiveDOMObjects();
541e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    void notifySuspendingActiveDOMObjects();
55591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch    void notifyStoppingActiveDOMObjects();
56591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch
57591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch    bool contains(ActiveDOMObject* object) const { return m_activeDOMObjects.contains(object); }
58591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch    bool hasPendingActivity() const;
59591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch
60591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdochprotected:
611e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    explicit ContextLifecycleNotifier(ExecutionContext*);
62591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch
63591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdochprivate:
64591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch    ActiveDOMObjectSet m_activeDOMObjects;
65591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch};
66591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch
671e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)inline PassOwnPtr<ContextLifecycleNotifier> ContextLifecycleNotifier::create(ExecutionContext* context)
68591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch{
69591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch    return adoptPtr(new ContextLifecycleNotifier(context));
70591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch}
71591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch
72c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)} // namespace blink
73591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch
74591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch#endif // ContextLifecycleNotifier_h
75