Permalink
Browse files

Fixed leak that caused all CtF views to not be deallocated by using v…

…alidateMenuItem to update the Add <site> to Whitelist menu item instead of a binding. Also moved the context menu loading code into menuForEvent so we don't pay the cost of loading that NSMenu for every view even if it is never needed.

Signed-off-by: Jonathan 'Wolf' Rentzsch <jwr.git@redshed.net>
  • Loading branch information...
1 parent 9e8b32a commit 912e28f5befe90db92be971d5899de5cbd3b6a89 Otyr Ugla committed with Feb 13, 2009
Showing with 24 additions and 36 deletions.
  1. +2 −18 Plugin/English.lproj/ContextualMenu.xib
  2. +0 −1 Plugin/Plugin.h
  3. +22 −17 Plugin/Plugin.m
@@ -8,7 +8,7 @@
<string key="IBDocument.HIToolboxVersion">353.00</string>
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
<bool key="EncodedWithXMLCoder">YES</bool>
- <integer value="21"/>
+ <integer value="14"/>
</object>
<object class="NSArray" key="IBDocument.PluginDependencies">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -152,22 +152,6 @@
<int key="connectionID">15</int>
</object>
<object class="IBConnectionRecord">
- <object class="IBBindingConnection" key="connection">
- <string key="label">title: self.addToWhiteListMenuTitle</string>
- <reference key="source" ref="1001518375"/>
- <reference key="destination" ref="1001"/>
- <object class="NSNibBindingConnector" key="connector">
- <reference key="NSSource" ref="1001518375"/>
- <reference key="NSDestination" ref="1001"/>
- <string key="NSLabel">title: self.addToWhiteListMenuTitle</string>
- <string key="NSBinding">title</string>
- <string key="NSKeyPath">self.addToWhiteListMenuTitle</string>
- <int key="NSNibBindingConnectorVersion">2</int>
- </object>
- </object>
- <int key="connectionID">18</int>
- </object>
- <object class="IBConnectionRecord">
<object class="IBActionConnection" key="connection">
<string key="label">loadAllOnPage:</string>
<reference key="source" ref="1001"/>
@@ -310,7 +294,7 @@
</object>
</object>
<nil key="sourceID"/>
- <int key="maxID">22</int>
+ <int key="maxID">23</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
View
@@ -51,7 +51,6 @@ THE SOFTWARE.
@property (nonatomic, retain) DOMElement *container;
@property (nonatomic, retain) NSString *host;
@property (nonatomic, retain) WebView *webView;
-@property (readonly, nonatomic, retain) NSString *addToWhiteListMenuTitle;
@property (retain) NSString *baseURL;
- (IBAction)addToWhitelist:(id)sender;
View
@@ -242,19 +242,6 @@ - (id) initWithArguments:(NSDictionary *)arguments
[self performSelector:@selector(_convertTypesForContainer) withObject:nil afterDelay:0];
}
- // Set up contextual menu
-
- if (![NSBundle loadNibNamed:@"ContextualMenu" owner:self])
- NSLog(@"Could not load contextual menu plugin");
- // NOTE [tgaul]: we could save memory by not loading the context menu until it was
- // needed by overriding menuForEvent and returning it there.
-
- if ([self _hasH264Version]) {
- [[self menu] insertItemWithTitle: NSLocalizedString( @"Load H.264", "Load H.264 context menu item" )
- action: @selector( loadH264: ) keyEquivalent: @"" atIndex: 1];
- [[[self menu] itemAtIndex: 1] setTarget: self];
- }
-
// Set up main menus
[ CTFMenubarMenuController sharedController ]; // trigger the menu items to be added
@@ -334,7 +321,6 @@ - (void) dealloc
[super dealloc];
}
-
- (void) drawRect:(NSRect)rect
{
if(!_isLoadingFromWhitelist)
@@ -488,17 +474,36 @@ - (BOOL) isConsideredInvisible
#pragma mark -
#pragma mark Contextual menu
-- (NSString*) addToWhiteListMenuTitle
+- (NSMenu*) menuForEvent: (NSEvent*) event
{
- return [NSString stringWithFormat:NSLocalizedString(@"Add %@ to Whitelist", @"Add <sitename> to Whitelist menu title"), self.host];
+ // Set up contextual menu
+
+ if( ![ self menu ] ) {
+ if (![NSBundle loadNibNamed:@"ContextualMenu" owner:self]) {
+ NSLog(@"Could not load contextual menu plugin");
+ }
+ else {
+ if ([self _hasH264Version]) {
+ [[self menu] insertItemWithTitle: NSLocalizedString( @"Load H.264", "Load H.264 context menu item" )
+ action: @selector( loadH264: ) keyEquivalent: @"" atIndex: 1];
+ [[[self menu] itemAtIndex: 1] setTarget: self];
+ }
+ }
+ }
+
+ return [self menu];
}
-- (BOOL)validateMenuItem:(NSMenuItem *)menuItem
+- (BOOL) validateMenuItem: (NSMenuItem *)menuItem
{
BOOL enabled = YES;
SEL action = [menuItem action];
if (action == @selector(addToWhitelist:))
{
+ NSString* title = [NSString stringWithFormat:
+ NSLocalizedString(@"Add %@ to Whitelist", @"Add <sitename> to Whitelist menu title"),
+ self.host];
+ [menuItem setTitle: title];
if ([self _isHostWhitelisted])
enabled = NO;
}

0 comments on commit 912e28f

Please sign in to comment.