Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(521)

Side by Side Diff: Source/core/page/DragController.cpp

Issue 517043003: Move Frame to the Oilpan heap. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase past r181245 conflict Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2007, 2009, 2010 Apple Inc. All rights reserved. 2 * Copyright (C) 2007, 2009, 2010 Apple Inc. All rights reserved.
3 * Copyright (C) 2008 Google Inc. 3 * Copyright (C) 2008 Google Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 29 matching lines...) Expand all
40 #include "core/dom/shadow/ShadowRoot.h" 40 #include "core/dom/shadow/ShadowRoot.h"
41 #include "core/editing/Editor.h" 41 #include "core/editing/Editor.h"
42 #include "core/editing/FrameSelection.h" 42 #include "core/editing/FrameSelection.h"
43 #include "core/editing/MoveSelectionCommand.h" 43 #include "core/editing/MoveSelectionCommand.h"
44 #include "core/editing/ReplaceSelectionCommand.h" 44 #include "core/editing/ReplaceSelectionCommand.h"
45 #include "core/editing/htmlediting.h" 45 #include "core/editing/htmlediting.h"
46 #include "core/editing/markup.h" 46 #include "core/editing/markup.h"
47 #include "core/events/TextEvent.h" 47 #include "core/events/TextEvent.h"
48 #include "core/fetch/ImageResource.h" 48 #include "core/fetch/ImageResource.h"
49 #include "core/fetch/ResourceFetcher.h" 49 #include "core/fetch/ResourceFetcher.h"
50 #include "core/frame/FrameProtector.h"
50 #include "core/frame/FrameView.h" 51 #include "core/frame/FrameView.h"
51 #include "core/frame/LocalFrame.h" 52 #include "core/frame/LocalFrame.h"
52 #include "core/html/HTMLAnchorElement.h" 53 #include "core/html/HTMLAnchorElement.h"
53 #include "core/html/HTMLFormElement.h" 54 #include "core/html/HTMLFormElement.h"
54 #include "core/html/HTMLInputElement.h" 55 #include "core/html/HTMLInputElement.h"
55 #include "core/html/HTMLPlugInElement.h" 56 #include "core/html/HTMLPlugInElement.h"
56 #include "core/loader/FrameLoadRequest.h" 57 #include "core/loader/FrameLoadRequest.h"
57 #include "core/loader/FrameLoader.h" 58 #include "core/loader/FrameLoader.h"
58 #include "core/page/DragClient.h" 59 #include "core/page/DragClient.h"
59 #include "core/page/DragData.h" 60 #include "core/page/DragData.h"
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 DragSession DragController::dragEntered(DragData* dragData) 209 DragSession DragController::dragEntered(DragData* dragData)
209 { 210 {
210 return dragEnteredOrUpdated(dragData); 211 return dragEnteredOrUpdated(dragData);
211 } 212 }
212 213
213 void DragController::dragExited(DragData* dragData) 214 void DragController::dragExited(DragData* dragData)
214 { 215 {
215 ASSERT(dragData); 216 ASSERT(dragData);
216 LocalFrame* mainFrame = m_page->deprecatedLocalMainFrame(); 217 LocalFrame* mainFrame = m_page->deprecatedLocalMainFrame();
217 218
218 if (RefPtr<FrameView> v = mainFrame->view()) { 219 if (FrameView* v = mainFrame->view()) {
220 FrameViewProtector protect(v);
219 DataTransferAccessPolicy policy = (!m_documentUnderMouse || m_documentUn derMouse->securityOrigin()->isLocal()) ? DataTransferReadable : DataTransferType sReadable; 221 DataTransferAccessPolicy policy = (!m_documentUnderMouse || m_documentUn derMouse->securityOrigin()->isLocal()) ? DataTransferReadable : DataTransferType sReadable;
220 RefPtrWillBeRawPtr<DataTransfer> dataTransfer = createDraggingDataTransf er(policy, dragData); 222 RefPtrWillBeRawPtr<DataTransfer> dataTransfer = createDraggingDataTransf er(policy, dragData);
221 dataTransfer->setSourceOperation(dragData->draggingSourceOperationMask() ); 223 dataTransfer->setSourceOperation(dragData->draggingSourceOperationMask() );
222 mainFrame->eventHandler().cancelDragAndDrop(createMouseEvent(dragData), dataTransfer.get()); 224 mainFrame->eventHandler().cancelDragAndDrop(createMouseEvent(dragData), dataTransfer.get());
223 dataTransfer->setAccessPolicy(DataTransferNumb); // invalidate clipboard here for security 225 dataTransfer->setAccessPolicy(DataTransferNumb); // invalidate clipboard here for security
224 } 226 }
225 mouseMovedIntoDocument(0); 227 mouseMovedIntoDocument(0);
226 if (m_fileInputElementUnderMouse) 228 if (m_fileInputElementUnderMouse)
227 m_fileInputElementUnderMouse->setCanReceiveDroppedFiles(false); 229 m_fileInputElementUnderMouse->setCanReceiveDroppedFiles(false);
228 m_fileInputElementUnderMouse = nullptr; 230 m_fileInputElementUnderMouse = nullptr;
229 } 231 }
230 232
231 DragSession DragController::dragUpdated(DragData* dragData) 233 DragSession DragController::dragUpdated(DragData* dragData)
232 { 234 {
233 return dragEnteredOrUpdated(dragData); 235 return dragEnteredOrUpdated(dragData);
234 } 236 }
235 237
236 bool DragController::performDrag(DragData* dragData) 238 bool DragController::performDrag(DragData* dragData)
237 { 239 {
238 ASSERT(dragData); 240 ASSERT(dragData);
239 m_documentUnderMouse = m_page->deprecatedLocalMainFrame()->documentAtPoint(d ragData->clientPosition()); 241 m_documentUnderMouse = m_page->deprecatedLocalMainFrame()->documentAtPoint(d ragData->clientPosition());
240 if ((m_dragDestinationAction & DragDestinationActionDHTML) && m_documentIsHa ndlingDrag) { 242 if ((m_dragDestinationAction & DragDestinationActionDHTML) && m_documentIsHa ndlingDrag) {
241 RefPtr<LocalFrame> mainFrame = m_page->deprecatedLocalMainFrame(); 243 LocalFrame* mainFrame = m_page->deprecatedLocalMainFrame();
244 FrameProtector protect(mainFrame);
242 bool preventedDefault = false; 245 bool preventedDefault = false;
243 if (mainFrame->view()) { 246 if (mainFrame->view()) {
244 // Sending an event can result in the destruction of the view and pa rt. 247 // Sending an event can result in the destruction of the view and pa rt.
245 RefPtrWillBeRawPtr<DataTransfer> dataTransfer = createDraggingDataTr ansfer(DataTransferReadable, dragData); 248 RefPtrWillBeRawPtr<DataTransfer> dataTransfer = createDraggingDataTr ansfer(DataTransferReadable, dragData);
246 dataTransfer->setSourceOperation(dragData->draggingSourceOperationMa sk()); 249 dataTransfer->setSourceOperation(dragData->draggingSourceOperationMa sk());
247 preventedDefault = mainFrame->eventHandler().performDragAndDrop(crea teMouseEvent(dragData), dataTransfer.get()); 250 preventedDefault = mainFrame->eventHandler().performDragAndDrop(crea teMouseEvent(dragData), dataTransfer.get());
248 dataTransfer->setAccessPolicy(DataTransferNumb); // Invalidate clipb oard here for security 251 dataTransfer->setAccessPolicy(DataTransferNumb); // Invalidate clipb oard here for security
249 } 252 }
250 if (preventedDefault) { 253 if (preventedDefault) {
251 m_documentUnderMouse = nullptr; 254 m_documentUnderMouse = nullptr;
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 // tryDHTMLDrag fires dragenter event. The event listener that listens 348 // tryDHTMLDrag fires dragenter event. The event listener that listens
346 // to this event may create a nested message loop (open a modal dialog), 349 // to this event may create a nested message loop (open a modal dialog),
347 // which could process dragleave event and reset m_documentUnderMouse in 350 // which could process dragleave event and reset m_documentUnderMouse in
348 // dragExited. 351 // dragExited.
349 if (!m_documentUnderMouse) 352 if (!m_documentUnderMouse)
350 return false; 353 return false;
351 } 354 }
352 355
353 // It's unclear why this check is after tryDHTMLDrag. 356 // It's unclear why this check is after tryDHTMLDrag.
354 // We send drag events in tryDHTMLDrag and that may be the reason. 357 // We send drag events in tryDHTMLDrag and that may be the reason.
355 RefPtr<FrameView> frameView = m_documentUnderMouse->view(); 358 FrameView* frameView = m_documentUnderMouse->view();
359 FrameViewProtector protect(frameView);
356 if (!frameView) 360 if (!frameView)
357 return false; 361 return false;
358 362
359 if (isHandlingDrag) { 363 if (isHandlingDrag) {
360 m_page->dragCaretController().clear(); 364 m_page->dragCaretController().clear();
361 return true; 365 return true;
362 } 366 }
363 367
364 if ((actionMask & DragDestinationActionEdit) && canProcessDrag(dragData)) { 368 if ((actionMask & DragDestinationActionEdit) && canProcessDrag(dragData)) {
365 IntPoint point = frameView->windowToContents(dragData->clientPosition()) ; 369 IntPoint point = frameView->windowToContents(dragData->clientPosition()) ;
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 m_fileInputElementUnderMouse = nullptr; 456 m_fileInputElementUnderMouse = nullptr;
453 } 457 }
454 458
455 if (!m_documentUnderMouse) 459 if (!m_documentUnderMouse)
456 return false; 460 return false;
457 461
458 IntPoint point = m_documentUnderMouse->view()->windowToContents(dragData->cl ientPosition()); 462 IntPoint point = m_documentUnderMouse->view()->windowToContents(dragData->cl ientPosition());
459 Element* element = elementUnderMouse(m_documentUnderMouse.get(), point); 463 Element* element = elementUnderMouse(m_documentUnderMouse.get(), point);
460 if (!element) 464 if (!element)
461 return false; 465 return false;
462 RefPtr<LocalFrame> innerFrame = element->ownerDocument()->frame(); 466 LocalFrame* innerFrame = element->ownerDocument()->frame();
467 FrameProtector protect(innerFrame);
463 ASSERT(innerFrame); 468 ASSERT(innerFrame);
464 469
465 if (m_page->dragCaretController().hasCaret() && !dispatchTextInputEventFor(i nnerFrame.get(), dragData)) 470 if (m_page->dragCaretController().hasCaret() && !dispatchTextInputEventFor(i nnerFrame, dragData))
466 return true; 471 return true;
467 472
468 if (dragData->containsFiles() && fileInput) { 473 if (dragData->containsFiles() && fileInput) {
469 // fileInput should be the element we hit tested for, unless it was made 474 // fileInput should be the element we hit tested for, unless it was made
470 // display:none in a drop event handler. 475 // display:none in a drop event handler.
471 ASSERT(fileInput == element || !fileInput->renderer()); 476 ASSERT(fileInput == element || !fileInput->renderer());
472 if (fileInput->isDisabledFormControl()) 477 if (fileInput->isDisabledFormControl())
473 return false; 478 return false;
474 479
475 return fileInput->receiveDroppedFiles(dragData); 480 return fileInput->receiveDroppedFiles(dragData);
(...skipping 10 matching lines...) Expand all
486 RefPtrWillBeRawPtr<Element> rootEditableElement = innerFrame->selection().ro otEditableElement(); 491 RefPtrWillBeRawPtr<Element> rootEditableElement = innerFrame->selection().ro otEditableElement();
487 492
488 // For range to be null a WebKit client must have done something bad while 493 // For range to be null a WebKit client must have done something bad while
489 // manually controlling drag behaviour 494 // manually controlling drag behaviour
490 if (!range) 495 if (!range)
491 return false; 496 return false;
492 ResourceFetcher* fetcher = range->ownerDocument().fetcher(); 497 ResourceFetcher* fetcher = range->ownerDocument().fetcher();
493 ResourceCacheValidationSuppressor validationSuppressor(fetcher); 498 ResourceCacheValidationSuppressor validationSuppressor(fetcher);
494 if (dragIsMove(innerFrame->selection(), dragData) || dragCaret.isContentRich lyEditable()) { 499 if (dragIsMove(innerFrame->selection(), dragData) || dragCaret.isContentRich lyEditable()) {
495 bool chosePlainText = false; 500 bool chosePlainText = false;
496 RefPtrWillBeRawPtr<DocumentFragment> fragment = documentFragmentFromDrag Data(dragData, innerFrame.get(), range, true, chosePlainText); 501 RefPtrWillBeRawPtr<DocumentFragment> fragment = documentFragmentFromDrag Data(dragData, innerFrame, range, true, chosePlainText);
497 if (!fragment) 502 if (!fragment)
498 return false; 503 return false;
499 504
500 if (dragIsMove(innerFrame->selection(), dragData)) { 505 if (dragIsMove(innerFrame->selection(), dragData)) {
501 // NSTextView behavior is to always smart delete on moving a selecti on, 506 // NSTextView behavior is to always smart delete on moving a selecti on,
502 // but only to smart insert if the selection granularity is word gra nularity. 507 // but only to smart insert if the selection granularity is word gra nularity.
503 bool smartDelete = innerFrame->editor().smartInsertDeleteEnabled(); 508 bool smartDelete = innerFrame->editor().smartInsertDeleteEnabled();
504 bool smartInsert = smartDelete && innerFrame->selection().granularit y() == WordGranularity && dragData->canSmartReplace(); 509 bool smartInsert = smartDelete && innerFrame->selection().granularit y() == WordGranularity && dragData->canSmartReplace();
505 MoveSelectionCommand::create(fragment, dragCaret.base(), smartInsert , smartDelete)->apply(); 510 MoveSelectionCommand::create(fragment, dragCaret.base(), smartInsert , smartDelete)->apply();
506 } else { 511 } else {
507 if (setSelectionToDragCaret(innerFrame.get(), dragCaret, range, poin t)) { 512 if (setSelectionToDragCaret(innerFrame, dragCaret, range, point)) {
508 ReplaceSelectionCommand::CommandOptions options = ReplaceSelecti onCommand::SelectReplacement | ReplaceSelectionCommand::PreventNesting; 513 ReplaceSelectionCommand::CommandOptions options = ReplaceSelecti onCommand::SelectReplacement | ReplaceSelectionCommand::PreventNesting;
509 if (dragData->canSmartReplace()) 514 if (dragData->canSmartReplace())
510 options |= ReplaceSelectionCommand::SmartReplace; 515 options |= ReplaceSelectionCommand::SmartReplace;
511 if (chosePlainText) 516 if (chosePlainText)
512 options |= ReplaceSelectionCommand::MatchStyle; 517 options |= ReplaceSelectionCommand::MatchStyle;
513 ASSERT(m_documentUnderMouse); 518 ASSERT(m_documentUnderMouse);
514 ReplaceSelectionCommand::create(*m_documentUnderMouse.get(), fra gment, options)->apply(); 519 ReplaceSelectionCommand::create(*m_documentUnderMouse.get(), fra gment, options)->apply();
515 } 520 }
516 } 521 }
517 } else { 522 } else {
518 String text = dragData->asPlainText(); 523 String text = dragData->asPlainText();
519 if (text.isEmpty()) 524 if (text.isEmpty())
520 return false; 525 return false;
521 526
522 if (setSelectionToDragCaret(innerFrame.get(), dragCaret, range, point)) { 527 if (setSelectionToDragCaret(innerFrame, dragCaret, range, point)) {
523 ASSERT(m_documentUnderMouse); 528 ASSERT(m_documentUnderMouse);
524 ReplaceSelectionCommand::create(*m_documentUnderMouse.get(), createF ragmentFromText(range.get(), text), ReplaceSelectionCommand::SelectReplacement | ReplaceSelectionCommand::MatchStyle | ReplaceSelectionCommand::PreventNesting) ->apply(); 529 ReplaceSelectionCommand::create(*m_documentUnderMouse.get(), createF ragmentFromText(range.get(), text), ReplaceSelectionCommand::SelectReplacement | ReplaceSelectionCommand::MatchStyle | ReplaceSelectionCommand::PreventNesting) ->apply();
525 } 530 }
526 } 531 }
527 532
528 if (rootEditableElement) { 533 if (rootEditableElement) {
529 if (LocalFrame* frame = rootEditableElement->document().frame()) 534 if (LocalFrame* frame = rootEditableElement->document().frame())
530 frame->eventHandler().updateDragStateAfterEditDragIfNeeded(rootEdita bleElement.get()); 535 frame->eventHandler().updateDragStateAfterEditDragIfNeeded(rootEdita bleElement.get());
531 } 536 }
532 537
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 return DragOperationLink; 587 return DragOperationLink;
583 588
584 // FIXME: Does IE really return "generic" even if no operations were allowed by the source? 589 // FIXME: Does IE really return "generic" even if no operations were allowed by the source?
585 return DragOperationGeneric; 590 return DragOperationGeneric;
586 } 591 }
587 592
588 bool DragController::tryDHTMLDrag(DragData* dragData, DragOperation& operation) 593 bool DragController::tryDHTMLDrag(DragData* dragData, DragOperation& operation)
589 { 594 {
590 ASSERT(dragData); 595 ASSERT(dragData);
591 ASSERT(m_documentUnderMouse); 596 ASSERT(m_documentUnderMouse);
592 RefPtr<LocalFrame> mainFrame = m_page->deprecatedLocalMainFrame(); 597 LocalFrame* mainFrame = m_page->deprecatedLocalMainFrame();
593 RefPtr<FrameView> viewProtector = mainFrame->view(); 598 FrameProtector protect(mainFrame);
594 if (!viewProtector) 599 if (!mainFrame->view())
595 return false; 600 return false;
596 601
602 FrameViewProtector viewProtector(mainFrame->view());
597 DataTransferAccessPolicy policy = m_documentUnderMouse->securityOrigin()->is Local() ? DataTransferReadable : DataTransferTypesReadable; 603 DataTransferAccessPolicy policy = m_documentUnderMouse->securityOrigin()->is Local() ? DataTransferReadable : DataTransferTypesReadable;
598 RefPtrWillBeRawPtr<DataTransfer> dataTransfer = createDraggingDataTransfer(p olicy, dragData); 604 RefPtrWillBeRawPtr<DataTransfer> dataTransfer = createDraggingDataTransfer(p olicy, dragData);
599 DragOperation srcOpMask = dragData->draggingSourceOperationMask(); 605 DragOperation srcOpMask = dragData->draggingSourceOperationMask();
600 dataTransfer->setSourceOperation(srcOpMask); 606 dataTransfer->setSourceOperation(srcOpMask);
601 607
602 PlatformMouseEvent event = createMouseEvent(dragData); 608 PlatformMouseEvent event = createMouseEvent(dragData);
603 if (!mainFrame->eventHandler().updateDragAndDrop(event, dataTransfer.get())) { 609 if (!mainFrame->eventHandler().updateDragAndDrop(event, dataTransfer.get())) {
604 dataTransfer->setAccessPolicy(DataTransferNumb); // invalidate clipboard here for security 610 dataTransfer->setAccessPolicy(DataTransferNumb); // invalidate clipboard here for security
605 return false; 611 return false;
606 } 612 }
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
920 } 926 }
921 927
922 return true; 928 return true;
923 } 929 }
924 930
925 void DragController::doSystemDrag(DragImage* image, const IntPoint& dragLocation , const IntPoint& eventPos, DataTransfer* dataTransfer, LocalFrame* frame, bool forLink) 931 void DragController::doSystemDrag(DragImage* image, const IntPoint& dragLocation , const IntPoint& eventPos, DataTransfer* dataTransfer, LocalFrame* frame, bool forLink)
926 { 932 {
927 m_didInitiateDrag = true; 933 m_didInitiateDrag = true;
928 m_dragInitiator = frame->document(); 934 m_dragInitiator = frame->document();
929 // Protect this frame and view, as a load may occur mid drag and attempt to unload this frame 935 // Protect this frame and view, as a load may occur mid drag and attempt to unload this frame
930 RefPtr<LocalFrame> frameProtector = m_page->deprecatedLocalMainFrame(); 936 LocalFrame* mainFrame = m_page->deprecatedLocalMainFrame();
931 RefPtr<FrameView> viewProtector = frameProtector->view(); 937 FrameProtector frameProtector(mainFrame);
932 m_client->startDrag(image, viewProtector->rootViewToContents(frame->view()-> contentsToRootView(dragLocation)), 938 FrameView* mainFrameView = mainFrame->view();
933 viewProtector->rootViewToContents(frame->view()->contentsToRootView(even tPos)), dataTransfer, frameProtector.get(), forLink); 939 FrameViewProtector viewProtector(mainFrameView);
940
941 m_client->startDrag(image, mainFrameView->rootViewToContents(frame->view()-> contentsToRootView(dragLocation)),
942 mainFrameView->rootViewToContents(frame->view()->contentsToRootView(even tPos)), dataTransfer, frame, forLink);
934 // DragClient::startDrag can cause our Page to dispear, deallocating |this|. 943 // DragClient::startDrag can cause our Page to dispear, deallocating |this|.
935 if (!frameProtector->page()) 944 if (!frame->page())
936 return; 945 return;
937 946
938 cleanupAfterSystemDrag(); 947 cleanupAfterSystemDrag();
939 } 948 }
940 949
941 DragOperation DragController::dragOperation(DragData* dragData) 950 DragOperation DragController::dragOperation(DragData* dragData)
942 { 951 {
943 // FIXME: To match the MacOS behaviour we should return DragOperationNone 952 // FIXME: To match the MacOS behaviour we should return DragOperationNone
944 // if we are a modal window, we are the drag source, or the window is an 953 // if we are a modal window, we are the drag source, or the window is an
945 // attached sheet If this can be determined from within WebCore 954 // attached sheet If this can be determined from within WebCore
(...skipping 19 matching lines...) Expand all
965 974
966 void DragController::trace(Visitor* visitor) 975 void DragController::trace(Visitor* visitor)
967 { 976 {
968 visitor->trace(m_page); 977 visitor->trace(m_page);
969 visitor->trace(m_documentUnderMouse); 978 visitor->trace(m_documentUnderMouse);
970 visitor->trace(m_dragInitiator); 979 visitor->trace(m_dragInitiator);
971 visitor->trace(m_fileInputElementUnderMouse); 980 visitor->trace(m_fileInputElementUnderMouse);
972 } 981 }
973 982
974 } // namespace blink 983 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698