Skip to content

Commit

Permalink
Fixed leak that caused all CtF views to not be deallocated by using v…
Browse files Browse the repository at this point in the history
…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 <[email protected]>
  • Loading branch information
Otyr Ugla authored and rentzsch committed Feb 13, 2009
1 parent 9e8b32a commit 912e28f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 36 deletions.
20 changes: 2 additions & 18 deletions Plugin/English.lproj/ContextualMenu.xib
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -151,22 +151,6 @@
</object>
<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>
Expand Down Expand Up @@ -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">
Expand Down
1 change: 0 additions & 1 deletion Plugin/Plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
39 changes: 22 additions & 17 deletions Plugin/Plugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -334,7 +321,6 @@ - (void) dealloc
[super dealloc];
}


- (void) drawRect:(NSRect)rect
{
if(!_isLoadingFromWhitelist)
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 912e28f

Please sign in to comment.