Changeset 28572 in webkit


Ignore:
Timestamp:
Dec 8, 2007 11:56:34 PM (16 years ago)
Author:
weinig@apple.com
Message:

Reviewed by Oliver.

Cleanup kjs_window.h/cpp.

  • bindings/js/kjs_window.cpp: (KJS::WindowPrivate::WindowPrivate): (KJS::DOMWindowTimer::DOMWindowTimer): (KJS::Window::Window): (KJS::Window::retrieveWindow): (KJS::Window::retrieveActive): (KJS::Window::retrieve): (KJS::Window::location): (KJS::Window::mark): (KJS::allowPopUp): (KJS::parseModalDialogFeatures): (KJS::floatFeature): (KJS::canShowModalDialog): (KJS::canShowModalDialogNow): (KJS::showModalDialog): (KJS::Window::getValueProperty): (KJS::Window::getOwnPropertySlot): (KJS::Window::globalExec): (KJS::Window::setListener): (KJS::Window::getListener): (KJS::Window::findOrCreateJSEventListener): (KJS::Window::findOrCreateJSUnprotectedEventListener): (KJS::Window::clearHelperObjectProperties): (KJS::Window::setCurrentEvent): (KJS::WindowProtoFuncAToB::callAsFunction): (KJS::WindowProtoFuncBToA::callAsFunction): (KJS::WindowProtoFuncOpen::callAsFunction): (KJS::WindowProtoFuncSetTimeout::callAsFunction): (KJS::WindowProtoFuncClearTimeout::callAsFunction): (KJS::WindowProtoFuncSetInterval::callAsFunction): (KJS::WindowProtoFuncAddEventListener::callAsFunction): (KJS::WindowProtoFuncRemoveEventListener::callAsFunction): (KJS::WindowProtoFuncShowModalDialog::callAsFunction): (KJS::WindowProtoFuncNotImplemented::callAsFunction):
  • bindings/js/kjs_window.h: (KJS::PausedTimeouts::PausedTimeouts): (KJS::PausedTimeouts::takeTimeouts): (KJS::ScheduledAction::ScheduledAction):
Location:
trunk/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r28570 r28572  
     12007-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
    1462007-12-08  Sam Weinig  <sam@webkit.org>
    247
  • trunk/WebCore/bindings/js/kjs_window.cpp

    r28570 r28572  
    3838#include "FrameLoader.h"
    3939#include "FrameTree.h"
    40 #include "FrameView.h"
    4140#include "GCController.h"
    4241#include "HTMLDocument.h"
    43 #include "JSCSSRule.h"
    44 #include "JSCSSValue.h"
    4542#include "JSDOMExceptionConstructor.h"
    4643#include "JSDOMWindow.h"
     
    4946#include "JSHTMLCollection.h"
    5047#include "JSHTMLOptionElementConstructor.h"
    51 #include "JSMutationEvent.h"
    52 #include "JSNode.h"
    53 #include "JSNodeFilter.h"
    54 #include "JSRange.h"
    5548#include "JSXMLHttpRequest.h"
    5649#include "Logging.h"
     
    8578
    8679struct WindowPrivate {
    87     WindowPrivate() 
     80    WindowPrivate()
    8881        : loc(0)
    8982        , m_evt(0)
     
    9790    Window::UnprotectedListenersMap jsUnprotectedHTMLEventListeners;
    9891    mutable Location* loc;
    99     WebCore::Event *m_evt;
     92    WebCore::Event* m_evt;
    10093    JSValue** m_returnValueSlot;
     94
    10195    typedef HashMap<int, DOMWindowTimer*> TimeoutsMap;
    10296    TimeoutsMap m_timeouts;
     
    10599class DOMWindowTimer : public TimerBase {
    106100public:
    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
    109109    virtual ~DOMWindowTimer()
    110110    {
     
    210210
    211211Window::Window(DOMWindow* window)
    212   : m_impl(window)
    213   , d(new WindowPrivate)
     212    : m_impl(window)
     213    , d(new WindowPrivate)
    214214{
    215215    // Window destruction is not thread-safe because of
     
    246246}
    247247
    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 *>(o);
    254 }
    255 
    256 Window *Window::retrieveActive(ExecState *exec)
    257 {
    258     JSValue *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())
     248Window* 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
     256Window* Window::retrieveActive(ExecState* exec)
     257{
     258    JSGlobalObject* globalObject = exec->dynamicGlobalObject();
     259    ASSERT(globalObject);
     260    return static_cast<Window*>(globalObject);
     261}
     262
     263JSValue* Window::retrieve(Frame* frame)
     264{
     265    ASSERT(frame);
     266    if (KJSProxy* proxy = frame->scriptProxy())
    267267        return proxy->globalObject(); // the Global object is the "window"
    268  
     268
    269269    return jsUndefined(); // This can happen with JS disabled on the domain of that window
    270270}
    271271
    272 Location *Window::location() const
    273 {
    274   if (!d->loc)
    275     d->loc = new Location(impl()->frame());
    276   return d->loc;
     272Location* Window::location() const
     273{
     274    if (!d->loc)
     275        d->loc = new Location(impl()->frame());
     276    return d->loc;
    277277}
    278278
     
    280280void Window::mark()
    281281{
    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
     287static bool allowPopUp(Frame* frame)
     288{
    290289    if (!frame)
    291290        return false;
    292     if (window->impl()->frame()->scriptProxy()->processingUserGesture())
     291    if (frame->scriptProxy()->processingUserGesture())
    293292        return true;
    294293    Settings* settings = frame->settings();
     
    296295}
    297296
    298 static HashMap<String, String> parseModalDialogFeatures(ExecState *exec, JSValue *featuresArg)
     297static HashMap<String, String> parseModalDialogFeatures(const String& featuresArg)
    299298{
    300299    HashMap<String, String> map;
    301300
    302     Vector<String> features = valueToStringWithUndefinedOrNullCheck(exec, featuresArg).split(';');
     301    Vector<String> features = featuresArg.split(';');
    303302    Vector<String>::const_iterator end = features.end();
    304303    for (Vector<String>::const_iterator it = features.begin(); it != end; ++it) {
     
    335334}
    336335
    337 static float floatFeature(const HashMap<String, String> &features, const char *key, float min, float max, float defaultValue)
     336static float floatFeature(const HashMap<String, String>& features, const char* key, float min, float max, float defaultValue)
    338337{
    339338    HashMap<String, String>::const_iterator it = features.find(key);
     
    401400}
    402401
    403 static bool canShowModalDialog(const Window *window)
    404 {
    405     Frame* frame = window->impl()->frame();
     402static bool canShowModalDialog(const Frame* frame)
     403{
    406404    if (!frame)
    407405        return false;
    408 
    409406    return frame->page()->chrome()->canRunModal();
    410407}
    411408
    412 static bool canShowModalDialogNow(const Window *window)
    413 {
    414     Frame* frame = window->impl()->frame();
     409static bool canShowModalDialogNow(const Frame* frame)
     410{
    415411    if (!frame)
    416412        return false;
    417 
    418413    return frame->page()->chrome()->canRunModalNow();
    419414}
    420415
    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;
     416static 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;
    431424
    432425    // The following features from Microsoft's documentation are not implemented:
     
    437430    // - help: boolFeature(features, "help", true), makes help icon appear in dialog (what does it do on Windows?)
    438431    // - unadorned: trusted && boolFeature(features, "unadorned");
    439     Frame* frame = openerWindow->impl()->frame();
    440432    if (!frame)
    441433        return jsUndefined();
     
    443435    FloatRect screenRect = screenAvailableRect(frame->view());
    444436
     437    WindowFeatures wargs;
    445438    wargs.width = floatFeature(features, "dialogwidth", 100, screenRect.width(), 620); // default here came from frame size of dialog in MacIE
    446439    wargs.widthSet = true;
     
    473466    wargs.fullscreen = false;
    474467   
    475     Frame* dialogFrame = createWindow(exec, frame, valueToStringWithUndefinedOrNullCheck(exec, args[0]), "", wargs, args[1]);
     468    Frame* dialogFrame = createWindow(exec, frame, url, "", wargs, dialogArgs);
    476469    if (!dialogFrame)
    477470        return jsUndefined();
     
    608601     return getListener(exec,submitEvent);
    609602   case Onbeforeunload:
    610       return getListener(exec, beforeunloadEvent);
    611     case Onunload:
     603     return getListener(exec, beforeunloadEvent);
     604   case Onunload:
    612605     return getListener(exec, unloadEvent);
    613606   }
     
    655648    if (entry->attr & Function) {
    656649      if (entry->value.functionValue == &WindowProtoFuncShowModalDialog::create) {
    657         if (!canShowModalDialog(this))
     650        if (!canShowModalDialog(impl()->frame()))
    658651          return false;
    659652      }
     
    883876ExecState* Window::globalExec()
    884877{
    885     // we need to make sure that any script execution happening in this
     878    // We need to make sure that any script execution happening in this
    886879    // frame does not destroy it
    887880    ASSERT(impl()->frame());
     
    908901}
    909902
    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
     903void 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
     913JSValue* 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();
    939923    return jsNull();
    940924}
     
    949933}
    950934
    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 list
    962   return new JSEventListener(object, this, html);
     935JSEventListener* 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);
    963947}
    964948
     
    972956}
    973957
    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);
     958JSUnprotectedEventListener* 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);
    986969}
    987970
    988971void Window::clearHelperObjectProperties()
    989972{
    990   d->loc = 0;
    991   d->m_evt = 0;
     973    d->loc = 0;
     974    d->m_evt = 0;
    992975}
    993976
     
    1012995}
    1013996
    1014 void Window::setCurrentEvent(Event *evt)
    1015 {
    1016   d->m_evt = evt;
     997void Window::setCurrentEvent(Event* evt)
     998{
     999    d->m_evt = evt;
    10171000}
    10181001
     
    11551138    if (!thisObj->inherits(&Window::info))
    11561139        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);
    11641140
    11651141    if (args.size() < 1)
    11661142        return throwError(exec, SyntaxError, "Not enough arguments");
     1143
     1144    JSValue* v = args[0];
    11671145    if (v->isNull())
    11681146        return jsString();
     1147   
     1148    UString s = v->toString(exec);
    11691149    if (!s.is8Bit()) {
    11701150        setDOMException(exec, INVALID_CHARACTER_ERR);
    11711151        return jsUndefined();
    11721152    }
    1173    
     1153
    11741154    Vector<char> in(s.size());
    11751155    for (int i = 0; i < s.size(); ++i)
     
    11791159    if (!base64Decode(in, out))
    11801160        return throwError(exec, GeneralError, "Cannot decode base64");
    1181    
     1161
    11821162    return jsString(String(out.data(), out.size()));
    11831163}
    11841164
    11851165JSValue* 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
     1193JSValue* WindowProtoFuncOpen::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args)
    11861194{
    11871195    if (!thisObj->inherits(&Window::info))
     
    11911199    if (!frame)
    11921200        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();
    12241201    Frame* activeFrame = Window::retrieveActive(exec)->impl()->frame();
    12251202    if (!activeFrame)
     
    12331210    // Because FrameTree::find() returns true for empty strings, we must check for empty framenames.
    12341211    // 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)))
    12361213        return jsUndefined();
    12371214
     
    12541231            completedURL = activeFrame->document()->completeURL(urlString);
    12551232
    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)))) {
    12581235            bool userGesture = activeFrame->scriptProxy()->processingUserGesture();
    12591236            frame->loader()->scheduleLocationChange(completedURL, activeFrame->loader()->outgoingReferrer(), false, userGesture);
     
    12871264        return throwError(exec, TypeError);
    12881265    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();
    13151277}
    13161278
     
    13191281    // Also the implementation for window.clearInterval()
    13201282
     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
     1291JSValue* 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
     1313JSValue* WindowProtoFuncAddEventListener::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args)
     1314{
    13211315    if (!thisObj->inherits(&Window::info))
    13221316        return throwError(exec, TypeError);
     
    13261320        return jsUndefined();
    13271321
    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
    13331327    return jsUndefined();
    13341328}
    13351329
    1336 JSValue* WindowProtoFuncSetInterval::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args)
     1330JSValue* WindowProtoFuncRemoveEventListener::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args)
    13371331{
    13381332    if (!thisObj->inherits(&Window::info))
     
    13431337        return jsUndefined();
    13441338
    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
     1347JSValue* WindowProtoFuncShowModalDialog::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args)
    13711348{
    13721349    if (!thisObj->inherits(&Window::info))
     
    13771354        return jsUndefined();
    13781355
    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
     1359JSValue* WindowProtoFuncNotImplemented::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args)
    13881360{
    13891361    if (!thisObj->inherits(&Window::info))
    13901362        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
    14221364    return jsUndefined();
    14231365}
  • trunk/WebCore/bindings/js/kjs_window.h

    r28570 r28572  
    2525#include <kjs/protect.h>
    2626#include <wtf/HashMap.h>
     27#include <wtf/Noncopyable.h>
    2728#include <wtf/OwnPtr.h>
    2829
     
    3132    class DOMWindow;
    3233    class Frame;
    33     class FrameView;
    34     class JSDOMWindow;
    3534    class JSEventListener;
    3635    class JSUnprotectedEventListener;
    37     class Node;
    3836}
    3937
    4038namespace KJS {
    4139
     40    class DOMWindowTimer;
    4241    class Location;
    4342    class PausedTimeout;
     
    4544    class Window;
    4645    class WindowFunc;
    47 
    48     class PausedTimeouts {
     46    class WindowPrivate;
     47
     48    class PausedTimeouts : Noncopyable {
    4949    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
    5156        ~PausedTimeouts();
    5257
    5358        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; }
    5660
    5761    private:
    58         PausedTimeout *m_array;
     62        PausedTimeout* m_array;
    5963        size_t m_length;
    60 
    61         PausedTimeouts(const PausedTimeouts&);
    62         PausedTimeouts& operator=(const PausedTimeouts&);
    6364    };
    6465
    65     class DOMWindowTimer;
    66 
    67   class WindowPrivate;
    6866
    6967  // This is the only WebCore JS binding which does not inherit from DOMObject
     
    7371  protected:
    7472    Window(WebCore::DOMWindow*);
     73
    7574  public:
    7675    virtual ~Window();
     76
    7777    WebCore::DOMWindow* impl() const { return m_impl.get(); }
     78
    7879    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.
    8484    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
    8887    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.
    9391    static Window* retrieveActive(ExecState*);
     92
    9493    virtual void mark();
     94
    9595    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);
    9898
    9999    int installTimeout(const UString& handler, int t, bool singleShot);
     
    168168    void setListener(ExecState*, const WebCore::AtomicString& eventType, JSValue* func);
    169169
    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&);
    174174
    175175    void clearHelperObjectProperties();
     
    206206        ScheduledAction(JSValue* func, const List& args);
    207207        ScheduledAction(const WebCore::String& code)
    208             : m_code(code) { }
     208            : m_code(code)
     209        {
     210        }
     211
    209212        void execute(Window *);
    210213
     
    216219
    217220  class Location : public DOMObject {
     221    friend class Window;
    218222  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
    222227    enum { Hash, Href, Hostname, Host, Pathname, Port, Protocol, Search,
    223228           Replace, Reload, ToString, Assign };
     229
    224230    WebCore::Frame* frame() const { return m_frame; }
     231
    225232    virtual const ClassInfo* classInfo() const { return &info; }
    226233    static const ClassInfo info;
     234
    227235  private:
    228     friend class Window;
    229236    Location(WebCore::Frame*);
     237
    230238    WebCore::Frame* m_frame;
    231239  };
     
    246254} // namespace WebCore
    247255
    248 #endif
     256#endif // kjs_window_h
Note: See TracChangeset for help on using the changeset viewer.