2016-01-31 Gyuyoung Kim <gyuyoung.kim@webkit.org>
+ Reduce PassRefPtr uses in dom - 5
+ https://bugs.webkit.org/show_bug.cgi?id=153470
+
+ Reviewed by Darin Adler.
+
+ As a step to remove PassRefPtr, this patch reduces uses of PassRefPtr in WebCore/dom.
+
+ * dom/Document.cpp:
+ (WebCore::Document::adoptNode):
+ (WebCore::Document::implicitClose):
+ (WebCore::Document::enqueuePopstateEvent):
+ (WebCore::Document::setInputCursor):
+ * dom/Document.h:
+ * dom/DocumentMarker.cpp:
+ (WebCore::DocumentMarkerTextMatch::instanceFor):
+ * dom/Event.cpp:
+ (WebCore::Event::setUnderlyingEvent):
+ * dom/Event.h:
+ * dom/EventDispatcher.h:
+ * dom/GenericEventQueue.cpp:
+ (WebCore::GenericEventQueue::enqueueEvent):
+ * dom/GenericEventQueue.h:
+ * dom/MouseEvent.cpp:
+ (WebCore::SimulatedMouseEvent::SimulatedMouseEvent):
+ * dom/Node.cpp:
+ (WebCore::Node::dispatchDOMActivateEvent):
+ * dom/NodeIterator.h:
+ * dom/PendingScript.h:
+ * dom/PopStateEvent.cpp:
+ (WebCore::PopStateEvent::create):
+ * dom/PopStateEvent.h:
+ * dom/ProcessingInstruction.cpp:
+ (WebCore::ProcessingInstruction::setCSSStyleSheet): Deleted. Nobody calls this function.
+ * dom/ProcessingInstruction.h:
+ * dom/RangeBoundaryPoint.h:
+ (WebCore::RangeBoundaryPoint::RangeBoundaryPoint):
+ * dom/TextEvent.cpp:
+ (WebCore::TextEvent::createForFragmentPaste):
+ (WebCore::TextEvent::TextEvent):
+ * dom/TextEvent.h:
+ * editing/Editor.cpp:
+ (WebCore::Editor::pasteAsFragment):
+ * editing/Editor.h:
+ * editing/mac/EditorMac.mm:
+ (WebCore::Editor::replaceNodeFromPasteboard):
+
+2016-01-31 Gyuyoung Kim <gyuyoung.kim@webkit.org>
+
Use std::make_unique<> when creating an unique_ptr object.
https://bugs.webkit.org/show_bug.cgi?id=153705
}
-RefPtr<Node> Document::adoptNode(PassRefPtr<Node> source, ExceptionCode& ec)
+RefPtr<Node> Document::adoptNode(Node* source, ExceptionCode& ec)
{
if (!source) {
ec = NOT_SUPPORTED_ERR;
}
}
- adoptIfNeeded(source.get());
+ adoptIfNeeded(source);
return source;
}
dispatchWindowLoadEvent();
enqueuePageshowEvent(PageshowEventNotPersisted);
if (m_pendingStateObject)
- enqueuePopstateEvent(m_pendingStateObject.release());
-
+ enqueuePopstateEvent(WTFMove(m_pendingStateObject));
+
if (f)
f->loader().dispatchOnloadEvents();
#ifdef INSTRUMENT_LAYOUT_SCHEDULING
enqueueWindowEvent(HashChangeEvent::create(oldURL, newURL));
}
-void Document::enqueuePopstateEvent(PassRefPtr<SerializedScriptValue> stateObject)
+void Document::enqueuePopstateEvent(RefPtr<SerializedScriptValue>&& stateObject)
{
- enqueueWindowEvent(PopStateEvent::create(stateObject, m_domWindow ? m_domWindow->history() : nullptr));
+ enqueueWindowEvent(PopStateEvent::create(WTFMove(stateObject), m_domWindow ? m_domWindow->history() : nullptr));
}
void Document::addMediaCanStartListener(MediaCanStartListener* listener)
#if ENABLE(WEB_REPLAY)
void Document::setInputCursor(PassRefPtr<InputCursor> cursor)
{
- m_inputCursor = cursor;
+ m_inputCursor = WTFMove(cursor);
}
#endif
DOMSecurityPolicy& securityPolicy();
#endif
- RefPtr<Node> adoptNode(PassRefPtr<Node> source, ExceptionCode&);
+ RefPtr<Node> adoptNode(Node* source, ExceptionCode&);
Ref<HTMLCollection> images();
Ref<HTMLCollection> embeds();
void enqueueOverflowEvent(Ref<Event>&&);
void enqueuePageshowEvent(PageshowEventPersistence);
void enqueueHashchangeEvent(const String& oldURL, const String& newURL);
- void enqueuePopstateEvent(PassRefPtr<SerializedScriptValue> stateObject);
+ void enqueuePopstateEvent(RefPtr<SerializedScriptValue>&& stateObject);
virtual DocumentEventQueue& eventQueue() const override final { return m_eventQueue; }
WEBCORE_EXPORT void addMediaCanStartListener(MediaCanStartListener*);
{
}
-class DocumentMarkerDescription : public DocumentMarkerDetails {
+class DocumentMarkerDescription final : public DocumentMarkerDetails {
public:
static Ref<DocumentMarkerDescription> create(const String&);
{
}
-void Event::setUnderlyingEvent(PassRefPtr<Event> ue)
+void Event::setUnderlyingEvent(Event* underlyingEvent)
{
// Prohibit creation of a cycle -- just do nothing in that case.
- for (Event* e = ue.get(); e; e = e->underlyingEvent())
- if (e == this)
+ for (Event* event = underlyingEvent; event; event = event->underlyingEvent()) {
+ if (event == this)
return;
- m_underlyingEvent = ue;
+ }
+ m_underlyingEvent = underlyingEvent;
}
} // namespace WebCore
void setCancelBubble(bool cancel) { m_cancelBubble = cancel; }
Event* underlyingEvent() const { return m_underlyingEvent.get(); }
- void setUnderlyingEvent(PassRefPtr<Event>);
+ void setUnderlyingEvent(Event*);
virtual DataTransfer* internalDataTransfer() const { return 0; }
#include "SimulatedClickOptions.h"
#include <wtf/Forward.h>
-#include <wtf/PassRefPtr.h>
namespace WebCore {
{
}
-void GenericEventQueue::enqueueEvent(PassRefPtr<Event> event)
+void GenericEventQueue::enqueueEvent(RefPtr<Event>&& event)
{
if (m_isClosed)
return;
if (event->target() == &m_owner)
event->setTarget(nullptr);
- m_pendingEvents.append(event);
+ m_pendingEvents.append(WTFMove(event));
if (m_isSuspended)
return;
explicit GenericEventQueue(EventTarget&);
~GenericEventQueue();
- void enqueueEvent(PassRefPtr<Event>);
+ void enqueueEvent(RefPtr<Event>&&);
void close();
void cancelAllEvents();
m_shiftKey = keyStateEvent->shiftKey();
m_metaKey = keyStateEvent->metaKey();
}
- setUnderlyingEvent(underlyingEvent);
+ setUnderlyingEvent(underlyingEvent.get());
if (is<MouseEvent>(this->underlyingEvent())) {
MouseEvent& mouseEvent = downcast<MouseEvent>(*this->underlyingEvent());
{
ASSERT_WITH_SECURITY_IMPLICATION(!NoEventDispatchAssertion::isEventDispatchForbidden());
Ref<UIEvent> event = UIEvent::create(eventNames().DOMActivateEvent, true, true, document().defaultView(), detail);
- event->setUnderlyingEvent(underlyingEvent);
+ event->setUnderlyingEvent(underlyingEvent.get());
dispatchScopedEvent(event);
return event->defaultHandled();
}
#include "NodeFilter.h"
#include "ScriptWrappable.h"
#include "Traversal.h"
-#include <wtf/PassRefPtr.h>
#include <wtf/RefCounted.h>
namespace WebCore {
#include "CachedResourceClient.h"
#include "CachedResourceHandle.h"
#include <wtf/text/TextPosition.h>
-#include <wtf/PassRefPtr.h>
#include <wtf/RefPtr.h>
namespace WebCore {
return adoptRef(*new PopStateEvent);
}
-Ref<PopStateEvent> PopStateEvent::create(PassRefPtr<SerializedScriptValue> serializedState, PassRefPtr<History> history)
+Ref<PopStateEvent> PopStateEvent::create(RefPtr<SerializedScriptValue>&& serializedState, PassRefPtr<History> history)
{
- return adoptRef(*new PopStateEvent(serializedState, history));
+ return adoptRef(*new PopStateEvent(WTFMove(serializedState), history));
}
Ref<PopStateEvent> PopStateEvent::create(const AtomicString& type, const PopStateEventInit& initializer)
public:
virtual ~PopStateEvent();
static Ref<PopStateEvent> create();
- static Ref<PopStateEvent> create(PassRefPtr<SerializedScriptValue>, PassRefPtr<History>);
+ static Ref<PopStateEvent> create(RefPtr<SerializedScriptValue>&&, PassRefPtr<History>);
static Ref<PopStateEvent> create(const AtomicString&, const PopStateEventInit&);
PassRefPtr<SerializedScriptValue> serializedState() const { ASSERT(m_serializedState); return m_serializedState; }
#endif
}
-void ProcessingInstruction::setCSSStyleSheet(PassRefPtr<CSSStyleSheet> sheet)
-{
- ASSERT(!m_cachedSheet);
- ASSERT(!m_loading);
- m_sheet = sheet;
- sheet->setTitle(m_title);
- sheet->setDisabled(m_alternate);
-}
-
void ProcessingInstruction::addSubresourceAttributeURLs(ListHashSet<URL>& urls) const
{
if (!sheet())
const String& localHref() const { return m_localHref; }
StyleSheet* sheet() const { return m_sheet.get(); }
- void setCSSStyleSheet(PassRefPtr<CSSStyleSheet>);
bool isCSS() const { return m_isCSS; }
#if ENABLE(XSLT)
class RangeBoundaryPoint {
public:
- explicit RangeBoundaryPoint(PassRefPtr<Node> container);
+ explicit RangeBoundaryPoint(Node* container);
explicit RangeBoundaryPoint(const RangeBoundaryPoint&);
RefPtr<Node> m_childBeforeBoundary;
};
-inline RangeBoundaryPoint::RangeBoundaryPoint(PassRefPtr<Node> container)
+inline RangeBoundaryPoint::RangeBoundaryPoint(Node* container)
: m_containerNode(container)
{
ASSERT(m_containerNode);
return adoptRef(*new TextEvent(view, data, 0, shouldSmartReplace, false, MailBlockquoteHandling::RespectBlockquote));
}
-Ref<TextEvent> TextEvent::createForFragmentPaste(AbstractView* view, PassRefPtr<DocumentFragment> data, bool shouldSmartReplace, bool shouldMatchStyle, MailBlockquoteHandling mailBlockquoteHandling)
+Ref<TextEvent> TextEvent::createForFragmentPaste(AbstractView* view, RefPtr<DocumentFragment>&& data, bool shouldSmartReplace, bool shouldMatchStyle, MailBlockquoteHandling mailBlockquoteHandling)
{
- return adoptRef(*new TextEvent(view, "", data, shouldSmartReplace, shouldMatchStyle, mailBlockquoteHandling));
+ return adoptRef(*new TextEvent(view, emptyString(), WTFMove(data), shouldSmartReplace, shouldMatchStyle, mailBlockquoteHandling));
}
Ref<TextEvent> TextEvent::createForDrop(AbstractView* view, const String& data)
{
}
-TextEvent::TextEvent(AbstractView* view, const String& data, PassRefPtr<DocumentFragment> pastingFragment, bool shouldSmartReplace, bool shouldMatchStyle, MailBlockquoteHandling mailBlockquoteHandling)
+TextEvent::TextEvent(AbstractView* view, const String& data, RefPtr<DocumentFragment>&& pastingFragment, bool shouldSmartReplace, bool shouldMatchStyle, MailBlockquoteHandling mailBlockquoteHandling)
: UIEvent(eventNames().textInputEvent, true, true, view, 0)
, m_inputType(TextEventInputPaste)
, m_data(data)
- , m_pastingFragment(pastingFragment)
+ , m_pastingFragment(WTFMove(pastingFragment))
, m_shouldSmartReplace(shouldSmartReplace)
, m_shouldMatchStyle(shouldMatchStyle)
, m_mailBlockquoteHandling(mailBlockquoteHandling)
static Ref<TextEvent> create();
static Ref<TextEvent> create(AbstractView*, const String& data, TextEventInputType = TextEventInputKeyboard);
static Ref<TextEvent> createForPlainTextPaste(AbstractView*, const String& data, bool shouldSmartReplace);
- static Ref<TextEvent> createForFragmentPaste(AbstractView*, PassRefPtr<DocumentFragment> data, bool shouldSmartReplace, bool shouldMatchStyle, MailBlockquoteHandling);
+ static Ref<TextEvent> createForFragmentPaste(AbstractView*, RefPtr<DocumentFragment>&& data, bool shouldSmartReplace, bool shouldMatchStyle, MailBlockquoteHandling);
static Ref<TextEvent> createForDrop(AbstractView*, const String& data);
static Ref<TextEvent> createForDictation(AbstractView*, const String& data, const Vector<DictationAlternative>& dictationAlternatives);
TextEvent();
TextEvent(AbstractView*, const String& data, TextEventInputType = TextEventInputKeyboard);
- TextEvent(AbstractView*, const String& data, PassRefPtr<DocumentFragment>, bool shouldSmartReplace, bool shouldMatchStyle, MailBlockquoteHandling);
+ TextEvent(AbstractView*, const String& data, RefPtr<DocumentFragment>&&, bool shouldSmartReplace, bool shouldMatchStyle, MailBlockquoteHandling);
TextEvent(AbstractView*, const String& data, const Vector<DictationAlternative>& dictationAlternatives);
virtual bool isTextEvent() const override;
target->dispatchEvent(TextEvent::createForPlainTextPaste(document().domWindow(), pastingText, smartReplace));
}
-void Editor::pasteAsFragment(PassRefPtr<DocumentFragment> pastingFragment, bool smartReplace, bool matchStyle, MailBlockquoteHandling respectsMailBlockquote)
+void Editor::pasteAsFragment(Ref<DocumentFragment>&& pastingFragment, bool smartReplace, bool matchStyle, MailBlockquoteHandling respectsMailBlockquote)
{
Node* target = findEventTargetFromSelection();
if (!target)
return;
- target->dispatchEvent(TextEvent::createForFragmentPaste(document().domWindow(), pastingFragment, smartReplace, matchStyle, respectsMailBlockquote));
+ target->dispatchEvent(TextEvent::createForFragmentPaste(document().domWindow(), WTFMove(pastingFragment), smartReplace, matchStyle, respectsMailBlockquote));
}
void Editor::pasteAsPlainTextBypassingDHTML()
WEBCORE_EXPORT void handleAlternativeTextUIResult(const String& correction);
void dismissCorrectionPanelAsIgnored();
- WEBCORE_EXPORT void pasteAsFragment(PassRefPtr<DocumentFragment>, bool smartReplace, bool matchStyle, MailBlockquoteHandling = MailBlockquoteHandling::RespectBlockquote);
+ WEBCORE_EXPORT void pasteAsFragment(Ref<DocumentFragment>&&, bool smartReplace, bool matchStyle, MailBlockquoteHandling = MailBlockquoteHandling::RespectBlockquote);
WEBCORE_EXPORT void pasteAsPlainText(const String&, bool smartReplace);
// This is only called on the mac where paste is implemented primarily at the WebKit level.
bool chosePlainText;
RefPtr<DocumentFragment> fragment = createFragmentFromPasteboardData(*pasteboard, m_frame, *range, allowPlainText, chosePlainText);
if (fragment && shouldInsertFragment(fragment, range, EditorInsertActionPasted))
- pasteAsFragment(fragment, canSmartReplaceWithPasteboard(*pasteboard), chosePlainText, mailBlockquoteHandling);
+ pasteAsFragment(fragment.releaseNonNull(), canSmartReplaceWithPasteboard(*pasteboard), chosePlainText, mailBlockquoteHandling);
}
static const AtomicString& elementURL(Element& element)
}
if (fragment && shouldInsertFragment(fragment, range, EditorInsertActionPasted))
- pasteAsFragment(fragment, canSmartReplaceWithPasteboard(*pasteboard), false, mailBlockquoteHandling);
+ pasteAsFragment(fragment.releaseNonNull(), canSmartReplaceWithPasteboard(*pasteboard), false, mailBlockquoteHandling);
}
PassRefPtr<DocumentFragment> Editor::createFragmentAndAddResources(NSAttributedString *string)
if (m_frame.selection().selection().isContentRichlyEditable()) {
RefPtr<DocumentFragment> fragment = createFragmentAndAddResources(attributedString);
if (fragment && shouldInsertFragment(fragment, selectedRange(), EditorInsertActionPasted))
- pasteAsFragment(fragment, false, false, mailBlockquoteHandling);
+ pasteAsFragment(fragment.releaseNonNull(), false, false, mailBlockquoteHandling);
} else {
String text = [attributedString string];
if (shouldInsertText(text, selectedRange().get(), EditorInsertActionPasted))
RefPtr<DocumentFragment> fragment = webContentFromPasteboard(*pasteboard, *range, allowPlainText, chosePlainText);
if (fragment && shouldInsertFragment(fragment, range, EditorInsertActionPasted))
- pasteAsFragment(fragment, canSmartReplaceWithPasteboard(*pasteboard), false, mailBlockquoteHandling);
+ pasteAsFragment(fragment.releaseNonNull(), canSmartReplaceWithPasteboard(*pasteboard), false, mailBlockquoteHandling);
client()->setInsertionPasteboard(String());
}
if (RefPtr<DocumentFragment> fragment = webContentFromPasteboard(pasteboard, *range, true, chosePlainText)) {
maybeCopyNodeAttributesToFragment(*node, *fragment);
if (shouldInsertFragment(fragment, range, EditorInsertActionPasted))
- pasteAsFragment(fragment.release(), canSmartReplaceWithPasteboard(pasteboard), false, MailBlockquoteHandling::IgnoreBlockquote);
+ pasteAsFragment(fragment.releaseNonNull(), canSmartReplaceWithPasteboard(pasteboard), false, MailBlockquoteHandling::IgnoreBlockquote);
}
client()->setInsertionPasteboard(String());
if (m_frame.selection().selection().isContentRichlyEditable()) {
RefPtr<DocumentFragment> fragment = createFragmentAndAddResources(attributedString);
if (fragment && shouldInsertFragment(fragment, selectedRange(), EditorInsertActionPasted))
- pasteAsFragment(fragment, false, false, mailBlockquoteHandling);
+ pasteAsFragment(fragment.releaseNonNull(), false, false, mailBlockquoteHandling);
} else {
String text = [attributedString string];
if (shouldInsertText(text, selectedRange().get(), EditorInsertActionPasted))
bool chosePlainText;
RefPtr<DocumentFragment> fragment = pasteboard->documentFragment(m_frame, *range, allowPlainText, chosePlainText);
if (fragment && shouldInsertFragment(fragment, range, EditorInsertActionPasted))
- pasteAsFragment(fragment, canSmartReplaceWithPasteboard(*pasteboard), chosePlainText, mailBlockquoteHandling);
+ pasteAsFragment(fragment.releaseNonNull(), canSmartReplaceWithPasteboard(*pasteboard), chosePlainText, mailBlockquoteHandling);
}
template <typename PlatformDragData>
DOMDocumentFragment *fragment = [self _documentFragmentFromPasteboard:pasteboard inContext:range allowPlainText:allowPlainText];
if (fragment && [self _shouldInsertFragment:fragment replacingDOMRange:range givenAction:WebViewInsertActionPasted])
- coreFrame->editor().pasteAsFragment(core(fragment), [self _canSmartReplaceWithPasteboard:pasteboard], false);
+ coreFrame->editor().pasteAsFragment(*core(fragment), [self _canSmartReplaceWithPasteboard:pasteboard], false);
[webView _setInsertionPasteboard:nil];
[webView release];