Skip to content

Commit

Permalink
[CHANGE] Mutate the existing object/embed DOM node instead of cloning…
Browse files Browse the repository at this point in the history
… it. This fixes previously-broken sites that discover and hold onto the node's reference. (Jonathan del Strother)
  • Loading branch information
rentzsch committed Mar 27, 2009
1 parent bb40241 commit e89c4df
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions Plugin/Plugin.m
Expand Up @@ -51,7 +51,6 @@ - (void) _convertTypesForFlashContainerAfterDelay;
- (void) _convertToMP4Container;
- (void) _convertToMP4ContainerAfterDelay;
- (void) _prepareForConversion;
- (void) _replaceSelfWithElement: (DOMElement*) newElement;

- (void) _drawBackground;
- (BOOL) _isOptionPressed;
Expand Down Expand Up @@ -720,7 +719,13 @@ - (void) _convertToMP4ContainerAfterDelay
DOMElement* newElement = (DOMElement*) [ self.container cloneNode: NO ];

[ self _convertElementForMP4: newElement ];
[ self _replaceSelfWithElement: newElement ];

// Just to be safe, since we are about to replace our containing element
[[self retain] autorelease];

// Replace self with element.
[self.container.parentNode replaceChild:newElement oldChild:self.container];
self.container = nil;
}


Expand Down Expand Up @@ -754,24 +759,27 @@ - (void) _convertTypesForFlashContainer

- (void) _convertTypesForFlashContainerAfterDelay
{
DOMElement *newElement = (DOMElement *)[self.container cloneNode:YES];

DOMNodeList *nodeList = nil;
NSUInteger i;

[self _convertTypesForElement:newElement];
[self _convertTypesForElement:self.container];

nodeList = [newElement getElementsByTagName:@"object"];
nodeList = [self.container getElementsByTagName:@"object"];
for (i = 0; i < nodeList.length; i++) {
[self _convertTypesForElement:(DOMElement *)[nodeList item:i]];
}

nodeList = [newElement getElementsByTagName:@"embed"];
nodeList = [self.container getElementsByTagName:@"embed"];
for (i = 0; i < nodeList.length; i++) {
[self _convertTypesForElement:(DOMElement *)[nodeList item:i]];
}

[self _replaceSelfWithElement: newElement];
// Remove & reinsert the node to persuade the plugin system to notice the type change:
id parent = self.container.parentNode;
id successor = self.container.nextSibling;
[parent removeChild:self.container];
[parent insertBefore:self.container refChild:successor];
self.container = nil;
}

- (void) _prepareForConversion
Expand All @@ -784,15 +792,6 @@ - (void) _prepareForConversion
[ self _abortAlert ];
}

- (void) _replaceSelfWithElement: (DOMElement *)newElement
{
// Just to be safe, since we are about to replace our containing element
[[self retain] autorelease];

[self.container.parentNode replaceChild:newElement oldChild:self.container];
self.container = nil;
}

@synthesize webView = _webView;
@synthesize container = _container;
@synthesize host = _host;
Expand Down

0 comments on commit e89c4df

Please sign in to comment.