adium-1.4 3331:3c7515d4ce40: Added a MessageViewVersion_MinimumC...
commits at adium.im
commits at adium.im
Thu Jan 27 03:06:50 UTC 2011
details: http://hg.adium.im/adium-1.4/rev/3c7515d4ce40
revision: 3331:3c7515d4ce40
author: Evan Schoenberg
date: Wed Jan 26 21:02:18 2011 -0600
Added a MessageViewVersion_MinimumCompatible key to message style Info.plist keys. If set, Adium will refuse to load the style if it has a minimum version greater than its latest known version. This way, a message style which depends upon a hypothetical future version 5 message style can gracefully fail to load in Adium 1.4.2 which knows nothing of it; however, a message style using version 5 which is backwards compatible with version 4 can still be loaded. Fixes #7438 (for future iterations of the problem; nothing can be done for the described historical incompatibility).
(transplanted from c7323a40d94faaf031aa01ed0e9ec63dadfde954)
diffs (114 lines):
diff -r 2cb58ee83c27 -r 3c7515d4ce40 Plugins/WebKit Message View/AIWebKitMessageViewPlugin.m
--- a/Plugins/WebKit Message View/AIWebKitMessageViewPlugin.m Tue Jan 25 18:58:45 2011 -0600
+++ b/Plugins/WebKit Message View/AIWebKitMessageViewPlugin.m Wed Jan 26 21:02:18 2011 -0600
@@ -197,11 +197,22 @@
group:loadFromGroup]];
if(!*thisStyle) {
/* If the path isn't cached yet, load the style and then store the path */
- *thisStyle = [AIWebkitMessageViewStyle messageViewStyleFromBundle:[self messageStyleBundleWithIdentifier:[prefs preferenceForKey:KEY_WEBKIT_STYLE
- group:loadFromGroup]]];
- [prefs setPreference:[[[*thisStyle bundle] bundlePath] stringByCollapsingBundlePath]
- forKey:KEY_CURRENT_WEBKIT_STYLE_PATH
- group:loadFromGroup];
+ *thisStyle = [AIWebkitMessageViewStyle messageViewStyleFromBundle:
+ [self messageStyleBundleWithIdentifier:[prefs preferenceForKey:KEY_WEBKIT_STYLE
+ group:loadFromGroup]]];
+ if (*thisStyle) {
+ [prefs setPreference:[[[*thisStyle bundle] bundlePath] stringByCollapsingBundlePath]
+ forKey:KEY_CURRENT_WEBKIT_STYLE_PATH
+ group:loadFromGroup];
+ } else {
+ /* If the style failed to load, clear our preference to fall back to the default */
+ /* XXX An error message could potentially be displayed here */
+ [prefs setPreference:nil forKey:KEY_WEBKIT_STYLE group:loadFromGroup];
+
+ *thisStyle = [AIWebkitMessageViewStyle messageViewStyleFromBundle:
+ [self messageStyleBundleWithIdentifier:[prefs preferenceForKey:KEY_WEBKIT_STYLE
+ group:loadFromGroup]]];
+ }
}
[*thisStyle retain];
}
diff -r 2cb58ee83c27 -r 3c7515d4ce40 Plugins/WebKit Message View/AIWebkitMessageViewStyle.h
--- a/Plugins/WebKit Message View/AIWebkitMessageViewStyle.h Tue Jan 25 18:58:45 2011 -0600
+++ b/Plugins/WebKit Message View/AIWebkitMessageViewStyle.h Wed Jan 26 21:02:18 2011 -0600
@@ -147,8 +147,10 @@
/*!
* @brief Reloads the content of the style, useful for style authors and updates
+ *
+ * @result YES if the style loaded succesfully; NO if an error (such as an incompatible style version) occurred.
*/
-- (void) reloadStyle;
+- (BOOL) reloadStyle;
/*!
* @brief The name of the active variant.
diff -r 2cb58ee83c27 -r 3c7515d4ce40 Plugins/WebKit Message View/AIWebkitMessageViewStyle.m
--- a/Plugins/WebKit Message View/AIWebkitMessageViewStyle.m Tue Jan 25 18:58:45 2011 -0600
+++ b/Plugins/WebKit Message View/AIWebkitMessageViewStyle.m Wed Jan 26 21:02:18 2011 -0600
@@ -39,9 +39,11 @@
//
#define LEGACY_VERSION_THRESHOLD 3 //Styles older than this version are considered legacy
+#define MAX_KNOWN_WEBKIT_VERSION 4 //Styles newer than this version are unknown entities
//
#define KEY_WEBKIT_VERSION @"MessageViewVersion"
+#define KEY_WEBKIT_VERSION_MIN @"MessageViewVersion_MinimumCompatible"
//BOM scripts for appending content.
#define APPEND_MESSAGE_WITH_SCROLL @"checkIfScrollToBottomIsNeeded(); appendMessage(\"%@\"); scrollToBottomIfNeeded();"
@@ -142,19 +144,20 @@
if ((self = [super init])) {
styleBundle = [inBundle retain];
stylePath = [[styleBundle resourcePath] retain];
- [self reloadStyle];
+
+ if ([self reloadStyle] == FALSE) {
+ [self release];
+ return nil;
+ }
}
return self;
}
-- (void) reloadStyle
+- (BOOL) reloadStyle
{
[self releaseResources];
- //Default behavior
- allowTextBackgrounds = YES;
-
/* Our styles are versioned so we can change how they work without breaking compatibility.
*
* Version 0: Initial Webkit Version
@@ -173,6 +176,17 @@
*/
styleVersion = [[styleBundle objectForInfoDictionaryKey:KEY_WEBKIT_VERSION] integerValue];
+ /* Refuse to load a version whose minimum compatible version is greater than the latest version we know about; that
+ * indicates this is a style FROM THE FUTURE, and we can't risk corrupting our own timeline.
+ */
+ NSInteger minimumCompatibleVersion = [[styleBundle objectForInfoDictionaryKey:KEY_WEBKIT_VERSION_MIN] integerValue];
+ if (minimumCompatibleVersion && (minimumCompatibleVersion > MAX_KNOWN_WEBKIT_VERSION)) {
+ return NO;
+ }
+
+ //Default behavior
+ allowTextBackgrounds = YES;
+
//Pre-fetch our templates
[self _loadTemplates];
@@ -191,6 +205,8 @@
NSNumber *allowsColorsNumber = [styleBundle objectForInfoDictionaryKey:@"AllowTextColors"];
allowsColors = (allowsColorsNumber ? [allowsColorsNumber boolValue] : YES);
+
+ return YES;
}
/*!
More information about the commits
mailing list