Commit 04dd6c3b authored by andersca@apple.com's avatar andersca@apple.com

WebKit:

2008-06-26  Anders Carlsson  <andersca@apple.com>

        Reviewed by Darin.

        Add MainThreadObjectDeallocator to sources.
        
        * WebKit.xcodeproj/project.pbxproj:

WebKit/mac:

2008-06-26  Anders Carlsson  <andersca@apple.com>

        Reviewed by Darin.

        Add a new MainThreadObjectDeallocator which can schedule dealloc calls on the main thread
        if necessary. Use this for the WebView class. 
                
        * WebView/MainThreadObjectDeallocator.h: Added.
        * WebView/MainThreadObjectDeallocator.mm: Added.
        (deallocCallback):
        (scheduleDeallocateOnMainThread):
        * WebView/WebView.mm:
        (-[WebViewPrivate dealloc]):
        (+[WebView initialize]):



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@34812 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 5b003677
2008-06-26 Anders Carlsson <andersca@apple.com>
Reviewed by Darin.
Add MainThreadObjectDeallocator to sources.
* WebKit.xcodeproj/project.pbxproj:
2008-06-24 John Sullivan <sullivan@apple.com>
Rubber-stamped by Sam Weinig
......
......@@ -17,6 +17,8 @@
1A2D754E0DE480B900F0A648 /* WebIconFetcher.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1A2D754C0DE480B900F0A648 /* WebIconFetcher.mm */; };
1A2D75500DE4810E00F0A648 /* WebIconFetcherInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A2D754F0DE4810E00F0A648 /* WebIconFetcherInternal.h */; };
1A7F9C4C0DD3DDEA0028F8A5 /* nptextinput.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A7F9C4B0DD3DDEA0028F8A5 /* nptextinput.h */; settings = {ATTRIBUTES = (Public, ); }; };
1AE1CEF20E141CC4000027BC /* MainThreadObjectDeallocator.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AE1CEF00E141CC4000027BC /* MainThreadObjectDeallocator.h */; };
1AE1CEF30E141CC4000027BC /* MainThreadObjectDeallocator.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1AE1CEF10E141CC4000027BC /* MainThreadObjectDeallocator.mm */; };
1AEA66D40DC6B1FF003D12BF /* WebNetscapePluginEventHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AEA66D20DC6B1FF003D12BF /* WebNetscapePluginEventHandler.h */; };
1AEA66D50DC6B1FF003D12BF /* WebNetscapePluginEventHandler.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1AEA66D30DC6B1FF003D12BF /* WebNetscapePluginEventHandler.mm */; };
1AEA66D80DC6B209003D12BF /* WebNetscapePluginEventHandlerCarbon.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AEA66D60DC6B209003D12BF /* WebNetscapePluginEventHandlerCarbon.h */; };
......@@ -309,6 +311,8 @@
1A2D754C0DE480B900F0A648 /* WebIconFetcher.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebIconFetcher.mm; sourceTree = "<group>"; };
1A2D754F0DE4810E00F0A648 /* WebIconFetcherInternal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebIconFetcherInternal.h; sourceTree = "<group>"; };
1A7F9C4B0DD3DDEA0028F8A5 /* nptextinput.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = nptextinput.h; sourceTree = "<group>"; };
1AE1CEF00E141CC4000027BC /* MainThreadObjectDeallocator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MainThreadObjectDeallocator.h; sourceTree = "<group>"; };
1AE1CEF10E141CC4000027BC /* MainThreadObjectDeallocator.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MainThreadObjectDeallocator.mm; sourceTree = "<group>"; };
1AEA66D20DC6B1FF003D12BF /* WebNetscapePluginEventHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebNetscapePluginEventHandler.h; sourceTree = "<group>"; };
1AEA66D30DC6B1FF003D12BF /* WebNetscapePluginEventHandler.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebNetscapePluginEventHandler.mm; sourceTree = "<group>"; };
1AEA66D60DC6B209003D12BF /* WebNetscapePluginEventHandlerCarbon.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebNetscapePluginEventHandlerCarbon.h; sourceTree = "<group>"; };
......@@ -982,6 +986,8 @@
84311A1305EAAAF00088EDA4 /* WebResource.mm */,
7E6FEF0608985A7200C44C3F /* WebScriptDebugDelegate.mm */,
51A8B57A042834F700CA2D3A /* WebView.mm */,
1AE1CEF00E141CC4000027BC /* MainThreadObjectDeallocator.h */,
1AE1CEF10E141CC4000027BC /* MainThreadObjectDeallocator.mm */,
);
name = WebView;
path = mac/WebView;
......@@ -1309,6 +1315,7 @@
1A7F9C4C0DD3DDEA0028F8A5 /* nptextinput.h in Headers */,
1A2D754D0DE480B900F0A648 /* WebIconFetcher.h in Headers */,
1A2D75500DE4810E00F0A648 /* WebIconFetcherInternal.h in Headers */,
1AE1CEF20E141CC4000027BC /* MainThreadObjectDeallocator.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -1594,6 +1601,7 @@
1AEA66D90DC6B209003D12BF /* WebNetscapePluginEventHandlerCarbon.mm in Sources */,
1AEA6A510DC8CE2F003D12BF /* WebNetscapePluginEventHandlerCocoa.mm in Sources */,
1A2D754E0DE480B900F0A648 /* WebIconFetcher.mm in Sources */,
1AE1CEF30E141CC4000027BC /* MainThreadObjectDeallocator.mm in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......
2008-06-26 Anders Carlsson <andersca@apple.com>
Reviewed by Darin.
Add a new MainThreadObjectDeallocator which can schedule dealloc calls on the main thread
if necessary. Use this for the WebView class.
* WebView/MainThreadObjectDeallocator.h: Added.
* WebView/MainThreadObjectDeallocator.mm: Added.
(deallocCallback):
(scheduleDeallocateOnMainThread):
* WebView/WebView.mm:
(-[WebViewPrivate dealloc]):
(+[WebView initialize]):
2008-06-25 Anders Carlsson <andersca@apple.com>
Reviewed by Mark.
......
/*
* Copyright (C) 2008 Apple Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef MainThreadObjectDeallocator_h
#define MainThreadObjectDeallocator_h
#include <objc/objc.h>
bool scheduleDeallocateOnMainThread(id object);
#endif // MainThreadDeallocator_h
/*
* Copyright (C) 2008 Apple Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "MainThreadObjectDeallocator.h"
#include <wtf/MainThread.h>
static void deallocCallback(void* context)
{
id object = static_cast<id>(context);
[object dealloc];
}
bool scheduleDeallocateOnMainThread(id object)
{
if (pthread_main_np() != 0)
return false;
callOnMainThread(deallocCallback, object);
return true;
}
......@@ -30,6 +30,7 @@
#import "WebViewInternal.h"
#import "DOMRangeInternal.h"
#import "MainThreadObjectDeallocator.h"
#import "WebBackForwardListInternal.h"
#import "WebBaseNetscapePluginView.h"
#import "WebChromeClient.h"
......@@ -491,6 +492,9 @@ static BOOL grammarCheckingEnabled;
- (void)dealloc
{
if (scheduleDeallocateOnMainThread(self))
return;
ASSERT(applicationIsTerminating || !page);
ASSERT(applicationIsTerminating || !preferences);
......@@ -1712,30 +1716,6 @@ WebFrameLoadDelegateImplementationCache* WebViewGetFrameLoadDelegateImplementati
@implementation WebView
#ifdef BUILDING_ON_TIGER
static IMP oldReleaseIMP;
static void
tigerMailReleaseIMP(WebView* self, SEL cmd)
{
// If we're on the main thread or the retain count is not 1, we can safely call the old release implementation.
if (pthread_main_np() != 0 || [self retainCount] > 1) {
oldReleaseIMP(self, cmd);
return;
}
// Release the web view on the main thread
[self performSelectorOnMainThread:@selector(release) withObject:nil waitUntilDone:NO];
}
// We declare a release method here so that we don't try to modify -[NSObject release].
- (void)release
{
[super release];
}
#endif
+ (void)initialize
{
static BOOL initialized = NO;
......@@ -1745,22 +1725,7 @@ tigerMailReleaseIMP(WebView* self, SEL cmd)
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_applicationWillTerminate) name:NSApplicationWillTerminateNotification object:NSApp];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_preferencesChangedNotification:) name:WebPreferencesChangedNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_preferencesRemovedNotification:) name:WebPreferencesRemovedNotification object:nil];
#ifdef BUILDING_ON_TIGER
// Tiger Mail can sometimes call release on a secondary thread, which can end up calling -[WebView dealloc] which isn't thread safe.
// To work around this we check if Mail is running and replace the release method which one that makes sure that the final release
// happens on the main thread.
if (![[[NSBundle mainBundle] bundleIdentifier] isEqualToString:@"com.apple.mail"])
return;
if (oldReleaseIMP)
return;
Method releaseMethod = class_getInstanceMethod(self, @selector(release));
ASSERT(releaseMethod);
oldReleaseIMP = method_setImplementation(releaseMethod,(IMP)tigerMailReleaseIMP);
#endif
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_preferencesRemovedNotification:) name:WebPreferencesRemovedNotification object:nil];
}
+ (void)_applicationWillTerminate
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment