Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(432)

Unified Diff: webkit/port/bindings/v8/v8_custom.cpp

Issue 113607: Use upstreamed v8 bindings for V8DOMWindowCustom (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « DEPS ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webkit/port/bindings/v8/v8_custom.cpp
===================================================================
--- webkit/port/bindings/v8/v8_custom.cpp (revision 16548)
+++ webkit/port/bindings/v8/v8_custom.cpp (working copy)
@@ -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 @@
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
« no previous file with comments | « DEPS ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698