Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[Mac] Do not try to update the cache model for every WebPreferences c…
…hange

https://bugs.webkit.org/show_bug.cgi?id=91302

Patch by Benjamin Poulain <bpoulain@apple.com> on 2012-07-14
Reviewed by Joseph Pecoraro.

Source/WebKit/mac:

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:]):

Tools:

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/mac/SetAndUpdateCacheModel.mm: Added.
(TestWebKitAPI):
(TestWebKitAPI::TEST):


Canonical link: https://commits.webkit.org/109147@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@122675 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
Benjamin Poulain authored and BenjaminPoulain committed Jul 14, 2012
1 parent b44c81c commit 125026d
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 2 deletions.
19 changes: 19 additions & 0 deletions Source/WebKit/mac/ChangeLog
@@ -1,3 +1,22 @@
2012-07-14 Benjamin Poulain <bpoulain@apple.com>

[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 <webkit.review.bot@gmail.com>

Unreviewed, rolling out r122665.
Expand Down
17 changes: 17 additions & 0 deletions Source/WebKit/mac/WebView/WebPreferences.mm
Expand Up @@ -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))

Expand Down Expand Up @@ -163,6 +164,10 @@ - (void)dealloc
}
@end

@interface WebPreferences ()
- (void)_postCacheModelChangedNotification;
@end

@interface WebPreferences (WebInternal)
+ (NSString *)_concatenateKeyWithIBCreatorID:(NSString *)key;
+ (NSString *)_IBCreatorID;
Expand Down Expand Up @@ -222,6 +227,7 @@ - (id)initWithIdentifier:(NSString *)anIdentifier
[[self class] _setInstance:self forIdentifier:_private->identifier];

[self _postPreferencesChangedNotification];
[self _postCacheModelChangedNotification];

return self;
}
Expand Down Expand Up @@ -802,10 +808,21 @@ - (BOOL)usesPageCache
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
Expand Down
1 change: 1 addition & 0 deletions Source/WebKit/mac/WebView/WebPreferencesPrivate.h
Expand Up @@ -46,6 +46,7 @@ typedef enum {
extern NSString *WebPreferencesChangedNotification;
extern NSString *WebPreferencesRemovedNotification;
extern NSString *WebPreferencesChangedInternalNotification;
extern NSString *WebPreferencesCacheModelChangedInternalNotification;

@interface WebPreferences (WebPrivate)

Expand Down
4 changes: 2 additions & 2 deletions Source/WebKit/mac/WebView/WebView.mm
Expand Up @@ -3040,7 +3040,7 @@ + (void)initialize
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];
Expand Down Expand Up @@ -5913,7 +5913,7 @@ + (WebCacheModel)_maxCacheModelInAnyInstance
return cacheModel;
}

+ (void)_preferencesChangedNotification:(NSNotification *)notification
+ (void)_cacheModelChangedNotification:(NSNotification *)notification
{
WebPreferences *preferences = (WebPreferences *)[notification object];
ASSERT([preferences isKindOfClass:[WebPreferences class]]);
Expand Down
12 changes: 12 additions & 0 deletions Tools/ChangeLog
@@ -1,3 +1,15 @@
2012-07-14 Benjamin Poulain <bpoulain@apple.com>

[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 <webkit.review.bot@gmail.com>

Unreviewed, rolling out r122665.
Expand Down
4 changes: 4 additions & 0 deletions Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -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>"; };
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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;
};
Expand Down
103 changes: 103 additions & 0 deletions Tools/TestWebKitAPI/Tests/mac/SetAndUpdateCacheModel.mm
@@ -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

0 comments on commit 125026d

Please sign in to comment.