Changeset 28572 in webkit
- Timestamp:
- Dec 8, 2007 11:56:34 PM (16 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r28570 r28572 1 2007-12-08 Sam Weinig <sam@webkit.org> 2 3 Reviewed by Oliver. 4 5 Cleanup kjs_window.h/cpp. 6 7 * bindings/js/kjs_window.cpp: 8 (KJS::WindowPrivate::WindowPrivate): 9 (KJS::DOMWindowTimer::DOMWindowTimer): 10 (KJS::Window::Window): 11 (KJS::Window::retrieveWindow): 12 (KJS::Window::retrieveActive): 13 (KJS::Window::retrieve): 14 (KJS::Window::location): 15 (KJS::Window::mark): 16 (KJS::allowPopUp): 17 (KJS::parseModalDialogFeatures): 18 (KJS::floatFeature): 19 (KJS::canShowModalDialog): 20 (KJS::canShowModalDialogNow): 21 (KJS::showModalDialog): 22 (KJS::Window::getValueProperty): 23 (KJS::Window::getOwnPropertySlot): 24 (KJS::Window::globalExec): 25 (KJS::Window::setListener): 26 (KJS::Window::getListener): 27 (KJS::Window::findOrCreateJSEventListener): 28 (KJS::Window::findOrCreateJSUnprotectedEventListener): 29 (KJS::Window::clearHelperObjectProperties): 30 (KJS::Window::setCurrentEvent): 31 (KJS::WindowProtoFuncAToB::callAsFunction): 32 (KJS::WindowProtoFuncBToA::callAsFunction): 33 (KJS::WindowProtoFuncOpen::callAsFunction): 34 (KJS::WindowProtoFuncSetTimeout::callAsFunction): 35 (KJS::WindowProtoFuncClearTimeout::callAsFunction): 36 (KJS::WindowProtoFuncSetInterval::callAsFunction): 37 (KJS::WindowProtoFuncAddEventListener::callAsFunction): 38 (KJS::WindowProtoFuncRemoveEventListener::callAsFunction): 39 (KJS::WindowProtoFuncShowModalDialog::callAsFunction): 40 (KJS::WindowProtoFuncNotImplemented::callAsFunction): 41 * bindings/js/kjs_window.h: 42 (KJS::PausedTimeouts::PausedTimeouts): 43 (KJS::PausedTimeouts::takeTimeouts): 44 (KJS::ScheduledAction::ScheduledAction): 45 1 46 2007-12-08 Sam Weinig <sam@webkit.org> 2 47 -
trunk/WebCore/bindings/js/kjs_window.cpp
r28570 r28572 38 38 #include "FrameLoader.h" 39 39 #include "FrameTree.h" 40 #include "FrameView.h"41 40 #include "GCController.h" 42 41 #include "HTMLDocument.h" 43 #include "JSCSSRule.h"44 #include "JSCSSValue.h"45 42 #include "JSDOMExceptionConstructor.h" 46 43 #include "JSDOMWindow.h" … … 49 46 #include "JSHTMLCollection.h" 50 47 #include "JSHTMLOptionElementConstructor.h" 51 #include "JSMutationEvent.h"52 #include "JSNode.h"53 #include "JSNodeFilter.h"54 #include "JSRange.h"55 48 #include "JSXMLHttpRequest.h" 56 49 #include "Logging.h" … … 85 78 86 79 struct WindowPrivate { 87 WindowPrivate() 80 WindowPrivate() 88 81 : loc(0) 89 82 , m_evt(0) … … 97 90 Window::UnprotectedListenersMap jsUnprotectedHTMLEventListeners; 98 91 mutable Location* loc; 99 WebCore::Event *m_evt;92 WebCore::Event* m_evt; 100 93 JSValue** m_returnValueSlot; 94 101 95 typedef HashMap<int, DOMWindowTimer*> TimeoutsMap; 102 96 TimeoutsMap m_timeouts; … … 105 99 class DOMWindowTimer : public TimerBase { 106 100 public: 107 DOMWindowTimer(int timeoutId, int nestingLevel, Window* o, ScheduledAction* a) 108 : m_timeoutId(timeoutId), m_nestingLevel(nestingLevel), m_object(o), m_action(a) { } 101 DOMWindowTimer(int timeoutId, int nestingLevel, Window* object, ScheduledAction* action) 102 : m_timeoutId(timeoutId) 103 , m_nestingLevel(nestingLevel) 104 , m_object(object) 105 , m_action(action) 106 { 107 } 108 109 109 virtual ~DOMWindowTimer() 110 110 { … … 210 210 211 211 Window::Window(DOMWindow* window) 212 : m_impl(window)213 , d(new WindowPrivate)212 : m_impl(window) 213 , d(new WindowPrivate) 214 214 { 215 215 // Window destruction is not thread-safe because of … … 246 246 } 247 247 248 Window *Window::retrieveWindow(Frame *f)249 { 250 JSObject *o = retrieve(f)->getObject();251 252 ASSERT(o || !f ->settings() || !f->settings()->isJavaScriptEnabled());253 return static_cast<Window 254 } 255 256 Window *Window::retrieveActive(ExecState *exec)257 { 258 JS Value *imp= exec->dynamicGlobalObject();259 ASSERT( imp);260 return static_cast<Window*>( imp);261 } 262 263 JSValue *Window::retrieve(Frame *p)264 { 265 ASSERT( p);266 if (KJSProxy *proxy = p->scriptProxy())248 Window* Window::retrieveWindow(Frame* frame) 249 { 250 JSObject* o = retrieve(frame)->getObject(); 251 252 ASSERT(o || !frame->settings() || !frame->settings()->isJavaScriptEnabled()); 253 return static_cast<Window*>(o); 254 } 255 256 Window* Window::retrieveActive(ExecState* exec) 257 { 258 JSGlobalObject* globalObject = exec->dynamicGlobalObject(); 259 ASSERT(globalObject); 260 return static_cast<Window*>(globalObject); 261 } 262 263 JSValue* Window::retrieve(Frame* frame) 264 { 265 ASSERT(frame); 266 if (KJSProxy* proxy = frame->scriptProxy()) 267 267 return proxy->globalObject(); // the Global object is the "window" 268 268 269 269 return jsUndefined(); // This can happen with JS disabled on the domain of that window 270 270 } 271 271 272 Location *Window::location() const273 { 274 if (!d->loc)275 d->loc = new Location(impl()->frame());276 return d->loc;272 Location* Window::location() const 273 { 274 if (!d->loc) 275 d->loc = new Location(impl()->frame()); 276 return d->loc; 277 277 } 278 278 … … 280 280 void Window::mark() 281 281 { 282 JSGlobalObject::mark(); 283 if (d->loc && !d->loc->marked()) 284 d->loc->mark(); 285 } 286 287 static bool allowPopUp(ExecState *exec, Window *window) 288 { 289 Frame* frame = window->impl()->frame(); 282 JSGlobalObject::mark(); 283 if (d->loc && !d->loc->marked()) 284 d->loc->mark(); 285 } 286 287 static bool allowPopUp(Frame* frame) 288 { 290 289 if (!frame) 291 290 return false; 292 if ( window->impl()->frame()->scriptProxy()->processingUserGesture())291 if (frame->scriptProxy()->processingUserGesture()) 293 292 return true; 294 293 Settings* settings = frame->settings(); … … 296 295 } 297 296 298 static HashMap<String, String> parseModalDialogFeatures( ExecState *exec, JSValue *featuresArg)297 static HashMap<String, String> parseModalDialogFeatures(const String& featuresArg) 299 298 { 300 299 HashMap<String, String> map; 301 300 302 Vector<String> features = valueToStringWithUndefinedOrNullCheck(exec, featuresArg).split(';');301 Vector<String> features = featuresArg.split(';'); 303 302 Vector<String>::const_iterator end = features.end(); 304 303 for (Vector<String>::const_iterator it = features.begin(); it != end; ++it) { … … 335 334 } 336 335 337 static float floatFeature(const HashMap<String, String> &features, const char *key, float min, float max, float defaultValue)336 static float floatFeature(const HashMap<String, String>& features, const char* key, float min, float max, float defaultValue) 338 337 { 339 338 HashMap<String, String>::const_iterator it = features.find(key); … … 401 400 } 402 401 403 static bool canShowModalDialog(const Window *window) 404 { 405 Frame* frame = window->impl()->frame(); 402 static bool canShowModalDialog(const Frame* frame) 403 { 406 404 if (!frame) 407 405 return false; 408 409 406 return frame->page()->chrome()->canRunModal(); 410 407 } 411 408 412 static bool canShowModalDialogNow(const Window *window) 413 { 414 Frame* frame = window->impl()->frame(); 409 static bool canShowModalDialogNow(const Frame* frame) 410 { 415 411 if (!frame) 416 412 return false; 417 418 413 return frame->page()->chrome()->canRunModalNow(); 419 414 } 420 415 421 static JSValue* showModalDialog(ExecState* exec, Window* openerWindow, const List& args) 422 { 423 if (!canShowModalDialogNow(openerWindow) || !allowPopUp(exec, openerWindow)) 424 return jsUndefined(); 425 426 const HashMap<String, String> features = parseModalDialogFeatures(exec, args[2]); 427 428 bool trusted = false; 429 430 WindowFeatures wargs; 416 static JSValue* showModalDialog(ExecState* exec, Frame* frame, const String& url, JSValue* dialogArgs, const String& featureArgs) 417 { 418 if (!canShowModalDialogNow(frame) || !allowPopUp(frame)) 419 return jsUndefined(); 420 421 const HashMap<String, String> features = parseModalDialogFeatures(featureArgs); 422 423 const bool trusted = false; 431 424 432 425 // The following features from Microsoft's documentation are not implemented: … … 437 430 // - help: boolFeature(features, "help", true), makes help icon appear in dialog (what does it do on Windows?) 438 431 // - unadorned: trusted && boolFeature(features, "unadorned"); 439 Frame* frame = openerWindow->impl()->frame();440 432 if (!frame) 441 433 return jsUndefined(); … … 443 435 FloatRect screenRect = screenAvailableRect(frame->view()); 444 436 437 WindowFeatures wargs; 445 438 wargs.width = floatFeature(features, "dialogwidth", 100, screenRect.width(), 620); // default here came from frame size of dialog in MacIE 446 439 wargs.widthSet = true; … … 473 466 wargs.fullscreen = false; 474 467 475 Frame* dialogFrame = createWindow(exec, frame, valueToStringWithUndefinedOrNullCheck(exec, args[0]), "", wargs, args[1]);468 Frame* dialogFrame = createWindow(exec, frame, url, "", wargs, dialogArgs); 476 469 if (!dialogFrame) 477 470 return jsUndefined(); … … 608 601 return getListener(exec,submitEvent); 609 602 case Onbeforeunload: 610 611 603 return getListener(exec, beforeunloadEvent); 604 case Onunload: 612 605 return getListener(exec, unloadEvent); 613 606 } … … 655 648 if (entry->attr & Function) { 656 649 if (entry->value.functionValue == &WindowProtoFuncShowModalDialog::create) { 657 if (!canShowModalDialog( this))650 if (!canShowModalDialog(impl()->frame())) 658 651 return false; 659 652 } … … 883 876 ExecState* Window::globalExec() 884 877 { 885 // we need to make sure that any script execution happening in this878 // We need to make sure that any script execution happening in this 886 879 // frame does not destroy it 887 880 ASSERT(impl()->frame()); … … 908 901 } 909 902 910 void Window::setListener(ExecState *exec, const AtomicString &eventType, JSValue *func) 911 { 912 if (!allowsAccessFrom(exec)) 913 return; 914 Frame* frame = impl()->frame(); 915 if (!frame) 916 return; 917 Document* doc = frame->document(); 918 if (!doc) 919 return; 920 921 doc->setHTMLWindowEventListener(eventType, findOrCreateJSEventListener(func,true)); 922 } 923 924 JSValue *Window::getListener(ExecState *exec, const AtomicString &eventType) const 925 { 926 if (!allowsAccessFrom(exec)) 927 return jsUndefined(); 928 Frame* frame = impl()->frame(); 929 if (!frame) 930 return jsUndefined(); 931 Document* doc = frame->document(); 932 if (!doc) 933 return jsUndefined(); 934 935 WebCore::EventListener *listener = doc->getHTMLWindowEventListener(eventType); 936 if (listener && static_cast<JSEventListener*>(listener)->listenerObj()) 937 return static_cast<JSEventListener*>(listener)->listenerObj(); 938 else 903 void Window::setListener(ExecState* exec, const AtomicString& eventType, JSValue* func) 904 { 905 ASSERT(impl()->frame()); 906 Document* doc = impl()->frame()->document(); 907 if (!doc) 908 return; 909 910 doc->setHTMLWindowEventListener(eventType, findOrCreateJSEventListener(func, true)); 911 } 912 913 JSValue* Window::getListener(ExecState* exec, const AtomicString& eventType) const 914 { 915 ASSERT(impl()->frame()); 916 Document* doc = impl()->frame()->document(); 917 if (!doc) 918 return jsUndefined(); 919 920 WebCore::EventListener* listener = doc->getHTMLWindowEventListener(eventType); 921 if (listener && static_cast<JSEventListener*>(listener)->listenerObj()) 922 return static_cast<JSEventListener*>(listener)->listenerObj(); 939 923 return jsNull(); 940 924 } … … 949 933 } 950 934 951 JSEventListener *Window::findOrCreateJSEventListener(JSValue *val, bool html)952 { 953 JSEventListener *listener = findJSEventListener(val, html);954 if (listener)955 return listener;956 957 if (!val->isObject())958 return 0;959 JSObject *object = static_cast<JSObject*>(val);960 961 // Note that the JSEventListener constructor adds it to our jsEventListeners list962 return new JSEventListener(object, this, html);935 JSEventListener* Window::findOrCreateJSEventListener(JSValue* val, bool html) 936 { 937 JSEventListener* listener = findJSEventListener(val, html); 938 if (listener) 939 return listener; 940 941 if (!val->isObject()) 942 return 0; 943 JSObject* object = static_cast<JSObject*>(val); 944 945 // Note that the JSEventListener constructor adds it to our jsEventListeners list 946 return new JSEventListener(object, this, html); 963 947 } 964 948 … … 972 956 } 973 957 974 JSUnprotectedEventListener *Window::findOrCreateJSUnprotectedEventListener(JSValue *val, bool html) 975 { 976 JSUnprotectedEventListener *listener = findJSUnprotectedEventListener(val, html); 977 if (listener) 978 return listener; 979 980 if (!val->isObject()) 981 return 0; 982 JSObject *object = static_cast<JSObject *>(val); 983 984 // The JSUnprotectedEventListener constructor adds it to our jsUnprotectedEventListeners map. 985 return new JSUnprotectedEventListener(object, this, html); 958 JSUnprotectedEventListener* Window::findOrCreateJSUnprotectedEventListener(JSValue* val, bool html) 959 { 960 JSUnprotectedEventListener* listener = findJSUnprotectedEventListener(val, html); 961 if (listener) 962 return listener; 963 if (!val->isObject()) 964 return 0; 965 JSObject* object = static_cast<JSObject*>(val); 966 967 // The JSUnprotectedEventListener constructor adds it to our jsUnprotectedEventListeners map. 968 return new JSUnprotectedEventListener(object, this, html); 986 969 } 987 970 988 971 void Window::clearHelperObjectProperties() 989 972 { 990 d->loc = 0;991 d->m_evt = 0;973 d->loc = 0; 974 d->m_evt = 0; 992 975 } 993 976 … … 1012 995 } 1013 996 1014 void Window::setCurrentEvent(Event *evt)1015 { 1016 d->m_evt = evt;997 void Window::setCurrentEvent(Event* evt) 998 { 999 d->m_evt = evt; 1017 1000 } 1018 1001 … … 1155 1138 if (!thisObj->inherits(&Window::info)) 1156 1139 return throwError(exec, TypeError); 1157 Window* window = static_cast<Window*>(thisObj);1158 Frame* frame = window->impl()->frame();1159 if (!frame)1160 return jsUndefined();1161 1162 JSValue* v = args[0];1163 UString s = v->toString(exec);1164 1140 1165 1141 if (args.size() < 1) 1166 1142 return throwError(exec, SyntaxError, "Not enough arguments"); 1143 1144 JSValue* v = args[0]; 1167 1145 if (v->isNull()) 1168 1146 return jsString(); 1147 1148 UString s = v->toString(exec); 1169 1149 if (!s.is8Bit()) { 1170 1150 setDOMException(exec, INVALID_CHARACTER_ERR); 1171 1151 return jsUndefined(); 1172 1152 } 1173 1153 1174 1154 Vector<char> in(s.size()); 1175 1155 for (int i = 0; i < s.size(); ++i) … … 1179 1159 if (!base64Decode(in, out)) 1180 1160 return throwError(exec, GeneralError, "Cannot decode base64"); 1181 1161 1182 1162 return jsString(String(out.data(), out.size())); 1183 1163 } 1184 1164 1185 1165 JSValue* WindowProtoFuncBToA::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args) 1166 { 1167 if (!thisObj->inherits(&Window::info)) 1168 return throwError(exec, TypeError); 1169 1170 if (args.size() < 1) 1171 return throwError(exec, SyntaxError, "Not enough arguments"); 1172 1173 JSValue* v = args[0]; 1174 if (v->isNull()) 1175 return jsString(); 1176 1177 UString s = v->toString(exec); 1178 if (!s.is8Bit()) { 1179 setDOMException(exec, INVALID_CHARACTER_ERR); 1180 return jsUndefined(); 1181 } 1182 1183 Vector<char> in(s.size()); 1184 for (int i = 0; i < s.size(); ++i) 1185 in[i] = static_cast<char>(s.data()[i].unicode()); 1186 Vector<char> out; 1187 1188 base64Encode(in, out); 1189 1190 return jsString(String(out.data(), out.size())); 1191 } 1192 1193 JSValue* WindowProtoFuncOpen::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args) 1186 1194 { 1187 1195 if (!thisObj->inherits(&Window::info)) … … 1191 1199 if (!frame) 1192 1200 return jsUndefined(); 1193 1194 JSValue* v = args[0];1195 UString s = v->toString(exec);1196 1197 if (args.size() < 1)1198 return throwError(exec, SyntaxError, "Not enough arguments");1199 if (v->isNull())1200 return jsString();1201 if (!s.is8Bit()) {1202 setDOMException(exec, INVALID_CHARACTER_ERR);1203 return jsUndefined();1204 }1205 1206 Vector<char> in(s.size());1207 for (int i = 0; i < s.size(); ++i)1208 in[i] = static_cast<char>(s.data()[i].unicode());1209 Vector<char> out;1210 1211 base64Encode(in, out);1212 1213 return jsString(String(out.data(), out.size()));1214 }1215 1216 JSValue* WindowProtoFuncOpen::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args)1217 {1218 if (!thisObj->inherits(&Window::info))1219 return throwError(exec, TypeError);1220 Window* window = static_cast<Window*>(thisObj);1221 Frame* frame = window->impl()->frame();1222 if (!frame)1223 return jsUndefined();1224 1201 Frame* activeFrame = Window::retrieveActive(exec)->impl()->frame(); 1225 1202 if (!activeFrame) … … 1233 1210 // Because FrameTree::find() returns true for empty strings, we must check for empty framenames. 1234 1211 // Otherwise, illegitimate window.open() calls with no name will pass right through the popup blocker. 1235 if (!allowPopUp( exec, window) && (frameName.isEmpty() || !frame->tree()->find(frameName)))1212 if (!allowPopUp(frame) && (frameName.isEmpty() || !frame->tree()->find(frameName))) 1236 1213 return jsUndefined(); 1237 1214 … … 1254 1231 completedURL = activeFrame->document()->completeURL(urlString); 1255 1232 1256 const Window* window = Window::retrieveWindow(frame);1257 if (!completedURL.isEmpty() && (!completedURL.startsWith("javascript:", false) || ( window && window->allowsAccessFrom(exec)))) {1233 const Window* targetedWindow = Window::retrieveWindow(frame); 1234 if (!completedURL.isEmpty() && (!completedURL.startsWith("javascript:", false) || (targetedWindow && targetedWindow->allowsAccessFrom(exec)))) { 1258 1235 bool userGesture = activeFrame->scriptProxy()->processingUserGesture(); 1259 1236 frame->loader()->scheduleLocationChange(completedURL, activeFrame->loader()->outgoingReferrer(), false, userGesture); … … 1287 1264 return throwError(exec, TypeError); 1288 1265 Window* window = static_cast<Window*>(thisObj); 1289 Frame* frame = window->impl()->frame(); 1290 if (!frame) 1291 return jsUndefined(); 1292 1293 JSValue *v = args[0]; 1294 UString s = v->toString(exec); 1295 1296 if (!window->allowsAccessFrom(exec)) 1297 return jsUndefined(); 1298 if (v->isString()) { 1299 int i = args[1]->toInt32(exec); 1300 int r = (const_cast<Window*>(window))->installTimeout(s, i, true /*single shot*/); 1301 return jsNumber(r); 1302 } 1303 else if (v->isObject() && static_cast<JSObject *>(v)->implementsCall()) { 1304 JSValue *func = args[0]; 1305 int i = args[1]->toInt32(exec); 1306 1307 List argsTail; 1308 args.getSlice(2, argsTail); 1309 1310 int r = (const_cast<Window*>(window))->installTimeout(func, argsTail, i, true /*single shot*/); 1311 return jsNumber(r); 1312 } 1313 else 1314 return jsUndefined(); 1266 1267 JSValue* v = args[0]; 1268 if (v->isString()) 1269 return jsNumber(window->installTimeout(v->toString(exec), args[1]->toInt32(exec), true /*single shot*/)); 1270 if (v->isObject() && static_cast<JSObject*>(v)->implementsCall()) { 1271 List argsTail; 1272 args.getSlice(2, argsTail); 1273 return jsNumber(window->installTimeout(v, argsTail, args[1]->toInt32(exec), true /*single shot*/)); 1274 } 1275 1276 return jsUndefined(); 1315 1277 } 1316 1278 … … 1319 1281 // Also the implementation for window.clearInterval() 1320 1282 1283 if (!thisObj->inherits(&Window::info)) 1284 return throwError(exec, TypeError); 1285 Window* window = static_cast<Window*>(thisObj); 1286 1287 window->clearTimeout(args[0]->toInt32(exec)); 1288 return jsUndefined(); 1289 } 1290 1291 JSValue* WindowProtoFuncSetInterval::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args) 1292 { 1293 if (!thisObj->inherits(&Window::info)) 1294 return throwError(exec, TypeError); 1295 Window* window = static_cast<Window*>(thisObj); 1296 1297 if (args.size() >= 2) { 1298 JSValue* v = args[0]; 1299 int delay = args[1]->toInt32(exec); 1300 if (v->isString()) 1301 return jsNumber(window->installTimeout(v->toString(exec), delay, false)); 1302 if (v->isObject() && static_cast<JSObject*>(v)->implementsCall()) { 1303 List argsTail; 1304 args.getSlice(2, argsTail); 1305 return jsNumber(window->installTimeout(v, argsTail, delay, false)); 1306 } 1307 } 1308 1309 return jsUndefined(); 1310 1311 } 1312 1313 JSValue* WindowProtoFuncAddEventListener::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args) 1314 { 1321 1315 if (!thisObj->inherits(&Window::info)) 1322 1316 return throwError(exec, TypeError); … … 1326 1320 return jsUndefined(); 1327 1321 1328 JSValue *v = args[0];1329 1330 if (!window->allowsAccessFrom(exec))1331 return jsUndefined();1332 (const_cast<Window*>(window))->clearTimeout(v->toInt32(exec)); 1322 if (JSEventListener* listener = window->findOrCreateJSEventListener(args[1])) { 1323 if (Document* doc = frame->document()) 1324 doc->addWindowEventListener(AtomicString(args[0]->toString(exec)), listener, args[2]->toBoolean(exec)); 1325 } 1326 1333 1327 return jsUndefined(); 1334 1328 } 1335 1329 1336 JSValue* WindowProtoFunc SetInterval::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args)1330 JSValue* WindowProtoFuncRemoveEventListener::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args) 1337 1331 { 1338 1332 if (!thisObj->inherits(&Window::info)) … … 1343 1337 return jsUndefined(); 1344 1338 1345 JSValue *v = args[0]; 1346 UString s = v->toString(exec); 1347 1348 if (!window->allowsAccessFrom(exec)) 1349 return jsUndefined(); 1350 if (args.size() >= 2 && v->isString()) { 1351 int i = args[1]->toInt32(exec); 1352 int r = (const_cast<Window*>(window))->installTimeout(s, i, false); 1353 return jsNumber(r); 1354 } 1355 else if (args.size() >= 2 && v->isObject() && static_cast<JSObject *>(v)->implementsCall()) { 1356 JSValue *func = args[0]; 1357 int i = args[1]->toInt32(exec); 1358 1359 List argsTail; 1360 args.getSlice(2, argsTail); 1361 1362 int r = (const_cast<Window*>(window))->installTimeout(func, argsTail, i, false); 1363 return jsNumber(r); 1364 } 1365 else 1366 return jsUndefined(); 1367 1368 } 1369 1370 JSValue* WindowProtoFuncAddEventListener::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args) 1339 if (JSEventListener* listener = window->findJSEventListener(args[1])) { 1340 if (Document* doc = frame->document()) 1341 doc->removeWindowEventListener(AtomicString(args[0]->toString(exec)), listener, args[2]->toBoolean(exec)); 1342 } 1343 1344 return jsUndefined(); 1345 } 1346 1347 JSValue* WindowProtoFuncShowModalDialog::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args) 1371 1348 { 1372 1349 if (!thisObj->inherits(&Window::info)) … … 1377 1354 return jsUndefined(); 1378 1355 1379 if (!window->allowsAccessFrom(exec)) 1380 return jsUndefined(); 1381 if (JSEventListener* listener = window->findOrCreateJSEventListener(args[1])) 1382 if (Document *doc = frame->document()) 1383 doc->addWindowEventListener(AtomicString(args[0]->toString(exec)), listener, args[2]->toBoolean(exec)); 1384 return jsUndefined(); 1385 } 1386 1387 JSValue* WindowProtoFuncRemoveEventListener::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args) 1356 return showModalDialog(exec, frame, valueToStringWithUndefinedOrNullCheck(exec, args[0]), args[1], valueToStringWithUndefinedOrNullCheck(exec, args[2])); 1357 } 1358 1359 JSValue* WindowProtoFuncNotImplemented::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args) 1388 1360 { 1389 1361 if (!thisObj->inherits(&Window::info)) 1390 1362 return throwError(exec, TypeError); 1391 Window* window = static_cast<Window*>(thisObj); 1392 Frame* frame = window->impl()->frame(); 1393 if (!frame) 1394 return jsUndefined(); 1395 1396 if (!window->allowsAccessFrom(exec)) 1397 return jsUndefined(); 1398 if (JSEventListener* listener = window->findJSEventListener(args[1])) 1399 if (Document *doc = frame->document()) 1400 doc->removeWindowEventListener(AtomicString(args[0]->toString(exec)), listener, args[2]->toBoolean(exec)); 1401 return jsUndefined(); 1402 } 1403 1404 JSValue* WindowProtoFuncShowModalDialog::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args) 1405 { 1406 if (!thisObj->inherits(&Window::info)) 1407 return throwError(exec, TypeError); 1408 Window* window = static_cast<Window*>(thisObj); 1409 Frame* frame = window->impl()->frame(); 1410 if (!frame) 1411 return jsUndefined(); 1412 1413 return showModalDialog(exec, window, args); 1414 } 1415 1416 JSValue* WindowProtoFuncNotImplemented::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args) 1417 { 1418 if (!thisObj->inherits(&Window::info)) 1419 return throwError(exec, TypeError); 1420 1421 // Not implemented. 1363 1422 1364 return jsUndefined(); 1423 1365 } -
trunk/WebCore/bindings/js/kjs_window.h
r28570 r28572 25 25 #include <kjs/protect.h> 26 26 #include <wtf/HashMap.h> 27 #include <wtf/Noncopyable.h> 27 28 #include <wtf/OwnPtr.h> 28 29 … … 31 32 class DOMWindow; 32 33 class Frame; 33 class FrameView;34 class JSDOMWindow;35 34 class JSEventListener; 36 35 class JSUnprotectedEventListener; 37 class Node;38 36 } 39 37 40 38 namespace KJS { 41 39 40 class DOMWindowTimer; 42 41 class Location; 43 42 class PausedTimeout; … … 45 44 class Window; 46 45 class WindowFunc; 47 48 class PausedTimeouts { 46 class WindowPrivate; 47 48 class PausedTimeouts : Noncopyable { 49 49 public: 50 PausedTimeouts(PausedTimeout *a, size_t length) : m_array(a), m_length(length) { } 50 PausedTimeouts(PausedTimeout* array, size_t length) 51 : m_array(array) 52 , m_length(length) 53 { 54 } 55 51 56 ~PausedTimeouts(); 52 57 53 58 size_t numTimeouts() const { return m_length; } 54 PausedTimeout *takeTimeouts() 55 { PausedTimeout *a = m_array; m_array = 0; return a; } 59 PausedTimeout* takeTimeouts() { PausedTimeout* a = m_array; m_array = 0; return a; } 56 60 57 61 private: 58 PausedTimeout *m_array;62 PausedTimeout* m_array; 59 63 size_t m_length; 60 61 PausedTimeouts(const PausedTimeouts&);62 PausedTimeouts& operator=(const PausedTimeouts&);63 64 }; 64 65 65 class DOMWindowTimer;66 67 class WindowPrivate;68 66 69 67 // This is the only WebCore JS binding which does not inherit from DOMObject … … 73 71 protected: 74 72 Window(WebCore::DOMWindow*); 73 75 74 public: 76 75 virtual ~Window(); 76 77 77 WebCore::DOMWindow* impl() const { return m_impl.get(); } 78 78 79 void disconnectFrame(); 79 /** 80 * Returns and registers a window object. In case there's already a Window 81 * for the specified frame p this will be returned in order to have unique 82 * bindings. 83 */ 80 81 // Returns and registers a window object. In case there's already a Window 82 // for the specified frame p this will be returned in order to have unique 83 // bindings. 84 84 static JSValue* retrieve(WebCore::Frame*); 85 /** 86 * Returns the Window object for a given HTML frame 87 */ 85 86 // Returns the Window object for a given HTML frame 88 87 static Window* retrieveWindow(WebCore::Frame*); 89 /** 90 * returns a pointer to the Window object this javascript interpreting instance 91 * was called from. 92 */ 88 89 // Returns a pointer to the Window object this javascript interpreting instance 90 // was called from. 93 91 static Window* retrieveActive(ExecState*); 92 94 93 virtual void mark(); 94 95 95 virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&); 96 JSValue *getValueProperty(ExecState *exec, int token) const;97 virtual void put(ExecState *exec, const Identifier &propertyName, JSValue *value, int attr = None);96 JSValue* getValueProperty(ExecState*, int token) const; 97 virtual void put(ExecState*, const Identifier& propertyName, JSValue*, int attr = None); 98 98 99 99 int installTimeout(const UString& handler, int t, bool singleShot); … … 168 168 void setListener(ExecState*, const WebCore::AtomicString& eventType, JSValue* func); 169 169 170 static JSValue *childFrameGetter(ExecState *exec, JSObject *, const Identifier&, const PropertySlot& slot);171 static JSValue *namedFrameGetter(ExecState *exec, JSObject *, const Identifier&, const PropertySlot& slot);172 static JSValue *indexGetter(ExecState *exec, JSObject *, const Identifier&, const PropertySlot& slot);173 static JSValue *namedItemGetter(ExecState *exec, JSObject *, const Identifier&, const PropertySlot& slot);170 static JSValue* childFrameGetter(ExecState*, JSObject*, const Identifier&, const PropertySlot&); 171 static JSValue* namedFrameGetter(ExecState*, JSObject*, const Identifier&, const PropertySlot&); 172 static JSValue* indexGetter(ExecState*, JSObject*, const Identifier&, const PropertySlot&); 173 static JSValue* namedItemGetter(ExecState*, JSObject*, const Identifier&, const PropertySlot&); 174 174 175 175 void clearHelperObjectProperties(); … … 206 206 ScheduledAction(JSValue* func, const List& args); 207 207 ScheduledAction(const WebCore::String& code) 208 : m_code(code) { } 208 : m_code(code) 209 { 210 } 211 209 212 void execute(Window *); 210 213 … … 216 219 217 220 class Location : public DOMObject { 221 friend class Window; 218 222 public: 219 virtual bool getOwnPropertySlot(ExecState *, const Identifier&, PropertySlot&); 220 JSValue *getValueProperty(ExecState *exec, int token) const; 221 virtual void put(ExecState *exec, const Identifier &propertyName, JSValue *value, int attr = None); 223 virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&); 224 JSValue* getValueProperty(ExecState*, int token) const; 225 virtual void put(ExecState*, const Identifier& propertyName, JSValue*, int attr = None); 226 222 227 enum { Hash, Href, Hostname, Host, Pathname, Port, Protocol, Search, 223 228 Replace, Reload, ToString, Assign }; 229 224 230 WebCore::Frame* frame() const { return m_frame; } 231 225 232 virtual const ClassInfo* classInfo() const { return &info; } 226 233 static const ClassInfo info; 234 227 235 private: 228 friend class Window;229 236 Location(WebCore::Frame*); 237 230 238 WebCore::Frame* m_frame; 231 239 }; … … 246 254 } // namespace WebCore 247 255 248 #endif 256 #endif // kjs_window_h
Note: See TracChangeset
for help on using the changeset viewer.