Index: Source/core/editing/ReplaceSelectionCommand.cpp |
diff --git a/Source/core/editing/ReplaceSelectionCommand.cpp b/Source/core/editing/ReplaceSelectionCommand.cpp |
index 3dcd36b7ecd71fdcb15db53f867c9264f6afedd1..57bc4417769adea40ab5b8dd39d7df2bde2c2cad 100644 |
--- a/Source/core/editing/ReplaceSelectionCommand.cpp |
+++ b/Source/core/editing/ReplaceSelectionCommand.cpp |
@@ -990,17 +990,17 @@ void ReplaceSelectionCommand::doApply() |
if (endBR) |
originalVisPosBeforeEndBR = VisiblePosition(positionBeforeNode(endBR), DOWNSTREAM).previous(); |
- startBlock = enclosingBlock(insertionPos.deprecatedNode()); |
+ RefPtr<Node> insertionBlock = enclosingBlock(insertionPos.deprecatedNode()); |
// Adjust insertionPos to prevent nesting. |
// If the start was in a Mail blockquote, we will have already handled adjusting insertionPos above. |
- if (m_preventNesting && startBlock && !isTableCell(startBlock) && !startIsInsideMailBlockquote) { |
- ASSERT(startBlock != currentRoot); |
+ if (m_preventNesting && insertionBlock && !isTableCell(insertionBlock.get()) && !startIsInsideMailBlockquote) { |
+ ASSERT(insertionBlock != currentRoot); |
VisiblePosition visibleInsertionPos(insertionPos); |
if (isEndOfBlock(visibleInsertionPos) && !(isStartOfBlock(visibleInsertionPos) && fragment.hasInterchangeNewlineAtEnd())) |
- insertionPos = positionInParentAfterNode(startBlock); |
+ insertionPos = positionInParentAfterNode(insertionBlock.get()); |
else if (isStartOfBlock(visibleInsertionPos)) |
- insertionPos = positionInParentBeforeNode(startBlock); |
+ insertionPos = positionInParentBeforeNode(insertionBlock.get()); |
} |
// Paste at start or end of link goes outside of link. |
@@ -1110,11 +1110,16 @@ void ReplaceSelectionCommand::doApply() |
if (!insertedNodes.firstNodeInserted() || !insertedNodes.firstNodeInserted()->inDocument()) |
return; |
+ // Scripts specified in javascript protocol may remove |insertionBlock| |
+ // during insertion, e.g. <iframe src="javascript:..."> |
+ if (insertionBlock && !insertionBlock->inDocument()) |
+ insertionBlock = 0; |
+ |
VisiblePosition startOfInsertedContent = firstPositionInOrBeforeNode(insertedNodes.firstNodeInserted()); |
- // We inserted before the startBlock to prevent nesting, and the content before the startBlock wasn't in its own block and |
+ // We inserted before the insertionBlock to prevent nesting, and the content before the insertionBlock wasn't in its own block and |
// didn't have a br after it, so the inserted content ended up in the same paragraph. |
- if (startBlock && insertionPos.deprecatedNode() == startBlock->parentNode() && (unsigned)insertionPos.deprecatedEditingOffset() < startBlock->nodeIndex() && !isStartOfParagraph(startOfInsertedContent)) |
+ if (insertionBlock && insertionPos.deprecatedNode() == insertionBlock->parentNode() && (unsigned)insertionPos.deprecatedEditingOffset() < insertionBlock->nodeIndex() && !isStartOfParagraph(startOfInsertedContent)) |
insertNodeAt(createBreakElement(document()).get(), startOfInsertedContent.deepEquivalent()); |
if (endBR && (plainTextFragment || shouldRemoveEndBR(endBR, originalVisPosBeforeEndBR))) { |