2 * Copyright (C) 2012 Apple Inc. All Rights Reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include "DOMWindowExtension.h"
29 #include "DOMWindow.h"
30 #include "DOMWrapperWorld.h"
32 #include "FrameLoaderClient.h"
36 DOMWindowExtension::DOMWindowExtension(Frame* frame, DOMWrapperWorld* world)
37 : DOMWindowProperty(frame)
39 , m_wasDetached(false)
41 ASSERT(this->frame());
45 void DOMWindowExtension::disconnectFrameForPageCache()
47 // Calling out to the client might result in this DOMWindowExtension being destroyed
48 // while there is still work to do.
49 RefPtr<DOMWindowExtension> protector = this;
51 Frame* frame = this->frame();
52 frame->loader()->client()->dispatchWillDisconnectDOMWindowExtensionFromGlobalObject(this);
54 m_disconnectedFrame = frame;
56 DOMWindowProperty::disconnectFrameForPageCache();
59 void DOMWindowExtension::reconnectFrameFromPageCache(Frame* frame)
61 ASSERT(m_disconnectedFrame == frame);
63 DOMWindowProperty::reconnectFrameFromPageCache(frame);
64 m_disconnectedFrame = 0;
66 this->frame()->loader()->client()->dispatchDidReconnectDOMWindowExtensionToGlobalObject(this);
69 void DOMWindowExtension::willDestroyGlobalObjectInCachedFrame()
71 ASSERT(m_disconnectedFrame);
73 // Calling out to the client might result in this DOMWindowExtension being destroyed
74 // while there is still work to do.
75 RefPtr<DOMWindowExtension> protector = this;
77 m_disconnectedFrame->loader()->client()->dispatchWillDestroyGlobalObjectForDOMWindowExtension(this);
78 m_disconnectedFrame = 0;
80 DOMWindowProperty::willDestroyGlobalObjectInCachedFrame();
83 void DOMWindowExtension::willDestroyGlobalObjectInFrame()
85 ASSERT(!m_disconnectedFrame);
87 // Calling out to the client might result in this DOMWindowExtension being destroyed
88 // while there is still work to do.
89 RefPtr<DOMWindowExtension> protector = this;
92 Frame* frame = this->frame();
94 frame->loader()->client()->dispatchWillDestroyGlobalObjectForDOMWindowExtension(this);
97 DOMWindowProperty::willDestroyGlobalObjectInFrame();
100 void DOMWindowExtension::willDetachGlobalObjectFromFrame()
102 ASSERT(!m_disconnectedFrame);
103 ASSERT(!m_wasDetached);
105 // Calling out to the client might result in this DOMWindowExtension being destroyed
106 // while there is still work to do.
107 RefPtr<DOMWindowExtension> protector = this;
109 Frame* frame = this->frame();
111 frame->loader()->client()->dispatchWillDestroyGlobalObjectForDOMWindowExtension(this);
113 m_wasDetached = true;
114 DOMWindowProperty::willDetachGlobalObjectFromFrame();
117 } // namespace WebCore