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-02-07 19:38:26 +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/. */
|
|
|
|
|
|
|
|
#include "mozilla/dom/HTMLSourceElement.h"
|
2013-02-07 19:39:10 +04:00
|
|
|
#include "mozilla/dom/HTMLSourceElementBinding.h"
|
2013-02-07 19:38:26 +04:00
|
|
|
|
2014-05-03 01:32:20 +04:00
|
|
|
#include "mozilla/dom/HTMLImageElement.h"
|
|
|
|
#include "mozilla/dom/ResponsiveImageSelector.h"
|
2015-05-26 14:01:14 +03:00
|
|
|
#include "mozilla/dom/MediaSource.h"
|
2014-05-03 01:32:20 +04:00
|
|
|
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
|
2014-04-18 01:38:18 +04:00
|
|
|
#include "nsIMediaList.h"
|
|
|
|
#include "nsCSSParser.h"
|
2015-05-26 14:01:14 +03:00
|
|
|
#include "nsHostObjectProtocolHandler.h"
|
2014-04-18 01:38:18 +04:00
|
|
|
|
2014-05-03 01:32:20 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
|
|
|
|
2013-02-07 19:38:26 +04:00
|
|
|
NS_IMPL_NS_NEW_HTML_ELEMENT(Source)
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
HTMLSourceElement::HTMLSourceElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
|
2013-02-07 19:38:26 +04:00
|
|
|
: nsGenericHTMLElement(aNodeInfo)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
HTMLSourceElement::~HTMLSourceElement()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-05-26 14:01:14 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED(HTMLSourceElement, nsGenericHTMLElement,
|
|
|
|
mSrcMediaSource)
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF_INHERITED(HTMLSourceElement, nsGenericHTMLElement)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(HTMLSourceElement, nsGenericHTMLElement)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(HTMLSourceElement)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLSourceElement)
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(nsGenericHTMLElement)
|
2013-02-07 19:38:26 +04:00
|
|
|
|
|
|
|
NS_IMPL_ELEMENT_CLONE(HTMLSourceElement)
|
|
|
|
|
|
|
|
NS_IMPL_URI_ATTR(HTMLSourceElement, Src, src)
|
|
|
|
NS_IMPL_STRING_ATTR(HTMLSourceElement, Type, type)
|
2014-04-24 00:55:05 +04:00
|
|
|
NS_IMPL_STRING_ATTR(HTMLSourceElement, Srcset, srcset)
|
|
|
|
NS_IMPL_STRING_ATTR(HTMLSourceElement, Sizes, sizes)
|
2013-02-07 19:38:26 +04:00
|
|
|
NS_IMPL_STRING_ATTR(HTMLSourceElement, Media, media)
|
|
|
|
|
2014-04-18 01:38:18 +04:00
|
|
|
bool
|
|
|
|
HTMLSourceElement::MatchesCurrentMedia()
|
|
|
|
{
|
|
|
|
if (mMediaList) {
|
|
|
|
nsIPresShell* presShell = OwnerDoc()->GetShell();
|
|
|
|
nsPresContext* pctx = presShell ? presShell->GetPresContext() : nullptr;
|
|
|
|
return pctx && mMediaList->Matches(pctx, nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
// No media specified
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-12-11 02:53:00 +03:00
|
|
|
/* static */ bool
|
|
|
|
HTMLSourceElement::WouldMatchMediaForDocument(const nsAString& aMedia,
|
|
|
|
const nsIDocument *aDocument)
|
|
|
|
{
|
|
|
|
if (aMedia.IsEmpty()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIPresShell* presShell = aDocument->GetShell();
|
|
|
|
nsPresContext* pctx = presShell ? presShell->GetPresContext() : nullptr;
|
|
|
|
|
|
|
|
nsCSSParser cssParser;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsMediaList> mediaList = new nsMediaList();
|
2014-12-11 02:53:00 +03:00
|
|
|
cssParser.ParseMediaList(aMedia, nullptr, 0, mediaList, false);
|
|
|
|
|
|
|
|
return pctx && mediaList->Matches(pctx, nullptr);
|
|
|
|
}
|
|
|
|
|
2016-02-03 04:53:00 +03:00
|
|
|
void
|
|
|
|
HTMLSourceElement::UpdateMediaList(const nsAttrValue* aValue)
|
|
|
|
{
|
|
|
|
mMediaList = nullptr;
|
|
|
|
nsString mediaStr;
|
|
|
|
if (!aValue || (mediaStr = aValue->GetStringValue()).IsEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSParser cssParser;
|
|
|
|
mMediaList = new nsMediaList();
|
|
|
|
cssParser.ParseMediaList(mediaStr, nullptr, 0, mMediaList, false);
|
|
|
|
}
|
|
|
|
|
2014-04-18 01:38:18 +04:00
|
|
|
nsresult
|
|
|
|
HTMLSourceElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
|
|
|
|
const nsAttrValue* aValue, bool aNotify)
|
|
|
|
{
|
2014-05-03 01:32:20 +04:00
|
|
|
// If we are associated with a <picture> with a valid <img>, notify it of
|
|
|
|
// responsive parameter changes
|
2015-03-10 17:23:14 +03:00
|
|
|
Element *parent = nsINode::GetParentElement();
|
2014-05-03 01:32:20 +04:00
|
|
|
if (aNameSpaceID == kNameSpaceID_None &&
|
2014-10-02 07:30:49 +04:00
|
|
|
(aName == nsGkAtoms::srcset ||
|
|
|
|
aName == nsGkAtoms::sizes ||
|
2014-10-09 01:01:19 +04:00
|
|
|
aName == nsGkAtoms::media ||
|
|
|
|
aName == nsGkAtoms::type) &&
|
2015-03-03 14:09:00 +03:00
|
|
|
parent && parent->IsHTMLElement(nsGkAtoms::picture)) {
|
2014-05-03 01:32:20 +04:00
|
|
|
nsString strVal = aValue ? aValue->GetStringValue() : EmptyString();
|
|
|
|
// Find all img siblings after this <source> and notify them of the change
|
2015-03-10 17:23:14 +03:00
|
|
|
nsCOMPtr<nsIContent> sibling = AsContent();
|
2014-05-03 01:32:20 +04:00
|
|
|
while ( (sibling = sibling->GetNextSibling()) ) {
|
2015-03-03 14:09:00 +03:00
|
|
|
if (sibling->IsHTMLElement(nsGkAtoms::img)) {
|
2014-05-03 01:32:20 +04:00
|
|
|
HTMLImageElement *img = static_cast<HTMLImageElement*>(sibling.get());
|
|
|
|
if (aName == nsGkAtoms::srcset) {
|
|
|
|
img->PictureSourceSrcsetChanged(AsContent(), strVal, aNotify);
|
|
|
|
} else if (aName == nsGkAtoms::sizes) {
|
|
|
|
img->PictureSourceSizesChanged(AsContent(), strVal, aNotify);
|
2016-02-03 04:53:00 +03:00
|
|
|
} else if (aName == nsGkAtoms::media) {
|
|
|
|
UpdateMediaList(aValue);
|
|
|
|
img->PictureSourceMediaOrTypeChanged(AsContent(), aNotify);
|
|
|
|
} else if (aName == nsGkAtoms::type) {
|
2014-10-09 01:01:19 +04:00
|
|
|
img->PictureSourceMediaOrTypeChanged(AsContent(), aNotify);
|
2014-05-03 01:32:20 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (aNameSpaceID == kNameSpaceID_None && aName == nsGkAtoms::media) {
|
2016-02-03 04:53:00 +03:00
|
|
|
UpdateMediaList(aValue);
|
2015-05-26 14:01:14 +03:00
|
|
|
} else if (aNameSpaceID == kNameSpaceID_None && aName == nsGkAtoms::src) {
|
|
|
|
mSrcMediaSource = nullptr;
|
|
|
|
if (aValue) {
|
|
|
|
nsString srcStr = aValue->GetStringValue();
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
NewURIFromString(srcStr, getter_AddRefs(uri));
|
|
|
|
if (uri && IsMediaSourceURI(uri)) {
|
|
|
|
NS_GetSourceForMediaSourceURI(uri, getter_AddRefs(mSrcMediaSource));
|
|
|
|
}
|
|
|
|
}
|
2014-04-18 01:38:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return nsGenericHTMLElement::AfterSetAttr(aNameSpaceID, aName,
|
|
|
|
aValue, aNotify);
|
|
|
|
}
|
|
|
|
|
2013-02-07 19:38:26 +04:00
|
|
|
nsresult
|
|
|
|
HTMLSourceElement::BindToTree(nsIDocument *aDocument,
|
|
|
|
nsIContent *aParent,
|
|
|
|
nsIContent *aBindingParent,
|
|
|
|
bool aCompileEventHandlers)
|
|
|
|
{
|
|
|
|
nsresult rv = nsGenericHTMLElement::BindToTree(aDocument,
|
|
|
|
aParent,
|
|
|
|
aBindingParent,
|
|
|
|
aCompileEventHandlers);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2014-05-03 01:32:20 +04:00
|
|
|
if (aParent && aParent->IsNodeOfType(nsINode::eMEDIA)) {
|
|
|
|
HTMLMediaElement* media = static_cast<HTMLMediaElement*>(aParent);
|
|
|
|
media->NotifyAddedSource();
|
|
|
|
}
|
2013-02-07 19:38:26 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-02-07 19:39:10 +04:00
|
|
|
JSObject*
|
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 17:13:33 +03:00
|
|
|
HTMLSourceElement::WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-02-07 19:39:10 +04: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 17:13:33 +03:00
|
|
|
return HTMLSourceElementBinding::Wrap(aCx, this, aGivenProto);
|
2013-02-07 19:39:10 +04:00
|
|
|
}
|
|
|
|
|
2013-02-07 19:38:26 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|