Index: Source/core/page/DragController.cpp |
diff --git a/Source/core/page/DragController.cpp b/Source/core/page/DragController.cpp |
index 0603715e990d4d7606896b0a495ec5112beec97c..28468bb59c357c1362f389a6dc9356f09ecb2706 100644 |
--- a/Source/core/page/DragController.cpp |
+++ b/Source/core/page/DragController.cpp |
@@ -47,6 +47,7 @@ |
#include "core/events/TextEvent.h" |
#include "core/fetch/ImageResource.h" |
#include "core/fetch/ResourceFetcher.h" |
+#include "core/frame/FrameProtector.h" |
#include "core/frame/FrameView.h" |
#include "core/frame/LocalFrame.h" |
#include "core/html/HTMLAnchorElement.h" |
@@ -215,7 +216,8 @@ void DragController::dragExited(DragData* dragData) |
ASSERT(dragData); |
LocalFrame* mainFrame = m_page->deprecatedLocalMainFrame(); |
- if (RefPtr<FrameView> v = mainFrame->view()) { |
+ if (FrameView* v = mainFrame->view()) { |
+ FrameViewProtector protect(v); |
DataTransferAccessPolicy policy = (!m_documentUnderMouse || m_documentUnderMouse->securityOrigin()->isLocal()) ? DataTransferReadable : DataTransferTypesReadable; |
RefPtrWillBeRawPtr<DataTransfer> dataTransfer = createDraggingDataTransfer(policy, dragData); |
dataTransfer->setSourceOperation(dragData->draggingSourceOperationMask()); |
@@ -238,7 +240,8 @@ bool DragController::performDrag(DragData* dragData) |
ASSERT(dragData); |
m_documentUnderMouse = m_page->deprecatedLocalMainFrame()->documentAtPoint(dragData->clientPosition()); |
if ((m_dragDestinationAction & DragDestinationActionDHTML) && m_documentIsHandlingDrag) { |
- RefPtr<LocalFrame> mainFrame = m_page->deprecatedLocalMainFrame(); |
+ LocalFrame* mainFrame = m_page->deprecatedLocalMainFrame(); |
+ FrameProtector protect(mainFrame); |
bool preventedDefault = false; |
if (mainFrame->view()) { |
// Sending an event can result in the destruction of the view and part. |
@@ -352,7 +355,8 @@ bool DragController::tryDocumentDrag(DragData* dragData, DragDestinationAction a |
// It's unclear why this check is after tryDHTMLDrag. |
// We send drag events in tryDHTMLDrag and that may be the reason. |
- RefPtr<FrameView> frameView = m_documentUnderMouse->view(); |
+ FrameView* frameView = m_documentUnderMouse->view(); |
+ FrameViewProtector protect(frameView); |
if (!frameView) |
return false; |
@@ -459,10 +463,11 @@ bool DragController::concludeEditDrag(DragData* dragData) |
Element* element = elementUnderMouse(m_documentUnderMouse.get(), point); |
if (!element) |
return false; |
- RefPtr<LocalFrame> innerFrame = element->ownerDocument()->frame(); |
+ LocalFrame* innerFrame = element->ownerDocument()->frame(); |
+ FrameProtector protect(innerFrame); |
ASSERT(innerFrame); |
- if (m_page->dragCaretController().hasCaret() && !dispatchTextInputEventFor(innerFrame.get(), dragData)) |
+ if (m_page->dragCaretController().hasCaret() && !dispatchTextInputEventFor(innerFrame, dragData)) |
return true; |
if (dragData->containsFiles() && fileInput) { |
@@ -493,7 +498,7 @@ bool DragController::concludeEditDrag(DragData* dragData) |
ResourceCacheValidationSuppressor validationSuppressor(fetcher); |
if (dragIsMove(innerFrame->selection(), dragData) || dragCaret.isContentRichlyEditable()) { |
bool chosePlainText = false; |
- RefPtrWillBeRawPtr<DocumentFragment> fragment = documentFragmentFromDragData(dragData, innerFrame.get(), range, true, chosePlainText); |
+ RefPtrWillBeRawPtr<DocumentFragment> fragment = documentFragmentFromDragData(dragData, innerFrame, range, true, chosePlainText); |
if (!fragment) |
return false; |
@@ -504,7 +509,7 @@ bool DragController::concludeEditDrag(DragData* dragData) |
bool smartInsert = smartDelete && innerFrame->selection().granularity() == WordGranularity && dragData->canSmartReplace(); |
MoveSelectionCommand::create(fragment, dragCaret.base(), smartInsert, smartDelete)->apply(); |
} else { |
- if (setSelectionToDragCaret(innerFrame.get(), dragCaret, range, point)) { |
+ if (setSelectionToDragCaret(innerFrame, dragCaret, range, point)) { |
ReplaceSelectionCommand::CommandOptions options = ReplaceSelectionCommand::SelectReplacement | ReplaceSelectionCommand::PreventNesting; |
if (dragData->canSmartReplace()) |
options |= ReplaceSelectionCommand::SmartReplace; |
@@ -519,7 +524,7 @@ bool DragController::concludeEditDrag(DragData* dragData) |
if (text.isEmpty()) |
return false; |
- if (setSelectionToDragCaret(innerFrame.get(), dragCaret, range, point)) { |
+ if (setSelectionToDragCaret(innerFrame, dragCaret, range, point)) { |
ASSERT(m_documentUnderMouse); |
ReplaceSelectionCommand::create(*m_documentUnderMouse.get(), createFragmentFromText(range.get(), text), ReplaceSelectionCommand::SelectReplacement | ReplaceSelectionCommand::MatchStyle | ReplaceSelectionCommand::PreventNesting)->apply(); |
} |
@@ -589,11 +594,12 @@ bool DragController::tryDHTMLDrag(DragData* dragData, DragOperation& operation) |
{ |
ASSERT(dragData); |
ASSERT(m_documentUnderMouse); |
- RefPtr<LocalFrame> mainFrame = m_page->deprecatedLocalMainFrame(); |
- RefPtr<FrameView> viewProtector = mainFrame->view(); |
- if (!viewProtector) |
+ LocalFrame* mainFrame = m_page->deprecatedLocalMainFrame(); |
+ FrameProtector protect(mainFrame); |
+ if (!mainFrame->view()) |
return false; |
+ FrameViewProtector viewProtector(mainFrame->view()); |
DataTransferAccessPolicy policy = m_documentUnderMouse->securityOrigin()->isLocal() ? DataTransferReadable : DataTransferTypesReadable; |
RefPtrWillBeRawPtr<DataTransfer> dataTransfer = createDraggingDataTransfer(policy, dragData); |
DragOperation srcOpMask = dragData->draggingSourceOperationMask(); |
@@ -927,12 +933,15 @@ void DragController::doSystemDrag(DragImage* image, const IntPoint& dragLocation |
m_didInitiateDrag = true; |
m_dragInitiator = frame->document(); |
// Protect this frame and view, as a load may occur mid drag and attempt to unload this frame |
- RefPtr<LocalFrame> frameProtector = m_page->deprecatedLocalMainFrame(); |
- RefPtr<FrameView> viewProtector = frameProtector->view(); |
- m_client->startDrag(image, viewProtector->rootViewToContents(frame->view()->contentsToRootView(dragLocation)), |
- viewProtector->rootViewToContents(frame->view()->contentsToRootView(eventPos)), dataTransfer, frameProtector.get(), forLink); |
+ LocalFrame* mainFrame = m_page->deprecatedLocalMainFrame(); |
+ FrameProtector frameProtector(mainFrame); |
+ FrameView* mainFrameView = mainFrame->view(); |
+ FrameViewProtector viewProtector(mainFrameView); |
+ |
+ m_client->startDrag(image, mainFrameView->rootViewToContents(frame->view()->contentsToRootView(dragLocation)), |
+ mainFrameView->rootViewToContents(frame->view()->contentsToRootView(eventPos)), dataTransfer, frame, forLink); |
// DragClient::startDrag can cause our Page to dispear, deallocating |this|. |
- if (!frameProtector->page()) |
+ if (!frame->page()) |
return; |
cleanupAfterSystemDrag(); |