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 #include "config.h"
32 #include "ScriptObjectQuarantine.h"
33
34 #include "Document.h"
35 #include "Frame.h"
36 #include "JSDOMBinding.h"
37 #include "JSInspectedObjectWrapper.h"
38 #include "JSNode.h"
39 #include "ScriptObject.h"
40 #include "ScriptValue.h"
41
42 #include <runtime/JSLock.h>
43
44 #if ENABLE(DATABASE)
45 #include "Database.h"
46 #include "JSDatabase.h"
47 #endif
48
49 #if ENABLE(DOM_STORAGE)
50 #include "JSStorage.h"
51 #endif
52
53 using namespace JSC;
54
55 namespace WebCore {
56
quarantineValue(ScriptState * scriptState,const ScriptValue & value)57 ScriptValue quarantineValue(ScriptState* scriptState, const ScriptValue& value)
58 {
59 JSLock lock(SilenceAssertionsOnly);
60 return ScriptValue(JSInspectedObjectWrapper::wrap(scriptState, value.jsValue()));
61 }
62
63 #if ENABLE(DATABASE)
getQuarantinedScriptObject(Database * database,ScriptObject & quarantinedObject)64 bool getQuarantinedScriptObject(Database* database, ScriptObject& quarantinedObject)
65 {
66 ASSERT(database);
67
68 Frame* frame = database->document()->frame();
69 if (!frame)
70 return false;
71
72 JSDOMGlobalObject* globalObject = toJSDOMWindow(frame);
73 ExecState* exec = globalObject->globalExec();
74
75 JSLock lock(SilenceAssertionsOnly);
76 quarantinedObject = ScriptObject(exec, asObject(JSInspectedObjectWrapper::wrap(exec, toJS(exec, globalObject, database))));
77
78 return true;
79 }
80 #endif
81
82 #if ENABLE(DOM_STORAGE)
getQuarantinedScriptObject(Frame * frame,Storage * storage,ScriptObject & quarantinedObject)83 bool getQuarantinedScriptObject(Frame* frame, Storage* storage, ScriptObject& quarantinedObject)
84 {
85 ASSERT(frame);
86 ASSERT(storage);
87
88 JSDOMGlobalObject* globalObject = toJSDOMWindow(frame);
89 ExecState* exec = globalObject->globalExec();
90
91 JSLock lock(SilenceAssertionsOnly);
92 quarantinedObject = ScriptObject(exec, asObject(JSInspectedObjectWrapper::wrap(exec, toJS(exec, globalObject, storage))));
93
94 return true;
95 }
96 #endif
97
getQuarantinedScriptObject(Node * node,ScriptObject & quarantinedObject)98 bool getQuarantinedScriptObject(Node* node, ScriptObject& quarantinedObject)
99 {
100 ExecState* exec = scriptStateFromNode(node);
101 if (!exec)
102 return false;
103
104 JSLock lock(SilenceAssertionsOnly);
105 // FIXME: Should use some sort of globalObjectFromNode()
106 quarantinedObject = ScriptObject(exec, asObject(JSInspectedObjectWrapper::wrap(exec, toJS(exec, deprecatedGlobalObjectForPrototype(exec), node))));
107
108 return true;
109 }
110
getQuarantinedScriptObject(DOMWindow * domWindow,ScriptObject & quarantinedObject)111 bool getQuarantinedScriptObject(DOMWindow* domWindow, ScriptObject& quarantinedObject)
112 {
113 ASSERT(domWindow);
114
115 JSDOMWindow* window = toJSDOMWindow(domWindow->frame());
116 ExecState* exec = window->globalExec();
117
118 JSLock lock(SilenceAssertionsOnly);
119 quarantinedObject = ScriptObject(exec, asObject(JSInspectedObjectWrapper::wrap(exec, window)));
120
121 return true;
122 }
123
124
125 } // namespace WebCore
126