OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
4 * (C) 2001 Dirk Mueller (mueller@kde.org) | 4 * (C) 2001 Dirk Mueller (mueller@kde.org) |
5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org) | 5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org) |
6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All | 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All |
7 * rights reserved. | 7 * rights reserved. |
8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. | 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. |
9 * (http://www.torchmobile.com/) | 9 * (http://www.torchmobile.com/) |
10 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved. | 10 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved. |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 #include "core/dom/custom/CustomElement.h" | 114 #include "core/dom/custom/CustomElement.h" |
115 #include "core/dom/custom/CustomElementDefinition.h" | 115 #include "core/dom/custom/CustomElementDefinition.h" |
116 #include "core/dom/custom/CustomElementDescriptor.h" | 116 #include "core/dom/custom/CustomElementDescriptor.h" |
117 #include "core/dom/custom/CustomElementRegistry.h" | 117 #include "core/dom/custom/CustomElementRegistry.h" |
118 #include "core/dom/custom/V0CustomElementMicrotaskRunQueue.h" | 118 #include "core/dom/custom/V0CustomElementMicrotaskRunQueue.h" |
119 #include "core/dom/custom/V0CustomElementRegistrationContext.h" | 119 #include "core/dom/custom/V0CustomElementRegistrationContext.h" |
120 #include "core/dom/shadow/ElementShadow.h" | 120 #include "core/dom/shadow/ElementShadow.h" |
121 #include "core/dom/shadow/FlatTreeTraversal.h" | 121 #include "core/dom/shadow/FlatTreeTraversal.h" |
122 #include "core/dom/shadow/ShadowRoot.h" | 122 #include "core/dom/shadow/ShadowRoot.h" |
123 #include "core/editing/EditingUtilities.h" | 123 #include "core/editing/EditingUtilities.h" |
124 #include "core/editing/Editor.h" | |
125 #include "core/editing/FrameSelection.h" | 124 #include "core/editing/FrameSelection.h" |
126 #include "core/editing/markers/DocumentMarkerController.h" | 125 #include "core/editing/markers/DocumentMarkerController.h" |
127 #include "core/editing/serializers/Serialization.h" | 126 #include "core/editing/serializers/Serialization.h" |
128 #include "core/editing/spellcheck/SpellChecker.h" | 127 #include "core/editing/spellcheck/SpellChecker.h" |
129 #include "core/events/BeforeUnloadEvent.h" | 128 #include "core/events/BeforeUnloadEvent.h" |
130 #include "core/events/Event.h" | 129 #include "core/events/Event.h" |
131 #include "core/events/EventFactory.h" | 130 #include "core/events/EventFactory.h" |
132 #include "core/events/EventListener.h" | 131 #include "core/events/EventListener.h" |
133 #include "core/events/HashChangeEvent.h" | 132 #include "core/events/HashChangeEvent.h" |
134 #include "core/events/PageTransitionEvent.h" | 133 #include "core/events/PageTransitionEvent.h" |
(...skipping 4817 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4952 const KURL& aboutBlankURL = blankURL(); | 4951 const KURL& aboutBlankURL = blankURL(); |
4953 shouldUseParentBaseURL = (baseURLOverride == aboutBlankURL); | 4952 shouldUseParentBaseURL = (baseURLOverride == aboutBlankURL); |
4954 } | 4953 } |
4955 if (shouldUseParentBaseURL) { | 4954 if (shouldUseParentBaseURL) { |
4956 if (Document* parent = parentDocument()) | 4955 if (Document* parent = parentDocument()) |
4957 baseURLFromParent = &parent->baseURL(); | 4956 baseURLFromParent = &parent->baseURL(); |
4958 } | 4957 } |
4959 return baseURLFromParent ? *baseURLFromParent : baseURLOverride; | 4958 return baseURLFromParent ? *baseURLFromParent : baseURLOverride; |
4960 } | 4959 } |
4961 | 4960 |
4962 // Support for Javascript execCommand, and related methods | |
4963 | |
4964 static Editor::Command command(Document* document, const String& commandName) { | |
4965 LocalFrame* frame = document->frame(); | |
4966 if (!frame || frame->document() != document) | |
4967 return Editor::Command(); | |
4968 | |
4969 document->updateStyleAndLayoutTree(); | |
4970 return frame->editor().createCommandFromDOM(commandName); | |
4971 } | |
4972 | |
4973 bool Document::execCommand(const String& commandName, | |
4974 bool, | |
4975 const String& value, | |
4976 ExceptionState& exceptionState) { | |
4977 if (!isHTMLDocument() && !isXHTMLDocument()) { | |
4978 exceptionState.throwDOMException( | |
4979 InvalidStateError, "execCommand is only supported on HTML documents."); | |
4980 return false; | |
4981 } | |
4982 if (focusedElement() && isTextControlElement(*focusedElement())) | |
4983 UseCounter::count(*this, UseCounter::ExecCommandOnInputOrTextarea); | |
4984 | |
4985 // We don't allow recursive |execCommand()| to protect against attack code. | |
4986 // Recursive call of |execCommand()| could be happened by moving iframe | |
4987 // with script triggered by insertion, e.g. <iframe src="javascript:..."> | |
4988 // <iframe onload="...">. This usage is valid as of the specification | |
4989 // although, it isn't common use case, rather it is used as attack code. | |
4990 if (m_isRunningExecCommand) { | |
4991 String message = | |
4992 "We don't execute document.execCommand() this time, because it is " | |
4993 "called recursively."; | |
4994 addConsoleMessage( | |
4995 ConsoleMessage::create(JSMessageSource, WarningMessageLevel, message)); | |
4996 return false; | |
4997 } | |
4998 AutoReset<bool> executeScope(&m_isRunningExecCommand, true); | |
4999 | |
5000 // Postpone DOM mutation events, which can execute scripts and change | |
5001 // DOM tree against implementation assumption. | |
5002 EventQueueScope eventQueueScope; | |
5003 Editor::tidyUpHTMLStructure(*this); | |
5004 Editor::Command editorCommand = command(this, commandName); | |
5005 | |
5006 DEFINE_STATIC_LOCAL(SparseHistogram, editorCommandHistogram, | |
5007 ("WebCore.Document.execCommand")); | |
5008 editorCommandHistogram.sample(editorCommand.idForHistogram()); | |
5009 return editorCommand.execute(value); | |
5010 } | |
5011 | |
5012 bool Document::queryCommandEnabled(const String& commandName, | |
5013 ExceptionState& exceptionState) { | |
5014 if (!isHTMLDocument() && !isXHTMLDocument()) { | |
5015 exceptionState.throwDOMException( | |
5016 InvalidStateError, | |
5017 "queryCommandEnabled is only supported on HTML documents."); | |
5018 return false; | |
5019 } | |
5020 | |
5021 return command(this, commandName).isEnabled(); | |
5022 } | |
5023 | |
5024 bool Document::queryCommandIndeterm(const String& commandName, | |
5025 ExceptionState& exceptionState) { | |
5026 if (!isHTMLDocument() && !isXHTMLDocument()) { | |
5027 exceptionState.throwDOMException( | |
5028 InvalidStateError, | |
5029 "queryCommandIndeterm is only supported on HTML documents."); | |
5030 return false; | |
5031 } | |
5032 | |
5033 return command(this, commandName).state() == MixedTriState; | |
5034 } | |
5035 | |
5036 bool Document::queryCommandState(const String& commandName, | |
5037 ExceptionState& exceptionState) { | |
5038 if (!isHTMLDocument() && !isXHTMLDocument()) { | |
5039 exceptionState.throwDOMException( | |
5040 InvalidStateError, | |
5041 "queryCommandState is only supported on HTML documents."); | |
5042 return false; | |
5043 } | |
5044 | |
5045 return command(this, commandName).state() == TrueTriState; | |
5046 } | |
5047 | |
5048 bool Document::queryCommandSupported(const String& commandName, | |
5049 ExceptionState& exceptionState) { | |
5050 if (!isHTMLDocument() && !isXHTMLDocument()) { | |
5051 exceptionState.throwDOMException( | |
5052 InvalidStateError, | |
5053 "queryCommandSupported is only supported on HTML documents."); | |
5054 return false; | |
5055 } | |
5056 | |
5057 return command(this, commandName).isSupported(); | |
5058 } | |
5059 | |
5060 String Document::queryCommandValue(const String& commandName, | |
5061 ExceptionState& exceptionState) { | |
5062 if (!isHTMLDocument() && !isXHTMLDocument()) { | |
5063 exceptionState.throwDOMException( | |
5064 InvalidStateError, | |
5065 "queryCommandValue is only supported on HTML documents."); | |
5066 return ""; | |
5067 } | |
5068 | |
5069 return command(this, commandName).value(); | |
5070 } | |
5071 | |
5072 KURL Document::openSearchDescriptionURL() { | 4961 KURL Document::openSearchDescriptionURL() { |
5073 static const char openSearchMIMEType[] = | 4962 static const char openSearchMIMEType[] = |
5074 "application/opensearchdescription+xml"; | 4963 "application/opensearchdescription+xml"; |
5075 static const char openSearchRelation[] = "search"; | 4964 static const char openSearchRelation[] = "search"; |
5076 | 4965 |
5077 // FIXME: Why do only top-level frames have openSearchDescriptionURLs? | 4966 // FIXME: Why do only top-level frames have openSearchDescriptionURLs? |
5078 if (!frame() || frame()->tree().parent()) | 4967 if (!frame() || frame()->tree().parent()) |
5079 return KURL(); | 4968 return KURL(); |
5080 | 4969 |
5081 // FIXME: Why do we need to wait for load completion? | 4970 // FIXME: Why do we need to wait for load completion? |
(...skipping 1501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6583 } | 6472 } |
6584 | 6473 |
6585 void showLiveDocumentInstances() { | 6474 void showLiveDocumentInstances() { |
6586 WeakDocumentSet& set = liveDocumentSet(); | 6475 WeakDocumentSet& set = liveDocumentSet(); |
6587 fprintf(stderr, "There are %u documents currently alive:\n", set.size()); | 6476 fprintf(stderr, "There are %u documents currently alive:\n", set.size()); |
6588 for (Document* document : set) | 6477 for (Document* document : set) |
6589 fprintf(stderr, "- Document %p URL: %s\n", document, | 6478 fprintf(stderr, "- Document %p URL: %s\n", document, |
6590 document->url().getString().utf8().data()); | 6479 document->url().getString().utf8().data()); |
6591 } | 6480 } |
6592 #endif | 6481 #endif |
OLD | NEW |