| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 #define ContextLifecycleObserver_h | 28 #define ContextLifecycleObserver_h |
| 29 | 29 |
| 30 #include "core/CoreExport.h" | 30 #include "core/CoreExport.h" |
| 31 #include "core/dom/ExecutionContext.h" | 31 #include "core/dom/ExecutionContext.h" |
| 32 #include "platform/LifecycleObserver.h" | 32 #include "platform/LifecycleObserver.h" |
| 33 | 33 |
| 34 namespace blink { | 34 namespace blink { |
| 35 | 35 |
| 36 class LocalFrame; | 36 class LocalFrame; |
| 37 | 37 |
| 38 // ContextClient and ContextLifecycleObserver are helpers to associate a |
| 39 // class with an ExecutionContext. ContextLifecycleObserver provides an |
| 40 // additional contextDestroyed() hook to execute cleanup code when a |
| 41 // context is destroyed. Prefer the simpler ContextClient when possible. |
| 42 // |
| 43 // getExecutionContext() returns null after the observing context is detached. |
| 44 // frame() returns null after the observing context is detached or if the |
| 45 // context doesn't have a frame (i.e., if the context is not a Document). |
| 46 |
| 47 class CORE_EXPORT ContextClient : public GarbageCollectedMixin { |
| 48 public: |
| 49 ExecutionContext* getExecutionContext() const; |
| 50 LocalFrame* frame() const; |
| 51 |
| 52 DECLARE_VIRTUAL_TRACE(); |
| 53 |
| 54 protected: |
| 55 explicit ContextClient(ExecutionContext* executionContext) |
| 56 : m_executionContext(executionContext) {} |
| 57 explicit ContextClient(LocalFrame*); |
| 58 |
| 59 private: |
| 60 WeakMember<ExecutionContext> m_executionContext; |
| 61 }; |
| 62 |
| 38 class CORE_EXPORT ContextLifecycleObserver | 63 class CORE_EXPORT ContextLifecycleObserver |
| 39 : public LifecycleObserver<ExecutionContext, ContextLifecycleObserver> { | 64 : public LifecycleObserver<ExecutionContext, ContextLifecycleObserver> { |
| 40 public: | 65 public: |
| 41 // Returns null after the observing context is detached. | |
| 42 ExecutionContext* getExecutionContext() const { return lifecycleContext(); } | 66 ExecutionContext* getExecutionContext() const { return lifecycleContext(); } |
| 43 | |
| 44 // Returns null after the observing context is detached or if the context | |
| 45 // doesn't have a frame (i.e., if the context is not a Document). | |
| 46 LocalFrame* frame() const; | 67 LocalFrame* frame() const; |
| 47 | 68 |
| 48 enum Type { | 69 enum Type { |
| 49 GenericType, | 70 GenericType, |
| 50 SuspendableObjectType, | 71 SuspendableObjectType, |
| 51 }; | 72 }; |
| 52 | 73 |
| 53 Type observerType() const { return m_observerType; } | 74 Type observerType() const { return m_observerType; } |
| 54 | 75 |
| 55 protected: | 76 protected: |
| 56 explicit ContextLifecycleObserver(ExecutionContext* executionContext, | 77 explicit ContextLifecycleObserver(ExecutionContext* executionContext, |
| 57 Type type = GenericType) | 78 Type type = GenericType) |
| 58 : LifecycleObserver(executionContext), m_observerType(type) {} | 79 : LifecycleObserver(executionContext), m_observerType(type) {} |
| 59 | 80 |
| 60 private: | 81 private: |
| 61 Type m_observerType; | 82 Type m_observerType; |
| 62 }; | 83 }; |
| 63 | 84 |
| 64 } // namespace blink | 85 } // namespace blink |
| 65 | 86 |
| 66 #endif // ContextLifecycleObserver_h | 87 #endif // ContextLifecycleObserver_h |
| OLD | NEW |