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

Unified Diff: Source/core/dom/Document.cpp

Issue 1155353002: Throw DOMException when invoked Document::execCommand on non-{X,}HTML documents (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: revert accidental edit Created 5 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/dom/Document.h ('k') | Source/core/dom/Document.idl » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/dom/Document.cpp
diff --git a/Source/core/dom/Document.cpp b/Source/core/dom/Document.cpp
index 582f900a5af515086f2eb2c6b5a9b5a57e19353b..b6e91f24d5543f0f9a7d752612536bf4db254e34 100644
--- a/Source/core/dom/Document.cpp
+++ b/Source/core/dom/Document.cpp
@@ -4245,8 +4245,13 @@ static Editor::Command command(Document* document, const String& commandName)
return frame->editor().command(commandName, CommandFromDOM);
}
-bool Document::execCommand(const String& commandName, bool, const String& value)
+bool Document::execCommand(const String& commandName, bool, const String& value, ExceptionState& exceptionState)
{
+ if (!isHTMLDocument() && !isXHTMLDocument()) {
+ exceptionState.throwDOMException(InvalidStateError, "execCommand is only supported on HTML documents.");
+ return false;
+ }
+
// We don't allow recursive |execCommand()| to protect against attack code.
// Recursive call of |execCommand()| could be happened by moving iframe
// with script triggered by insertion, e.g. <iframe src="javascript:...">
@@ -4268,28 +4273,53 @@ bool Document::execCommand(const String& commandName, bool, const String& value)
return editorCommand.execute(value);
}
-bool Document::queryCommandEnabled(const String& commandName)
+bool Document::queryCommandEnabled(const String& commandName, ExceptionState& exceptionState)
{
+ if (!isHTMLDocument() && !isXHTMLDocument()) {
+ exceptionState.throwDOMException(InvalidStateError, "queryCommandEnabled is only supported on HTML documents.");
+ return false;
+ }
+
return command(this, commandName).isEnabled();
}
-bool Document::queryCommandIndeterm(const String& commandName)
+bool Document::queryCommandIndeterm(const String& commandName, ExceptionState& exceptionState)
{
+ if (!isHTMLDocument() && !isXHTMLDocument()) {
+ exceptionState.throwDOMException(InvalidStateError, "queryCommandIndeterm is only supported on HTML documents.");
+ return false;
+ }
+
return command(this, commandName).state() == MixedTriState;
}
-bool Document::queryCommandState(const String& commandName)
+bool Document::queryCommandState(const String& commandName, ExceptionState& exceptionState)
{
+ if (!isHTMLDocument() && !isXHTMLDocument()) {
+ exceptionState.throwDOMException(InvalidStateError, "queryCommandState is only supported on HTML documents.");
+ return false;
+ }
+
return command(this, commandName).state() == TrueTriState;
}
-bool Document::queryCommandSupported(const String& commandName)
+bool Document::queryCommandSupported(const String& commandName, ExceptionState& exceptionState)
{
+ if (!isHTMLDocument() && !isXHTMLDocument()) {
+ exceptionState.throwDOMException(InvalidStateError, "queryCommandSupported is only supported on HTML documents.");
+ return false;
+ }
+
return command(this, commandName).isSupported();
}
-String Document::queryCommandValue(const String& commandName)
+String Document::queryCommandValue(const String& commandName, ExceptionState& exceptionState)
{
+ if (!isHTMLDocument() && !isXHTMLDocument()) {
+ exceptionState.throwDOMException(InvalidStateError, "queryCommandValue is only supported on HTML documents.");
+ return "";
+ }
+
return command(this, commandName).value();
}
« no previous file with comments | « Source/core/dom/Document.h ('k') | Source/core/dom/Document.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698