Diff
Modified: trunk/Source/WebKit/mac/ChangeLog (122674 => 122675)
--- trunk/Source/WebKit/mac/ChangeLog 2012-07-14 21:56:59 UTC (rev 122674)
+++ trunk/Source/WebKit/mac/ChangeLog 2012-07-14 23:31:03 UTC (rev 122675)
@@ -1,3 +1,22 @@
+2012-07-14 Benjamin Poulain <[email protected]>
+
+ [Mac] Do not try to update the cache model for every WebPreferences change
+ https://bugs.webkit.org/show_bug.cgi?id=91302
+
+ Reviewed by Joseph Pecoraro.
+
+ WebView was listening to any change on any WebPreferences in order to update the cache model. This is unneeded in most cases,
+ we can just listen to updates of the CacheModel property.
+
+ * WebView/WebPreferences.mm:
+ (-[WebPreferences initWithIdentifier:]):
+ (-[WebPreferences _postCacheModelChangedNotification]):
+ (-[WebPreferences setCacheModel:]):
+ * WebView/WebPreferencesPrivate.h:
+ * WebView/WebView.mm:
+ (+[WebView initialize]):
+ (+[WebView _cacheModelChangedNotification:]):
+
2012-07-14 Sheriff Bot <[email protected]>
Unreviewed, rolling out r122665.
Modified: trunk/Source/WebKit/mac/WebView/WebPreferences.mm (122674 => 122675)
--- trunk/Source/WebKit/mac/WebView/WebPreferences.mm 2012-07-14 21:56:59 UTC (rev 122674)
+++ trunk/Source/WebKit/mac/WebView/WebPreferences.mm 2012-07-14 23:31:03 UTC (rev 122675)
@@ -47,6 +47,7 @@
NSString *WebPreferencesChangedNotification = @"WebPreferencesChangedNotification";
NSString *WebPreferencesRemovedNotification = @"WebPreferencesRemovedNotification";
NSString *WebPreferencesChangedInternalNotification = @"WebPreferencesChangedInternalNotification";
+NSString *WebPreferencesCacheModelChangedInternalNotification = @"WebPreferencesCacheModelChangedInternalNotification";
#define KEY(x) (_private->identifier ? [_private->identifier stringByAppendingString:(x)] : (x))
@@ -163,6 +164,10 @@
}
@end
+@interface WebPreferences ()
+- (void)_postCacheModelChangedNotification;
+@end
+
@interface WebPreferences (WebInternal)
+ (NSString *)_concatenateKeyWithIBCreatorID:(NSString *)key;
+ (NSString *)_IBCreatorID;
@@ -222,6 +227,7 @@
[[self class] _setInstance:self forIdentifier:_private->identifier];
[self _postPreferencesChangedNotification];
+ [self _postCacheModelChangedNotification];
return self;
}
@@ -802,10 +808,21 @@
return [self _boolValueForKey:WebKitUsesPageCachePreferenceKey];
}
+- (void)_postCacheModelChangedNotification
+{
+ if (!pthread_main_np()) {
+ [self performSelectorOnMainThread:_cmd withObject:nil waitUntilDone:NO];
+ return;
+ }
+
+ [[NSNotificationCenter defaultCenter] postNotificationName:WebPreferencesCacheModelChangedInternalNotification object:self userInfo:nil];
+}
+
- (void)setCacheModel:(WebCacheModel)cacheModel
{
[self _setIntegerValue:cacheModel forKey:WebKitCacheModelPreferenceKey];
[self setAutomaticallyDetectsCacheModel:NO];
+ [self _postCacheModelChangedNotification];
}
- (WebCacheModel)cacheModel
Modified: trunk/Source/WebKit/mac/WebView/WebPreferencesPrivate.h (122674 => 122675)
--- trunk/Source/WebKit/mac/WebView/WebPreferencesPrivate.h 2012-07-14 21:56:59 UTC (rev 122674)
+++ trunk/Source/WebKit/mac/WebView/WebPreferencesPrivate.h 2012-07-14 23:31:03 UTC (rev 122675)
@@ -46,6 +46,7 @@
extern NSString *WebPreferencesChangedNotification;
extern NSString *WebPreferencesRemovedNotification;
extern NSString *WebPreferencesChangedInternalNotification;
+extern NSString *WebPreferencesCacheModelChangedInternalNotification;
@interface WebPreferences (WebPrivate)
Modified: trunk/Source/WebKit/mac/WebView/WebView.mm (122674 => 122675)
--- trunk/Source/WebKit/mac/WebView/WebView.mm 2012-07-14 21:56:59 UTC (rev 122674)
+++ trunk/Source/WebKit/mac/WebView/WebView.mm 2012-07-14 23:31:03 UTC (rev 122675)
@@ -3040,7 +3040,7 @@
WebCore::RunLoop::initializeMainRunLoop();
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_applicationWillTerminate) name:NSApplicationWillTerminateNotification object:NSApp];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_preferencesChangedNotification:) name:WebPreferencesChangedInternalNotification object:nil];
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_cacheModelChangedNotification:) name:WebPreferencesCacheModelChangedInternalNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_preferencesRemovedNotification:) name:WebPreferencesRemovedNotification object:nil];
continuousSpellCheckingEnabled = [[NSUserDefaults standardUserDefaults] boolForKey:WebContinuousSpellCheckingEnabled];
@@ -5913,7 +5913,7 @@
return cacheModel;
}
-+ (void)_preferencesChangedNotification:(NSNotification *)notification
++ (void)_cacheModelChangedNotification:(NSNotification *)notification
{
WebPreferences *preferences = (WebPreferences *)[notification object];
ASSERT([preferences isKindOfClass:[WebPreferences class]]);
Modified: trunk/Tools/ChangeLog (122674 => 122675)
--- trunk/Tools/ChangeLog 2012-07-14 21:56:59 UTC (rev 122674)
+++ trunk/Tools/ChangeLog 2012-07-14 23:31:03 UTC (rev 122675)
@@ -1,3 +1,15 @@
+2012-07-14 Benjamin Poulain <[email protected]>
+
+ [Mac] Do not try to update the cache model for every WebPreferences change
+ https://bugs.webkit.org/show_bug.cgi?id=91302
+
+ Reviewed by Joseph Pecoraro.
+
+ * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+ * TestWebKitAPI/Tests/mac/SetAndUpdateCacheModel.mm: Added.
+ (TestWebKitAPI):
+ (TestWebKitAPI::TEST):
+
2012-07-14 Sheriff Bot <[email protected]>
Unreviewed, rolling out r122665.
Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (122674 => 122675)
--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj 2012-07-14 21:56:59 UTC (rev 122674)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj 2012-07-14 23:31:03 UTC (rev 122675)
@@ -20,6 +20,7 @@
1ADBEFAE130C689C00D61D19 /* ForceRepaint.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1ADBEFAD130C689C00D61D19 /* ForceRepaint.cpp */; };
1ADBEFE3130C6AA100D61D19 /* simple-accelerated-compositing.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 1ADBEFBC130C6A0100D61D19 /* simple-accelerated-compositing.html */; };
1AEDE22613E5E7E700E62FE8 /* InjectedBundleControllerMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1AEDE22413E5E7A000E62FE8 /* InjectedBundleControllerMac.mm */; };
+ 261516D615B0E60500A2C201 /* SetAndUpdateCacheModel.mm in Sources */ = {isa = PBXBuildFile; fileRef = 261516D515B0E60500A2C201 /* SetAndUpdateCacheModel.mm */; };
26DF5A5E15A29BAA003689C2 /* CancelLoadFromResourceLoadDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 26DF5A5D15A29BAA003689C2 /* CancelLoadFromResourceLoadDelegate.mm */; };
26DF5A6315A2A27E003689C2 /* CancelLoadFromResourceLoadDelegate.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 26DF5A6115A2A22B003689C2 /* CancelLoadFromResourceLoadDelegate.html */; };
333B9CE21277F23100FEFCE3 /* PreventEmptyUserAgent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 333B9CE11277F23100FEFCE3 /* PreventEmptyUserAgent.cpp */; };
@@ -240,6 +241,7 @@
1ADBEFAD130C689C00D61D19 /* ForceRepaint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ForceRepaint.cpp; sourceTree = "<group>"; };
1ADBEFBC130C6A0100D61D19 /* simple-accelerated-compositing.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "simple-accelerated-compositing.html"; sourceTree = "<group>"; };
1AEDE22413E5E7A000E62FE8 /* InjectedBundleControllerMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = InjectedBundleControllerMac.mm; sourceTree = "<group>"; };
+ 261516D515B0E60500A2C201 /* SetAndUpdateCacheModel.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SetAndUpdateCacheModel.mm; sourceTree = "<group>"; };
26DF5A5D15A29BAA003689C2 /* CancelLoadFromResourceLoadDelegate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CancelLoadFromResourceLoadDelegate.mm; sourceTree = "<group>"; };
26DF5A6115A2A22B003689C2 /* CancelLoadFromResourceLoadDelegate.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = CancelLoadFromResourceLoadDelegate.html; sourceTree = "<group>"; };
333B9CE11277F23100FEFCE3 /* PreventEmptyUserAgent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PreventEmptyUserAgent.cpp; sourceTree = "<group>"; };
@@ -695,6 +697,7 @@
E1220D9F155B25480013E2FC /* MemoryCacheDisableWithinResourceLoadDelegate.mm */,
517E7DFB15110EA600D0B008 /* MemoryCachePruneWithinResourceLoadDelegate.mm */,
3722C8681461E03E00C45D00 /* RenderedImageFromDOMRange.mm */,
+ 261516D515B0E60500A2C201 /* SetAndUpdateCacheModel.mm */,
52B8CF9515868CF000281053 /* SetDocumentURI.mm */,
C540F775152E4DA000A40C8C /* SimplifyMarkup.mm */,
3799AD3914120A43005EB0C6 /* StringByEvaluatingJavaScriptFromString.mm */,
@@ -933,6 +936,7 @@
F660AA0D15A5F061003A1243 /* GetInjectedBundleInitializationUserDataCallback.cpp in Sources */,
F660AA1315A619C9003A1243 /* InjectedBundleInitializationUserDataCallbackWins.cpp in Sources */,
0F17BBD615AF6C4D007AB753 /* WebCoreStatisticsWithNoWebProcess.cpp in Sources */,
+ 261516D615B0E60500A2C201 /* SetAndUpdateCacheModel.mm in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Added: trunk/Tools/TestWebKitAPI/Tests/mac/SetAndUpdateCacheModel.mm (0 => 122675)
--- trunk/Tools/TestWebKitAPI/Tests/mac/SetAndUpdateCacheModel.mm (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/mac/SetAndUpdateCacheModel.mm 2012-07-14 23:31:03 UTC (rev 122675)
@@ -0,0 +1,103 @@
+/*
+ * Copyright (C) 2012 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. AND ITS CONTRIBUTORS ``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 ITS 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 "config.h"
+#include <wtf/RetainPtr.h>
+
+#import <WebKit/WebView.h>
+#import <WebKit/WebPreferences.h>
+
+@interface WebView (WebViewOtherInternal)
++ (WebCacheModel)_cacheModel;
+@end
+
+namespace TestWebKitAPI {
+
+TEST(WebKit1, SetAndUpdateCacheModelInitialModel)
+{
+ EXPECT_EQ((int)WebCacheModelDocumentViewer, (int)[WebView _cacheModel]);
+
+ RetainPtr<WebView> webView(AdoptNS, [[WebView alloc] initWithFrame:NSMakeRect(0, 0, 120, 200) frameName:nil groupName:nil]);
+
+ EXPECT_EQ((int)WebCacheModelDocumentBrowser, (int)[WebView _cacheModel]);
+}
+
+TEST(WebKit1, SetAndUpdateCacheModelStandardPreferenceChange)
+{
+ EXPECT_EQ((int)WebCacheModelDocumentViewer, (int)[WebView _cacheModel]);
+
+ WebPreferences *standardPreferences = [WebPreferences standardPreferences];
+ EXPECT_EQ((int)WebCacheModelDocumentBrowser, (int)[WebView _cacheModel]);
+
+ [standardPreferences setCacheModel:WebCacheModelPrimaryWebBrowser];
+ EXPECT_EQ((int)WebCacheModelPrimaryWebBrowser, (int)[WebView _cacheModel]);
+
+ [standardPreferences setCacheModel:WebCacheModelDocumentViewer];
+ EXPECT_EQ((int)WebCacheModelDocumentViewer, (int)[WebView _cacheModel]);
+}
+
+TEST(WebKit1, SetAndUpdateCacheModelPreferencesChangeMix)
+{
+ // On change, the cache model always take the highest value of any preference bound to a WebView.
+ EXPECT_EQ((int)WebCacheModelDocumentViewer, (int)[WebView _cacheModel]);
+
+ WebPreferences *standardPreferences = [WebPreferences standardPreferences];
+ RetainPtr<WebPreferences> customPreferences(AdoptNS, [[WebPreferences alloc] initWithIdentifier:@"SetAndUpdateCacheModelPreferencesChangeMix"]);
+
+ // 1) The customPreferences is not set on a view.
+ EXPECT_EQ((int)WebCacheModelDocumentBrowser, (int)[WebView _cacheModel]);
+
+ [standardPreferences setCacheModel:WebCacheModelPrimaryWebBrowser];
+ EXPECT_EQ((int)WebCacheModelPrimaryWebBrowser, (int)[WebView _cacheModel]);
+
+ [standardPreferences setCacheModel:WebCacheModelDocumentViewer];
+ EXPECT_EQ((int)WebCacheModelDocumentViewer, (int)[WebView _cacheModel]);
+ [customPreferences.get() setCacheModel:WebCacheModelPrimaryWebBrowser];
+ EXPECT_EQ((int)WebCacheModelPrimaryWebBrowser, (int)[WebView _cacheModel]);
+
+
+ // 2) The cache model should follow the highest value of cache model between the two preferences.
+ RetainPtr<WebView> webView(AdoptNS, [[WebView alloc] initWithFrame:NSMakeRect(0, 0, 120, 200) frameName:nil groupName:nil]);
+ [webView.get() setPreferences:customPreferences.get()];
+ EXPECT_EQ((int)WebCacheModelPrimaryWebBrowser, (int)[WebView _cacheModel]);
+
+ [customPreferences.get() setCacheModel:WebCacheModelDocumentBrowser];
+ EXPECT_EQ((int)WebCacheModelDocumentBrowser, (int)[WebView _cacheModel]);
+
+ [standardPreferences setCacheModel:WebCacheModelPrimaryWebBrowser];
+ EXPECT_EQ((int)WebCacheModelPrimaryWebBrowser, (int)[WebView _cacheModel]);
+ [customPreferences.get() setCacheModel:WebCacheModelDocumentViewer];
+ EXPECT_EQ((int)WebCacheModelPrimaryWebBrowser, (int)[WebView _cacheModel]);
+
+ // 3) Resetting the view should fall back to standardPreferences.
+ [standardPreferences setCacheModel:WebCacheModelDocumentViewer];
+ [customPreferences.get() setCacheModel:WebCacheModelPrimaryWebBrowser];
+ EXPECT_EQ((int)WebCacheModelPrimaryWebBrowser, (int)[WebView _cacheModel]);
+
+ webView.clear();
+ EXPECT_EQ((int)WebCacheModelDocumentViewer, (int)[WebView _cacheModel]);
+}
+
+} // namespace TestWebKitAPI