2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2013-03-17 18:42:01 +04:00
|
|
|
/* 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/. */
|
|
|
|
|
2014-04-03 08:18:36 +04:00
|
|
|
#include "mozilla/EventStates.h"
|
2017-07-29 07:35:43 +03:00
|
|
|
#include "mozilla/dom/HTMLEmbedElement.h"
|
2013-03-17 18:42:05 +04:00
|
|
|
#include "mozilla/dom/HTMLEmbedElementBinding.h"
|
2013-10-03 00:09:18 +04:00
|
|
|
#include "mozilla/dom/ElementInlines.h"
|
2013-03-17 18:42:01 +04:00
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
#include "mozilla/dom/Document.h"
|
2013-03-17 18:42:01 +04:00
|
|
|
#include "nsIPluginDocument.h"
|
|
|
|
#include "nsThreadUtils.h"
|
|
|
|
#include "nsIScriptError.h"
|
|
|
|
#include "nsIWidget.h"
|
|
|
|
#include "nsContentUtils.h"
|
2015-02-20 19:37:02 +03:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
# include "mozilla/EventDispatcher.h"
|
|
|
|
# include "mozilla/dom/Event.h"
|
2016-04-29 00:48:14 +03:00
|
|
|
#endif
|
2016-04-29 00:57:34 +03:00
|
|
|
#include "mozilla/dom/HTMLObjectElement.h"
|
2013-03-17 18:42:01 +04:00
|
|
|
|
2017-07-29 07:35:43 +03:00
|
|
|
NS_IMPL_NS_NEW_HTML_ELEMENT_CHECK_PARSER(Embed)
|
2013-03-17 18:42:01 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2018-09-21 23:45:49 +03:00
|
|
|
HTMLEmbedElement::HTMLEmbedElement(
|
|
|
|
already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
|
2017-07-29 07:35:43 +03:00
|
|
|
FromParser aFromParser)
|
2018-09-21 23:45:49 +03:00
|
|
|
: nsGenericHTMLElement(std::move(aNodeInfo)) {
|
2014-06-19 06:09:35 +04:00
|
|
|
RegisterActivityObserver();
|
2013-03-17 18:42:01 +04:00
|
|
|
SetIsNetworkCreated(aFromParser == FROM_PARSER_NETWORK);
|
|
|
|
|
|
|
|
// By default we're in the loading state
|
|
|
|
AddStatesSilently(NS_EVENT_STATE_LOADING);
|
|
|
|
}
|
|
|
|
|
2017-07-29 07:35:43 +03:00
|
|
|
HTMLEmbedElement::~HTMLEmbedElement() {
|
2015-03-25 01:02:52 +03:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
HTMLObjectElement::OnFocusBlurPlugin(this, false);
|
|
|
|
#endif
|
2014-06-19 06:09:35 +04:00
|
|
|
UnregisterActivityObserver();
|
2013-03-17 18:42:01 +04:00
|
|
|
DestroyImageLoadingContent();
|
|
|
|
}
|
|
|
|
|
2017-07-29 07:35:43 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(HTMLEmbedElement)
|
2013-03-17 18:42:01 +04:00
|
|
|
|
2017-07-29 07:35:43 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(HTMLEmbedElement,
|
2013-03-17 18:42:01 +04:00
|
|
|
nsGenericHTMLElement)
|
2017-07-29 07:35:43 +03:00
|
|
|
nsObjectLoadingContent::Traverse(tmp, cb);
|
2013-03-17 18:42:01 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
2017-08-16 23:14:11 +03:00
|
|
|
NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED(
|
|
|
|
HTMLEmbedElement, nsGenericHTMLElement, nsIRequestObserver,
|
2019-02-16 01:20:53 +03:00
|
|
|
nsIStreamListener, nsFrameLoaderOwner, nsIObjectLoadingContent,
|
2017-08-16 23:14:11 +03:00
|
|
|
imgINotificationObserver, nsIImageLoadingContent, nsIChannelEventSink)
|
2013-03-17 18:42:01 +04:00
|
|
|
|
2017-07-29 07:35:43 +03:00
|
|
|
NS_IMPL_ELEMENT_CLONE(HTMLEmbedElement)
|
2013-03-17 18:42:01 +04:00
|
|
|
|
2015-02-20 19:37:02 +03:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2017-07-29 07:35:43 +03:00
|
|
|
HTMLEmbedElement::PostHandleEvent(EventChainPostVisitor& aVisitor) {
|
2015-02-20 19:37:02 +03:00
|
|
|
HTMLObjectElement::HandleFocusBlurPlugin(this, aVisitor.mEvent);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // #ifdef XP_MACOSX
|
|
|
|
|
2017-07-29 07:35:43 +03:00
|
|
|
void HTMLEmbedElement::AsyncEventRunning(AsyncEventDispatcher* aEvent) {
|
2016-10-06 07:30:35 +03:00
|
|
|
nsImageLoadingContent::AsyncEventRunning(aEvent);
|
|
|
|
}
|
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
nsresult HTMLEmbedElement::BindToTree(Document* aDocument, nsIContent* aParent,
|
2018-07-31 21:18:38 +03:00
|
|
|
nsIContent* aBindingParent) {
|
2013-03-17 18:42:01 +04:00
|
|
|
nsresult rv =
|
|
|
|
nsGenericHTMLElement::BindToTree(aDocument, aParent, aBindingParent);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = nsObjectLoadingContent::BindToTree(aDocument, aParent, aBindingParent);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Don't kick off load from being bound to a plugin document - the plugin
|
|
|
|
// document will call nsObjectLoadingContent::InitializeFromChannel() for the
|
|
|
|
// initial load.
|
|
|
|
nsCOMPtr<nsIPluginDocument> pluginDoc = do_QueryInterface(aDocument);
|
|
|
|
|
2017-07-29 07:35:43 +03:00
|
|
|
if (!pluginDoc) {
|
|
|
|
void (HTMLEmbedElement::*start)() = &HTMLEmbedElement::StartObjectLoad;
|
2017-06-12 22:34:10 +03:00
|
|
|
nsContentUtils::AddScriptRunner(
|
2017-07-29 07:35:43 +03:00
|
|
|
NewRunnableMethod("dom::HTMLEmbedElement::BindToTree", this, start));
|
2013-03-17 18:42:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2019-05-29 01:47:08 +03:00
|
|
|
void HTMLEmbedElement::UnbindFromTree(bool aNullParent) {
|
2015-03-25 01:02:52 +03:00
|
|
|
#ifdef XP_MACOSX
|
2019-01-02 16:05:23 +03:00
|
|
|
// When a page is reloaded (when an Document's content is removed), the
|
2015-09-02 09:08:00 +03:00
|
|
|
// focused element isn't necessarily sent an eBlur event. See
|
2015-03-25 01:02:52 +03:00
|
|
|
// nsFocusManager::ContentRemoved(). This means that a widget may think it
|
|
|
|
// still contains a focused plugin when it doesn't -- which in turn can
|
|
|
|
// disable text input in the browser window. See bug 1137229.
|
|
|
|
HTMLObjectElement::OnFocusBlurPlugin(this, false);
|
|
|
|
#endif
|
2019-05-29 01:47:08 +03:00
|
|
|
nsObjectLoadingContent::UnbindFromTree(aNullParent);
|
|
|
|
nsGenericHTMLElement::UnbindFromTree(aNullParent);
|
2013-03-17 18:42:01 +04:00
|
|
|
}
|
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
nsresult HTMLEmbedElement::AfterSetAttr(int32_t aNamespaceID, nsAtom* aName,
|
2017-07-29 07:35:43 +03:00
|
|
|
const nsAttrValue* aValue,
|
|
|
|
const nsAttrValue* aOldValue,
|
2017-10-10 00:33:38 +03:00
|
|
|
nsIPrincipal* aSubjectPrincipal,
|
2017-07-29 07:35:43 +03:00
|
|
|
bool aNotify) {
|
2017-06-07 20:28:20 +03:00
|
|
|
if (aValue) {
|
|
|
|
nsresult rv = AfterMaybeChangeAttr(aNamespaceID, aName, aNotify);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsGenericHTMLElement::AfterSetAttr(
|
2017-10-10 00:33:38 +03:00
|
|
|
aNamespaceID, aName, aValue, aOldValue, aSubjectPrincipal, aNotify);
|
2017-06-07 20:28:20 +03:00
|
|
|
}
|
2013-03-17 18:42:01 +04:00
|
|
|
|
2017-07-29 07:35:43 +03:00
|
|
|
nsresult HTMLEmbedElement::OnAttrSetButNotChanged(
|
|
|
|
int32_t aNamespaceID, nsAtom* aName, const nsAttrValueOrString& aValue,
|
|
|
|
bool aNotify) {
|
2017-06-07 20:28:20 +03:00
|
|
|
nsresult rv = AfterMaybeChangeAttr(aNamespaceID, aName, aNotify);
|
2013-03-17 18:42:01 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2017-06-07 20:28:20 +03:00
|
|
|
return nsGenericHTMLElement::OnAttrSetButNotChanged(aNamespaceID, aName,
|
|
|
|
aValue, aNotify);
|
|
|
|
}
|
|
|
|
|
2017-07-29 07:35:43 +03:00
|
|
|
nsresult HTMLEmbedElement::AfterMaybeChangeAttr(int32_t aNamespaceID,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* aName, bool aNotify) {
|
2017-06-07 20:28:20 +03:00
|
|
|
if (aNamespaceID == kNameSpaceID_None) {
|
2017-07-11 02:00:30 +03:00
|
|
|
if (aName == nsGkAtoms::src) {
|
2017-06-07 20:28:20 +03:00
|
|
|
// If aNotify is false, we are coming from the parser or some such place;
|
|
|
|
// we'll get bound after all the attributes have been set, so we'll do the
|
2017-07-29 07:35:43 +03:00
|
|
|
// object load from BindToTree.
|
2017-06-07 20:28:20 +03:00
|
|
|
// Skip the LoadObject call in that case.
|
|
|
|
// We also don't want to start loading the object when we're not yet in
|
|
|
|
// a document, just in case that the caller wants to set additional
|
|
|
|
// attributes before inserting the node into the document.
|
|
|
|
if (aNotify && IsInComposedDoc() && !BlockEmbedOrObjectContentLoading()) {
|
|
|
|
nsresult rv = LoadObject(aNotify, true);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
}
|
2013-03-17 18:42:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-07-29 07:35:43 +03:00
|
|
|
bool HTMLEmbedElement::IsHTMLFocusable(bool aWithMouse, bool* aIsFocusable,
|
|
|
|
int32_t* aTabIndex) {
|
|
|
|
// Has plugin content: let the plugin decide what to do in terms of
|
|
|
|
// internal focus from mouse clicks
|
|
|
|
if (aTabIndex) {
|
|
|
|
*aTabIndex = TabIndex();
|
2013-03-17 18:42:01 +04:00
|
|
|
}
|
|
|
|
|
2017-07-29 07:35:43 +03:00
|
|
|
*aIsFocusable = true;
|
|
|
|
|
|
|
|
// Let the plugin decide, so override.
|
|
|
|
return true;
|
2013-03-17 18:42:01 +04:00
|
|
|
}
|
|
|
|
|
2017-07-29 07:35:43 +03:00
|
|
|
nsIContent::IMEState HTMLEmbedElement::GetDesiredIMEState() {
|
2013-03-17 18:42:01 +04:00
|
|
|
if (Type() == eType_Plugin) {
|
|
|
|
return IMEState(IMEState::PLUGIN);
|
|
|
|
}
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2013-03-17 18:42:01 +04:00
|
|
|
return nsGenericHTMLElement::GetDesiredIMEState();
|
|
|
|
}
|
|
|
|
|
2017-07-29 07:35:43 +03:00
|
|
|
int32_t HTMLEmbedElement::TabIndexDefault() { return -1; }
|
2013-03-17 18:42:01 +04:00
|
|
|
|
2017-07-29 07:35:43 +03:00
|
|
|
bool HTMLEmbedElement::ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
|
|
|
|
const nsAString& aValue,
|
2017-11-02 06:35:52 +03:00
|
|
|
nsIPrincipal* aMaybeScriptedPrincipal,
|
2017-07-29 07:35:43 +03:00
|
|
|
nsAttrValue& aResult) {
|
2013-03-17 18:42:01 +04:00
|
|
|
if (aNamespaceID == kNameSpaceID_None) {
|
|
|
|
if (aAttribute == nsGkAtoms::align) {
|
|
|
|
return ParseAlignValue(aValue, aResult);
|
|
|
|
}
|
|
|
|
if (ParseImageAttribute(aAttribute, aValue, aResult)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute, aValue,
|
2017-11-02 06:35:52 +03:00
|
|
|
aMaybeScriptedPrincipal, aResult);
|
2013-03-17 18:42:01 +04:00
|
|
|
}
|
|
|
|
|
2013-07-11 18:39:18 +04:00
|
|
|
static void MapAttributesIntoRuleBase(const nsMappedAttributes* aAttributes,
|
2018-06-22 19:48:42 +03:00
|
|
|
MappedDeclarations& aDecls) {
|
|
|
|
nsGenericHTMLElement::MapImageBorderAttributeInto(aAttributes, aDecls);
|
|
|
|
nsGenericHTMLElement::MapImageMarginAttributeInto(aAttributes, aDecls);
|
|
|
|
nsGenericHTMLElement::MapImageSizeAttributesInto(aAttributes, aDecls);
|
|
|
|
nsGenericHTMLElement::MapImageAlignAttributeInto(aAttributes, aDecls);
|
2013-07-11 18:39:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void MapAttributesIntoRuleExceptHidden(
|
|
|
|
const nsMappedAttributes* aAttributes, MappedDeclarations& aDecls) {
|
2018-06-22 19:48:42 +03:00
|
|
|
MapAttributesIntoRuleBase(aAttributes, aDecls);
|
|
|
|
nsGenericHTMLElement::MapCommonAttributesIntoExceptHidden(aAttributes,
|
|
|
|
aDecls);
|
2013-07-11 18:39:18 +04:00
|
|
|
}
|
|
|
|
|
2017-07-29 07:35:43 +03:00
|
|
|
void HTMLEmbedElement::MapAttributesIntoRule(
|
|
|
|
const nsMappedAttributes* aAttributes, MappedDeclarations& aDecls) {
|
2018-06-22 19:48:42 +03:00
|
|
|
MapAttributesIntoRuleBase(aAttributes, aDecls);
|
|
|
|
nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aDecls);
|
2013-03-17 18:42:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(bool)
|
2017-10-03 01:05:19 +03:00
|
|
|
HTMLEmbedElement::IsAttributeMapped(const nsAtom* aAttribute) const {
|
2013-03-17 18:42:01 +04:00
|
|
|
static const MappedAttributeEntry* const map[] = {
|
|
|
|
sCommonAttributeMap,
|
|
|
|
sImageMarginSizeAttributeMap,
|
|
|
|
sImageBorderAttributeMap,
|
|
|
|
sImageAlignAttributeMap,
|
|
|
|
};
|
|
|
|
|
|
|
|
return FindAttributeDependence(aAttribute, map);
|
|
|
|
}
|
|
|
|
|
2017-07-29 07:35:43 +03:00
|
|
|
nsMapRuleToAttributesFunc HTMLEmbedElement::GetAttributeMappingFunction()
|
|
|
|
const {
|
|
|
|
return &MapAttributesIntoRuleExceptHidden;
|
2013-03-17 18:42:01 +04:00
|
|
|
}
|
|
|
|
|
2017-07-29 07:35:43 +03:00
|
|
|
void HTMLEmbedElement::StartObjectLoad(bool aNotify, bool aForceLoad) {
|
2013-03-17 18:42:01 +04:00
|
|
|
// BindToTree can call us asynchronously, and we may be removed from the tree
|
|
|
|
// in the interim
|
2016-04-11 20:58:08 +03:00
|
|
|
if (!IsInComposedDoc() || !OwnerDoc()->IsActive() ||
|
2017-02-09 02:19:01 +03:00
|
|
|
BlockEmbedOrObjectContentLoading()) {
|
2013-03-17 18:42:01 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-04-29 00:57:34 +03:00
|
|
|
LoadObject(aNotify, aForceLoad);
|
2013-03-17 18:42:01 +04:00
|
|
|
SetIsNetworkCreated(false);
|
|
|
|
}
|
|
|
|
|
2017-07-29 07:35:43 +03:00
|
|
|
EventStates HTMLEmbedElement::IntrinsicState() const {
|
2013-03-17 18:42:01 +04:00
|
|
|
return nsGenericHTMLElement::IntrinsicState() | ObjectState();
|
|
|
|
}
|
|
|
|
|
2017-07-29 07:35:43 +03:00
|
|
|
uint32_t HTMLEmbedElement::GetCapabilities() const {
|
|
|
|
return eSupportPlugins | eAllowPluginSkipChannel | eSupportImages |
|
|
|
|
eSupportDocuments;
|
2013-03-17 18:42:01 +04:00
|
|
|
}
|
|
|
|
|
2017-07-29 07:35:43 +03:00
|
|
|
void HTMLEmbedElement::DestroyContent() {
|
2013-03-17 18:42:01 +04:00
|
|
|
nsObjectLoadingContent::DestroyContent();
|
|
|
|
nsGenericHTMLElement::DestroyContent();
|
|
|
|
}
|
|
|
|
|
2018-08-09 02:58:44 +03:00
|
|
|
nsresult HTMLEmbedElement::CopyInnerTo(HTMLEmbedElement* aDest) {
|
|
|
|
nsresult rv = nsGenericHTMLElement::CopyInnerTo(aDest);
|
2013-03-17 18:42:01 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (aDest->OwnerDoc()->IsStaticDocument()) {
|
2018-08-09 02:58:44 +03:00
|
|
|
CreateStaticClone(aDest);
|
2013-03-17 18:42:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2017-07-29 07:35:43 +03:00
|
|
|
JSObject* HTMLEmbedElement::WrapNode(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) {
|
2013-03-17 18:42:05 +04:00
|
|
|
JSObject* obj;
|
2018-06-26 00:20:54 +03:00
|
|
|
obj = HTMLEmbedElement_Binding::Wrap(aCx, this, aGivenProto);
|
2017-07-11 02:00:30 +03:00
|
|
|
|
2013-03-17 18:42:05 +04:00
|
|
|
if (!obj) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-05-02 13:12:45 +04:00
|
|
|
JS::Rooted<JSObject*> rootedObj(aCx, obj);
|
|
|
|
SetupProtoChain(aCx, rootedObj);
|
|
|
|
return rootedObj;
|
2013-03-17 18:42:05 +04:00
|
|
|
}
|
|
|
|
|
2017-07-29 07:35:43 +03:00
|
|
|
nsContentPolicyType HTMLEmbedElement::GetContentPolicyType() const {
|
2017-07-29 02:44:39 +03:00
|
|
|
return nsIContentPolicy::TYPE_INTERNAL_EMBED;
|
2015-07-18 18:51:00 +03:00
|
|
|
}
|
|
|
|
|
2013-03-17 18:42:01 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|