Reviewed by Geoff.
authorweinig <weinig@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 5 Jul 2007 22:56:24 +0000 (22:56 +0000)
committerweinig <weinig@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 5 Jul 2007 22:56:24 +0000 (22:56 +0000)
        Add focus, blur and close functions to DOMWindow implementation class
        and move bindings from Window to JSDOMWindow.

        * bindings/js/JSDOMWindowCustom.cpp:
        (WebCore::JSDOMWindow::customGetOwnPropertySlot):
        * bindings/js/kjs_window.cpp:
        (KJS::Window::getOwnPropertySlot):
        (KJS::WindowFunc::callAsFunction):
        * bindings/js/kjs_window.h:
        (KJS::Window::):
        * bindings/scripts/CodeGeneratorJS.pm: Move prototype function declaration from
        the implementation to the header.
        * page/DOMWindow.cpp:
        (WebCore::DOMWindow::focus):
        (WebCore::DOMWindow::blur):
        (WebCore::DOMWindow::close):
        * page/DOMWindow.h:
        * page/DOMWindow.idl:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@24028 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog
WebCore/bindings/js/JSDOMWindowCustom.cpp
WebCore/bindings/js/kjs_window.cpp
WebCore/bindings/js/kjs_window.h
WebCore/bindings/scripts/CodeGeneratorJS.pm
WebCore/page/DOMWindow.cpp
WebCore/page/DOMWindow.h
WebCore/page/DOMWindow.idl

index 65cd9d8e006984e9c30f1eea72635c8c13c69d92..6e3a7443ae3db41b07d89bd20e1fc6af93244d49 100644 (file)
@@ -1,3 +1,26 @@
+2007-07-05  Sam Weinig  <sam@webkit.org>
+
+        Reviewed by Geoff.
+
+        Add focus, blur and close functions to DOMWindow implementation class
+        and move bindings from Window to JSDOMWindow.
+
+        * bindings/js/JSDOMWindowCustom.cpp:
+        (WebCore::JSDOMWindow::customGetOwnPropertySlot):
+        * bindings/js/kjs_window.cpp:
+        (KJS::Window::getOwnPropertySlot):
+        (KJS::WindowFunc::callAsFunction):
+        * bindings/js/kjs_window.h:
+        (KJS::Window::):
+        * bindings/scripts/CodeGeneratorJS.pm: Move prototype function declaration from
+        the implementation to the header.
+        * page/DOMWindow.cpp:
+        (WebCore::DOMWindow::focus):
+        (WebCore::DOMWindow::blur):
+        (WebCore::DOMWindow::close):
+        * page/DOMWindow.h:
+        * page/DOMWindow.idl:
+
 2007-07-05  Justin Garcia  <justin.garcia@apple.com>
 
         Reviewed by Harrison.
index 1055bc4058930ccf0b56d2f7db520c7f4f0bb9f4..b7f58e036c1c56293b2896ceb118af8838c0f115 100644 (file)
@@ -29,13 +29,23 @@ bool JSDOMWindow::customGetOwnPropertySlot(KJS::ExecState* exec, const KJS::Iden
     // we don't want any properties other than "closed" on a closed window
     if (!frame()) {
         if (propertyName == "closed") {
-            slot.setStaticEntry(this, KJS::Lookup::findEntry(KJS::Window::classInfo()->propHashTable, "closed"), KJS::staticValueGetter<KJS::Window>);
-            return true;
+            const KJS::HashEntry* entry = KJS::Lookup::findEntry(KJS::Window::classInfo()->propHashTable, propertyName);
+            ASSERT(entry);
+            if (entry) {
+                slot.setStaticEntry(this, entry, KJS::staticValueGetter<KJS::Window>);
+                return true;
+            }
         }
         if (propertyName == "close") {
-            const KJS::HashEntry* entry = KJS::Lookup::findEntry(KJS::Window::classInfo()->propHashTable, propertyName);
-            slot.setStaticEntry(this, entry, KJS::staticFunctionGetter<KJS::WindowFunc>);
-            return true;
+            KJS::JSValue* proto = prototype();
+            if (proto->isObject()) {
+                const KJS::HashEntry* entry = KJS::Lookup::findEntry(static_cast<KJS::JSObject*>(proto)->classInfo()->propHashTable, propertyName);
+                ASSERT(entry);
+                if (entry) {
+                    slot.setStaticEntry(this, entry, KJS::staticFunctionGetter<JSDOMWindowPrototypeFunction>);
+                    return true;
+                }
+            }
         }
 
         slot.setUndefined(this);
@@ -58,6 +68,24 @@ bool JSDOMWindow::customGetOwnPropertySlot(KJS::ExecState* exec, const KJS::Iden
         return true;
     }
 
+    // FIXME: We need this to work around the blanket isSafeScript check in KJS::Window.  Once we remove that, we
+    // can move this to JSDOMWindowPrototype.
+    KJS::JSValue* proto = prototype();
+    if (proto->isObject()) {
+        const KJS::HashEntry* entry = KJS::Lookup::findEntry(static_cast<KJS::JSObject*>(proto)->classInfo()->propHashTable, propertyName);
+        if (entry) {
+            if (entry->attr & KJS::Function) {
+                switch (entry->value) {
+                    case FocusFuncNum:
+                    case BlurFuncNum:
+                    case CloseFuncNum:
+                        slot.setStaticEntry(this, entry, KJS::staticFunctionGetter<JSDOMWindowPrototypeFunction>);
+                        return true;
+                }
+            }
+        }
+    }
+
     return false;
 }
 
index 76bc8865e69bdb24ee5bc5c6a508b7eae11c9a5f..699905c29c3b73831bdf447a00d75af2f78ee6d5 100644 (file)
@@ -197,9 +197,6 @@ const ClassInfo Window::info = { "Window", 0, &WindowTable, 0 };
   print         Window::Print           DontDelete|Function 2
   setTimeout    Window::SetTimeout      DontDelete|Function 2
   clearTimeout  Window::ClearTimeout    DontDelete|Function 1
-  focus         Window::Focus           DontDelete|Function 0
-  blur          Window::Blur            DontDelete|Function 0
-  close         Window::Close           DontDelete|Function 0
   setInterval   Window::SetInterval     DontDelete|Function 2
   clearInterval Window::ClearInterval   DontDelete|Function 1
   captureEvents Window::CaptureEvents   DontDelete|Function 0
@@ -784,11 +781,6 @@ bool Window::getOwnPropertySlot(ExecState *exec, const Identifier& propertyName,
   if (entry) {
     if (entry->attr & Function) {
       switch (entry->value) {
-      case Focus:
-      case Blur:
-      case Close:
-        slot.setStaticEntry(this, entry, staticFunctionGetter<WindowFunc>);
-        break;
       case ShowModalDialog:
         if (!canShowModalDialog(this))
           return false;
@@ -1568,17 +1560,6 @@ JSValue *WindowFunc::callAsFunction(ExecState *exec, JSObject *thisObj, const Li
         return jsUndefined();
     (const_cast<Window*>(window))->clearTimeout(v->toInt32(exec));
     return jsUndefined();
-  case Window::Focus:
-    frame->focusWindow();
-    return jsUndefined();
-  case Window::Blur:
-    frame->unfocusWindow();
-    return jsUndefined();
-  case Window::Close:
-    // Do not close windows that have history unless they were opened by JavaScript.
-    if (frame->loader()->openedByDOM() || frame->loader()->getHistoryLength() <= 1)
-      const_cast<Window*>(window)->scheduleClose();
-    return jsUndefined();
   case Window::CaptureEvents:
   case Window::ReleaseEvents:
     // If anyone implements these, they need the safe script security check.
index 58db2066d8f11dc63dc5feae568fe5efa84d857d..ed3882b305d7e02f533131b91070b344789d1378 100644 (file)
@@ -151,7 +151,7 @@ namespace KJS {
            ScreenTop, ScreenLeft,
            ScrollTo, ScrollX, ScrollY, MoveBy, MoveTo, ResizeBy, ResizeTo, Self, Window_, Top,
            Image, Option, Alert, Confirm, Prompt, Open, Print, SetTimeout, ClearTimeout,
-           Focus, Blur, Close, SetInterval, ClearInterval, CaptureEvents, 
+           SetInterval, ClearInterval, CaptureEvents, 
            ReleaseEvents, AddEventListener, RemoveEventListener,
            XMLHttpRequest, XSLTProcessor_,
            Onabort, Onblur, Onchange, Onclick, Ondblclick, Onerror, 
index 98e1240937e41b53f17527a27cc31ed1e5c3c999..b40701053e8c5443d5e3ee9dcb3dbca0b152ffcc 100644 (file)
@@ -529,7 +529,12 @@ sub GenerateHeader
     }
 
     push(@headerContent, "};\n\n");
-    push(@headerContent, "}\n\n");
+
+    if ($numFunctions > 0) {
+        push(@headerContent, prototypeFunctionFor($className));
+    }
+
+    push(@headerContent, "} // namespace WebCore\n\n");
     push(@headerContent, "#endif // ${conditionalString}\n\n") if $conditional;
     push(@headerContent, "#endif\n");
 }
@@ -706,10 +711,6 @@ sub GenerateImplementation
                                \@hashKeys, \@hashValues,
                                \@hashSpecials, \@hashParameters);
 
-    if ($numFunctions > 0) {
-        push(@implContent, prototypeFunctionFor($className));
-    }
-
     push(@implContent, "const ClassInfo ${className}Prototype::info = { \"${interfaceName}Prototype\", 0, &${className}PrototypeTable, 0 };\n\n");
     if ($dataNode->extendedAttributes->{"DoNotCache"}) {
         push(@implContent, "JSObject* ${className}Prototype::self()\n");
@@ -1477,9 +1478,6 @@ sub NativeToJSValue
         $implIncludes{"EventTargetNode.h"} = 1;
         $implIncludes{"JSEventTargetNode.h"} = 1;
         $implIncludes{"kjs_dom.h"} = 1;
-    } elsif ($type eq "HTMLCanvasElement") {
-        $implIncludes{"kjs_dom.h"} = 1;
-        $implIncludes{"HTMLCanvasElement.h"} = 1;
     } elsif ($type eq "DOMWindow") {
         $implIncludes{"kjs_window.h"} = 1;
     } elsif ($type eq "DOMObject") {
@@ -1756,15 +1754,16 @@ sub prototypeFunctionFor
     my $className = shift;
 
 my $implContent = << "EOF";
-class ${className}PrototypeFunction : public InternalFunctionImp {
+class ${className}PrototypeFunction : public KJS::InternalFunctionImp {
 public:
-    ${className}PrototypeFunction(ExecState* exec, int i, int len, const Identifier& name)
-        : InternalFunctionImp(static_cast<FunctionPrototype*>(exec->lexicalInterpreter()->builtinFunctionPrototype()), name)
+    ${className}PrototypeFunction(KJS::ExecState* exec, int i, int len, const KJS::Identifier& name)
+        : KJS::InternalFunctionImp(static_cast<KJS::FunctionPrototype*>(exec->lexicalInterpreter()->builtinFunctionPrototype()), name)
         , id(i)
     {
-        put(exec, exec->propertyNames().length, jsNumber(len), DontDelete|ReadOnly|DontEnum);
+        put(exec, exec->propertyNames().length, KJS::jsNumber(len), KJS::DontDelete|KJS::ReadOnly|KJS::DontEnum);
     }
-    virtual JSValue* callAsFunction(ExecState*, JSObject*, const List&);
+    virtual KJS::JSValue* callAsFunction(KJS::ExecState*, KJS::JSObject*, const KJS::List&);
+
 private:
     int id;
 };
index 77b2d7938a398d3809039a8f1ca5af5e95d8b2bd..e8a95f5910ab9a2ace659c3436bea258f7710143 100644 (file)
@@ -143,6 +143,29 @@ DOMSelection* DOMWindow::getSelection()
     return m_selection.get();
 }
 
+void DOMWindow::focus()
+{
+    if (!m_frame)
+        return;
+    m_frame->focusWindow();
+}
+
+void DOMWindow::blur()
+{
+    if (!m_frame)
+        return;
+    m_frame->unfocusWindow();
+}
+
+void DOMWindow::close()
+{
+    if (!m_frame)
+        return;
+
+    if (m_frame->loader()->openedByDOM() || m_frame->loader()->getHistoryLength() <= 1)
+        m_frame->scheduleClose();
+}
+
 Document* DOMWindow::document() const
 {
     if (!m_frame)
index f399d4ad139c5560afbc9649512550ecba259ff9..53e29c42f5b86a712effb5861154f73bf4e56d1e 100644 (file)
@@ -63,6 +63,10 @@ namespace WebCore {
 
         DOMSelection* getSelection();
 
+        void focus();
+        void blur();
+        void close();
+
         // DOM Level 2 AbstractView Interface
         Document* document() const;
 
index ef0cd5957aaab32c9619daa729691fc2d34e1ee1..cb4fecf0dc32386173149a07064eecc2803e393e 100644 (file)
@@ -38,6 +38,10 @@ module window {
 
         DOMSelection getSelection();
 
+        [DoNotCheckDomainSecurity] void focus();
+        [DoNotCheckDomainSecurity] void blur();
+        [DoNotCheckDomainSecurity] void close();
+
         // DOM Level 2 AbstractView Interface
         readonly attribute Document document;