OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_PROXY_H__ | 5 #ifndef V8_PROXY_H__ |
6 #define V8_PROXY_H__ | 6 #define V8_PROXY_H__ |
7 | 7 |
8 #include <v8.h> | 8 #include <v8.h> |
9 #include "v8_index.h" | 9 #include "v8_index.h" |
10 #include "v8_custom.h" | 10 #include "v8_custom.h" |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 // Run an already compiled script. | 231 // Run an already compiled script. |
232 v8::Local<v8::Value> RunScript(v8::Handle<v8::Script> script, | 232 v8::Local<v8::Value> RunScript(v8::Handle<v8::Script> script, |
233 bool inline_code); | 233 bool inline_code); |
234 | 234 |
235 // Call the function with the given receiver and arguments. | 235 // Call the function with the given receiver and arguments. |
236 v8::Local<v8::Value> CallFunction(v8::Handle<v8::Function> function, | 236 v8::Local<v8::Value> CallFunction(v8::Handle<v8::Function> function, |
237 v8::Handle<v8::Object> receiver, | 237 v8::Handle<v8::Object> receiver, |
238 int argc, | 238 int argc, |
239 v8::Handle<v8::Value> argv[]); | 239 v8::Handle<v8::Value> argv[]); |
240 | 240 |
| 241 // Returns the dom constructor function for the given node type. |
| 242 v8::Local<v8::Function> GetConstructor(V8ClassIndex::V8WrapperType type); |
| 243 |
241 // Returns the window object of the currently executing context. | 244 // Returns the window object of the currently executing context. |
242 static DOMWindow* retrieveWindow(); | 245 static DOMWindow* retrieveWindow(); |
243 // Returns the window object associated with a context. | 246 // Returns the window object associated with a context. |
244 static DOMWindow* retrieveWindow(v8::Handle<v8::Context> context); | 247 static DOMWindow* retrieveWindow(v8::Handle<v8::Context> context); |
245 // Returns V8Proxy object of the currently executing context. | 248 // Returns V8Proxy object of the currently executing context. |
246 static V8Proxy* retrieve(); | 249 static V8Proxy* retrieve(); |
247 // Returns V8Proxy object associated with a frame. | 250 // Returns V8Proxy object associated with a frame. |
248 static V8Proxy* retrieve(Frame* frame); | 251 static V8Proxy* retrieve(Frame* frame); |
249 // Returns V8Proxy object associated with a script execution context. | 252 // Returns V8Proxy object associated with a script execution context. |
250 static V8Proxy* retrieve(ScriptExecutionContext* context); | 253 static V8Proxy* retrieve(ScriptExecutionContext* context); |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 // Check whether a V8 value is a wrapper of type |classType|. | 423 // Check whether a V8 value is a wrapper of type |classType|. |
421 static bool IsWrapperOfType(v8::Handle<v8::Value> obj, | 424 static bool IsWrapperOfType(v8::Handle<v8::Value> obj, |
422 V8ClassIndex::V8WrapperType classType); | 425 V8ClassIndex::V8WrapperType classType); |
423 | 426 |
424 private: | 427 private: |
425 void initContextIfNeeded(); | 428 void initContextIfNeeded(); |
426 void DisconnectEventListeners(); | 429 void DisconnectEventListeners(); |
427 void SetSecurityToken(); | 430 void SetSecurityToken(); |
428 void ClearDocumentWrapper(); | 431 void ClearDocumentWrapper(); |
429 void UpdateDocumentWrapper(v8::Handle<v8::Value> wrapper); | 432 void UpdateDocumentWrapper(v8::Handle<v8::Value> wrapper); |
| 433 // Dispose global handles of m_contexts and friends. |
| 434 void DisposeContext(); |
430 | 435 |
431 static bool CanAccessPrivate(DOMWindow* target); | 436 static bool CanAccessPrivate(DOMWindow* target); |
432 | 437 |
433 // Check whether a V8 value is a DOM Event wrapper | 438 // Check whether a V8 value is a DOM Event wrapper |
434 static bool IsDOMEventWrapper(v8::Handle<v8::Value> obj); | 439 static bool IsDOMEventWrapper(v8::Handle<v8::Value> obj); |
435 | 440 |
436 static void* ToNativeObjectImpl(V8ClassIndex::V8WrapperType type, | 441 static void* ToNativeObjectImpl(V8ClassIndex::V8WrapperType type, |
437 v8::Handle<v8::Value> object); | 442 v8::Handle<v8::Value> object); |
438 | 443 |
439 // Take C pointer out of a v8 wrapper | 444 // Take C pointer out of a v8 wrapper |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 static V8ClassIndex::V8WrapperType GetSVGElementType(SVGElement* elm); | 494 static V8ClassIndex::V8WrapperType GetSVGElementType(SVGElement* elm); |
490 static const char* GetSVGExceptionName(int exception_code); | 495 static const char* GetSVGExceptionName(int exception_code); |
491 #endif | 496 #endif |
492 | 497 |
493 // Returns a local handle of the context. | 498 // Returns a local handle of the context. |
494 v8::Local<v8::Context> GetContext() { | 499 v8::Local<v8::Context> GetContext() { |
495 return v8::Local<v8::Context>::New(m_context); | 500 return v8::Local<v8::Context>::New(m_context); |
496 } | 501 } |
497 | 502 |
498 Frame* m_frame; | 503 Frame* m_frame; |
| 504 |
499 v8::Persistent<v8::Context> m_context; | 505 v8::Persistent<v8::Context> m_context; |
| 506 // DOM constructors are cached per context. A DOM constructor is a function |
| 507 // instance created from a DOM constructor template. There is one instance |
| 508 // per context. A DOM constructor is different from a normal function in |
| 509 // two ways: 1) it cannot be called as constructor (aka, used to create |
| 510 // a DOM object); 2) its __proto__ points to Object.prototype rather than |
| 511 // Function.prototype. The reason for 2) is that, in Safari, a DOM constructor |
| 512 // is a normal JS object, but not a function. Hotmail relies on the fact |
| 513 // that, in Safari, HTMLElement.__proto__ == Object.prototype. |
| 514 // |
| 515 // m_object_prototype is a cache of the original Object.prototype. |
| 516 // |
| 517 // Both handles must be disposed when the context is disposed. Otherwise, |
| 518 // it can keep all objects alive. |
| 519 v8::Persistent<v8::Array> m_dom_constructor_cache; |
| 520 v8::Persistent<v8::Value> m_object_prototype; |
| 521 |
500 v8::Persistent<v8::Object> m_global; | 522 v8::Persistent<v8::Object> m_global; |
501 | |
502 v8::Persistent<v8::Value> m_document; | 523 v8::Persistent<v8::Value> m_document; |
503 | 524 |
504 int m_handlerLineno; | 525 int m_handlerLineno; |
505 | 526 |
506 // A list of event listeners created for this frame, | 527 // A list of event listeners created for this frame, |
507 // the list gets cleared when removing all timeouts. | 528 // the list gets cleared when removing all timeouts. |
508 V8EventListenerList m_event_listeners; | 529 V8EventListenerList m_event_listeners; |
509 | 530 |
510 // A list of event listeners create for XMLHttpRequest object for this frame, | 531 // A list of event listeners create for XMLHttpRequest object for this frame, |
511 // the list gets cleared when removing all timeouts. | 532 // the list gets cleared when removing all timeouts. |
(...skipping 29 matching lines...) Expand all Loading... |
541 obj->ref(); | 562 obj->ref(); |
542 V8Proxy::SetJSWrapperForDOMObject( | 563 V8Proxy::SetJSWrapperForDOMObject( |
543 obj.get(), v8::Persistent<v8::Object>::New(args.Holder())); | 564 obj.get(), v8::Persistent<v8::Object>::New(args.Holder())); |
544 return args.Holder(); | 565 return args.Holder(); |
545 } | 566 } |
546 | 567 |
547 } // namespace WebCore | 568 } // namespace WebCore |
548 | 569 |
549 #endif // V8_PROXY_H__ | 570 #endif // V8_PROXY_H__ |
550 | 571 |
OLD | NEW |