WebKit:
authorrjw <rjw@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 18 May 2004 23:15:30 +0000 (23:15 +0000)
committerrjw <rjw@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 18 May 2004 23:15:30 +0000 (23:15 +0000)
Added WebKit portion of webView:windowScriptObjectAvailable:
implementation.  Still need to implement creating the WebScriptObject
wrapper on the WebCore side.

        Reviewed by Maciej.

Removed "_" from _setPageWidthForPrinting:.  This method facilitates
a work-around for carbon printing.  At some point we may make this
method public API.

        Reviewed by Chris.

        * WebCoreSupport.subproj/WebBridge.m:
        (-[WebBridge overrideMediaType]):
        (-[WebBridge windowObjectCleared]):
        * WebView.subproj/WebDefaultFrameLoadDelegate.m:
        (-[WebDefaultFrameLoadDelegate webView:windowScriptObjectAvailable:]):
        * WebView.subproj/WebHTMLView.m:
        (-[WebHTMLView setPageWidthForPrinting:]):

WebCore:
Added stubs to get the WebScriptObject for the window
JS object.

Made updateRenderingForBindings more robust when handed a
nil root object.  This was causing a crash in DB.  Still need to
address root cause of nil root object.

        Reviewed by Maciej.

        * khtml/khtml_part.cpp:
        (KHTMLPart::begin):
        * kwq/KWQKHTMLPart.h:
        * kwq/KWQKHTMLPart.mm:
        (KWQKHTMLPart::windowScriptObject):
        (KWQKHTMLPart::partClearedInBegin):
        * kwq/WebCoreBridge.h:
        * kwq/WebCoreBridge.mm:
        (updateRenderingForBindings):
        (-[WebCoreBridge init]):
        (-[WebCoreBridge stringByEvaluatingJavaScriptFromString:]):
        (-[WebCoreBridge windowScriptObject]):

JavaScriptCore:
Use KVC to set/get values instead of directly accessing
ivars.

        Reviewed by Maciej.

        * bindings/objc/WebScriptObject.mm:
        (-[WebScriptObject callWebScriptMethod:withArguments:]):
        (+[WebScriptObject _convertValueToObjcValue:KJS::root:Bindings::]):
        * bindings/objc/objc_runtime.mm:
        (ObjcField::valueFromInstance):
        (convertValueToObjcObject):
        (ObjcField::setValueToInstance):

WebKitExamples:
Changed printing work-around to use a method that may be
made public at some point in the future.

        Reviewed by Chris.

        * CarbonWeb/TWebWindow.cp:

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

13 files changed:
JavaScriptCore/ChangeLog
JavaScriptCore/bindings/objc/WebScriptObject.mm
JavaScriptCore/bindings/objc/objc_runtime.mm
WebCore/ChangeLog-2005-08-23
WebCore/khtml/khtml_part.cpp
WebCore/kwq/KWQKHTMLPart.h
WebCore/kwq/KWQKHTMLPart.mm
WebCore/kwq/WebCoreBridge.h
WebCore/kwq/WebCoreBridge.mm
WebKit/ChangeLog
WebKit/WebCoreSupport.subproj/WebBridge.m
WebKit/WebView.subproj/WebDefaultFrameLoadDelegate.m
WebKit/WebView.subproj/WebHTMLView.m

index 0529e5771c8061c7672618e59e1f02eddfbe9cf2..10ff84b010135dfcf8f4fd9d99e1b1b3b6ee4efa 100644 (file)
@@ -1,3 +1,18 @@
+2004-05-18  Richard Williamson   <rjw@apple.com>
+
+       Use KVC to set/get values instead of directly accessing
+       ivars.
+
+        Reviewed by Maciej.
+
+        * bindings/objc/WebScriptObject.mm:
+        (-[WebScriptObject callWebScriptMethod:withArguments:]):
+        (+[WebScriptObject _convertValueToObjcValue:KJS::root:Bindings::]):
+        * bindings/objc/objc_runtime.mm:
+        (ObjcField::valueFromInstance):
+        (convertValueToObjcObject):
+        (ObjcField::setValueToInstance):
+
 2004-05-17  Richard Williamson   <rjw@apple.com>
 
        Implemented new API for WebScriptObject.
index fafe638d5872bcd063842ce46fbd30a89bfb0df2..558bd7543c4c4021982bdfbb597d9d41369d5d17 100644 (file)
@@ -121,10 +121,10 @@ static KJS::List listFromNSArray(ExecState *exec, NSArray *array)
     }
 
     // Call the function object.    
+    Interpreter::lock();
     ObjectImp *funcImp = static_cast<ObjectImp*>(func.imp());
     Object thisObj = Object(const_cast<ObjectImp*>(_private->imp));
     List argList = listFromNSArray(exec, args);
-    Interpreter::lock();
     Value result = funcImp->call (exec, thisObj, argList);
     Interpreter::unlock();
 
@@ -240,7 +240,7 @@ static KJS::List listFromNSArray(ExecState *exec, NSArray *array)
 + (id)_convertValueToObjcValue:(KJS::Value)value root:(const Bindings::RootObject *)root
 {
     id result = 0;
-   
+
     // First see if we have a ObjC instance.
     if (value.type() == KJS::ObjectType){
         ObjectImp *objectImp = static_cast<ObjectImp*>(value.imp());
index f4ff21d801716a2eaca3963bfc863b64f13c7905..0b4582fc58bc9727a1be85f5481cb57bcbace8c5 100644 (file)
@@ -82,142 +82,55 @@ RuntimeType ObjcField::type() const
 Value ObjcField::valueFromInstance(KJS::ExecState *exec, const Instance *instance) const
 {
     Value aValue;
-    char *ivarValuePtr = ((char *)(static_cast<const ObjcInstance*>(instance))->getObject() + _ivar->ivar_offset);
-
-    ObjcValueType ctype = objcValueTypeForType(_ivar->ivar_type);
-    switch (ctype){
-        case ObjcVoidType: {
-            aValue = Undefined();
-        }
-        break;
-        
-        case ObjcObjectType: {
-            ObjectStructPtr obj = *(ObjectStructPtr *)(ivarValuePtr);
-            if ([obj isKindOfClass:[WebScriptObject class]]) {
-                WebScriptObject *jsobject = (WebScriptObject *)obj;
-                aValue = Object([jsobject _imp]);
-            }
-            else {
-                Instance *anInstance = Instance::createBindingForLanguageInstance (Instance::ObjectiveCLanguage, (void *)obj);
-                aValue = Object(new RuntimeObjectImp(anInstance,true));
-            }
-        }
-        break;
-        
-        case ObjcCharType: {
-            char aChar = *(char *)(ivarValuePtr);
-            aValue = Number(aChar);
-        }
-        break;
-        
-        case ObjcShortType: {
-            short aShort = *(short *)(ivarValuePtr);
-            aValue = Number(aShort);
-        }
-        break;
-        
-        case ObjcIntType: {
-            int anInt = *(int *)(ivarValuePtr);
-            aValue = Number(anInt);
-        }
-        break;
-        
-        case ObjcLongType: {
-            long aLong = *(long *)(ivarValuePtr);
-            aValue = Number(aLong);
-        }
-        break;
+    id targetObject = (static_cast<const ObjcInstance*>(instance))->getObject();
+    id objcValue = nil;
+
+    NS_DURING
+    
+        NSString *key = [NSString stringWithCString:_ivar->ivar_name];
+        objcValue = [targetObject valueForKey:key];
         
-        case ObjcFloatType: {
-            float aFloat = *(float *)(ivarValuePtr);
-            aValue = Number(aFloat);
-        }
-        break;
+    NS_HANDLER
         
-        case ObjcDoubleType: {
-            double aDouble = *(double *)(ivarValuePtr);
-            aValue = Number(aDouble);
-        }
-        break;
+        Value exceptionValue = Error::create(exec, GeneralError, [[localException reason] lossyCString]);
+        exec->setException(exceptionValue);
         
-        case ObjcInvalidType:
-        default: {
-            aValue = Error::create(exec, TypeError, "Invalid ObjectiveC type.");
-            exec->setException(aValue);
-        }
-        break;
-    }
+    NS_ENDHANDLER
+
+    if (objcValue)
+        aValue = convertObjcValueToValue (exec, &objcValue, ObjcObjectType);
+
     return aValue;
 }
 
+static id convertValueToObjcObject (KJS::ExecState *exec, const KJS::Value &value)
+{
+    const Bindings::RootObject *root = rootForInterpreter(exec->interpreter());
+    if (!root) {
+        Bindings::RootObject *newRoot = new KJS::Bindings::RootObject(0);
+        newRoot->setInterpreter (exec->interpreter());
+        root = newRoot;
+    }
+    return [WebScriptObject _convertValueToObjcValue:value root:root];
+}
+
+
 void ObjcField::setValueToInstance(KJS::ExecState *exec, const Instance *instance, const KJS::Value &aValue) const
 {
-    char *ivarValuePtr = ((char *)(static_cast<const ObjcInstance*>(instance))->getObject() + _ivar->ivar_offset);
-
-    ObjcValueType ctype = objcValueTypeForType(_ivar->ivar_type);
-    ObjcValue result = convertValueToObjcValue(exec, aValue, ctype);
-    switch (ctype){
-        case ObjcVoidType: {
-        }
-        break;
-        
-        case ObjcObjectType: {
-            // First see if we have an ObjC instance.
-            if (aValue.type() == KJS::ObjectType){
-                ObjcValue result = convertValueToObjcValue(exec, aValue, objcValueTypeForType(_ivar->ivar_type));
-                
-                // Release the previous value.
-                [*(ObjectStructPtr *)(ivarValuePtr) autorelease];
-                
-                // Retain the new value.
-                *(ObjectStructPtr *)(ivarValuePtr) = [result.objectValue retain];
-            }
-            
-            // FIXME.  Deal with numbers.
-            
-            // FIXME.  Deal with arrays.
-            
-            // FIXME.  Deal with strings.
-        }
-        break;
-        
-        case ObjcCharType: {
-            *(char *)(ivarValuePtr) = result.charValue;
-        }
-        break;
-        
-        case ObjcShortType: {
-            *(short *)(ivarValuePtr) = result.shortValue;
-        }
-        break;
-        
-        case ObjcIntType: {
-            *(int *)(ivarValuePtr) = result.intValue;
-        }
-        break;
-        
-        case ObjcLongType: {
-            *(long *)(ivarValuePtr) = result.longValue;
-        }
-        break;
+    id targetObject = (static_cast<const ObjcInstance*>(instance))->getObject();
+    id value = convertValueToObjcObject(exec, aValue);
+    
+    NS_DURING
+    
+        NSString *key = [NSString stringWithCString:_ivar->ivar_name];
+        [targetObject setValue:value forKey:key];
         
-        case ObjcFloatType: {
-            *(float *)(ivarValuePtr) = result.floatValue;
-        }
-        break;
+    NS_HANDLER
         
-        case ObjcDoubleType: {
-            *(double *)(ivarValuePtr) = result.doubleValue;
-        }
-        break;
+        Value aValue = Error::create(exec, GeneralError, [[localException reason] lossyCString]);
+        exec->setException(aValue);
         
-        case ObjcInvalidType:
-        default: {
-            Object error = Error::create(exec, TypeError, "Invalid ObjectiveC type.");
-            exec->setException(error);
-        }
-        break;
-    }
+    NS_ENDHANDLER
 }
 
 // ---------------------- ObjcArray ----------------------
index 6b3f8d87810b506aecffa758004af7e4f5bfb2f0..3c1df7052d1b3d1eb0185a918fe363200915d7dd 100644 (file)
@@ -1,3 +1,27 @@
+2004-05-18  Richard Williamson   <rjw@apple.com>
+
+       Added stubs to get the WebScriptObject for the window
+       JS object.
+       
+       Made updateRenderingForBindings more robust when handed a
+       nil root object.  This was causing a crash in DB.  Still need to
+       address root cause of nil root object.
+
+        Reviewed by Maciej.
+
+        * khtml/khtml_part.cpp:
+        (KHTMLPart::begin):
+        * kwq/KWQKHTMLPart.h:
+        * kwq/KWQKHTMLPart.mm:
+        (KWQKHTMLPart::windowScriptObject):
+        (KWQKHTMLPart::partClearedInBegin):
+        * kwq/WebCoreBridge.h:
+        * kwq/WebCoreBridge.mm:
+        (updateRenderingForBindings):
+        (-[WebCoreBridge init]):
+        (-[WebCoreBridge stringByEvaluatingJavaScriptFromString:]):
+        (-[WebCoreBridge windowScriptObject]):
+
 2004-05-17  Maciej Stachowiak  <mjs@apple.com>
 
         Reviewed by Ken.
index b755cf8a326bc1ea0f611f6aa31751c3dd77837b..5098d839f50d6485ad3e32eeefd94c8b6c4d978e 100644 (file)
@@ -1420,6 +1420,10 @@ void KHTMLPart::begin( const KURL &url, int xOffset, int yOffset )
 
   clear();
 
+#if APPLE_CHANGE
+  KWQ(this)->partClearedInBegin();
+#endif
+
   // Only do this after clearing the part, so that JavaScript can
   // clean up properly if it was on for the last load.
 #if !APPLE_CHANGES
index 247e89e931676c681d5a140da1473d46bcc49308..10db20bb0c4268fd78508b12801ef69e094bef42 100644 (file)
@@ -72,6 +72,7 @@ typedef DOMElement ObjCDOMElement;
 @class NSString;
 @class NSView;
 @class WebCoreBridge;
+@class WebScriptObject;
 
 #else
 
@@ -89,6 +90,7 @@ class NSResponder;
 class NSString;
 class NSView;
 class WebCoreBridge;
+class WebScriptObject;
 
 #endif
 
@@ -282,8 +284,11 @@ public:
     void postDidChangeSelectionNotification();
     void postDidChangeNotification();
 
+    WebScriptObject *windowScriptObject();
     void bindObject(void *object, QString name);
     
+    void partClearedInBegin();
+    
 private:
     virtual void khtmlMousePressEvent(khtml::MousePressEvent *);
     virtual void khtmlMouseDoubleClickEvent(khtml::MouseDoubleClickEvent *);
index 7bfaff6422e30d12ae34d89aa7ae970b0fcd5a9a..8a6b1bd9d7738a2d233c2b0cff1a887157688e2c 100644 (file)
@@ -62,6 +62,7 @@
 #import <JavaScriptCore/property_map.h>
 #import <JavaScriptCore/runtime.h>
 #import <JavaScriptCore/runtime_root.h>
+#import <JavaScriptCore/WebScriptObject.h>
 
 #undef _KWQ_TIMING
 
@@ -1130,6 +1131,12 @@ bool KWQKHTMLPart::tabsToAllControls() const
         return KWQKHTMLPart::currentEventIsKeyboardOptionTab();
 }
 
+WebScriptObject *KWQKHTMLPart::windowScriptObject()
+{
+    // FIXME:  Create a WindowScriptObject wrapper.
+    return 0;
+}
+
 void KWQKHTMLPart::bindObject(void *object, QString name)
 {
     if (d->m_doc && jScript()) {
@@ -1138,6 +1145,10 @@ void KWQKHTMLPart::bindObject(void *object, QString name)
     }
 }
 
+void KWQKHTMLPart::partClearedInBegin()
+{
+    [_bridge windowObjectCleared];
+}
 
 QMap<int, ScheduledAction*> *KWQKHTMLPart::pauseActions(const void *key)
 {
index 4ab44a5e17e4a64d5f7364ad47277554f6cafbd0..d2e7ce57a7b0088a9731544dbcdfb90d802bc359 100644 (file)
@@ -58,6 +58,7 @@ typedef khtml::RenderPart KHTMLRenderPart;
 @class DOMNode;
 @class DOMRange;
 @class WebCoreSettings;
+@class WebScriptObject;
 
 @protocol WebCoreDOMTreeCopier;
 @protocol WebCoreRenderTreeCopier;
@@ -295,6 +296,7 @@ typedef enum {
 - (void)applyStyle:(DOMCSSStyleDeclaration *)style;
 - (void)ensureCaretVisible;
 
+- (WebScriptObject *)windowScriptObject;
 - (void)bindObject:(id)object withName:(NSString *)name;
 
 @end
@@ -450,6 +452,8 @@ typedef enum {
 
 - (NSString *)overrideMediaType;
 
+- (void)windowObjectCleared;
+
 @end
 
 // This interface definition allows those who hold a WebCoreBridge * to call all the methods
index e0745ec58b2b469b1e4affe959e1c8be6e214186..f9f84a01c3123d9fa962a6a7c532f35f93352f5e 100644 (file)
@@ -149,9 +149,20 @@ static RootObject *rootForView(void *v)
     return 0;
 }
 
+static pthread_t mainThread = 0;
+
 static void updateRenderingForBindings (KJS::ExecState *exec, KJS::ObjectImp *rootObject)
 {
+    if (pthread_self() != mainThread)
+        return;
+        
+    if (!rootObject)
+        return;
+        
     KJS::Window *window = static_cast<KJS::Window*>(rootObject);
+    if (!window)
+        return;
+        
     DOM::DocumentImpl *doc = static_cast<DOM::DocumentImpl*>(window->part()->document().handle());
     doc->updateRendering();
 }
@@ -180,6 +191,8 @@ static bool initializedKJS = FALSE;
     }
     
     if (!initializedKJS) {
+        mainThread = pthread_self();
+        
         KJS::Bindings::RootObject::setFindRootObjectForNativeHandleFunction (rootForView);
         
         KJS::Bindings::Instance::setDidExecuteFunction(updateRenderingForBindings);
@@ -1079,6 +1092,11 @@ static HTMLFormElementImpl *formElementFromDOMElement(DOMElement *element)
     return _part->executeScript(QString::fromNSString(string), true).asString().getNSString();
 }
 
+- (WebScriptObject *)windowScriptObject
+{
+    return _part->windowScriptObject();
+}
+
 - (void)bindObject:(id)object withName:(NSString *)name
 {
     // Create an empty document, if necessary.  
index 90cce5313e792a18368ff2da13c9648ad21aca9b..da03e3dbd97f25c7bdfae591294db6b93b528666 100644 (file)
@@ -1,3 +1,25 @@
+2004-05-18  Richard Williamson   <rjw@apple.com>
+
+               Added WebKit portion of webView:windowScriptObjectAvailable:
+               implementation.  Still need to implement creating the WebScriptObject
+               wrapper on the WebCore side.
+               
+        Reviewed by Maciej.
+
+               Removed "_" from _setPageWidthForPrinting:.  This method facilitates
+               a work-around for carbon printing.  At some point we may make this
+               method public API.
+               
+        Reviewed by Chris.
+
+        * WebCoreSupport.subproj/WebBridge.m:
+        (-[WebBridge overrideMediaType]):
+        (-[WebBridge windowObjectCleared]):
+        * WebView.subproj/WebDefaultFrameLoadDelegate.m:
+        (-[WebDefaultFrameLoadDelegate webView:windowScriptObjectAvailable:]):
+        * WebView.subproj/WebHTMLView.m:
+        (-[WebHTMLView setPageWidthForPrinting:]):
+
 2004-05-18  Darin Adler  <darin@apple.com>
 
         Reviewed by John.
index 96a7c607ea0a68bd7ad984450b15380e57de3b08..a38ed35e3347e16ee50dd7b98c9e34562a5423cd 100644 (file)
@@ -16,6 +16,7 @@
 #import <WebKit/WebEditingDelegate.h>
 #import <WebKit/WebFileButton.h>
 #import <WebKit/WebFormDelegate.h>
+#import <WebKit/WebFrameLoadDelegate.h>
 #import <WebKit/WebFramePrivate.h>
 #import <WebKit/WebFrameViewPrivate.h>
 #import <WebKit/WebHistoryItemPrivate.h>
@@ -1278,4 +1279,10 @@ static id <WebFormDelegate> formDelegate(WebBridge *self)
     return [[_frame webView] mediaStyle];
 }
 
+- (void)windowObjectCleared
+{
+    WebView *wv = [_frame webView];
+    [[wv _frameLoadDelegateForwarder] webView:wv windowScriptObjectAvailable:[self windowScriptObject]];
+}
+
 @end
index 7b95939eb4840276e6663008b254e16de7ba086d..ca41591a66a9bc5cf2ae517fab8f5c3f29577cf2 100644 (file)
@@ -5,6 +5,7 @@
 #import <WebKit/WebDefaultFrameLoadDelegate.h>
 #import <WebKit/WebDataSource.h>
 #import <WebKit/WebFrame.h>
+#import <WebKit/WebScriptObject.h>
 
 @implementation WebDefaultFrameLoadDelegate
 
@@ -44,4 +45,6 @@ static WebDefaultFrameLoadDelegate *sharedDelegate = nil;
 
 - (void)webView:(WebView *)sender willCloseFrame:(WebFrame *)frame { }
 
+- (void)webView:(WebView *)sender windowScriptObjectAvailable:(WebScriptObject *)obj { }
+
 @end
index 7641998e00414dab9d163277adfa9ef82f0c26f5..2d058d87c66aa36d7a8c11a63d4f45bcdcffe71c 100644 (file)
@@ -1930,7 +1930,7 @@ static WebHTMLView *lastHitView = nil;
     return [self _scaleFactorForPrintOperation:printOperation];
 }
 
-- (void)_setPageWidthForPrinting:(float)pageWidth
+- (void)setPageWidthForPrinting:(float)pageWidth
 {
     [self _setPrinting:NO minimumPageWidth:0. maximumPageWidth:0. adjustViewSize:NO];
     [self _setPrinting:YES minimumPageWidth:pageWidth maximumPageWidth:pageWidth adjustViewSize:YES];