Changeset 139111 in webkit


Ignore:
Timestamp:
Jan 8, 2013 2:11:02 PM (11 years ago)
Author:
tsepez@chromium.org
Message:

Copy-paste preserves <embed> tags containing active content.
https://bugs.webkit.org/show_bug.cgi?id=77625

Reviewed by Ryosuke Niwa.

Source/WebCore:

Test: editing/pasteboard/paste-noplugin.html

  • dom/FragmentScriptingPermission.h:

(WebCore::scriptingContentIsAllowed):
(WebCore::pluginContentIsAllowed):
Add new permission to restrict plugin pasting. Add inline functions to check
the implications of each permission rather than having a list of raw comparisions
sprinkled throughout the code.

  • editing/markup.cpp:

(WebCore::createFragmentFromMarkup):
Revert back to unsafe plugin pasting regardless of caller's intentions when
the settings allow it.

  • dom/Element.cpp:

(WebCore::Element::parserSetAttributes):

  • html/parser/HTMLConstructionSite.cpp:

(WebCore::HTMLConstructionSite::insertScriptElement):

  • xml/parser/XMLDocumentParserLibxml2.cpp:

(WebCore::XMLDocumentParser::endElementNs):

  • xml/parser/XMLDocumentParserQt.cpp:

(WebCore::XMLDocumentParser::parseEndElement):
Use new inline functions to check implications of permissions rather than raw
comparisions.

  • html/parser/HTMLTreeBuilder.cpp:

(WebCore::HTMLTreeBuilder::processStartTagForInBody):
(WebCore::HTMLTreeBuilder::processEndTag):
Check if plugin pasting is allowed before inserting applet/embed/oject elements.

  • page/Settings.in:

Declaration of new unsafePluginPastingEnabled setting.

  • platform/mac/PasteboardMac.mm:

(WebCore::Pasteboard::documentFragment):

  • platform/blackberry/PasteboardBlackBerry.cpp:

(WebCore::Pasteboard::documentFragment):

  • platform/chromium/DragDataChromium.cpp:

(WebCore::DragData::asFragment):

  • platform/chromium/PasteboardChromium.cpp:

(WebCore::Pasteboard::documentFragment):

  • platform/gtk/PasteboardGtk.cpp:

(WebCore::Pasteboard::documentFragment):

  • platform/qt/DragDataQt.cpp:

(WebCore::DragData::asFragment):

  • platform/qt/PasteboardQt.cpp:

(WebCore::Pasteboard::documentFragment):

  • platform/win/ClipboardUtilitiesWin.cpp:

(WebCore::fragmentFromCFHTML):
(WebCore::fragmentFromHTML):

  • platform/wx/PasteboardWx.cpp:

(WebCore::Pasteboard::documentFragment):
Pass DisallowScriptingAndPluginContent enum value.

Source/WebKit/chromium:

Adds chromium API to new unsafePluginPastingEnabled setting.

  • public/WebSettings.h:
  • src/WebSettingsImpl.cpp:

(WebKit::WebSettingsImpl::setUnsafePluginPastingEnabled):
(WebKit):

  • src/WebSettingsImpl.h:

(WebSettingsImpl):

LayoutTests:

  • editing/pasteboard/paste-noplugin-expected.txt: Added.
  • editing/pasteboard/paste-noplugin.html: Added.
Location:
trunk
Files:
2 added
23 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r139109 r139111  
     12013-01-08  Tom Sepez  <tsepez@chromium.org>
     2
     3        Copy-paste preserves <embed> tags containing active content.
     4        https://bugs.webkit.org/show_bug.cgi?id=77625
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        * editing/pasteboard/paste-noplugin-expected.txt: Added.
     9        * editing/pasteboard/paste-noplugin.html: Added.
     10
    1112013-01-08  Filip Pizlo  <fpizlo@apple.com>
    212
  • trunk/Source/WebCore/ChangeLog

    r139106 r139111  
     12013-01-08  Tom Sepez  <tsepez@chromium.org>
     2
     3        Copy-paste preserves <embed> tags containing active content.
     4        https://bugs.webkit.org/show_bug.cgi?id=77625
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        Test: editing/pasteboard/paste-noplugin.html
     9
     10        * dom/FragmentScriptingPermission.h:
     11        (WebCore::scriptingContentIsAllowed):
     12        (WebCore::pluginContentIsAllowed):
     13        Add new permission to restrict plugin pasting.  Add inline functions to check
     14        the implications of each permission rather than having a list of raw comparisions
     15        sprinkled throughout the code.
     16       
     17        * editing/markup.cpp:
     18        (WebCore::createFragmentFromMarkup):
     19        Revert back to unsafe plugin pasting regardless of caller's intentions when
     20        the settings allow it.
     21
     22        * dom/Element.cpp:
     23        (WebCore::Element::parserSetAttributes):
     24        * html/parser/HTMLConstructionSite.cpp:
     25        (WebCore::HTMLConstructionSite::insertScriptElement):
     26        * xml/parser/XMLDocumentParserLibxml2.cpp:
     27        (WebCore::XMLDocumentParser::endElementNs):
     28        * xml/parser/XMLDocumentParserQt.cpp:
     29        (WebCore::XMLDocumentParser::parseEndElement):
     30        Use new inline functions to check implications of permissions rather than raw
     31        comparisions.
     32       
     33        * html/parser/HTMLTreeBuilder.cpp:
     34        (WebCore::HTMLTreeBuilder::processStartTagForInBody):
     35        (WebCore::HTMLTreeBuilder::processEndTag):
     36        Check if plugin pasting is allowed before inserting applet/embed/oject elements.
     37
     38        * page/Settings.in:
     39        Declaration of new unsafePluginPastingEnabled setting.
     40
     41        * platform/mac/PasteboardMac.mm:
     42        (WebCore::Pasteboard::documentFragment):
     43        * platform/blackberry/PasteboardBlackBerry.cpp:
     44        (WebCore::Pasteboard::documentFragment):
     45        * platform/chromium/DragDataChromium.cpp:
     46        (WebCore::DragData::asFragment):
     47        * platform/chromium/PasteboardChromium.cpp:
     48        (WebCore::Pasteboard::documentFragment):
     49        * platform/gtk/PasteboardGtk.cpp:
     50        (WebCore::Pasteboard::documentFragment):
     51        * platform/qt/DragDataQt.cpp:
     52        (WebCore::DragData::asFragment):
     53        * platform/qt/PasteboardQt.cpp:
     54        (WebCore::Pasteboard::documentFragment):
     55        * platform/win/ClipboardUtilitiesWin.cpp:
     56        (WebCore::fragmentFromCFHTML):
     57        (WebCore::fragmentFromHTML):
     58        * platform/wx/PasteboardWx.cpp:
     59        (WebCore::Pasteboard::documentFragment):
     60        Pass DisallowScriptingAndPluginContent enum value.
     61       
    1622013-01-08  Alexis Menard  <alexis@webkit.org>
    263
  • trunk/Source/WebCore/dom/Element.cpp

    r139100 r139111  
    981981    // If the element is created as result of a paste or drag-n-drop operation
    982982    // we want to remove all the script and event handlers.
    983     if (scriptingPermission == DisallowScriptingContent) {
    984         unsigned i = 0;
     983    if (!scriptingContentIsAllowed(scriptingPermission)) {
     984        size_t i = 0;
    985985        while (i < filteredAttributes.size()) {
    986986            Attribute& attribute = filteredAttributes[i];
  • trunk/Source/WebCore/dom/FragmentScriptingPermission.h

    r117731 r139111  
    3232// generating DocumentFragments for paste in platform/*/Pasteboard.*.
    3333enum FragmentScriptingPermission {
     34    DisallowScriptingAndPluginContentIfNeeded,
    3435    DisallowScriptingContent,
    3536    AllowScriptingContent,
     
    3738};
    3839
    39 };
     40static inline bool scriptingContentIsAllowed(FragmentScriptingPermission scriptingPermission)
     41{
     42    return scriptingPermission == AllowScriptingContent || scriptingPermission == AllowScriptingContentAndDoNotMarkAlreadyStarted;
     43}
     44
     45static inline bool pluginContentIsAllowed(FragmentScriptingPermission scriptingPermission)
     46{
     47    return scriptingPermission != DisallowScriptingAndPluginContentIfNeeded;
     48}
     49
     50} // namespace WebCore
    4051
    4152#endif // FragmentScriptingPermission_h
  • trunk/Source/WebCore/editing/markup.cpp

    r138811 r139111  
    5555#include "Range.h"
    5656#include "RenderObject.h"
     57#include "Settings.h"
    5758#include "StylePropertySet.h"
    5859#include "StyleResolver.h"
     
    664665    RefPtr<HTMLBodyElement> fakeBody = HTMLBodyElement::create(document);
    665666    RefPtr<DocumentFragment> fragment = DocumentFragment::create(document);
     667
     668    if (scriptingPermission == DisallowScriptingAndPluginContentIfNeeded && (!document->settings() || document->settings()->unsafePluginPastingEnabled()))
     669        scriptingPermission = DisallowScriptingContent;
     670
    666671    fragment->parseHTML(markup, fakeBody.get(), scriptingPermission);
    667672
  • trunk/Source/WebCore/html/parser/HTMLConstructionSite.cpp

    r139042 r139111  
    347347    const bool alreadyStarted = m_isParsingFragment && parserInserted;
    348348    RefPtr<HTMLScriptElement> element = HTMLScriptElement::create(scriptTag, ownerDocumentForCurrentNode(), parserInserted, alreadyStarted);
    349     if (m_fragmentScriptingPermission != DisallowScriptingContent)
     349    if (scriptingContentIsAllowed(m_fragmentScriptingPermission))
    350350        element->parserSetAttributes(token->attributes(), m_fragmentScriptingPermission);
    351351    attachLater(currentNode(), element);
  • trunk/Source/WebCore/html/parser/HTMLTreeBuilder.cpp

    r139042 r139111  
    819819        m_tree.insertFormattingElement(token);
    820820        return;
     821    }
     822    if (token->name() == appletTag
     823        || token->name() == embedTag
     824        || token->name() == objectTag) {
     825        if (isParsingFragment() && !pluginContentIsAllowed(m_fragmentContext.scriptingPermission()))
     826            return;
    821827    }
    822828    if (token->name() == appletTag
     
    21822188            m_scriptToProcess = m_tree.currentElement();
    21832189            m_tree.openElements()->pop();
    2184             if (isParsingFragment() && m_fragmentContext.scriptingPermission() == DisallowScriptingContent)
     2190            if (isParsingFragment() && !scriptingContentIsAllowed(m_fragmentContext.scriptingPermission()))
    21852191                m_scriptToProcess->removeAllChildren();
    21862192            setInsertionMode(m_originalInsertionMode);
  • trunk/Source/WebCore/page/Settings.in

    r139026 r139111  
    8383
    8484xssAuditorEnabled initial=false
     85unsafePluginPastingEnabled initial=true
    8586acceleratedCompositingFor3DTransformsEnabled initial=true
    8687acceleratedCompositingForVideoEnabled initial=true
  • trunk/Source/WebCore/platform/blackberry/PasteboardBlackBerry.cpp

    r131316 r139111  
    9898    if (!html.isEmpty()) {
    9999        String url = BlackBerry::Platform::Clipboard::readURL();
    100         if (fragment = createFragmentFromMarkup(frame->document(), html, url, DisallowScriptingContent))
     100        if (fragment = createFragmentFromMarkup(frame->document(), html, url, DisallowScriptingAndPluginContentIfNeeded))
    101101            return fragment.release();
    102102    }
  • trunk/Source/WebCore/platform/chromium/DragDataChromium.cpp

    r127757 r139111  
    3333#include "ChromiumDataObject.h"
    3434#include "ClipboardMimeTypes.h"
     35#include "Document.h"
    3536#include "DocumentFragment.h"
    3637#include "FileSystem.h"
     
    154155        KURL baseURL;
    155156        m_platformDragData->htmlAndBaseURL(html, baseURL);
    156         RefPtr<DocumentFragment> fragment = createFragmentFromMarkup(frame->document(), html, baseURL, DisallowScriptingContent);
    157         return fragment.release();
     157        if (RefPtr<DocumentFragment> fragment = createFragmentFromMarkup(frame->document(), html, baseURL, DisallowScriptingAndPluginContentIfNeeded))
     158            return fragment.release();
    158159    }
    159160
  • trunk/Source/WebCore/platform/chromium/PasteboardChromium.cpp

    r125247 r139111  
    183183
    184184    if (WebKit::Platform::current()->clipboard()->isFormatAvailable(WebKit::WebClipboard::FormatHTML, buffer)) {
    185         WebKit::WebString markup;
    186185        unsigned fragmentStart = 0;
    187186        unsigned fragmentEnd = 0;
    188187        WebKit::WebURL url;
    189         markup = WebKit::Platform::current()->clipboard()->readHTML(buffer, &url, &fragmentStart, &fragmentEnd);
     188        WebKit::WebString markup = WebKit::Platform::current()->clipboard()->readHTML(buffer, &url, &fragmentStart, &fragmentEnd);
    190189        if (!markup.isEmpty()) {
    191           RefPtr<DocumentFragment> fragment =
    192               createFragmentFromMarkupWithContext(frame->document(), markup, fragmentStart, fragmentEnd, KURL(url), DisallowScriptingContent);
    193           if (fragment)
    194               return fragment.release();
     190            if (RefPtr<DocumentFragment> fragment = createFragmentFromMarkupWithContext(frame->document(), markup, fragmentStart, fragmentEnd, KURL(url), DisallowScriptingAndPluginContentIfNeeded))
     191                return fragment.release();
    195192        }
    196193    }
     
    200197        if (!markup.isEmpty()) {
    201198            chosePlainText = true;
    202 
    203             RefPtr<DocumentFragment> fragment =
    204                 createFragmentFromText(context.get(), markup);
    205             if (fragment)
     199            if (RefPtr<DocumentFragment> fragment = createFragmentFromText(context.get(), markup))
    206200                return fragment.release();
    207201        }
  • trunk/Source/WebCore/platform/gtk/PasteboardGtk.cpp

    r127862 r139111  
    172172
    173173    if (dataObject->hasMarkup()) {
    174         RefPtr<DocumentFragment> fragment = createFragmentFromMarkup(frame->document(), dataObject->markup(), "", DisallowScriptingContent);
     174        RefPtr<DocumentFragment> fragment = createFragmentFromMarkup(frame->document(), dataObject->markup(), "", DisallowScriptingAndPluginContentIfNeeded);
    175175        if (fragment)
    176176            return fragment.release();
  • trunk/Source/WebCore/platform/mac/PasteboardMac.mm

    r130947 r139111  
    467467                    if (DocumentLoader* loader = frame->loader()->documentLoader())
    468468                        loader->addAllArchiveResources(coreArchive.get());
    469                    
    470                     fragment = createFragmentFromMarkup(frame->document(), markupString, mainResource->url(), DisallowScriptingContent);
     469
     470                    fragment = createFragmentFromMarkup(frame->document(), markupString, mainResource->url(), DisallowScriptingAndPluginContentIfNeeded);
    471471                    [markupString release];
    472472                } else if (MIMETypeRegistry::isSupportedImageMIMEType(MIMEType))
     
    507507        }
    508508        if ([HTMLString length] != 0 &&
    509             (fragment = createFragmentFromMarkup(frame->document(), HTMLString, "", DisallowScriptingContent)))
     509            (fragment = createFragmentFromMarkup(frame->document(), HTMLString, "", DisallowScriptingAndPluginContentIfNeeded)))
    510510            return fragment.release();
    511511    }
  • trunk/Source/WebCore/platform/qt/DragDataQt.cpp

    r117731 r139111  
    138138{
    139139    if (m_platformDragData && m_platformDragData->hasHtml())
    140         return createFragmentFromMarkup(frame->document(), m_platformDragData->html(), "", DisallowScriptingContent);
     140        return createFragmentFromMarkup(frame->document(), m_platformDragData->html(), "", DisallowScriptingAndPluginContentIfNeeded);
    141141
    142142    return 0;
  • trunk/Source/WebCore/platform/qt/PasteboardQt.cpp

    r130636 r139111  
    112112        QString html = mimeData->html();
    113113        if (!html.isEmpty()) {
    114             RefPtr<DocumentFragment> fragment = createFragmentFromMarkup(frame->document(), html, "", DisallowScriptingContent);
     114            RefPtr<DocumentFragment> fragment = createFragmentFromMarkup(frame->document(), html, "", DisallowScriptingAndPluginContentIfNeeded);
    115115            if (fragment)
    116116                return fragment.release();
  • trunk/Source/WebCore/platform/win/ClipboardUtilitiesWin.cpp

    r135763 r139111  
    642642
    643643    String markup = extractMarkupFromCFHTML(cfhtml);
    644     return createFragmentFromMarkup(doc, markup, srcURL, DisallowScriptingContent);
     644    return createFragmentFromMarkup(doc, markup, srcURL, DisallowScriptingAndPluginContentIfNeeded);
    645645}
    646646
     
    659659    String srcURL;
    660660    if (!html.isEmpty())
    661         return createFragmentFromMarkup(doc, html, srcURL, DisallowScriptingContent);
     661        return createFragmentFromMarkup(doc, html, srcURL, DisallowScriptingAndPluginContentIfNeeded);
    662662
    663663    return 0;
     
    677677    String srcURL;
    678678    if (getDataMapItem(data, texthtmlFormat(), stringData))
    679         return createFragmentFromMarkup(document, stringData, srcURL, DisallowScriptingContent);
     679        return createFragmentFromMarkup(document, stringData, srcURL, DisallowScriptingAndPluginContentIfNeeded);
    680680
    681681    return 0;
  • trunk/Source/WebCore/platform/wx/PasteboardWx.cpp

    r127757 r139111  
    100100            wxTheClipboard->GetData(data);
    101101            chosePlainText = false;
    102             fragment = createFragmentFromMarkup(frame->document(), data.GetHTML(), "", DisallowScriptingContent);
     102            fragment = createFragmentFromMarkup(frame->document(), data.GetHTML(), "", DisallowScriptingAndPluginContentIfNeeded);
    103103        } else
    104104#endif
  • trunk/Source/WebCore/xml/parser/XMLDocumentParserLibxml2.cpp

    r138863 r139111  
    853853        setDepthTriggeringEntityExpansion(-1);
    854854
    855     if (m_scriptingPermission == DisallowScriptingContent && n->isElementNode() && toScriptElement(static_cast<Element*>(n.get()))) {
     855    if (!scriptingContentIsAllowed(m_scriptingPermission) && n->isElementNode() && toScriptElement(static_cast<Element*>(n.get()))) {
    856856        popCurrentNode();
    857857        ExceptionCode ec;
  • trunk/Source/WebCore/xml/parser/XMLDocumentParserQt.cpp

    r138863 r139111  
    507507    n->finishParsingChildren();
    508508
    509     if (m_scriptingPermission == DisallowScriptingContent && n->isElementNode() && toScriptElement(static_cast<Element*>(n.get()))) {
     509    if (!scriptingContentIsAllowed(m_scriptingPermission) && n->isElementNode() && toScriptElement(static_cast<Element*>(n.get()))) {
    510510        popCurrentNode();
    511511        ExceptionCode ec;
  • trunk/Source/WebKit/chromium/ChangeLog

    r139078 r139111  
     12013-01-08  Tom Sepez  <tsepez@chromium.org>
     2
     3        Copy-paste preserves <embed> tags containing active content.
     4        https://bugs.webkit.org/show_bug.cgi?id=77625
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        Adds chromium API to new unsafePluginPastingEnabled setting.
     9
     10        * public/WebSettings.h:
     11        * src/WebSettingsImpl.cpp:
     12        (WebKit::WebSettingsImpl::setUnsafePluginPastingEnabled):
     13        (WebKit):
     14        * src/WebSettingsImpl.h:
     15        (WebSettingsImpl):
     16
    1172013-01-08  Mark Lam  <mark.lam@apple.com>
    218
  • trunk/Source/WebKit/chromium/public/WebSettings.h

    r139028 r139111  
    162162    virtual void setTouchDragDropEnabled(bool) = 0;
    163163    virtual void setUnifiedTextCheckerEnabled(bool) = 0;
     164    virtual void setUnsafePluginPastingEnabled(bool) = 0;
    164165    virtual void setUserStyleSheetLocation(const WebURL&) = 0;
    165166    virtual void setUsesEncodingDetector(bool) = 0;
  • trunk/Source/WebKit/chromium/src/WebSettingsImpl.cpp

    r139028 r139111  
    294294}
    295295
     296void WebSettingsImpl::setUnsafePluginPastingEnabled(bool enabled)
     297{
     298    m_settings->setUnsafePluginPastingEnabled(enabled);
     299}
     300
    296301void WebSettingsImpl::setDNSPrefetchingEnabled(bool enabled)
    297302{
  • trunk/Source/WebKit/chromium/src/WebSettingsImpl.h

    r139028 r139111  
    159159    virtual void setTouchDragDropEnabled(bool);
    160160    virtual void setUnifiedTextCheckerEnabled(bool);
     161    virtual void setUnsafePluginPastingEnabled(bool);
    161162    virtual void setUserStyleSheetLocation(const WebURL&);
    162163    virtual void setUsesEncodingDetector(bool);
Note: See TracChangeset for help on using the changeset viewer.