Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / bindings / core / v8 / WindowProxy.h
1 /*
2  * Copyright (C) 2009 Google 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 are
6  * met:
7  *
8  *     * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *     * Redistributions in binary form must reproduce the above
11  * copyright notice, this list of conditions and the following disclaimer
12  * in the documentation and/or other materials provided with the
13  * distribution.
14  *     * Neither the name of Google Inc. nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30
31 #ifndef WindowProxy_h
32 #define WindowProxy_h
33
34 #include "bindings/core/v8/DOMWrapperWorld.h"
35 #include "bindings/core/v8/ScopedPersistent.h"
36 #include "bindings/core/v8/ScriptState.h"
37 #include "platform/heap/Handle.h"
38 #include "platform/weborigin/SecurityOrigin.h"
39 #include "wtf/HashMap.h"
40 #include "wtf/PassRefPtr.h"
41 #include "wtf/RefPtr.h"
42 #include "wtf/text/AtomicString.h"
43 #include <v8.h>
44
45 namespace blink {
46
47 class LocalFrame;
48 class HTMLDocument;
49 class SecurityOrigin;
50
51 // WindowProxy represents all the per-global object state for a LocalFrame that
52 // persist between navigations.
53 class WindowProxy final : public NoBaseWillBeGarbageCollectedFinalized<WindowProxy> {
54 public:
55     static PassOwnPtrWillBeRawPtr<WindowProxy> create(LocalFrame*, DOMWrapperWorld&, v8::Isolate*);
56
57     ~WindowProxy();
58     void trace(Visitor*);
59
60     v8::Local<v8::Context> context() const { return m_scriptState ? m_scriptState->context() : v8::Local<v8::Context>(); }
61     ScriptState* scriptState() const { return m_scriptState.get(); }
62
63     // Update document object of the frame.
64     void updateDocument();
65
66     void namedItemAdded(HTMLDocument*, const AtomicString&);
67     void namedItemRemoved(HTMLDocument*, const AtomicString&);
68
69     // Update the security origin of a document
70     // (e.g., after setting docoument.domain).
71     void updateSecurityOrigin(SecurityOrigin*);
72
73     bool isContextInitialized() { return m_scriptState && !!m_scriptState->perContextData(); }
74     bool isGlobalInitialized() { return !m_global.isEmpty(); }
75
76     bool initializeIfNeeded();
77     void updateDocumentWrapper(v8::Handle<v8::Object> wrapper);
78
79     void clearForNavigation();
80     void clearForClose();
81
82     DOMWrapperWorld& world() { return *m_world; }
83
84 private:
85     WindowProxy(LocalFrame*, PassRefPtr<DOMWrapperWorld>, v8::Isolate*);
86     bool initialize();
87
88     enum GlobalDetachmentBehavior {
89         DoNotDetachGlobal,
90         DetachGlobal
91     };
92     void disposeContext(GlobalDetachmentBehavior);
93
94     void setSecurityToken(SecurityOrigin*);
95
96     // The JavaScript wrapper for the document object is cached on the global
97     // object for fast access. UpdateDocumentProperty sets the wrapper
98     // for the current document on the global object. ClearDocumentProperty
99     // deletes the document wrapper from the global object.
100     void updateDocumentProperty();
101     void clearDocumentProperty();
102
103     // Updates Activity Logger for the current context.
104     void updateActivityLogger();
105
106     void createContext();
107     bool installDOMWindow();
108
109     RawPtrWillBeMember<LocalFrame> m_frame;
110     v8::Isolate* m_isolate;
111     RefPtr<ScriptState> m_scriptState;
112     RefPtr<DOMWrapperWorld> m_world;
113     ScopedPersistent<v8::Object> m_global;
114     ScopedPersistent<v8::Object> m_document;
115 };
116
117 } // namespace blink
118
119 #endif // WindowProxy_h