+2009-01-10 Darin Adler <darin@apple.com>
+
+ Reviewed by Sam Weinig.
+
+ <rdar://problem/5845089> REGRESSION (r30044): Mail custom stationery missing images
+ because of change to -[HTMLObjectElement data]
+
+ * WebView/WebView.mm:
+ (-[WebView _commonInitializationWithFrameName:groupName:usesDocumentViews:]): Added a thread
+ violation check because I saw this being done off the main thread while testing Mail, and it
+ caused problems. Put all the one time initialization under a single guard to make things just
+ a little faster other times, and to make it clearer which things are one-time. Added a call to
+ the new patchMailRemoveAttributesMethod function.
+ (-[WebView initWithFrame:frameName:groupName:]): Added a thread violation check here too,
+ because I assumed it would be slightly better to have a public method name in the violation
+ message. This calls commonInitialization later, so it will hit that one eventually.
+ (objectElementDataAttribute): Added. Just returns the value of the "data" attribute.
+ (recursivelyRemoveMailAttributes): Added. Patch to an internal Mail method that in turn patches
+ a WebKit method and removes the patch again on the way out.
+ (patchMailRemoveAttributesMethod): Added. On Leopard only, checks the Mail version, and then
+ applies the patch that fixes this bug.
+
2009-01-09 Dan Bernstein <mitz@apple.com>
Reviewed by Darin Adler.
/*
- * Copyright (C) 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
* Copyright (C) 2006 David Smith (catfish.man@gmail.com)
*
* Redistribution and use in source and binary forms, with or without
#import <WebCore/SelectionController.h>
#import <WebCore/Settings.h>
#import <WebCore/TextResourceDecoder.h>
+#import <WebCore/ThreadCheck.h>
#import <WebCore/WebCoreObjCExtras.h>
#import <WebCore/WebCoreTextRenderer.h>
#import <WebCore/WebCoreView.h>
@interface WebView (WebCallDelegateFunctions)
@end
+static void patchMailRemoveAttributesMethod();
+
NSString *WebElementDOMNodeKey = @"WebElementDOMNode";
NSString *WebElementFrameKey = @"WebElementFrame";
NSString *WebElementImageKey = @"WebElementImage";
- (void)_commonInitializationWithFrameName:(NSString *)frameName groupName:(NSString *)groupName usesDocumentViews:(BOOL)usesDocumentViews
{
+ WebCoreThreadViolationCheck();
+
#ifndef NDEBUG
WTF::RefCountedLeakCounter::suppressMessages(webViewIsOpen);
#endif
[frameView release];
}
- WebKitInitializeLoggingChannelsIfNecessary();
- WebCore::InitializeLoggingChannelsIfNecessary();
- [WebHistoryItem initWindowWatcherIfNecessary];
- WebKitInitializeDatabasesIfNecessary();
- WebKitInitializeApplicationCachePathIfNecessary();
-
+ static bool didOneTimeInitialization = false;
+ if (!didOneTimeInitialization) {
+ WebKitInitializeLoggingChannelsIfNecessary();
+ WebCore::InitializeLoggingChannelsIfNecessary();
+ [WebHistoryItem initWindowWatcherIfNecessary];
+ WebKitInitializeDatabasesIfNecessary();
+ WebKitInitializeApplicationCachePathIfNecessary();
+ patchMailRemoveAttributesMethod();
+ didOneTimeInitialization = true;
+ }
+
_private->page = new Page(new WebChromeClient(self), new WebContextMenuClient(self), new WebEditorClient(self), new WebDragClient(self), new WebInspectorClient(self));
_private->page->settings()->setLocalStorageDatabasePath([[self preferences] _localStorageDatabasePath]);
- (id)initWithFrame:(NSRect)f frameName:(NSString *)frameName groupName:(NSString *)groupName
{
+ WebCoreThreadViolationCheck();
return [self _initWithFrame:f frameName:frameName groupName:groupName usesDocumentViews:YES];
}
}
@end
+
+#ifdef BUILDING_ON_LEOPARD
+
+static IMP originalRecursivelyRemoveMailAttributesImp;
+
+static id objectElementDataAttribute(DOMHTMLObjectElement *self, SEL)
+{
+ return [self getAttribute:@"data"];
+}
+
+static void recursivelyRemoveMailAttributes(DOMNode *self, SEL selector, BOOL a, BOOL b, BOOL c)
+{
+ // While inside this Mail function, change the behavior of -[DOMHTMLObjectElement data] back to what it used to be
+ // before we fixed a bug in it (see http://trac.webkit.org/changeset/30044 for that change).
+
+ // It's a little bit strange to patch a method defined by WebKit, but it helps keep this workaround self-contained.
+
+ Method methodToPatch = class_getInstanceMethod(objc_getRequiredClass("DOMHTMLObjectElement"), @selector(data));
+ IMP originalDataImp = method_setImplementation(methodToPatch, reinterpret_cast<IMP>(objectElementDataAttribute));
+ originalRecursivelyRemoveMailAttributesImp(self, selector, a, b, c);
+ method_setImplementation(methodToPatch, originalDataImp);
+}
+
+#endif
+
+static void patchMailRemoveAttributesMethod()
+{
+#ifdef BUILDING_ON_LEOPARD
+ if (!WKAppVersionCheckLessThan(@"com.apple.mail", -1, 4.0))
+ return;
+ Method methodToPatch = class_getInstanceMethod(objc_getRequiredClass("DOMNode"), @selector(recursivelyRemoveMailAttributes:convertObjectsToImages:convertEditableElements:));
+ if (!methodToPatch)
+ return;
+ originalRecursivelyRemoveMailAttributesImp = method_setImplementation(methodToPatch, reinterpret_cast<IMP>(recursivelyRemoveMailAttributes));
+#endif
+}