diff options
author | japhet@chromium.org <japhet@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-20 23:05:24 +0000 |
---|---|---|
committer | japhet@chromium.org <japhet@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-20 23:05:24 +0000 |
commit | 740dd5b00dd02b4e867c19c7d02adac0dca4a692 (patch) | |
tree | daa2eb6692b9b5dfc3ab2bae05e6c75a47bdbe3a /webkit/port | |
parent | d459e99fd93e47d0783b301d9501f34af957e2e6 (diff) | |
download | chromium_src-740dd5b00dd02b4e867c19c7d02adac0dca4a692.zip chromium_src-740dd5b00dd02b4e867c19c7d02adac0dca4a692.tar.gz chromium_src-740dd5b00dd02b4e867c19c7d02adac0dca4a692.tar.bz2 |
Use upstreamed v8 bindings for V8DOMWindowCustom
BUG=12274
Review URL: http://codereview.chromium.org/113607
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16549 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/port')
-rw-r--r-- | webkit/port/bindings/v8/v8_custom.cpp | 291 |
1 files changed, 0 insertions, 291 deletions
diff --git a/webkit/port/bindings/v8/v8_custom.cpp b/webkit/port/bindings/v8/v8_custom.cpp index 857d7dc..0af5143 100644 --- a/webkit/port/bindings/v8/v8_custom.cpp +++ b/webkit/port/bindings/v8/v8_custom.cpp @@ -56,7 +56,6 @@ #include "DOMParser.h" #include "DOMStringList.h" #include "DOMTimer.h" -#include "DOMWindow.h" #include "Document.h" #include "DocumentFragment.h" #include "Event.h" @@ -142,297 +141,7 @@ ACCESSOR_GETTER(DocumentImplementation) { return wrapper; } -// TODO(mbelshe): This should move into V8DOMWindowCustom.cpp -// Can't move it right now because it depends on V8ScheduledAction, -// which is private to this file (v8_custom.cpp). -v8::Handle<v8::Value> V8Custom::WindowSetTimeoutImpl(const v8::Arguments& args, - bool single_shot) { - int num_arguments = args.Length(); - - if (num_arguments < 1) return v8::Undefined(); - - DOMWindow* imp = V8Proxy::ToNativeObject<DOMWindow>( - V8ClassIndex::DOMWINDOW, args.Holder()); - - if (!imp->frame()) - return v8::Undefined(); - - if (!V8Proxy::CanAccessFrame(imp->frame(), true)) - return v8::Undefined(); - - ScriptExecutionContext* script_context = - static_cast<ScriptExecutionContext*>(imp->frame()->document()); - - v8::Handle<v8::Value> function = args[0]; - - int32_t timeout = 0; - if (num_arguments >= 2) timeout = args[1]->Int32Value(); - - int id; - if (function->IsString()) { - // Don't allow setting timeouts to run empty functions! - // (Bug 1009597) - WebCore::String string_function = ToWebCoreString(function); - if (string_function.length() == 0) - return v8::Undefined(); - - id = DOMTimer::install(script_context, - new ScheduledAction(string_function), timeout, - single_shot); - } else if (function->IsFunction()) { - int param_count = num_arguments >= 2 ? num_arguments - 2 : 0; - v8::Local<v8::Value>* params = 0; - if (param_count > 0) { - params = new v8::Local<v8::Value>[param_count]; - for (int i = 0; i < param_count; i++) - // parameters must be globalized - params[i] = args[i+2]; - } - - // params is passed to action, and released in action's destructor - ScheduledAction* action = new ScheduledAction( - v8::Handle<v8::Function>::Cast(function), param_count, params); - - delete[] params; - - id = DOMTimer::install(script_context, action, timeout, single_shot); - } else { - // TODO(fqian): what's the right return value if failed. - return v8::Undefined(); - } - return v8::Integer::New(id); -} - - -// DOMWindow ------------------------------------------------------------------- - -static bool IsAscii(const String& str) { - for (size_t i = 0; i < str.length(); i++) { - if (str[i] > 0xFF) - return false; - } - return true; -} - -static v8::Handle<v8::Value> Base64Convert(const String& str, bool encode) { - if (!IsAscii(str)) { - V8Proxy::SetDOMException(INVALID_CHARACTER_ERR); - return v8::Handle<v8::Value>(); - } - - Vector<char> in(str.length()); - for (size_t i = 0; i < str.length(); i++) { - in[i] = static_cast<char>(str[i]); - } - Vector<char> out; - - if (encode) { - base64Encode(in, out); - } else { - if (!base64Decode(in, out)) { - V8Proxy::ThrowError(V8Proxy::GENERAL_ERROR, "Cannot decode base64"); - return v8::Undefined(); - } - } - - return v8String(String(out.data(), out.size())); -} - -CALLBACK_FUNC_DECL(DOMWindowAtob) { - INC_STATS("DOM.DOMWindow.atob()"); - DOMWindow* imp = V8Proxy::ToNativeObject<DOMWindow>( - V8ClassIndex::DOMWINDOW, args.Holder()); - - if (!V8Proxy::CanAccessFrame(imp->frame(), true)) - return v8::Undefined(); - - if (args.Length() < 1) { - V8Proxy::ThrowError(V8Proxy::SYNTAX_ERROR, "Not enough arguments"); - return v8::Undefined(); - } - - if (args[0]->IsNull()) return v8String(""); - - String str = ToWebCoreString(args[0]); - return Base64Convert(str, false); -} - -CALLBACK_FUNC_DECL(DOMWindowBtoa) { - INC_STATS("DOM.DOMWindow.btoa()"); - DOMWindow* imp = V8Proxy::ToNativeObject<DOMWindow>( - V8ClassIndex::DOMWINDOW, args.Holder()); - - if (!V8Proxy::CanAccessFrame(imp->frame(), true)) - return v8::Undefined(); - - if (args.Length() < 1) { - V8Proxy::ThrowError(V8Proxy::SYNTAX_ERROR, "Not enough arguments"); - return v8::Undefined(); - } - - if (args[0]->IsNull()) return v8String(""); - - String str = ToWebCoreString(args[0]); - return Base64Convert(str, true); -} - -// TODO(fqian): returning string is cheating, and we should -// fix this by calling toString function on the receiver. -// However, V8 implements toString in JavaScript, which requires -// switching context of receiver. I consider it is dangerous. -CALLBACK_FUNC_DECL(DOMWindowToString) -{ - INC_STATS("DOM.DOMWindow.toString()"); - return args.This()->ObjectProtoToString(); -} - -CALLBACK_FUNC_DECL(DOMWindowNOP) -{ - INC_STATS("DOM.DOMWindow.nop()"); - return v8::Undefined(); -} - - -static String EventNameFromAttributeName(const String& name) { - ASSERT(name.startsWith("on")); - String event_type = name.substring(2); - - if (event_type.startsWith("w")) { - switch(event_type[event_type.length() - 1]) { - case 't': - event_type = "webkitAnimationStart"; - break; - case 'n': - event_type = "webkitAnimationIteration"; - break; - case 'd': - ASSERT(event_type.length() > 7); - if (event_type[7] == 'a') - event_type = "webkitAnimationEnd"; - else - event_type = "webkitTransitionEnd"; - break; - } - } - - return event_type; -} - - -ACCESSOR_SETTER(DOMWindowEventHandler) { - v8::Handle<v8::Object> holder = V8Proxy::LookupDOMWrapper( - V8ClassIndex::DOMWINDOW, info.This()); - if (holder.IsEmpty()) - return; - - DOMWindow* imp = V8Proxy::ToNativeObject<DOMWindow>( - V8ClassIndex::DOMWINDOW, holder); - if (!imp->frame()) - return; - - Document* doc = imp->frame()->document(); - if (!doc) - return; - - String key = ToWebCoreString(name); - String event_type = EventNameFromAttributeName(key); - - if (value->IsNull()) { - // Clear the event listener - imp->clearAttributeEventListener(event_type); - } else { - V8Proxy* proxy = V8Proxy::retrieve(imp->frame()); - if (!proxy) - return; - - RefPtr<EventListener> listener = - proxy->FindOrCreateV8EventListener(value, true); - if (listener) { - imp->setAttributeEventListener(event_type, listener); - } - } -} - - -ACCESSOR_GETTER(DOMWindowEventHandler) { - v8::Handle<v8::Object> holder = V8Proxy::LookupDOMWrapper( - V8ClassIndex::DOMWINDOW, info.This()); - if (holder.IsEmpty()) - return v8::Undefined(); - - DOMWindow* imp = V8Proxy::ToNativeObject<DOMWindow>( - V8ClassIndex::DOMWINDOW, holder); - if (!imp->frame()) - return v8::Undefined(); - - Document* doc = imp->frame()->document(); - if (!doc) - return v8::Undefined(); - - String key = ToWebCoreString(name); - String event_type = EventNameFromAttributeName(key); - - EventListener* listener = imp->getAttributeEventListener(event_type); - return V8Proxy::EventListenerToV8Object(listener); -} - // --------------- Security Checks ------------------------- -NAMED_ACCESS_CHECK(DOMWindow) { - ASSERT(V8ClassIndex::FromInt(data->Int32Value()) == V8ClassIndex::DOMWINDOW); - v8::Handle<v8::Value> window = - V8Proxy::LookupDOMWrapper(V8ClassIndex::DOMWINDOW, host); - if (window.IsEmpty()) - return false; // the frame is gone. - - DOMWindow* target_win = - V8Proxy::ToNativeObject<DOMWindow>(V8ClassIndex::DOMWINDOW, window); - - ASSERT(target_win); - - Frame* target = target_win->frame(); - if (!target) - return false; - - if (key->IsString()) { - String name = ToWebCoreString(key); - - // Allow access of GET and HAS if index is a subframe. - if ((type == v8::ACCESS_GET || type == v8::ACCESS_HAS) && - target->tree()->child(name)) { - return true; - } - } - - return V8Proxy::CanAccessFrame(target, false); -} - - -INDEXED_ACCESS_CHECK(DOMWindow) { - ASSERT(V8ClassIndex::FromInt(data->Int32Value()) == V8ClassIndex::DOMWINDOW); - v8::Handle<v8::Value> window = - V8Proxy::LookupDOMWrapper(V8ClassIndex::DOMWINDOW, host); - if (window.IsEmpty()) - return false; - - DOMWindow* target_win = - V8Proxy::ToNativeObject<DOMWindow>(V8ClassIndex::DOMWINDOW, window); - - ASSERT(target_win); - - Frame* target = target_win->frame(); - if (!target) - return false; - - // Allow access of GET and HAS if index is a subframe. - if ((type == v8::ACCESS_GET || type == v8::ACCESS_HAS) && - target->tree()->child(index)) { - return true; - } - - return V8Proxy::CanAccessFrame(target, false); -} - - INDEXED_ACCESS_CHECK(History) { ASSERT(V8ClassIndex::FromInt(data->Int32Value()) == V8ClassIndex::HISTORY); // Only allow same origin access |