Merge "[CherryPick] Refactoring: Move the content of HTMLInputElement::subtreeHasChan...
[framework/web/webkit-efl.git] / Source / WebCore / page / DOMWindowExtension.cpp
1 /*
2  * Copyright (C) 2012 Apple Inc. All Rights Reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
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.
12  *
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.
24  */
25
26 #include "config.h"
27 #include "DOMWindowExtension.h"
28
29 #include "DOMWindow.h"
30 #include "DOMWrapperWorld.h"
31 #include "Frame.h"
32 #include "FrameLoaderClient.h"
33
34 namespace WebCore {
35
36 DOMWindowExtension::DOMWindowExtension(Frame* frame, DOMWrapperWorld* world)
37     : DOMWindowProperty(frame)
38     , m_world(world)
39     , m_wasDetached(false)
40 {
41     ASSERT(this->frame());
42     ASSERT(m_world);
43 }
44
45 void DOMWindowExtension::disconnectFrameForPageCache()
46 {
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;
50     
51     Frame* frame = this->frame();
52     frame->loader()->client()->dispatchWillDisconnectDOMWindowExtensionFromGlobalObject(this);
53
54     m_disconnectedFrame = frame;
55
56     DOMWindowProperty::disconnectFrameForPageCache();
57 }
58
59 void DOMWindowExtension::reconnectFrameFromPageCache(Frame* frame)
60 {
61     ASSERT(m_disconnectedFrame == frame);
62     
63     DOMWindowProperty::reconnectFrameFromPageCache(frame);
64     m_disconnectedFrame = 0;
65
66     this->frame()->loader()->client()->dispatchDidReconnectDOMWindowExtensionToGlobalObject(this);
67 }
68
69 void DOMWindowExtension::willDestroyGlobalObjectInCachedFrame()
70 {
71     ASSERT(m_disconnectedFrame);
72
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;
76     
77     m_disconnectedFrame->loader()->client()->dispatchWillDestroyGlobalObjectForDOMWindowExtension(this);
78     m_disconnectedFrame = 0;
79
80     DOMWindowProperty::willDestroyGlobalObjectInCachedFrame();
81 }
82
83 void DOMWindowExtension::willDestroyGlobalObjectInFrame()
84 {
85     ASSERT(!m_disconnectedFrame);
86
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;
90
91     if (!m_wasDetached) {
92         Frame* frame = this->frame();
93         ASSERT(frame);
94         frame->loader()->client()->dispatchWillDestroyGlobalObjectForDOMWindowExtension(this);
95     }
96
97     DOMWindowProperty::willDestroyGlobalObjectInFrame();
98 }
99
100 void DOMWindowExtension::willDetachGlobalObjectFromFrame()
101 {
102     ASSERT(!m_disconnectedFrame);
103     ASSERT(!m_wasDetached);
104
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;
108
109     Frame* frame = this->frame();
110     ASSERT(frame);
111     frame->loader()->client()->dispatchWillDestroyGlobalObjectForDOMWindowExtension(this);
112
113     m_wasDetached = true;
114     DOMWindowProperty::willDetachGlobalObjectFromFrame();
115 }
116
117 } // namespace WebCore