Bug 1577969 - Get rid of nsIHTMLEditor.getLinkedObject and nsIURIRefObject. r=masayuki

Since bug 1577443 is landed in comm-central, no one uses `nsIHTMLEditor.getLinkedObject`.

Differential Revision: https://phabricator.services.mozilla.com/D44361

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Makoto Kato 2019-09-02 12:15:41 +00:00
parent 06950779ab
commit 9d24379b0f
7 changed files with 0 additions and 390 deletions

View File

@ -25,7 +25,6 @@
#include "HTMLEditorEventListener.h"
#include "HTMLEditRules.h"
#include "HTMLEditUtils.h"
#include "HTMLURIRefObject.h"
#include "TextEditUtils.h"
#include "TypeInState.h"
@ -38,7 +37,6 @@
#include "mozilla/css/Loader.h"
#include "nsIContent.h"
#include "nsIMutableArray.h"
#include "nsContentUtils.h"
#include "nsIDocumentEncoder.h"
#include "nsGenericHTMLElement.h"
@ -3047,39 +3045,6 @@ nsresult HTMLEditor::SetHTMLBackgroundColorWithTransaction(
*rootElementOfBackgroundColor, *nsGkAtoms::bgcolor);
}
NS_IMETHODIMP
HTMLEditor::GetLinkedObjects(nsIArray** aNodeList) {
NS_ENSURE_TRUE(aNodeList, NS_ERROR_NULL_POINTER);
nsresult rv;
nsCOMPtr<nsIMutableArray> nodes = do_CreateInstance(NS_ARRAY_CONTRACTID, &rv);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
RefPtr<Document> doc = GetDocument();
NS_ENSURE_TRUE(doc, NS_ERROR_UNEXPECTED);
PostContentIterator postOrderIter;
postOrderIter.Init(doc->GetRootElement());
// loop through the content iterator for each content node
for (; !postOrderIter.IsDone(); postOrderIter.Next()) {
nsCOMPtr<nsINode> node = postOrderIter.GetCurrentNode();
if (node) {
// Let nsURIRefObject make the hard decisions:
nsCOMPtr<nsIURIRefObject> refObject;
rv = NS_NewHTMLURIRefObject(getter_AddRefs(refObject), node);
if (NS_SUCCEEDED(rv)) {
nodes->AppendElement(refObject);
}
}
}
nodes.forget(aNodeList);
return NS_OK;
}
NS_IMETHODIMP
HTMLEditor::AddOverrideStyleSheet(const nsAString& aURL) {
AutoEditActionDataSetter editActionData(*this,

View File

@ -1,252 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* Here is the list, from beppe and glazman:
href >> A, AREA, BASE, LINK
src >> FRAME, IFRAME, IMG, INPUT, SCRIPT
<META http-equiv="refresh" content="3,http://www.acme.com/intro.html">
longdesc >> FRAME, IFRAME, IMG
usemap >> IMG, INPUT, OBJECT
action >> FORM
background >> BODY
codebase >> OBJECT, APPLET
classid >> OBJECT
data >> OBJECT
cite >> BLOCKQUOTE, DEL, INS, Q
profile >> HEAD
ARCHIVE attribute on APPLET ; warning, it contains a list of URIs.
Easier way of organizing the list:
a: href
area: href
base: href
body: background
blockquote: cite (not normally rewritable)
link: href
frame: src, longdesc
iframe: src, longdesc
input: src, usemap
form: action
img: src, longdesc, usemap
script: src
applet: codebase, archive <list>
object: codebase, data, classid, usemap
head: profile
del: cite
ins: cite
q: cite
*/
#include "HTMLURIRefObject.h"
#include "mozilla/mozalloc.h"
#include "mozilla/dom/Attr.h"
#include "mozilla/dom/Element.h"
#include "nsAString.h"
#include "nsDebug.h"
#include "nsDOMAttributeMap.h"
#include "nsError.h"
#include "nsID.h"
#include "nsINode.h"
#include "nsISupportsUtils.h"
#include "nsString.h"
#include "nsGkAtoms.h"
namespace mozilla {
// String classes change too often and I can't keep up.
// Set this macro to this week's approved case-insensitive compare routine.
#define MATCHES(tagName, str) tagName.EqualsIgnoreCase(str)
HTMLURIRefObject::HTMLURIRefObject()
: mCurAttrIndex(0), mAttributeCnt(0), mAttrsInited(false) {}
HTMLURIRefObject::~HTMLURIRefObject() {}
// Interfaces for addref and release and queryinterface
NS_IMPL_ISUPPORTS(HTMLURIRefObject, nsIURIRefObject)
NS_IMETHODIMP
HTMLURIRefObject::Reset() {
mCurAttrIndex = 0;
return NS_OK;
}
NS_IMETHODIMP
HTMLURIRefObject::GetNextURI(nsAString& aURI) {
NS_ENSURE_TRUE(mNode, NS_ERROR_NOT_INITIALIZED);
if (NS_WARN_IF(!mNode->IsElement())) {
return NS_ERROR_INVALID_ARG;
}
RefPtr<dom::Element> element = mNode->AsElement();
// Loop over attribute list:
if (!mAttrsInited) {
mAttrsInited = true;
mAttributeCnt = element->GetAttrCount();
NS_ENSURE_TRUE(mAttributeCnt, NS_ERROR_FAILURE);
mCurAttrIndex = 0;
}
while (mCurAttrIndex < mAttributeCnt) {
BorrowedAttrInfo attrInfo = element->GetAttrInfoAt(mCurAttrIndex++);
NS_ENSURE_ARG_POINTER(attrInfo.mName);
// href >> A, AREA, BASE, LINK
if (attrInfo.mName->Equals(nsGkAtoms::href)) {
if (!element->IsAnyOfHTMLElements(nsGkAtoms::a, nsGkAtoms::area,
nsGkAtoms::base, nsGkAtoms::link)) {
continue;
}
attrInfo.mValue->ToString(aURI);
// href pointing to a named anchor doesn't count
if (StringBeginsWith(aURI, NS_LITERAL_STRING("#"))) {
aURI.Truncate();
return NS_ERROR_INVALID_ARG;
}
return NS_OK;
}
// src >> FRAME, IFRAME, IMG, INPUT, SCRIPT
else if (attrInfo.mName->Equals(nsGkAtoms::src)) {
if (!element->IsAnyOfHTMLElements(nsGkAtoms::img, nsGkAtoms::frame,
nsGkAtoms::iframe, nsGkAtoms::input,
nsGkAtoms::script)) {
continue;
}
attrInfo.mValue->ToString(aURI);
return NS_OK;
}
//<META http-equiv="refresh" content="3,http://www.acme.com/intro.html">
else if (attrInfo.mName->Equals(nsGkAtoms::content)) {
if (!element->IsHTMLElement(nsGkAtoms::meta)) {
continue;
}
// XXXbz And if it is?
}
// longdesc >> FRAME, IFRAME, IMG
else if (attrInfo.mName->Equals(nsGkAtoms::longdesc)) {
if (!element->IsAnyOfHTMLElements(nsGkAtoms::img, nsGkAtoms::frame,
nsGkAtoms::iframe)) {
continue;
}
// XXXbz And if it is?
}
// usemap >> IMG, INPUT, OBJECT
else if (attrInfo.mName->Equals(nsGkAtoms::usemap)) {
if (!element->IsAnyOfHTMLElements(nsGkAtoms::img, nsGkAtoms::input,
nsGkAtoms::object)) {
continue;
}
}
// action >> FORM
else if (attrInfo.mName->Equals(nsGkAtoms::action)) {
if (!element->IsHTMLElement(nsGkAtoms::form)) {
continue;
}
// XXXbz And if it is?
}
// background >> BODY
else if (attrInfo.mName->Equals(nsGkAtoms::background)) {
if (!element->IsHTMLElement(nsGkAtoms::body)) {
continue;
}
// XXXbz And if it is?
}
// codebase >> OBJECT
else if (attrInfo.mName->Equals(nsGkAtoms::codebase)) {
if (!element->IsHTMLElement(nsGkAtoms::object)) {
continue;
}
// XXXbz And if it is?
}
// classid >> OBJECT
else if (attrInfo.mName->Equals(nsGkAtoms::classid)) {
if (!element->IsHTMLElement(nsGkAtoms::object)) {
continue;
}
// XXXbz And if it is?
}
// data >> OBJECT
else if (attrInfo.mName->Equals(nsGkAtoms::data)) {
if (!element->IsHTMLElement(nsGkAtoms::object)) {
continue;
}
// XXXbz And if it is?
}
// cite >> BLOCKQUOTE, DEL, INS, Q
else if (attrInfo.mName->Equals(nsGkAtoms::cite)) {
if (!element->IsAnyOfHTMLElements(nsGkAtoms::blockquote, nsGkAtoms::q,
nsGkAtoms::del, nsGkAtoms::ins)) {
continue;
}
// XXXbz And if it is?
}
// profile >> HEAD
else if (attrInfo.mName->Equals(nsGkAtoms::profile)) {
if (!element->IsHTMLElement(nsGkAtoms::head)) {
continue;
}
// XXXbz And if it is?
}
}
// Return a code to indicate that there are no more,
// to distinguish that case from real errors.
return NS_ERROR_NOT_AVAILABLE;
}
NS_IMETHODIMP
HTMLURIRefObject::RewriteAllURIs(const nsAString& aOldPat,
const nsAString& aNewPat, bool aMakeRel) {
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
HTMLURIRefObject::GetNode(nsINode** aNode) {
NS_ENSURE_TRUE(mNode, NS_ERROR_NOT_INITIALIZED);
NS_ENSURE_TRUE(aNode, NS_ERROR_NULL_POINTER);
*aNode = do_AddRef(mNode).take();
return NS_OK;
}
NS_IMETHODIMP
HTMLURIRefObject::SetNode(nsINode* aNode) {
mNode = aNode;
nsAutoString dummyURI;
if (NS_SUCCEEDED(GetNextURI(dummyURI))) {
mCurAttrIndex = 0; // Reset so we'll get the first node next time
return NS_OK;
}
// If there weren't any URIs in the attributes,
// then don't accept this node.
mNode = nullptr;
return NS_ERROR_INVALID_ARG;
}
} // namespace mozilla
nsresult NS_NewHTMLURIRefObject(nsIURIRefObject** aResult, nsINode* aNode) {
RefPtr<mozilla::HTMLURIRefObject> refObject = new mozilla::HTMLURIRefObject();
nsresult rv = refObject->SetNode(aNode);
if (NS_FAILED(rv)) {
*aResult = 0;
return rv;
}
refObject.forget(aResult);
return NS_OK;
}

View File

@ -1,49 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef HTMLURIRefObject_h
#define HTMLURIRefObject_h
#include "nsCOMPtr.h"
#include "nsISupportsImpl.h"
#include "nsIURIRefObject.h"
#include "nscore.h"
#include "mozilla/RefPtr.h"
#define NS_URI_REF_OBJECT_CID \
{ /* {bdd79df6-1dd1-11b2-b29c-c3d63a58f1d2} */ \
0xbdd79df6, 0x1dd1, 0x11b2, { \
0xb2, 0x9c, 0xc3, 0xd6, 0x3a, 0x58, 0xf1, 0xd2 \
} \
}
class nsDOMAttributeMap;
class nsINode;
namespace mozilla {
class HTMLURIRefObject final : public nsIURIRefObject {
public:
HTMLURIRefObject();
// Interfaces for addref and release and queryinterface
NS_DECL_ISUPPORTS
NS_DECL_NSIURIREFOBJECT
protected:
virtual ~HTMLURIRefObject();
nsCOMPtr<nsINode> mNode;
uint32_t mCurAttrIndex;
uint32_t mAttributeCnt;
bool mAttrsInited;
};
} // namespace mozilla
nsresult NS_NewHTMLURIRefObject(nsIURIRefObject** aResult, nsINode* aNode);
#endif // #ifndef HTMLURIRefObject_h

View File

@ -62,7 +62,6 @@ UNIFIED_SOURCES += [
'HTMLInlineTableEditor.cpp',
'HTMLStyleEditor.cpp',
'HTMLTableEditor.cpp',
'HTMLURIRefObject.cpp',
'InsertNodeTransaction.cpp',
'InsertTextTransaction.cpp',
'InternetCiter.cpp',

View File

@ -25,7 +25,6 @@ XPIDL_SOURCES += [
'nsIHTMLObjectResizer.idl',
'nsIPlaintextEditor.idl',
'nsITableEditor.idl',
'nsIURIRefObject.idl',
]
XPIDL_MODULE = 'editor'

View File

@ -7,7 +7,6 @@
#include "domstubs.idl"
interface nsIContent;
interface nsIArray;
webidl Document;
webidl Element;
@ -389,15 +388,6 @@ interface nsIHTMLEditor : nsISupports
[can_run_script]
void setBackgroundColor(in AString aColor);
/**
* Find all the nodes in the document which contain references
* to outside URIs (e.g. a href, img src, script src, etc.)
* The objects in the array will be type nsIURIRefObject.
*
* @return aNodeList the linked nodes found
*/
nsIArray getLinkedObjects();
/**
* A boolean which is true is the HTMLEditor has been instantiated
* with CSS knowledge and if the CSS pref is currently checked

View File

@ -1,42 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsISupports.idl"
#include "domstubs.idl"
webidl Node;
/** A class which can represent any node which points to an
* external URI, e.g. <a>, <img>, <script> etc,
* and has the capability to rewrite URLs to be
* relative or absolute.
* Used by the editor but not dependant on it.
*/
[scriptable, uuid(2226927e-1dd2-11b2-b57f-faab47288563)]
interface nsIURIRefObject : nsISupports
{
attribute Node node;
/**
* Go back to the beginning of the attribute list.
*/
void Reset();
/**
* Return the next rewritable URI.
*/
AString GetNextURI();
/**
* Go back to the beginning of the attribute list
*
* @param aOldPat Old pattern to be replaced, e.g. file:///a/b/
* @param aNewPat New pattern to be replaced, e.g. http://mypage.aol.com/
* @param aMakeRel Rewrite links as relative vs. absolute
*/
void RewriteAllURIs(in AString aOldPat, in AString aNewPat,
in boolean aMakeRel);
};