Thu, 15 Jan 2015 21:03:48 +0100
Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "nsScriptElement.h" |
michael@0 | 7 | #include "mozilla/BasicEvents.h" |
michael@0 | 8 | #include "mozilla/EventDispatcher.h" |
michael@0 | 9 | #include "mozilla/dom/Element.h" |
michael@0 | 10 | #include "nsContentUtils.h" |
michael@0 | 11 | #include "nsPresContext.h" |
michael@0 | 12 | #include "nsScriptLoader.h" |
michael@0 | 13 | #include "nsIParser.h" |
michael@0 | 14 | #include "nsAutoPtr.h" |
michael@0 | 15 | #include "nsGkAtoms.h" |
michael@0 | 16 | #include "nsContentSink.h" |
michael@0 | 17 | |
michael@0 | 18 | using namespace mozilla; |
michael@0 | 19 | using namespace mozilla::dom; |
michael@0 | 20 | |
michael@0 | 21 | NS_IMETHODIMP |
michael@0 | 22 | nsScriptElement::ScriptAvailable(nsresult aResult, |
michael@0 | 23 | nsIScriptElement *aElement, |
michael@0 | 24 | bool aIsInline, |
michael@0 | 25 | nsIURI *aURI, |
michael@0 | 26 | int32_t aLineNo) |
michael@0 | 27 | { |
michael@0 | 28 | if (!aIsInline && NS_FAILED(aResult)) { |
michael@0 | 29 | return FireErrorEvent(); |
michael@0 | 30 | } |
michael@0 | 31 | return NS_OK; |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | /* virtual */ nsresult |
michael@0 | 35 | nsScriptElement::FireErrorEvent() |
michael@0 | 36 | { |
michael@0 | 37 | nsCOMPtr<nsIContent> cont = |
michael@0 | 38 | do_QueryInterface((nsIScriptElement*) this); |
michael@0 | 39 | |
michael@0 | 40 | return nsContentUtils::DispatchTrustedEvent(cont->OwnerDoc(), |
michael@0 | 41 | cont, |
michael@0 | 42 | NS_LITERAL_STRING("error"), |
michael@0 | 43 | false /* bubbles */, |
michael@0 | 44 | false /* cancelable */); |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | NS_IMETHODIMP |
michael@0 | 48 | nsScriptElement::ScriptEvaluated(nsresult aResult, |
michael@0 | 49 | nsIScriptElement *aElement, |
michael@0 | 50 | bool aIsInline) |
michael@0 | 51 | { |
michael@0 | 52 | nsresult rv = NS_OK; |
michael@0 | 53 | if (!aIsInline) { |
michael@0 | 54 | nsCOMPtr<nsIContent> cont = |
michael@0 | 55 | do_QueryInterface((nsIScriptElement*) this); |
michael@0 | 56 | |
michael@0 | 57 | nsRefPtr<nsPresContext> presContext = |
michael@0 | 58 | nsContentUtils::GetContextForContent(cont); |
michael@0 | 59 | |
michael@0 | 60 | nsEventStatus status = nsEventStatus_eIgnore; |
michael@0 | 61 | uint32_t type = NS_SUCCEEDED(aResult) ? NS_LOAD : NS_LOAD_ERROR; |
michael@0 | 62 | WidgetEvent event(true, type); |
michael@0 | 63 | // Load event doesn't bubble. |
michael@0 | 64 | event.mFlags.mBubbles = (type != NS_LOAD); |
michael@0 | 65 | |
michael@0 | 66 | EventDispatcher::Dispatch(cont, presContext, &event, nullptr, &status); |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | return rv; |
michael@0 | 70 | } |
michael@0 | 71 | |
michael@0 | 72 | void |
michael@0 | 73 | nsScriptElement::CharacterDataChanged(nsIDocument *aDocument, |
michael@0 | 74 | nsIContent* aContent, |
michael@0 | 75 | CharacterDataChangeInfo* aInfo) |
michael@0 | 76 | { |
michael@0 | 77 | MaybeProcessScript(); |
michael@0 | 78 | } |
michael@0 | 79 | |
michael@0 | 80 | void |
michael@0 | 81 | nsScriptElement::AttributeChanged(nsIDocument* aDocument, |
michael@0 | 82 | Element* aElement, |
michael@0 | 83 | int32_t aNameSpaceID, |
michael@0 | 84 | nsIAtom* aAttribute, |
michael@0 | 85 | int32_t aModType) |
michael@0 | 86 | { |
michael@0 | 87 | MaybeProcessScript(); |
michael@0 | 88 | } |
michael@0 | 89 | |
michael@0 | 90 | void |
michael@0 | 91 | nsScriptElement::ContentAppended(nsIDocument* aDocument, |
michael@0 | 92 | nsIContent* aContainer, |
michael@0 | 93 | nsIContent* aFirstNewContent, |
michael@0 | 94 | int32_t aNewIndexInContainer) |
michael@0 | 95 | { |
michael@0 | 96 | MaybeProcessScript(); |
michael@0 | 97 | } |
michael@0 | 98 | |
michael@0 | 99 | void |
michael@0 | 100 | nsScriptElement::ContentInserted(nsIDocument *aDocument, |
michael@0 | 101 | nsIContent* aContainer, |
michael@0 | 102 | nsIContent* aChild, |
michael@0 | 103 | int32_t aIndexInContainer) |
michael@0 | 104 | { |
michael@0 | 105 | MaybeProcessScript(); |
michael@0 | 106 | } |
michael@0 | 107 | |
michael@0 | 108 | bool |
michael@0 | 109 | nsScriptElement::MaybeProcessScript() |
michael@0 | 110 | { |
michael@0 | 111 | nsCOMPtr<nsIContent> cont = |
michael@0 | 112 | do_QueryInterface((nsIScriptElement*) this); |
michael@0 | 113 | |
michael@0 | 114 | NS_ASSERTION(cont->DebugGetSlots()->mMutationObservers.Contains(this), |
michael@0 | 115 | "You forgot to add self as observer"); |
michael@0 | 116 | |
michael@0 | 117 | if (mAlreadyStarted || !mDoneAddingChildren || !cont->IsInDoc() || |
michael@0 | 118 | mMalformed || !HasScriptContent()) { |
michael@0 | 119 | return false; |
michael@0 | 120 | } |
michael@0 | 121 | |
michael@0 | 122 | FreezeUriAsyncDefer(); |
michael@0 | 123 | |
michael@0 | 124 | mAlreadyStarted = true; |
michael@0 | 125 | |
michael@0 | 126 | nsIDocument* ownerDoc = cont->OwnerDoc(); |
michael@0 | 127 | nsCOMPtr<nsIParser> parser = ((nsIScriptElement*) this)->GetCreatorParser(); |
michael@0 | 128 | if (parser) { |
michael@0 | 129 | nsCOMPtr<nsIContentSink> sink = parser->GetContentSink(); |
michael@0 | 130 | if (sink) { |
michael@0 | 131 | nsCOMPtr<nsIDocument> parserDoc = do_QueryInterface(sink->GetTarget()); |
michael@0 | 132 | if (ownerDoc != parserDoc) { |
michael@0 | 133 | // Willful violation of HTML5 as of 2010-12-01 |
michael@0 | 134 | return false; |
michael@0 | 135 | } |
michael@0 | 136 | } |
michael@0 | 137 | } |
michael@0 | 138 | |
michael@0 | 139 | nsRefPtr<nsScriptLoader> loader = ownerDoc->ScriptLoader(); |
michael@0 | 140 | return loader->ProcessScriptElement(this); |
michael@0 | 141 | } |