2015-05-03 19:32:37 +00: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: */
|
2012-05-21 11:12:37 +00: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/. */
|
2006-05-21 21:00:09 +00:00
|
|
|
|
2014-04-03 04:18:36 +00:00
|
|
|
#include "mozilla/EventStates.h"
|
Bug 1555216 - Change the signature of BindToTree to be (BindContext&, nsINode& aParentNode). r=bzbarsky
BindContext was going to have way more information at first, but then I realized
that most of the things I wanted to know were basically a flag away using the
parent node.
Still I think it's worth it, now experimenting with BindToTree will only mean
adding a field to a struct that's included from a couple cpp files, instead of a
massive pain.
I also think this is clearer, and doing this highlights quite a few
inconsistencies in our code which I've left untouched, but commented with
FIXMEs.
Steps are:
$ for file in $(rg 'nsresult BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#nsresult BindToTree(Document\* aDocument, nsIContent\* aParent,#nsresult BindToTree(BindContext\&, nsINode\& aParent)#g' $file; done
$ for file in $(rg 'nsresult BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's# nsIContent\* aBindingParent) override#override#g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#::BindToTree(Document\* aDocument, nsIContent\* aParent,#::BindToTree(BindContext\& aContext, nsINode\& aParent)#g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#nsIContent\* aBindingParent)##g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#::BindToTree(aDocument, aParent, aBindingParent)#::BindToTree(aContext, aParent)#g' $file; done
$ ./mach clang-format
Then manual fixups.
Depends on D32948
Differential Revision: https://phabricator.services.mozilla.com/D32949
2019-05-29 04:27:04 +00:00
|
|
|
#include "mozilla/dom/BindContext.h"
|
2016-06-16 07:24:16 +00:00
|
|
|
#include "mozilla/dom/HTMLFormSubmission.h"
|
2013-03-04 19:08:23 +00:00
|
|
|
#include "mozilla/dom/HTMLObjectElement.h"
|
2013-01-06 23:55:14 +00:00
|
|
|
#include "mozilla/dom/HTMLObjectElementBinding.h"
|
2013-10-02 20:09:18 +00:00
|
|
|
#include "mozilla/dom/ElementInlines.h"
|
2019-01-03 07:11:00 +00:00
|
|
|
#include "mozilla/dom/WindowProxyHolder.h"
|
2012-09-30 16:40:24 +00:00
|
|
|
#include "nsAttrValueInlines.h"
|
2007-01-30 00:06:41 +00:00
|
|
|
#include "nsGkAtoms.h"
|
2012-07-27 14:03:27 +00:00
|
|
|
#include "nsError.h"
|
2019-01-02 13:05:23 +00:00
|
|
|
#include "mozilla/dom/Document.h"
|
2012-12-11 00:35:05 +00:00
|
|
|
#include "nsIPluginDocument.h"
|
2005-03-09 17:01:22 +00:00
|
|
|
#include "nsIObjectFrame.h"
|
2011-05-18 01:48:34 +00:00
|
|
|
#include "nsNPAPIPluginInstance.h"
|
2011-11-27 11:51:53 +00:00
|
|
|
#include "nsIWidget.h"
|
2013-01-31 23:11:49 +00:00
|
|
|
#include "nsContentUtils.h"
|
2015-02-20 16:37:02 +00:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
# include "mozilla/EventDispatcher.h"
|
|
|
|
# include "mozilla/dom/Event.h"
|
2015-03-27 00:38:13 +00:00
|
|
|
# include "nsFocusManager.h"
|
2015-02-20 16:37:02 +00:00
|
|
|
#endif
|
2010-08-28 00:36:45 +00:00
|
|
|
|
2013-01-06 18:43:40 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2018-09-21 20:45:49 +00:00
|
|
|
HTMLObjectElement::HTMLObjectElement(
|
|
|
|
already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
|
2013-01-06 18:43:40 +00:00
|
|
|
FromParser aFromParser)
|
2018-09-21 20:45:49 +00:00
|
|
|
: nsGenericHTMLFormElement(std::move(aNodeInfo), NS_FORM_OBJECT),
|
2006-05-21 21:00:09 +00:00
|
|
|
mIsDoneAddingChildren(!aFromParser) {
|
2014-06-19 02:09:35 +00:00
|
|
|
RegisterActivityObserver();
|
2010-10-25 12:17:38 +00:00
|
|
|
SetIsNetworkCreated(aFromParser == FROM_PARSER_NETWORK);
|
2010-09-10 05:08:56 +00:00
|
|
|
|
|
|
|
// <object> is always barred from constraint validation.
|
2011-10-17 14:59:28 +00:00
|
|
|
SetBarredFromConstraintValidation(true);
|
2011-06-01 01:46:57 +00:00
|
|
|
|
|
|
|
// By default we're in the loading state
|
|
|
|
AddStatesSilently(NS_EVENT_STATE_LOADING);
|
1998-07-14 18:52:27 +00:00
|
|
|
}
|
|
|
|
|
2013-01-06 18:43:40 +00:00
|
|
|
HTMLObjectElement::~HTMLObjectElement() {
|
2015-03-24 22:02:52 +00:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
OnFocusBlurPlugin(this, false);
|
|
|
|
#endif
|
2014-06-19 02:09:35 +00:00
|
|
|
UnregisterActivityObserver();
|
2006-06-01 18:35:21 +00:00
|
|
|
DestroyImageLoadingContent();
|
|
|
|
}
|
|
|
|
|
2015-03-17 20:42:14 +00:00
|
|
|
bool HTMLObjectElement::IsInteractiveHTMLContent(bool aIgnoreTabindex) const {
|
2015-03-23 09:02:33 +00:00
|
|
|
return HasAttr(kNameSpaceID_None, nsGkAtoms::usemap) ||
|
|
|
|
nsGenericHTMLFormElement::IsInteractiveHTMLContent(aIgnoreTabindex);
|
2015-01-20 20:39:28 +00:00
|
|
|
}
|
|
|
|
|
2016-10-06 04:30:35 +00:00
|
|
|
void HTMLObjectElement::AsyncEventRunning(AsyncEventDispatcher* aEvent) {
|
|
|
|
nsImageLoadingContent::AsyncEventRunning(aEvent);
|
|
|
|
}
|
|
|
|
|
2013-01-06 18:43:40 +00:00
|
|
|
bool HTMLObjectElement::IsDoneAddingChildren() { return mIsDoneAddingChildren; }
|
2004-06-02 00:25:00 +00:00
|
|
|
|
2013-01-06 18:43:40 +00:00
|
|
|
void HTMLObjectElement::DoneAddingChildren(bool aHaveNotified) {
|
2011-10-17 14:59:28 +00:00
|
|
|
mIsDoneAddingChildren = true;
|
2005-09-21 19:14:30 +00:00
|
|
|
|
|
|
|
// If we're already in a document, we need to trigger the load
|
|
|
|
// Otherwise, BindToTree takes care of that.
|
2015-02-24 14:41:43 +00:00
|
|
|
if (IsInComposedDoc()) {
|
2017-02-08 23:19:01 +00:00
|
|
|
StartObjectLoad(aHaveNotified, false);
|
2005-09-21 19:14:30 +00:00
|
|
|
}
|
2004-06-02 00:25:00 +00:00
|
|
|
}
|
1998-09-01 01:31:20 +00:00
|
|
|
|
2013-08-02 01:29:05 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(HTMLObjectElement)
|
|
|
|
|
2013-01-06 18:43:40 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(HTMLObjectElement,
|
2007-03-08 11:17:16 +00:00
|
|
|
nsGenericHTMLFormElement)
|
2013-02-01 14:10:08 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mValidity)
|
2011-08-28 14:07:24 +00:00
|
|
|
nsObjectLoadingContent::Traverse(tmp, cb);
|
2007-03-08 11:17:16 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
2013-08-02 01:29:05 +00:00
|
|
|
|
2013-02-01 14:10:08 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(HTMLObjectElement,
|
|
|
|
nsGenericHTMLFormElement)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mValidity)
|
2013-09-12 01:57:53 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
2007-03-08 11:17:16 +00:00
|
|
|
|
2017-08-31 23:29:22 +00:00
|
|
|
NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED(
|
|
|
|
HTMLObjectElement, nsGenericHTMLFormElement, imgINotificationObserver,
|
2019-02-15 22:20:53 +00:00
|
|
|
nsIRequestObserver, nsIStreamListener, nsFrameLoaderOwner,
|
2017-08-31 23:29:22 +00:00
|
|
|
nsIObjectLoadingContent, nsIImageLoadingContent, nsIChannelEventSink,
|
|
|
|
nsIConstraintValidation)
|
1998-09-01 01:31:20 +00:00
|
|
|
|
2013-01-06 18:43:40 +00:00
|
|
|
NS_IMPL_ELEMENT_CLONE(HTMLObjectElement)
|
2000-12-23 10:56:31 +00:00
|
|
|
|
2015-02-20 16:37:02 +00:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
|
|
|
|
static nsIWidget* GetWidget(Element* aElement) {
|
2015-03-24 22:02:52 +00:00
|
|
|
return nsContentUtils::WidgetForDocument(aElement->OwnerDoc());
|
2015-03-24 17:07:26 +00:00
|
|
|
}
|
2015-03-24 16:41:32 +00:00
|
|
|
|
2015-03-24 22:02:52 +00:00
|
|
|
Element* HTMLObjectElement::sLastFocused = nullptr; // Weak
|
|
|
|
|
2016-04-26 00:23:21 +00:00
|
|
|
class PluginFocusSetter : public Runnable {
|
2015-03-24 22:02:52 +00:00
|
|
|
public:
|
|
|
|
PluginFocusSetter(nsIWidget* aWidget, Element* aElement)
|
2017-06-12 19:34:10 +00:00
|
|
|
: Runnable("PluginFocusSetter"), mWidget(aWidget), mElement(aElement) {}
|
2015-03-24 22:02:52 +00:00
|
|
|
|
2016-08-08 02:18:10 +00:00
|
|
|
NS_IMETHOD Run() override {
|
2015-03-24 22:02:52 +00:00
|
|
|
if (mElement) {
|
|
|
|
HTMLObjectElement::sLastFocused = mElement;
|
|
|
|
bool value = true;
|
|
|
|
mWidget->SetPluginFocused(value);
|
|
|
|
} else if (!HTMLObjectElement::sLastFocused) {
|
|
|
|
bool value = false;
|
|
|
|
mWidget->SetPluginFocused(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsCOMPtr<nsIWidget> mWidget;
|
|
|
|
nsCOMPtr<Element> mElement;
|
|
|
|
};
|
|
|
|
|
|
|
|
void HTMLObjectElement::OnFocusBlurPlugin(Element* aElement, bool aFocus) {
|
2015-03-27 00:38:13 +00:00
|
|
|
// In general we don't want to call nsIWidget::SetPluginFocused() for any
|
|
|
|
// Element that doesn't have a plugin running. But if SetPluginFocused(true)
|
|
|
|
// was just called for aElement while it had a plugin running, we want to
|
|
|
|
// make sure nsIWidget::SetPluginFocused(false) gets called for it now, even
|
|
|
|
// if aFocus is true.
|
|
|
|
if (aFocus) {
|
|
|
|
nsCOMPtr<nsIObjectLoadingContent> olc = do_QueryInterface(aElement);
|
|
|
|
bool hasRunningPlugin = false;
|
|
|
|
if (olc) {
|
2015-06-10 20:30:25 +00:00
|
|
|
hasRunningPlugin =
|
|
|
|
static_cast<nsObjectLoadingContent*>(olc.get())->HasRunningPlugin();
|
2015-03-27 00:38:13 +00:00
|
|
|
}
|
|
|
|
if (!hasRunningPlugin) {
|
|
|
|
aFocus = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-24 22:02:52 +00:00
|
|
|
if (aFocus || aElement == sLastFocused) {
|
|
|
|
if (!aFocus) {
|
|
|
|
sLastFocused = nullptr;
|
|
|
|
}
|
|
|
|
nsIWidget* widget = GetWidget(aElement);
|
|
|
|
if (widget) {
|
|
|
|
nsContentUtils::AddScriptRunner(
|
|
|
|
new PluginFocusSetter(widget, aFocus ? aElement : nullptr));
|
|
|
|
}
|
2015-02-20 16:37:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-27 00:38:13 +00:00
|
|
|
void HTMLObjectElement::HandlePluginCrashed(Element* aElement) {
|
|
|
|
OnFocusBlurPlugin(aElement, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void HTMLObjectElement::HandlePluginInstantiated(Element* aElement) {
|
|
|
|
// If aElement is already focused when a plugin is instantiated, we need
|
|
|
|
// to initiate a call to nsIWidget::SetPluginFocused(true). Otherwise
|
|
|
|
// keyboard input won't work in a click-to-play plugin until aElement
|
|
|
|
// loses focus and regains it.
|
|
|
|
nsFocusManager* fm = nsFocusManager::GetFocusManager();
|
2018-04-26 19:28:31 +00:00
|
|
|
if (fm && fm->GetFocusedElement() == aElement) {
|
2015-03-27 00:38:13 +00:00
|
|
|
OnFocusBlurPlugin(aElement, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-20 16:37:02 +00:00
|
|
|
void HTMLObjectElement::HandleFocusBlurPlugin(Element* aElement,
|
|
|
|
WidgetEvent* aEvent) {
|
2016-03-17 07:01:30 +00:00
|
|
|
if (!aEvent->IsTrusted()) {
|
2015-02-20 16:37:02 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-08-22 01:34:51 +00:00
|
|
|
switch (aEvent->mMessage) {
|
2015-09-02 06:08:00 +00:00
|
|
|
case eFocus: {
|
2015-02-20 16:37:02 +00:00
|
|
|
OnFocusBlurPlugin(aElement, true);
|
|
|
|
break;
|
|
|
|
}
|
2015-09-02 06:08:00 +00:00
|
|
|
case eBlur: {
|
2015-02-20 16:37:02 +00:00
|
|
|
OnFocusBlurPlugin(aElement, false);
|
|
|
|
break;
|
|
|
|
}
|
2015-08-26 12:56:59 +00:00
|
|
|
default:
|
|
|
|
break;
|
2015-02-20 16:37:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLObjectElement::PostHandleEvent(EventChainPostVisitor& aVisitor) {
|
|
|
|
HandleFocusBlurPlugin(this, aVisitor.mEvent);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // #ifdef XP_MACOSX
|
|
|
|
|
Bug 1555216 - Change the signature of BindToTree to be (BindContext&, nsINode& aParentNode). r=bzbarsky
BindContext was going to have way more information at first, but then I realized
that most of the things I wanted to know were basically a flag away using the
parent node.
Still I think it's worth it, now experimenting with BindToTree will only mean
adding a field to a struct that's included from a couple cpp files, instead of a
massive pain.
I also think this is clearer, and doing this highlights quite a few
inconsistencies in our code which I've left untouched, but commented with
FIXMEs.
Steps are:
$ for file in $(rg 'nsresult BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#nsresult BindToTree(Document\* aDocument, nsIContent\* aParent,#nsresult BindToTree(BindContext\&, nsINode\& aParent)#g' $file; done
$ for file in $(rg 'nsresult BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's# nsIContent\* aBindingParent) override#override#g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#::BindToTree(Document\* aDocument, nsIContent\* aParent,#::BindToTree(BindContext\& aContext, nsINode\& aParent)#g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#nsIContent\* aBindingParent)##g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#::BindToTree(aDocument, aParent, aBindingParent)#::BindToTree(aContext, aParent)#g' $file; done
$ ./mach clang-format
Then manual fixups.
Depends on D32948
Differential Revision: https://phabricator.services.mozilla.com/D32949
2019-05-29 04:27:04 +00:00
|
|
|
nsresult HTMLObjectElement::BindToTree(BindContext& aContext,
|
|
|
|
nsINode& aParent) {
|
|
|
|
nsresult rv = nsGenericHTMLFormElement::BindToTree(aContext, aParent);
|
2006-05-21 21:00:09 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2005-09-21 19:14:30 +00:00
|
|
|
|
Bug 1555216 - Change the signature of BindToTree to be (BindContext&, nsINode& aParentNode). r=bzbarsky
BindContext was going to have way more information at first, but then I realized
that most of the things I wanted to know were basically a flag away using the
parent node.
Still I think it's worth it, now experimenting with BindToTree will only mean
adding a field to a struct that's included from a couple cpp files, instead of a
massive pain.
I also think this is clearer, and doing this highlights quite a few
inconsistencies in our code which I've left untouched, but commented with
FIXMEs.
Steps are:
$ for file in $(rg 'nsresult BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#nsresult BindToTree(Document\* aDocument, nsIContent\* aParent,#nsresult BindToTree(BindContext\&, nsINode\& aParent)#g' $file; done
$ for file in $(rg 'nsresult BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's# nsIContent\* aBindingParent) override#override#g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#::BindToTree(Document\* aDocument, nsIContent\* aParent,#::BindToTree(BindContext\& aContext, nsINode\& aParent)#g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#nsIContent\* aBindingParent)##g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#::BindToTree(aDocument, aParent, aBindingParent)#::BindToTree(aContext, aParent)#g' $file; done
$ ./mach clang-format
Then manual fixups.
Depends on D32948
Differential Revision: https://phabricator.services.mozilla.com/D32949
2019-05-29 04:27:04 +00:00
|
|
|
rv = nsObjectLoadingContent::BindToTree(aContext, aParent);
|
2012-03-28 15:53:56 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2012-12-11 00:35:05 +00:00
|
|
|
// Don't kick off load from being bound to a plugin document - the plugin
|
|
|
|
// document will call nsObjectLoadingContent::InitializeFromChannel() for the
|
|
|
|
// initial load.
|
2019-05-31 14:33:33 +00:00
|
|
|
if (IsInComposedDoc()) {
|
|
|
|
nsCOMPtr<nsIPluginDocument> pluginDoc =
|
|
|
|
do_QueryInterface(&aContext.OwnerDoc());
|
|
|
|
// If we already have all the children, start the load.
|
|
|
|
if (mIsDoneAddingChildren && !pluginDoc) {
|
|
|
|
void (HTMLObjectElement::*start)() = &HTMLObjectElement::StartObjectLoad;
|
|
|
|
nsContentUtils::AddScriptRunner(
|
|
|
|
NewRunnableMethod("dom::HTMLObjectElement::BindToTree", this, start));
|
|
|
|
}
|
2005-09-21 19:14:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2019-05-28 22:47:08 +00:00
|
|
|
void HTMLObjectElement::UnbindFromTree(bool aNullParent) {
|
2015-03-24 22:02:52 +00:00
|
|
|
#ifdef XP_MACOSX
|
2019-01-02 13:05:23 +00:00
|
|
|
// When a page is reloaded (when an Document's content is removed), the
|
2015-09-02 06:08:00 +00:00
|
|
|
// focused element isn't necessarily sent an eBlur event. See
|
2015-03-24 22:02:52 +00: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.
|
|
|
|
OnFocusBlurPlugin(this, false);
|
|
|
|
#endif
|
2019-05-28 22:47:08 +00:00
|
|
|
nsObjectLoadingContent::UnbindFromTree(aNullParent);
|
|
|
|
nsGenericHTMLFormElement::UnbindFromTree(aNullParent);
|
2005-09-21 19:14:30 +00:00
|
|
|
}
|
|
|
|
|
2017-10-02 22:05:19 +00:00
|
|
|
nsresult HTMLObjectElement::AfterSetAttr(int32_t aNamespaceID, nsAtom* aName,
|
2017-06-07 17:28:20 +00:00
|
|
|
const nsAttrValue* aValue,
|
2017-10-09 21:33:38 +00:00
|
|
|
const nsAttrValue* aOldValue,
|
|
|
|
nsIPrincipal* aSubjectPrincipal,
|
|
|
|
bool aNotify) {
|
2017-06-07 17:28:20 +00:00
|
|
|
nsresult rv = AfterMaybeChangeAttr(aNamespaceID, aName, aNotify);
|
2012-07-05 21:07:46 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2017-06-07 17:28:20 +00:00
|
|
|
return nsGenericHTMLFormElement::AfterSetAttr(
|
2017-10-09 21:33:38 +00:00
|
|
|
aNamespaceID, aName, aValue, aOldValue, aSubjectPrincipal, aNotify);
|
2005-09-21 19:14:30 +00:00
|
|
|
}
|
|
|
|
|
2017-10-02 22:05:19 +00:00
|
|
|
nsresult HTMLObjectElement::OnAttrSetButNotChanged(
|
2017-06-07 17:28:20 +00:00
|
|
|
int32_t aNamespaceID, nsAtom* aName, const nsAttrValueOrString& aValue,
|
|
|
|
bool aNotify) {
|
|
|
|
nsresult rv = AfterMaybeChangeAttr(aNamespaceID, aName, aNotify);
|
2012-07-05 21:07:46 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2017-06-07 17:28:20 +00:00
|
|
|
return nsGenericHTMLFormElement::OnAttrSetButNotChanged(aNamespaceID, aName,
|
|
|
|
aValue, aNotify);
|
|
|
|
}
|
|
|
|
|
2017-10-02 22:05:19 +00:00
|
|
|
nsresult HTMLObjectElement::AfterMaybeChangeAttr(int32_t aNamespaceID,
|
2017-06-07 17:28:20 +00:00
|
|
|
nsAtom* aName, bool aNotify) {
|
|
|
|
if (aNamespaceID == kNameSpaceID_None) {
|
|
|
|
// 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
|
|
|
|
// object load from BindToTree/DoneAddingChildren.
|
|
|
|
// 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() && mIsDoneAddingChildren &&
|
|
|
|
aName == nsGkAtoms::data && !BlockEmbedOrObjectContentLoading()) {
|
|
|
|
return LoadObject(aNotify, true);
|
|
|
|
}
|
2008-12-12 19:41:11 +00:00
|
|
|
}
|
|
|
|
|
2012-07-05 21:07:46 +00:00
|
|
|
return NS_OK;
|
2008-12-12 19:41:11 +00:00
|
|
|
}
|
|
|
|
|
2013-01-06 18:43:40 +00:00
|
|
|
bool HTMLObjectElement::IsFocusableForTabIndex() {
|
2019-01-02 13:05:23 +00:00
|
|
|
Document* doc = GetComposedDoc();
|
2010-10-08 10:20:20 +00:00
|
|
|
if (!doc || doc->HasFlag(NODE_IS_EDITABLE)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-11-10 23:30:15 +00:00
|
|
|
return IsEditableRoot() ||
|
2015-05-20 13:30:05 +00:00
|
|
|
((Type() == eType_Document || Type() == eType_FakePlugin) &&
|
2012-11-10 23:30:15 +00:00
|
|
|
nsContentUtils::IsSubDocumentTabbable(this));
|
2010-10-08 10:20:20 +00:00
|
|
|
}
|
|
|
|
|
2013-01-06 18:43:40 +00:00
|
|
|
bool HTMLObjectElement::IsHTMLFocusable(bool aWithMouse, bool* aIsFocusable,
|
|
|
|
int32_t* aTabIndex) {
|
2010-10-08 10:20:20 +00:00
|
|
|
// TODO: this should probably be managed directly by IsHTMLFocusable.
|
|
|
|
// See bug 597242.
|
2019-01-02 13:05:23 +00:00
|
|
|
Document* doc = GetComposedDoc();
|
2010-10-08 10:20:20 +00:00
|
|
|
if (!doc || doc->HasFlag(NODE_IS_EDITABLE)) {
|
|
|
|
if (aTabIndex) {
|
2017-07-14 03:45:49 +00:00
|
|
|
*aTabIndex = TabIndex();
|
2010-10-08 10:20:20 +00:00
|
|
|
}
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
*aIsFocusable = false;
|
2010-10-08 10:20:20 +00:00
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2010-10-08 10:20:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This method doesn't call nsGenericHTMLFormElement intentionally.
|
|
|
|
// TODO: It should probably be changed when bug 597242 will be fixed.
|
|
|
|
if (Type() == eType_Plugin || IsEditableRoot() ||
|
2015-05-20 13:30:05 +00:00
|
|
|
((Type() == eType_Document || Type() == eType_FakePlugin) &&
|
|
|
|
nsContentUtils::IsSubDocumentTabbable(this))) {
|
2005-10-03 19:29:52 +00:00
|
|
|
// Has plugin content: let the plugin decide what to do in terms of
|
|
|
|
// internal focus from mouse clicks
|
2005-10-04 23:43:54 +00:00
|
|
|
if (aTabIndex) {
|
2017-07-14 03:45:49 +00:00
|
|
|
*aTabIndex = TabIndex();
|
2005-10-04 23:43:54 +00:00
|
|
|
}
|
2010-10-08 10:20:20 +00:00
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
*aIsFocusable = true;
|
2008-04-15 18:40:38 +00:00
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2005-10-03 19:29:52 +00:00
|
|
|
}
|
2005-10-04 23:43:54 +00:00
|
|
|
|
2010-10-08 10:20:20 +00:00
|
|
|
// TODO: this should probably be managed directly by IsHTMLFocusable.
|
|
|
|
// See bug 597242.
|
2018-08-07 19:07:26 +00:00
|
|
|
const nsAttrValue* attrVal = mAttrs.GetAttr(nsGkAtoms::tabindex);
|
2010-10-08 10:20:20 +00:00
|
|
|
|
|
|
|
*aIsFocusable = attrVal && attrVal->Type() == nsAttrValue::eInteger;
|
|
|
|
|
|
|
|
if (aTabIndex && *aIsFocusable) {
|
|
|
|
*aTabIndex = attrVal->GetIntegerValue();
|
|
|
|
}
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2005-10-03 19:29:52 +00:00
|
|
|
}
|
|
|
|
|
2013-01-06 18:43:40 +00:00
|
|
|
nsIContent::IMEState HTMLObjectElement::GetDesiredIMEState() {
|
2006-05-21 21:00:09 +00:00
|
|
|
if (Type() == eType_Plugin) {
|
2011-11-27 11:51:53 +00:00
|
|
|
return IMEState(IMEState::PLUGIN);
|
2006-05-21 21:00:09 +00:00
|
|
|
}
|
2015-05-20 13:30:05 +00:00
|
|
|
|
2005-11-14 23:55:24 +00:00
|
|
|
return nsGenericHTMLFormElement::GetDesiredIMEState();
|
|
|
|
}
|
|
|
|
|
2002-08-06 08:32:19 +00:00
|
|
|
NS_IMETHODIMP
|
2013-01-06 18:43:40 +00:00
|
|
|
HTMLObjectElement::Reset() { return NS_OK; }
|
1998-09-02 23:53:16 +00:00
|
|
|
|
2002-08-06 08:32:19 +00:00
|
|
|
NS_IMETHODIMP
|
2016-06-16 07:24:16 +00:00
|
|
|
HTMLObjectElement::SubmitNamesValues(HTMLFormSubmission* aFormSubmission) {
|
2005-03-09 17:01:22 +00:00
|
|
|
nsAutoString name;
|
2006-05-21 21:00:09 +00:00
|
|
|
if (!GetAttr(kNameSpaceID_None, nsGkAtoms::name, name)) {
|
2005-03-09 17:01:22 +00:00
|
|
|
// No name, don't submit.
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-06-12 16:14:31 +00:00
|
|
|
nsIFrame* frame = GetPrimaryFrame();
|
2005-03-09 17:01:22 +00:00
|
|
|
|
2009-01-12 19:20:59 +00:00
|
|
|
nsIObjectFrame* objFrame = do_QueryFrame(frame);
|
2005-03-09 17:01:22 +00:00
|
|
|
if (!objFrame) {
|
|
|
|
// No frame, nothing to submit.
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2018-11-20 01:20:17 +00:00
|
|
|
RefPtr<nsNPAPIPluginInstance> pi = objFrame->GetPluginInstance();
|
|
|
|
if (!pi) {
|
2005-03-09 17:01:22 +00:00
|
|
|
return NS_OK;
|
2018-11-20 01:20:17 +00:00
|
|
|
}
|
2005-03-09 17:01:22 +00:00
|
|
|
|
|
|
|
nsAutoString value;
|
2009-07-02 04:52:07 +00:00
|
|
|
nsresult rv = pi->GetFormValue(value);
|
2005-03-09 17:01:22 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-02-25 05:58:16 +00:00
|
|
|
return aFormSubmission->AddNameValuePair(name, value);
|
2002-08-06 08:32:19 +00:00
|
|
|
}
|
|
|
|
|
2013-01-06 18:43:40 +00:00
|
|
|
int32_t HTMLObjectElement::TabIndexDefault() {
|
2012-10-06 07:19:51 +00:00
|
|
|
return IsFocusableForTabIndex() ? 0 : -1;
|
|
|
|
}
|
|
|
|
|
2019-01-02 13:26:56 +00:00
|
|
|
Nullable<WindowProxyHolder> HTMLObjectElement::GetContentWindow(
|
2016-10-11 01:07:48 +00:00
|
|
|
nsIPrincipal& aSubjectPrincipal) {
|
2019-01-02 13:05:23 +00:00
|
|
|
Document* doc = GetContentDocument(aSubjectPrincipal);
|
2013-03-04 19:08:24 +00:00
|
|
|
if (doc) {
|
2019-01-02 13:26:56 +00:00
|
|
|
nsPIDOMWindowOuter* win = doc->GetWindow();
|
|
|
|
if (win) {
|
2019-01-02 13:27:05 +00:00
|
|
|
return WindowProxyHolder(win->GetBrowsingContext());
|
2019-01-02 13:26:56 +00:00
|
|
|
}
|
2002-04-17 04:17:16 +00:00
|
|
|
}
|
2002-04-05 05:42:10 +00:00
|
|
|
|
2013-03-04 19:08:24 +00:00
|
|
|
return nullptr;
|
2000-04-18 22:57:42 +00:00
|
|
|
}
|
|
|
|
|
2013-01-06 18:43:40 +00:00
|
|
|
bool HTMLObjectElement::ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
|
|
|
|
const nsAString& aValue,
|
2017-11-02 03:35:52 +00:00
|
|
|
nsIPrincipal* aMaybeScriptedPrincipal,
|
2013-01-06 18:43:40 +00:00
|
|
|
nsAttrValue& aResult) {
|
2005-11-29 16:37:15 +00:00
|
|
|
if (aNamespaceID == kNameSpaceID_None) {
|
2006-05-21 21:00:09 +00:00
|
|
|
if (aAttribute == nsGkAtoms::align) {
|
2005-11-29 16:37:15 +00:00
|
|
|
return ParseAlignValue(aValue, aResult);
|
|
|
|
}
|
|
|
|
if (ParseImageAttribute(aAttribute, aValue, aResult)) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2005-11-29 16:37:15 +00:00
|
|
|
}
|
1998-09-01 01:31:20 +00:00
|
|
|
}
|
2000-12-23 10:56:31 +00:00
|
|
|
|
2005-11-29 16:37:15 +00:00
|
|
|
return nsGenericHTMLFormElement::ParseAttribute(
|
2017-11-02 03:35:52 +00:00
|
|
|
aNamespaceID, aAttribute, aValue, aMaybeScriptedPrincipal, aResult);
|
1998-09-01 01:31:20 +00:00
|
|
|
}
|
|
|
|
|
2018-06-22 16:48:42 +00:00
|
|
|
void HTMLObjectElement::MapAttributesIntoRule(
|
|
|
|
const nsMappedAttributes* aAttributes, MappedDeclarations& aDecls) {
|
|
|
|
nsGenericHTMLFormElement::MapImageAlignAttributeInto(aAttributes, aDecls);
|
|
|
|
nsGenericHTMLFormElement::MapImageBorderAttributeInto(aAttributes, aDecls);
|
|
|
|
nsGenericHTMLFormElement::MapImageMarginAttributeInto(aAttributes, aDecls);
|
|
|
|
nsGenericHTMLFormElement::MapImageSizeAttributesInto(aAttributes, aDecls);
|
|
|
|
nsGenericHTMLFormElement::MapCommonAttributesInto(aAttributes, aDecls);
|
1998-09-05 04:00:06 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
NS_IMETHODIMP_(bool)
|
2017-10-02 22:05:19 +00:00
|
|
|
HTMLObjectElement::IsAttributeMapped(const nsAtom* aAttribute) const {
|
2004-02-25 21:04:50 +00:00
|
|
|
static const MappedAttributeEntry* const map[] = {
|
2003-04-16 20:54:20 +00:00
|
|
|
sCommonAttributeMap,
|
2003-07-11 21:16:12 +00:00
|
|
|
sImageMarginSizeAttributeMap,
|
2003-04-16 20:54:20 +00:00
|
|
|
sImageBorderAttributeMap,
|
|
|
|
sImageAlignAttributeMap,
|
|
|
|
};
|
|
|
|
|
2011-12-18 10:09:27 +00:00
|
|
|
return FindAttributeDependence(aAttribute, map);
|
1999-07-07 01:24:40 +00:00
|
|
|
}
|
|
|
|
|
2013-01-06 18:43:40 +00:00
|
|
|
nsMapRuleToAttributesFunc HTMLObjectElement::GetAttributeMappingFunction()
|
|
|
|
const {
|
2005-01-12 19:45:38 +00:00
|
|
|
return &MapAttributesIntoRule;
|
1998-09-01 01:31:20 +00:00
|
|
|
}
|
2005-09-18 18:05:40 +00:00
|
|
|
|
2017-02-08 23:19:01 +00:00
|
|
|
void HTMLObjectElement::StartObjectLoad(bool aNotify, bool aForce) {
|
2012-07-06 00:56:25 +00:00
|
|
|
// BindToTree can call us asynchronously, and we may be removed from the tree
|
|
|
|
// in the interim
|
2017-02-08 23:19:01 +00:00
|
|
|
if (!IsInComposedDoc() || !OwnerDoc()->IsActive() ||
|
|
|
|
BlockEmbedOrObjectContentLoading()) {
|
2012-07-06 00:56:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-02-08 23:19:01 +00:00
|
|
|
LoadObject(aNotify, aForce);
|
2011-10-17 14:59:28 +00:00
|
|
|
SetIsNetworkCreated(false);
|
2005-09-21 19:14:30 +00:00
|
|
|
}
|
|
|
|
|
2013-01-06 18:43:40 +00:00
|
|
|
EventStates HTMLObjectElement::IntrinsicState() const {
|
2005-09-21 19:14:30 +00:00
|
|
|
return nsGenericHTMLFormElement::IntrinsicState() | ObjectState();
|
|
|
|
}
|
2005-09-18 18:05:40 +00:00
|
|
|
|
2013-01-06 18:43:40 +00:00
|
|
|
uint32_t HTMLObjectElement::GetCapabilities() const {
|
2018-05-01 04:53:48 +00:00
|
|
|
return nsObjectLoadingContent::GetCapabilities() | eFallbackIfClassIDPresent;
|
2005-09-21 19:14:30 +00:00
|
|
|
}
|
2007-12-05 07:11:00 +00:00
|
|
|
|
2013-01-06 18:43:40 +00:00
|
|
|
void HTMLObjectElement::DestroyContent() {
|
2012-07-05 21:07:46 +00:00
|
|
|
nsObjectLoadingContent::DestroyContent();
|
2007-12-05 07:11:00 +00:00
|
|
|
nsGenericHTMLFormElement::DestroyContent();
|
|
|
|
}
|
2009-12-11 04:02:13 +00:00
|
|
|
|
2018-08-08 23:58:44 +00:00
|
|
|
nsresult HTMLObjectElement::CopyInnerTo(Element* aDest) {
|
|
|
|
nsresult rv = nsGenericHTMLFormElement::CopyInnerTo(aDest);
|
2009-12-11 04:02:13 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2011-10-18 10:53:36 +00:00
|
|
|
if (aDest->OwnerDoc()->IsStaticDocument()) {
|
2013-01-06 18:43:40 +00:00
|
|
|
CreateStaticClone(static_cast<HTMLObjectElement*>(aDest));
|
2009-12-11 04:02:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
2013-01-06 18:43:40 +00:00
|
|
|
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 14:13:33 +00:00
|
|
|
JSObject* HTMLObjectElement::WrapNode(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) {
|
2013-05-02 09:12:45 +00:00
|
|
|
JS::Rooted<JSObject*> obj(
|
2018-06-25 21:20:54 +00:00
|
|
|
aCx, HTMLObjectElement_Binding::Wrap(aCx, this, aGivenProto));
|
2013-01-06 23:55:14 +00:00
|
|
|
if (!obj) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
SetupProtoChain(aCx, obj);
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
2013-01-06 18:43:40 +00:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
NS_IMPL_NS_NEW_HTML_ELEMENT_CHECK_PARSER(Object)
|