diff --git a/allmakefiles.sh b/allmakefiles.sh index 95d61f3e645..b73147ea7cf 100755 --- a/allmakefiles.sh +++ b/allmakefiles.sh @@ -1096,6 +1096,7 @@ calendar/sunbird/base/Makefile MAKEFILES_macbrowser=" camino/Makefile +camino/flashblock/Makefile camino/installer/Makefile " diff --git a/camino/Camino.xcode/project.pbxproj b/camino/Camino.xcode/project.pbxproj index 1e739aaec0d..f00318ad2a9 100644 --- a/camino/Camino.xcode/project.pbxproj +++ b/camino/Camino.xcode/project.pbxproj @@ -6564,6 +6564,7 @@ dstSubfolderSpec = 6; files = ( 3F44AD5805BDFB9F00CB4B08, + 3F44AD5805BDFB9F00CB4B18, 3F44AD5905BDFB9F00CB4B08, ); isa = PBXCopyFilesBuildPhase; @@ -6575,6 +6576,12 @@ settings = { }; }; + 3F44AD5805BDFB9F00CB4B18 = { + fileRef = F6BD650001B3184301A96307; + isa = PBXBuildFile; + settings = { + }; + }; 3F44AD5905BDFB9F00CB4B08 = { fileRef = F5DA444A027DD5AA01A80166; isa = PBXBuildFile; @@ -10294,6 +10301,7 @@ dstSubfolderSpec = 6; files = ( 3F44AF7305BDFBA000CB4B08, + 3F44AF7305BDFBA000CB4B18, 3F44AF7405BDFBA000CB4B08, ); isa = PBXCopyFilesBuildPhase; @@ -10305,6 +10313,12 @@ settings = { }; }; + 3F44AF7305BDFBA000CB4B18 = { + fileRef = F6BD650001B3184301A96307; + isa = PBXBuildFile; + settings = { + }; + }; 3F44AF7405BDFBA000CB4B08 = { fileRef = F5DA444A027DD5AA01A80166; isa = PBXBuildFile; @@ -18744,6 +18758,7 @@ F6BD64FF01B3184301A962F7 = { children = ( F6BD650001B3184301A962F7, + F6BD650001B3184301A96307, F54EF7ED022A2F9C01A80165, F5DA444A027DD5AA01A80166, ); @@ -18760,6 +18775,14 @@ refType = 2; sourceTree = SOURCE_ROOT; }; + F6BD650001B3184301A96307 = { + isa = PBXFileReference; + lastKnownFileType = archive.jar; + name = flashblock.jar; + path = ../dist/Embed/chrome/flashblock.jar; + refType = 2; + sourceTree = SOURCE_ROOT; + }; }; rootObject = 29B97313FDCFA39411CA2CEA; } diff --git a/camino/Makefile.in b/camino/Makefile.in index fbd8f8e3a6b..916bc4a9f72 100644 --- a/camino/Makefile.in +++ b/camino/Makefile.in @@ -44,6 +44,7 @@ include $(DEPTH)/config/autoconf.mk DIRS = \ IBPalette \ + flashblock \ $(NULL) APP_NAME = Camino diff --git a/camino/PreferencePanes/WebFeatures/English.lproj/WebFeatures.nib/classes.nib b/camino/PreferencePanes/WebFeatures/English.lproj/WebFeatures.nib/classes.nib index ffa24d175df..cb1d067a43c 100644 --- a/camino/PreferencePanes/WebFeatures/English.lproj/WebFeatures.nib/classes.nib +++ b/camino/PreferencePanes/WebFeatures/English.lproj/WebFeatures.nib/classes.nib @@ -18,6 +18,7 @@ addWhitelistSite = id; clickEnableAdBlocking = id; clickEnableAnnoyanceBlocker = id; + clickEnableFlashBlock = id; clickEnableImageResizing = id; clickEnableJS = id; clickEnableJava = id; @@ -37,6 +38,7 @@ mEditWhitelist = NSButton; mEnableAdBlocking = NSButton; mEnableAnnoyanceBlocker = NSButton; + mEnableFlashBlock = NSButton; mEnableJS = NSButton; mEnableJava = NSButton; mEnablePlugins = NSButton; diff --git a/camino/PreferencePanes/WebFeatures/English.lproj/WebFeatures.nib/info.nib b/camino/PreferencePanes/WebFeatures/English.lproj/WebFeatures.nib/info.nib index aa5233133ae..75c61fd4cfd 100644 --- a/camino/PreferencePanes/WebFeatures/English.lproj/WebFeatures.nib/info.nib +++ b/camino/PreferencePanes/WebFeatures/English.lproj/WebFeatures.nib/info.nib @@ -3,17 +3,13 @@ IBDocumentLocation - 2 4 356 240 0 0 1024 746 + 5 7 356 240 0 0 1920 1178 IBFramework Version 446.1 IBOldestOS 2 - IBOpenObjects - - 5 - IBSystem Version - 8J135 + 8L127 IBUserGuides 312 @@ -25,6 +21,16 @@ guidesLocked + 5 + + guideLocations + + Vertical:297.000000 + Vertical:297.000000 + + guidesLocked + + diff --git a/camino/PreferencePanes/WebFeatures/English.lproj/WebFeatures.nib/keyedobjects.nib b/camino/PreferencePanes/WebFeatures/English.lproj/WebFeatures.nib/keyedobjects.nib index 5761d16818a..d92e359bfd2 100644 Binary files a/camino/PreferencePanes/WebFeatures/English.lproj/WebFeatures.nib/keyedobjects.nib and b/camino/PreferencePanes/WebFeatures/English.lproj/WebFeatures.nib/keyedobjects.nib differ diff --git a/camino/PreferencePanes/WebFeatures/WebFeatures.h b/camino/PreferencePanes/WebFeatures/WebFeatures.h index 64eebb567c6..1e9eeac9adc 100644 --- a/camino/PreferencePanes/WebFeatures/WebFeatures.h +++ b/camino/PreferencePanes/WebFeatures/WebFeatures.h @@ -58,6 +58,7 @@ class nsISupportsArray; IBOutlet NSButton *mImageResize; IBOutlet NSButton *mPreventAnimation; IBOutlet NSButton *mEditWhitelist; + IBOutlet NSButton *mEnableFlashBlock; IBOutlet id mWhitelistPanel; IBOutlet ExtendedTableView* mWhitelistTable; @@ -82,6 +83,7 @@ class nsISupportsArray; -(IBAction) clickEnableImageResizing:(id)sender; -(IBAction) clickPreventAnimation:(id)sender; -(IBAction) editWhitelist:(id)sender; +-(IBAction) clickEnableFlashBlock:(id)sender; -(IBAction) clickEnableAnnoyanceBlocker:(id)sender; -(void) setAnnoyingWindowPrefsTo:(BOOL)inValue; diff --git a/camino/PreferencePanes/WebFeatures/WebFeatures.mm b/camino/PreferencePanes/WebFeatures/WebFeatures.mm index a869cc56d95..893f1de6900 100644 --- a/camino/PreferencePanes/WebFeatures/WebFeatures.mm +++ b/camino/PreferencePanes/WebFeatures/WebFeatures.mm @@ -56,8 +56,9 @@ // but that requires linkage and extra search paths. static NSString* XPCOMShutDownNotificationName = @"XPCOMShutDown"; -// needs to match the string in PreferenceManager.mm +// need to match the strings in PreferenceManager.mm static NSString* const AdBlockingChangedNotificationName = @"AdBlockingChanged"; +static NSString* const kFlashBlockChangedNotificationName = @"FlashBlockChanged"; // for camino.enable_plugins; needs to match string in BrowserWrapper.mm static NSString* const kEnablePluginsChangedNotificationName = @"EnablePluginsChanged"; @@ -76,6 +77,8 @@ const int kAnnoyancePrefSome = 3; -(NSString*)profilePath; - (int)annoyingWindowPrefs; - (int)preventAnimationCheckboxState; +- (BOOL)isFlashBlockAllowed; +- (void)updateFlashBlock; @end @@ -144,6 +147,15 @@ const int kAnnoyancePrefSome = 3; BOOL enableAdBlock = [self getBooleanPref:"camino.enable_ad_blocking" withSuccess:&gotPref]; [mEnableAdBlocking setState:enableAdBlock]; + // Only allow FlashBlock if dependencies are set correctly + BOOL flashBlockAllowed = [self isFlashBlockAllowed]; + [mEnableFlashBlock setEnabled:flashBlockAllowed]; + + if (flashBlockAllowed) { + BOOL enableFlashBlock = [self getBooleanPref:"camino.enable_flashblock" withSuccess:nil]; + [mEnableFlashBlock setState:(enableFlashBlock ? NSOnState : NSOffState)]; + } + // Set inital values for tabfocus pref. Internally, it's a bitwise additive pref: // bit 0 adds focus for text fields (not exposed in the UI, so not given a constant) // bit 1 adds focus for other form elements (kFocusForms) @@ -167,6 +179,9 @@ const int kAnnoyancePrefSome = 3; -(IBAction) clickEnableJS:(id)sender { [self setPref:"javascript.enabled" toBoolean:([sender state] == NSOnState)]; + + // FlashBlock depends on Javascript so make sure to update the FlashBlock settings + [self updateFlashBlock]; } // @@ -188,6 +203,9 @@ const int kAnnoyancePrefSome = 3; { [self setPref:"camino.enable_plugins" toBoolean:([sender state] == NSOnState)]; [[NSNotificationCenter defaultCenter] postNotificationName:kEnablePluginsChangedNotificationName object:nil]; + + // FlashBlock depends on plug-ins so make sure to update the FlashBlock settings + [self updateFlashBlock]; } // @@ -235,6 +253,18 @@ const int kAnnoyancePrefSome = 3; [self setPref:"image.animation_mode" toString:([sender state] ? @"once" : @"normal")]; } +// +// clickEnableFlashBlock: +// +// Enable and disable FlashBlock. When enabled, an icon is displayed and the +// Flash animation plays when the user clicks it. When disabled, Flash plays automatically +// +-(IBAction) clickEnableFlashBlock:(id)sender +{ + [self setPref:"camino.enable_flashblock" toBoolean:([sender state] == NSOnState)]; + [[NSNotificationCenter defaultCenter] postNotificationName:kFlashBlockChangedNotificationName object:nil]; +} + // // populatePermissionCache: // @@ -501,4 +531,43 @@ const int kAnnoyancePrefSome = 3; return [NSString stringWithUTF8String:nativePath.get()]; } +// +// isFlashBlockAllowed +// +// Checks whether FlashBlock can be enabled +// FlashBlock only allowed if javascript and plug-ins enabled +// NOTE: This code is duplicated in PreferenceManager.mm since the FlashBlock checkbox +// settings are done by WebFeatures and stylesheet loading is done by PreferenceManager +// +-(BOOL) isFlashBlockAllowed +{ + BOOL gotPref = NO; + BOOL jsEnabled = [self getBooleanPref:"javascript.enabled" withSuccess:&gotPref] && gotPref; + BOOL pluginsEnabled = [self getBooleanPref:"camino.enable_plugins" withSuccess:&gotPref] || !gotPref; + + return jsEnabled && pluginsEnabled; +} + +// +// updateFlashBlock +// +// Update the state of the FlashBlock checkbox +// +-(void) updateFlashBlock +{ + BOOL allowed = [self isFlashBlockAllowed]; + [mEnableFlashBlock setEnabled:allowed]; + + // FlashBlock state can only change if it's already enabled + // since changing dependencies won't have affect on disabled FlashBlock + if (![self getBooleanPref:"camino.enable_flashblock" withSuccess:nil]) + return; + + // FlashBlock preference is enabled. Checkbox is on if FlashBlock also allowed + [mEnableFlashBlock setState:(allowed ? NSOnState : NSOffState)]; + + // Always send a notification, dependency verification is done by receiver. + [[NSNotificationCenter defaultCenter] postNotificationName:kFlashBlockChangedNotificationName object:nil]; +} + @end diff --git a/camino/flashblock/Makefile.in b/camino/flashblock/Makefile.in new file mode 100644 index 00000000000..7e8247772ea --- /dev/null +++ b/camino/flashblock/Makefile.in @@ -0,0 +1,63 @@ +# ***** BEGIN LICENSE BLOCK ***** +# Version: MPL 1.1/GPL 2.0/LGPL 2.1 +# +# The contents of this file are subject to the Mozilla Public License Version +# 1.1 (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License +# for the specific language governing rights and limitations under the +# License. +# +# The Original Code is just a lowly Makefile. +# +# The Initial Developer of the Original Code is Google Inc. +# Portions created by the Initial Developer are Copyright (C) 2007 +# the Initial Developer. All Rights Reserved. +# +# Contributor(s): +# Mark Mentovai (Original Author) +# +# Alternatively, the contents of this file may be used under the terms of +# either the GNU General Public License Version 2 or later (the "GPL"), or +# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), +# in which case the provisions of the GPL or the LGPL are applicable instead +# of those above. If you wish to allow use of your version of this file only +# under the terms of either the GPL or the LGPL, and not to allow others to +# use your version of this file under the terms of the MPL, indicate your +# decision by deleting the provisions above and replace them with the notice +# and other provisions required by the GPL or the LGPL. If you do not delete +# the provisions above, a recipient may use your version of this file under +# the terms of any one of the MPL, the GPL or the LGPL. +# +# ***** END LICENSE BLOCK ***** + +DEPTH = ../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +include $(topsrcdir)/config/rules.mk + +# The presence of jar.mn causes $(SOURCE_CHROME_DIR)/$(JAR_FILE).jar to be +# built and $(SOURCE_CHROME_DIR)/installed-chrome.txt to be updated. Camino +# uses $(TARGET_CHROME_DIR)/installed-chrome.txt instead, though, so copy +# the jar and update the correct installed-chrome.txt file. + +SOURCE_CHROME_DIR = $(DIST)/bin/chrome +TARGET_CHROME_DIR = $(DIST)/Embed/chrome +INSTALLED_CHROME = $(TARGET_CHROME_DIR)/installed-chrome.txt +CHROME_TYPE = content +CHROME_PKG_NAME = flashblock +JAR_FILE = $(CHROME_PKG_NAME) + +libs realchrome:: $(CHROME_DEPS) + chmod a-x $(INSTALLED_CHROME) + $(NSINSTALL) -t -m 0644 \ + $(SOURCE_CHROME_DIR)/$(JAR_FILE).jar $(TARGET_CHROME_DIR) + $(PERL) -I$(MOZILLA_DIR)/config $(MOZILLA_DIR)/config/add-chrome.pl \ + $(INSTALLED_CHROME) 0 $(CHROME_TYPE) $(CHROME_PKG_NAME) $(JAR_FILE) diff --git a/camino/flashblock/README b/camino/flashblock/README new file mode 100644 index 00000000000..3742f6fcf74 --- /dev/null +++ b/camino/flashblock/README @@ -0,0 +1,10 @@ +Flash blocking for Camino is implemented using the FlashBlock extension +from http://flashblock.mozdev.org/. FlashBlock is available under the +MPL/GPL/LGPL tri-license. The files necessary for operation in Camino +are placed in the content directory and referenced by the jar.mn +manifest. A contents.rdf file is included to allow Camino to identify +the contents of flashblock.jar. + +Camino's bundled FlashBlock extension is currently synchronized with +FlashBlock 1.5.2 from +http://downloads.mozdev.org/flashblock/flashblock-1.5.2.xpi. diff --git a/camino/flashblock/content/authorware.png b/camino/flashblock/content/authorware.png new file mode 100644 index 00000000000..fd562961256 Binary files /dev/null and b/camino/flashblock/content/authorware.png differ diff --git a/camino/flashblock/content/contents.rdf b/camino/flashblock/content/contents.rdf new file mode 100644 index 00000000000..97362a95a34 --- /dev/null +++ b/camino/flashblock/content/contents.rdf @@ -0,0 +1,18 @@ + + + + + + + + + + + + diff --git a/camino/flashblock/content/director.png b/camino/flashblock/content/director.png new file mode 100644 index 00000000000..4da6cf9545e Binary files /dev/null and b/camino/flashblock/content/director.png differ diff --git a/camino/flashblock/content/flash.png b/camino/flashblock/content/flash.png new file mode 100644 index 00000000000..61dc080dad1 Binary files /dev/null and b/camino/flashblock/content/flash.png differ diff --git a/camino/flashblock/content/flashblock.css b/camino/flashblock/content/flashblock.css new file mode 100644 index 00000000000..b31820a316e --- /dev/null +++ b/camino/flashblock/content/flashblock.css @@ -0,0 +1,79 @@ +/* + * Flash Click to View by Ted Mielczarek (luser_mozilla@perilith.com) + * Original code by Jesse Ruderman (jruderman@hmc.edu) + * taken from http://www.squarefree.com/userstyles/xbl.html + * + * Change XBL binding for tags, click to view flash + */ + +/* + * Flash identifiers. +*/ +object[classid*=":D27CDB6E-AE6D-11cf-96B8-444553540000"], +object[codebase*="swflash.cab"], +object[data*=".swf"], +embed[type="application/x-shockwave-flash"], +embed[src*=".swf"], +object[type="application/x-shockwave-flash"], +object[src*=".swf"] +{ -moz-binding: url("chrome://flashblock/content/flashblock.xml#flash") !important; } + +/* + * Director identifiers. +*/ +object[classid*=":166B1BCA-3F9C-11CF-8075-444553540000"], +object[codebase*="sw.cab"], +object[data*=".dcr"], +embed[type="application/x-director"], +embed[src*=".dcr"], +object[type="application/x-director"], +object[src*=".dcr"] +{ -moz-binding: url("chrome://flashblock/content/flashblock.xml#director") !important; } + +/* + * Authorware identifiers. +*/ +object[classid*=":15B782AF-55D8-11D1-B477-006097098764"], +object[codebase*="awswaxf.cab"], +object[data*=".aam"], +embed[type="application/x-authorware-map"], +embed[src*=".aam"], +object[type="application/x-authorware-map"], +object[src*=".aam"] +{ -moz-binding: url("chrome://flashblock/content/flashblock.xml#authorware") !important; } + +/* + * Broken Objects. +*/ +object +{ -moz-binding: url("chrome://flashblock/content/flashblock.xml#brokenobject") !important; } + +/* +* Java identifiers. +*/ +/* +applet, +object[classid*=":8AD9C840-044E-11D1-B3E9-00805F499D93"], +object[classid^="clsid:CAFEEFAC-"], +object[classid^="java:"], +object[type="application/x-java-applet"], +embed[classid*=":8AD9C840-044E-11D1-B3E9-00805F499D93"], +embed[classid^="clsid:CAFEEFAC-"], +embed[classid^="java:"], +embed[type="application/x-java-applet"] +{ + -moz-binding: none !important; +} +*/ + +/* sIFR styles */ +.sIFR-flash, .sIFR-flash object, .sIFR-flash embed, +.sIFR-replaced div[style*="chrome://flashblock"] { + -moz-binding: url("chrome://flashblock/content/flashblock.xml#sifr-replaced") !important; +} + +span.sIFR-alternate { + -moz-binding: url("chrome://flashblock/content/flashblock.xml#sifr-alternate") !important; + position: static !important; + letter-spacing: normal !important; +} diff --git a/camino/flashblock/content/flashblock.xml b/camino/flashblock/content/flashblock.xml new file mode 100644 index 00000000000..f4bb663d88f --- /dev/null +++ b/camino/flashblock/content/flashblock.xml @@ -0,0 +1,267 @@ + + + + + + + + = 32) { + placeholder.style.width = width + "px"; + } + } + + if(flash.height.match("%$")) { + placeholder.style.height = flash.height; + } else { + var height = parseInt(flash.height || flash.style.height); + if (height && height >= 32) { + placeholder.style.height = height + "px"; + } + } + + // Add styling rules to placeholder div. + placeholder.style.background = placeholder.bgInactive; + placeholder.style.border = "1px solid #dfdfdf"; + placeholder.style.cursor = "pointer"; + placeholder.style.overflow = "hidden"; + + // The size of the placeholder should include borders too, + // otherwise scrollbars appear for blocked standalone objects + placeholder.style.MozBoxSizing = "border-box"; +} + +var current = this; +var parent = current.parentNode; + +if(flashblockIsWhitelisted()) + return; + +// Check parent too (case of working EMBED inside broken OBJECT) +if (current.overrideCTV || parent.overrideCTV) { + return; +} +current.overrideCTV = true; + +if (this.brokenObject) { + var params = this.getElementsByTagName("param"); + var isFlash = false; + for (var ii = 0; ii < params.length; ii++) { + var pvalue = params[ii].getAttribute("value"); + if (/\.swf/i.test(pvalue)) { + isFlash = true; + break; + } + } + var embeds = this.getElementsByTagName("embed"); + for (var jj = 0; jj < embeds.length; jj++) { + var embed = embeds[jj]; + if (/x-shockwave-flash/i.test(embed.getAttribute("type")) || + /\.swf/i.test(embed.getAttribute("src"))) { + isFlash = true; + break; + } + } + if (!isFlash) {return;} +} + +// Create placeholder div +var isStandalone = ("src" in current && current.src == current.ownerDocument.location); +var placeholder = flashblockCreatePlaceholder(isStandalone); + +// Set placeholder image +var type = this.flashblockType ? this.flashblockType : "flash" +flashblockSetImage(placeholder, type); + +flashblockStylePlaceholder(current, placeholder); + +// Change the placeholder background when the mouse enters/exits the div. +placeholder.onmouseover = function() +{ + this.style.background = this.bgActive; +} + +placeholder.onmouseout = function() +{ + this.style.background = this.bgInactive; +} + +// Replace the flash document with a placeholder. +var flashblockSetTimeout = nativeMethod(window, "setTimeout"); +flashblockSetTimeout(flashblockShowPlaceholder, 0); + +// Replace the placeholder with the flash document. +placeholder.onclick = flashblockShowFlash; + + ]]> + + + + + + + "director" + + + + + + "authorware" + + + + + + "yes" + + + + + + + + + + + + + + + + + + + + diff --git a/camino/flashblock/content/flashplay.png b/camino/flashblock/content/flashplay.png new file mode 100644 index 00000000000..b9ffb40423c Binary files /dev/null and b/camino/flashblock/content/flashplay.png differ diff --git a/camino/flashblock/jar.mn b/camino/flashblock/jar.mn new file mode 100644 index 00000000000..8744d2f66d4 --- /dev/null +++ b/camino/flashblock/jar.mn @@ -0,0 +1,8 @@ +flashblock.jar: + content/flashblock/contents.rdf (content/contents.rdf) + content/flashblock/flashblock.xml (content/flashblock.xml) + content/flashblock/flashblock.css (content/flashblock.css) + content/flashblock/authorware.png (content/authorware.png) + content/flashblock/director.png (content/director.png) + content/flashblock/flash.png (content/flash.png) + content/flashblock/flashplay.png (content/flashplay.png) diff --git a/camino/src/preferences/PreferenceManager.mm b/camino/src/preferences/PreferenceManager.mm index acc8fc6ff00..de2654fc33e 100644 --- a/camino/src/preferences/PreferenceManager.mm +++ b/camino/src/preferences/PreferenceManager.mm @@ -78,6 +78,7 @@ NSString* const kPrefChangedPrefNameUserInfoKey = @"pref_name"; static NSString* const AdBlockingChangedNotificationName = @"AdBlockingChanged"; +static NSString* const kFlashBlockChangedNotificationName = @"FlashBlockChanged"; #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_4 // These are supposedly not available before the 10.4 SDK, but some of the @@ -223,6 +224,9 @@ WriteVersion(nsIFile* aProfileDir, const nsACString& aVersion, - (BOOL)cleanupUserContentCSS; - (void)refreshAdBlockingStyleSheet:(BOOL)inLoad; +- (void)refreshFlashBlockStyleSheet:(BOOL)inLoad; +- (void)refreshStyleSheet:(nsIURI *)cssFileURI load:(BOOL)inLoad; +- (BOOL)isFlashBlockAllowed; @end @@ -437,6 +441,10 @@ static BOOL gMadePrefManager; name:AdBlockingChangedNotificationName object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(flashBlockPrefChanged:) + name:kFlashBlockChangedNotificationName + object:nil]; } - (void)savePrefsFile @@ -827,6 +835,11 @@ static BOOL gMadePrefManager; if (enableAdBlocking) [self refreshAdBlockingStyleSheet:YES]; + + // Load flashblock if enabled. Make sure to test dependencies to avoid conflicts + BOOL flashBlockAllowed = [self isFlashBlockAllowed]; + if (flashBlockAllowed && [self getBooleanPref:"camino.enable_flashblock" withSuccess:nil]) + [self refreshFlashBlockStyleSheet:YES]; } #pragma mark - @@ -997,6 +1010,14 @@ typedef enum EProxyConfig { [self refreshAdBlockingStyleSheet:adBlockingEnabled]; } +- (void)flashBlockPrefChanged:(NSNotification*)inNotification +{ + BOOL allowed = [self isFlashBlockAllowed]; + + BOOL flashBlockEnabled = allowed && [self getBooleanPref:"camino.enable_flashblock" withSuccess:nil]; + [self refreshFlashBlockStyleSheet:flashBlockEnabled]; +} + // some versions of 0.9a copied ad_blocking.css into /chrome/userContent.css. // now that we load ad_blocking.css dynamically, we have to move that file aside to // avoid loading it. @@ -1024,10 +1045,6 @@ typedef enum EProxyConfig { // param is NO - (void)refreshAdBlockingStyleSheet:(BOOL)inLoad { - nsCOMPtr ssService = do_GetService("@mozilla.org/content/style-sheet-service;1"); - if (!ssService) - return; - // the the uri of the sheet in our bundle NSString* cssFilePath = [[NSBundle mainBundle] pathForResource:@"ad_blocking" ofType:@"css"]; if (![[NSFileManager defaultManager] isReadableFileAtPath:cssFilePath]) { @@ -1046,8 +1063,30 @@ typedef enum EProxyConfig { if (NS_FAILED(rv)) return; + [self refreshStyleSheet:cssFileURI load:inLoad]; +} + +// this will reload the flashblock sheet if it's already registered, or unload it if the +// param is NO +- (void)refreshFlashBlockStyleSheet:(BOOL)inLoad +{ + // the the uri of the flashblock sheet in the chrome path + nsCOMPtr cssFileURI; + nsresult rv = NS_NewURI(getter_AddRefs(cssFileURI), "chrome://flashblock/content/flashblock.css"); + if (NS_FAILED(rv)) + return; + + [self refreshStyleSheet:cssFileURI load:inLoad]; +} + +- (void)refreshStyleSheet:(nsIURI *)cssFileURI load:(BOOL)inLoad +{ + nsCOMPtr ssService = do_GetService("@mozilla.org/content/style-sheet-service;1"); + if (!ssService) + return; + PRBool alreadyRegistered = PR_FALSE; - rv = ssService->SheetRegistered(cssFileURI, nsIStyleSheetService::USER_SHEET, &alreadyRegistered); + ssService->SheetRegistered(cssFileURI, nsIStyleSheetService::USER_SHEET, &alreadyRegistered); if (alreadyRegistered) ssService->UnregisterSheet(cssFileURI, nsIStyleSheetService::USER_SHEET); @@ -1338,4 +1377,21 @@ typedef enum EProxyConfig { [existingObservers removeObjectIdenticalTo:prefObserverOwner]; // this should release it and unregister the observer } +// +// isFlashBlockAllowed +// +// Checks whether FlashBlock can be enabled +// FlashBlock only allowed if javascript and plug-ins enabled +// NOTE: This code is duplicated in WebFeatures.mm since the FlashBlock checkbox +// settings are done by WebFeatures and stylesheet loading is done by PreferenceManager +// +-(BOOL) isFlashBlockAllowed +{ + BOOL gotPref = NO; + BOOL jsEnabled = [self getBooleanPref:"javascript.enabled" withSuccess:&gotPref] && gotPref; + BOOL pluginsEnabled = [self getBooleanPref:"camino.enable_plugins" withSuccess:&gotPref] || !gotPref; + + return jsEnabled && pluginsEnabled; +} + @end