Permalink
Browse files

Initial commit of sIFR removal code

TODO: add preferences for en/disabling this feature.

*note: this feature necessitates the inclusion of two completely unaltered LGPL-licensed JS files

-Ian J. Wessman
  • Loading branch information...
Ian Wessman
Ian Wessman committed Feb 3, 2009
1 parent a5ba33f commit f768f8a8b24beac50b174b81216520ea5c1f818e
@@ -47,6 +47,8 @@
55EB70590E04A8B80016593D /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 55EB70570E04A8B80016593D /* WebKit.framework */; };
69A26D0C0F302C10006648BC /* NSBezierPath-RoundedRectangle.m in Sources */ = {isa = PBXBuildFile; fileRef = 69A26D0B0F302C10006648BC /* NSBezierPath-RoundedRectangle.m */; };
79A21C4D0F30B735009424B8 /* CTFWhitelistWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = 79A21C490F30B735009424B8 /* CTFWhitelistWindowController.m */; };
+ D9566D8C0F380C9F00358646 /* sifr2-addons.js in Resources */ = {isa = PBXBuildFile; fileRef = D9566C2C0F37EA0800358646 /* sifr2-addons.js */; };
+ D9566D8D0F380C9F00358646 /* sifr3-addons.js in Resources */ = {isa = PBXBuildFile; fileRef = D9566C2D0F37EA0800358646 /* sifr3-addons.js */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@@ -99,6 +101,8 @@
69A26D0B0F302C10006648BC /* NSBezierPath-RoundedRectangle.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "NSBezierPath-RoundedRectangle.m"; path = "Plugin/NSBezierPath-RoundedRectangle.m"; sourceTree = "<group>"; };
79A21C490F30B735009424B8 /* CTFWhitelistWindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CTFWhitelistWindowController.m; path = Plugin/CTFWhitelistWindowController.m; sourceTree = "<group>"; };
79A21C4A0F30B735009424B8 /* CTFWhitelistWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CTFWhitelistWindowController.h; path = Plugin/CTFWhitelistWindowController.h; sourceTree = "<group>"; };
+ D9566C2C0F37EA0800358646 /* sifr2-addons.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = "sifr2-addons.js"; sourceTree = "<group>"; };
+ D9566C2D0F37EA0800358646 /* sifr3-addons.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = "sifr3-addons.js"; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -156,6 +160,7 @@
55EB70540E04A89C0016593D /* Plugin */ = {
isa = PBXGroup;
children = (
+ D9566C2B0F37EA0800358646 /* deSIFR Resources */,
072189BA0F30D9C3008C8944 /* ContextualMenu.xib */,
79A21C490F30B735009424B8 /* CTFWhitelistWindowController.m */,
79A21C4A0F30B735009424B8 /* CTFWhitelistWindowController.h */,
@@ -178,6 +183,16 @@
name = Frameworks;
sourceTree = "<group>";
};
+ D9566C2B0F37EA0800358646 /* deSIFR Resources */ = {
+ isa = PBXGroup;
+ children = (
+ D9566C2C0F37EA0800358646 /* sifr2-addons.js */,
+ D9566C2D0F37EA0800358646 /* sifr3-addons.js */,
+ );
+ name = "deSIFR Resources";
+ path = "Plugin/deSIFR Resources";
+ sourceTree = "<group>";
+ };
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
@@ -252,6 +267,8 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
+ D9566D8C0F380C9F00358646 /* sifr2-addons.js in Resources */,
+ D9566D8D0F380C9F00358646 /* sifr3-addons.js in Resources */,
072189BE0F30D9C3008C8944 /* ContextualMenu.xib in Resources */,
072189BF0F30D9C3008C8944 /* WhitelistPanel.xib in Resources */,
);
View
@@ -7,7 +7,7 @@
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIdentifier</key>
- <string>com.github.rentzsch.clicktoflash</string>
+ <string>com.github.wessman.clicktoflash</string>
<key>CFBundleIconFile</key>
<string></string>
<key>CFBundleInfoDictionaryVersion</key>
@@ -30,10 +30,10 @@
<dict>
<key>application/x-shockwave-flash</key>
<dict>
- <key>WebPluginExtensions</key>
- <array>
- <string>swf</string>
- </array>
+ <key>WebPluginExtensions</key>
+ <array>
+ <string>swf</string>
+ </array>
<key>WebPluginTypeDescription</key>
<string>ClickToFlash</string>
</dict>
View
@@ -38,6 +38,8 @@ THE SOFTWARE.
BOOL mouseIsDown;
BOOL mouseInside;
BOOL _isLoadingFromWhitelist;
+ WebView *_webView;
+ NSUInteger _sifrVersion;
}
+ (NSView *)plugInViewWithArguments:(NSDictionary *)arguments;
@@ -46,6 +48,7 @@ THE SOFTWARE.
@property (nonatomic, retain) DOMElement *container;
@property (nonatomic, retain) NSString *host;
+@property (nonatomic, retain) WebView *webView;
@property (readonly, nonatomic, retain) NSString *addToWhiteListMenuTitle;
- (IBAction)addToWhitelist:(id)sender;
View
@@ -34,6 +34,13 @@ of this software and associated documentation files (the "Software"), to deal
static NSString *sHostWhitelistDefaultsKey = @"ClickToFlash.whitelist";
static NSString *sCTFWhitelistAdditionMade = @"CTFWhitelistAdditionMade";
+static NSString *sifr2Test = @"sIFR != null && typeof sIFR == \"function\"";
+static NSString *sifr3Test = @"sIFR != null && typeof sIFR == \"object\"";
+static NSString *sifrAddOnTest = @"sIFR.rollback == null || typeof sIFR.rollback != \"function\"";
+static NSString *sifrRollbackJS = @"sIFR.rollback()";
+static NSString *sifr2AddOnJSFilename = @"sifr2-addons";
+static NSString *sifr3AddOnJSFilename = @"sifr3-addons";
+
@interface CTFClickToFlashPlugin (Internal)
- (void) _convertTypesForContainer;
- (void) _drawBackground;
@@ -44,6 +51,10 @@ - (void) _addHostToWhitelist;
- (void) _removeHostFromWhitelist;
- (void) _askToAddCurrentSiteToWhitelist;
- (void) _whitelistAdditionMade: (NSNotification*) note;
+
+// deSIFR
+- (NSUInteger) _sifrVersionInstalled;
+- (void) _disableSIFR;
@end
@@ -66,19 +77,30 @@ - (id) initWithArguments:(NSDictionary *)arguments
{
self = [super init];
if (self) {
+
+ self.webView = [[[arguments objectForKey:WebPlugInContainerKey] webFrame] webView];
+
self.container = [arguments objectForKey:WebPlugInContainingElementKey];
NSURL *base = [arguments objectForKey:WebPlugInBaseURLKey];
if (base) {
self.host = [base host];
+
+ _sifrVersion = [self _sifrVersionInstalled];
+
+ if( _sifrVersion != 0 )
+ {
+ [self performSelector:@selector(_disableSIFR) withObject:nil afterDelay:0];
+ }
+
if ([self _isHostWhitelisted] && ![self _isOptionPressed]) {
_isLoadingFromWhitelist = YES;
[self performSelector:@selector(_convertTypesForContainer) withObject:nil afterDelay:0];
}
}
if (![NSBundle loadNibNamed:@"ContextualMenu" owner:self])
- NSLog(@"Could not load conextual menu plugin");
+ NSLog(@"Could not load contextual menu plugin");
NSDictionary *attributes = [arguments objectForKey:WebPlugInAttributesKey];
if (attributes != nil) {
@@ -108,6 +130,7 @@ - (void) dealloc
{
self.container = nil;
self.host = nil;
+ self.webView = nil;
[_whitelistWindowController release];
[[NSNotificationCenter defaultCenter] removeObserver: self];
[super dealloc];
@@ -479,6 +502,59 @@ - (void) _convertTypesForContainer
}
+#pragma mark -
+#pragma mark deSIFR methods
+
+- (NSUInteger) _sifrVersionInstalled
+{
+ // get the container's WebView
+ WebView *sifrWebView = self.webView;
+ NSUInteger version = 0;
+
+ if( sifrWebView )
+ {
+ if( [[sifrWebView stringByEvaluatingJavaScriptFromString:sifr2Test] isEqualToString:@"true"] ) // test for sIFR v.2
+ {
+ version = 2;
+ } else if( [[sifrWebView stringByEvaluatingJavaScriptFromString:sifr3Test] isEqualToString:@"true"] ) { // test for sIFR v.3
+ version = 3;
+ }
+ }
+
+ return version;
+}
+
+- (void) _disableSIFR
+{
+ // get the container's WebView
+ WebView *sifrWebView = self.webView;
+
+ // if sifr add-ons are not installed, load version-appropriate version into page
+ if( [[sifrWebView stringByEvaluatingJavaScriptFromString:sifrAddOnTest] isEqualToString:@"true"] )
+ {
+ NSBundle *clickBundle = [NSBundle bundleForClass:[self class]];
+
+ NSString *jsFileName = ( _sifrVersion == 2 ? sifr2AddOnJSFilename : sifr3AddOnJSFilename );
+
+ NSString *addOnPath = [clickBundle pathForResource:jsFileName ofType:@"js"];
+
+ if( addOnPath )
+ {
+ NSString *sifrAddOnJS = [NSString stringWithContentsOfFile:addOnPath];
+
+ if( sifrAddOnJS && !([sifrAddOnJS isEqualToString:@""]) )
+ {
+ [[sifrWebView windowScriptObject] evaluateWebScript:sifrAddOnJS];
+ }
+ }
+ }
+
+ // implement rollback
+ [[sifrWebView windowScriptObject] evaluateWebScript:sifrRollbackJS];
+}
+
+
+@synthesize webView = _webView;
@synthesize container = _container;
@synthesize host = _host;

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -0,0 +1,74 @@
+/* sIFR Unofficial Rollback addon for sIFR 3
+ Modified by Paul Hassinger - hassinger.paul@ipaul.com - http://www.ipaul.com
+ (modified from sIFR 2.0.1 Official Add-ons 1.2)
+
+ Copyright 2005 Mark Wubben
+
+ This software is licensed under the CC-GNU LGPL <http://creativecommons.org/licenses/LGPL/2.1/>
+ */
+
+if(typeof sIFR == "object"){
+ sIFR.rollback = function(){
+ function rollback(sSelector){
+ if(sSelector == null){
+ sSelector = "";
+ } else {
+ sSelector += ">";
+ };
+
+ sIFR.removeFlashClass();
+
+ if(doRollback(sSelector+"embed") == false){
+ doRollback(sSelector+"object");
+ };
+ };
+
+ function doRollback(sSelector){
+ var node, nodeParent, nodeAlternate, nodeAlternateChild, nodeAlternateNextChild, indexNodeToRemove;
+ var listNodes = parseSelector(sSelector);
+ var i = listNodes.length - 1;
+ var bHasRun = false;
+
+ while(i >= 0){
+ node = listNodes[i];
+ listNodes.length--;
+ nodeParent = node.parentNode;
+
+ if(node.className == 'sIFR-flash'){
+ /* Flash blockers may add other nodes as siblings to the Flash element.
+ Thus, we remove all children of nodeParent, and look for nodeAlternate at the same time */
+ indexNodeToRemove = 0;
+
+ while(indexNodeToRemove < nodeParent.childNodes.length){
+ node = nodeParent.childNodes[indexNodeToRemove];
+ if(node.className == "sIFR-alternate"){
+ nodeAlternate = node;
+ indexNodeToRemove++;
+ continue;
+ };
+ nodeParent.removeChild(node);
+ };
+
+ if(nodeAlternate != null){
+ nodeAlternateChild = nodeAlternate.firstChild;
+ while(nodeAlternateChild != null){
+ nodeAlternateNextChild = nodeAlternateChild.nextSibling;
+ nodeParent.appendChild(nodeAlternate.removeChild(nodeAlternateChild));
+ nodeAlternateChild = nodeAlternateNextChild;
+ };
+ nodeParent.removeChild(nodeAlternate);
+ };
+
+ nodeParent.className = nodeParent.className.replace(/\bsIFR\-replaced\b/, "");
+ bHasRun = true;
+ };
+
+ i--;
+ };
+
+ return bHasRun;
+ };
+
+ return rollback;
+ }();
+};

0 comments on commit f768f8a

Please sign in to comment.