• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2006, 2007, 2008, 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 V8Utilities_h
32 #define V8Utilities_h
33 
34 #if ENABLE(V8_LOCKERS)
35 // TODO(benm): Need to re-add in locking for V8. We lost some of the lock points during the merge. Define it to void here so we don't lock some of the time.
36 #define LOCK_V8 ((void) 0)
37 #else
38 #define LOCK_V8 ((void) 0)
39 #endif
40 
41 #include <v8.h>
42 
43 namespace WebCore {
44 
45     class Frame;
46     class KURL;
47     class String;
48 
49     // Use an array to hold dependents. It works like a ref-counted scheme. A value can be added more than once to the DOM object.
50     void createHiddenDependency(v8::Local<v8::Object>, v8::Local<v8::Value>, int cacheIndex);
51     void removeHiddenDependency(v8::Local<v8::Object>, v8::Local<v8::Value>, int cacheIndex);
52 
53     bool processingUserGesture();
54     bool shouldAllowNavigation(Frame*);
55     KURL completeURL(const String& relativeURL);
56     void navigateIfAllowed(Frame*, const KURL&, bool lockHistory, bool lockBackForwardList);
57 
58     class AllowAllocation {
59     public:
AllowAllocation()60         inline AllowAllocation()
61         {
62             m_previous = m_current;
63             m_current = true;
64         }
65 
~AllowAllocation()66         inline ~AllowAllocation()
67         {
68             m_current = m_previous;
69         }
70 
71         static bool m_current;
72 
73     private:
74         bool m_previous;
75     };
76 
77     class SafeAllocation {
78      public:
79       static inline v8::Local<v8::Object> newInstance(v8::Handle<v8::Function>);
80       static inline v8::Local<v8::Object> newInstance(v8::Handle<v8::ObjectTemplate>);
81       static inline v8::Local<v8::Object> newInstance(v8::Handle<v8::Function>, int argc, v8::Handle<v8::Value> argv[]);
82     };
83 
newInstance(v8::Handle<v8::Function> function)84     v8::Local<v8::Object> SafeAllocation::newInstance(v8::Handle<v8::Function> function)
85     {
86         if (function.IsEmpty())
87             return v8::Local<v8::Object>();
88         AllowAllocation allow;
89         return function->NewInstance();
90     }
91 
newInstance(v8::Handle<v8::ObjectTemplate> objectTemplate)92     v8::Local<v8::Object> SafeAllocation::newInstance(v8::Handle<v8::ObjectTemplate> objectTemplate)
93     {
94         if (objectTemplate.IsEmpty())
95             return v8::Local<v8::Object>();
96         AllowAllocation allow;
97         return objectTemplate->NewInstance();
98     }
99 
newInstance(v8::Handle<v8::Function> function,int argc,v8::Handle<v8::Value> argv[])100     v8::Local<v8::Object> SafeAllocation::newInstance(v8::Handle<v8::Function> function, int argc, v8::Handle<v8::Value> argv[])
101     {
102         if (function.IsEmpty())
103             return v8::Local<v8::Object>();
104         AllowAllocation allow;
105         return function->NewInstance(argc, argv);
106     }
107 
108 } // namespace WebCore
109 
110 #endif // V8Utilities_h
111