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/. */
|
2001-12-12 07:59:31 +00:00
|
|
|
|
2013-03-20 16:22:26 +00:00
|
|
|
#include "mozilla/dom/SVGDocument.h"
|
2014-05-24 20:37:48 +00:00
|
|
|
|
|
|
|
#include "mozilla/css/Loader.h"
|
|
|
|
#include "nsICategoryManager.h"
|
|
|
|
#include "nsISimpleEnumerator.h"
|
|
|
|
#include "nsIStyleSheetService.h"
|
|
|
|
#include "nsISupportsPrimitives.h"
|
2014-05-24 19:29:11 +00:00
|
|
|
#include "nsLayoutStylesheetCache.h"
|
2014-05-24 20:37:48 +00:00
|
|
|
#include "nsNetUtil.h"
|
|
|
|
#include "nsServiceManagerUtils.h"
|
2002-03-21 01:43:51 +00:00
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsLiteralString.h"
|
2013-02-08 19:55:07 +00:00
|
|
|
#include "nsIDOMSVGElement.h"
|
2010-05-05 18:18:05 +00:00
|
|
|
#include "mozilla/dom/Element.h"
|
2013-03-20 16:22:26 +00:00
|
|
|
#include "nsSVGElement.h"
|
|
|
|
#include "mozilla/dom/SVGDocumentBinding.h"
|
2010-04-30 13:12:05 +00:00
|
|
|
|
2014-05-24 20:37:48 +00:00
|
|
|
using namespace mozilla::css;
|
2010-04-30 13:12:05 +00:00
|
|
|
using namespace mozilla::dom;
|
2004-11-18 23:32:06 +00:00
|
|
|
|
2013-03-20 16:22:26 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2004-11-18 23:32:06 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsISupports methods:
|
2001-12-12 07:59:31 +00:00
|
|
|
|
2013-03-20 16:22:26 +00:00
|
|
|
void
|
|
|
|
SVGDocument::GetDomain(nsAString& aDomain, ErrorResult& aRv)
|
2004-11-18 23:32:06 +00:00
|
|
|
{
|
|
|
|
SetDOMStringToNull(aDomain);
|
2003-06-21 00:26:28 +00:00
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
if (mDocumentURI) {
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString domain;
|
2004-01-09 23:54:21 +00:00
|
|
|
nsresult rv = mDocumentURI->GetHost(domain);
|
2013-03-20 16:22:26 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (domain.IsEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
2004-11-18 23:32:06 +00:00
|
|
|
CopyUTF8toUTF16(domain, aDomain);
|
2001-12-12 07:59:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-20 16:22:26 +00:00
|
|
|
nsSVGElement*
|
|
|
|
SVGDocument::GetRootElement(ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
Element* root = nsDocument::GetRootElement();
|
|
|
|
if (!root) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2015-03-03 11:08:59 +00:00
|
|
|
if (!root->IsSVGElement()) {
|
2013-03-20 16:22:26 +00:00
|
|
|
aRv.Throw(NS_NOINTERFACE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return static_cast<nsSVGElement*>(root);
|
2001-12-12 07:59:31 +00:00
|
|
|
}
|
|
|
|
|
2014-06-05 00:01:39 +00:00
|
|
|
nsresult
|
|
|
|
SVGDocument::InsertChildAt(nsIContent* aKid, uint32_t aIndex, bool aNotify)
|
|
|
|
{
|
2015-04-13 23:36:57 +00:00
|
|
|
if (aKid->IsElement() && !aKid->IsSVGElement()) {
|
2014-06-05 00:01:39 +00:00
|
|
|
// We can get here when well formed XML with a non-SVG root element is
|
|
|
|
// served with the SVG MIME type, for example. In that case we need to load
|
2015-04-13 23:36:57 +00:00
|
|
|
// the non-SVG UA sheets or else we can get bugs like bug 1016145. Note
|
|
|
|
// that we have to do this _before_ the XMLDocument::InsertChildAt call,
|
|
|
|
// since that can try to construct frames, and we need to have the sheets
|
|
|
|
// loaded by then.
|
2014-06-05 00:01:39 +00:00
|
|
|
EnsureNonSVGUserAgentStyleSheetsLoaded();
|
|
|
|
}
|
|
|
|
|
2015-04-13 23:36:57 +00:00
|
|
|
return XMLDocument::InsertChildAt(aKid, aIndex, aNotify);
|
2014-06-05 00:01:39 +00:00
|
|
|
}
|
|
|
|
|
2009-12-11 04:02:13 +00:00
|
|
|
nsresult
|
2014-06-20 02:01:40 +00:00
|
|
|
SVGDocument::Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult) const
|
2009-12-11 04:02:13 +00:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aNodeInfo->NodeInfoManager() == mNodeInfoManager,
|
|
|
|
"Can't import this document into another document!");
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<SVGDocument> clone = new SVGDocument();
|
2009-12-11 04:02:13 +00:00
|
|
|
nsresult rv = CloneDocHelper(clone.get());
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return CallQueryInterface(clone.get(), aResult);
|
|
|
|
}
|
|
|
|
|
2014-05-24 19:29:11 +00:00
|
|
|
void
|
|
|
|
SVGDocument::EnsureNonSVGUserAgentStyleSheetsLoaded()
|
|
|
|
{
|
|
|
|
if (mHasLoadedNonSVGUserAgentStyleSheets) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-19 21:59:37 +00:00
|
|
|
if (IsStaticDocument()) {
|
|
|
|
// If we're a static clone of a document, then
|
|
|
|
// nsIDocument::CreateStaticClone will handle cloning the original
|
|
|
|
// document's sheets, including the on-demand non-SVG UA sheets,
|
|
|
|
// for us.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-05-24 19:29:11 +00:00
|
|
|
mHasLoadedNonSVGUserAgentStyleSheets = true;
|
|
|
|
|
2015-06-16 01:34:47 +00:00
|
|
|
BeginUpdate(UPDATE_STYLE);
|
|
|
|
|
2014-05-24 20:37:48 +00:00
|
|
|
if (IsBeingUsedAsImage()) {
|
|
|
|
// nsDocumentViewer::CreateStyleSet skipped loading all user-agent/user
|
2015-04-23 19:10:30 +00:00
|
|
|
// style sheets in this case, but we'll need B2G/Fennec's
|
2014-05-24 20:37:48 +00:00
|
|
|
// content.css. We could load all the sheets registered with the
|
|
|
|
// nsIStyleSheetService (and maybe we should) but most likely it isn't
|
|
|
|
// desirable or necessary for foreignObject in SVG-as-an-image. Instead we
|
|
|
|
// only load the "agent-style-sheets" that nsStyleSheetService::Init()
|
|
|
|
// pulls in from the category manager. That keeps memory use of
|
|
|
|
// SVG-as-an-image down.
|
|
|
|
//
|
|
|
|
// We do this before adding UASheet() etc. below because
|
2015-04-23 19:10:30 +00:00
|
|
|
// EnsureOnDemandBuiltInUASheet prepends, and B2G/Fennec's
|
2014-05-24 20:37:48 +00:00
|
|
|
// content.css must come after UASheet() etc.
|
|
|
|
nsCOMPtr<nsICategoryManager> catMan =
|
|
|
|
do_GetService(NS_CATEGORYMANAGER_CONTRACTID);
|
|
|
|
if (catMan) {
|
|
|
|
nsCOMPtr<nsISimpleEnumerator> sheets;
|
|
|
|
catMan->EnumerateCategory("agent-style-sheets", getter_AddRefs(sheets));
|
|
|
|
if (sheets) {
|
|
|
|
bool hasMore;
|
|
|
|
while (NS_SUCCEEDED(sheets->HasMoreElements(&hasMore)) && hasMore) {
|
|
|
|
nsCOMPtr<nsISupports> sheet;
|
|
|
|
if (NS_FAILED(sheets->GetNext(getter_AddRefs(sheet))))
|
|
|
|
break;
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupportsCString> icStr = do_QueryInterface(sheet);
|
|
|
|
MOZ_ASSERT(icStr,
|
|
|
|
"category manager entries must be nsISupportsCStrings");
|
|
|
|
|
|
|
|
nsAutoCString name;
|
|
|
|
icStr->GetData(name);
|
|
|
|
|
|
|
|
nsXPIDLCString spec;
|
|
|
|
catMan->GetCategoryEntry("agent-style-sheets", name.get(),
|
|
|
|
getter_Copies(spec));
|
|
|
|
|
|
|
|
mozilla::css::Loader* cssLoader = CSSLoader();
|
|
|
|
if (cssLoader->GetEnabled()) {
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
NS_NewURI(getter_AddRefs(uri), spec);
|
|
|
|
if (uri) {
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<CSSStyleSheet> cssSheet;
|
2015-10-13 21:43:16 +00:00
|
|
|
cssLoader->LoadSheetSync(uri,
|
|
|
|
mozilla::css::eAgentSheetFeatures,
|
|
|
|
true, getter_AddRefs(cssSheet));
|
2014-05-24 20:37:48 +00:00
|
|
|
if (cssSheet) {
|
|
|
|
EnsureOnDemandBuiltInUASheet(cssSheet);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-20 10:32:49 +00:00
|
|
|
CSSStyleSheet* sheet = nsLayoutStylesheetCache::NumberControlSheet();
|
2014-05-28 13:28:34 +00:00
|
|
|
if (sheet) {
|
|
|
|
// number-control.css can be behind a pref
|
|
|
|
EnsureOnDemandBuiltInUASheet(sheet);
|
|
|
|
}
|
2014-05-24 19:29:11 +00:00
|
|
|
EnsureOnDemandBuiltInUASheet(nsLayoutStylesheetCache::FormsSheet());
|
2014-06-12 01:12:00 +00:00
|
|
|
EnsureOnDemandBuiltInUASheet(nsLayoutStylesheetCache::CounterStylesSheet());
|
2014-05-24 19:29:11 +00:00
|
|
|
EnsureOnDemandBuiltInUASheet(nsLayoutStylesheetCache::HTMLSheet());
|
2015-06-16 01:34:47 +00:00
|
|
|
if (nsLayoutUtils::ShouldUseNoFramesSheet(this)) {
|
|
|
|
EnsureOnDemandBuiltInUASheet(nsLayoutStylesheetCache::NoFramesSheet());
|
|
|
|
}
|
2015-06-16 01:34:47 +00:00
|
|
|
if (nsLayoutUtils::ShouldUseNoScriptSheet(this)) {
|
|
|
|
EnsureOnDemandBuiltInUASheet(nsLayoutStylesheetCache::NoScriptSheet());
|
|
|
|
}
|
2014-05-24 19:29:11 +00:00
|
|
|
EnsureOnDemandBuiltInUASheet(nsLayoutStylesheetCache::UASheet());
|
2015-06-16 01:34:47 +00:00
|
|
|
|
|
|
|
EndUpdate(UPDATE_STYLE);
|
2014-05-24 19:29:11 +00:00
|
|
|
}
|
|
|
|
|
2013-03-20 16:22:26 +00: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 14:13:33 +00:00
|
|
|
SVGDocument::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-03-20 16:22:26 +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
|
|
|
return SVGDocumentBinding::Wrap(aCx, this, aGivenProto);
|
2013-03-20 16:22:26 +00:00
|
|
|
}
|
|
|
|
|
2013-03-20 16:22:26 +00:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2004-11-18 23:32:06 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// Exported creation functions
|
|
|
|
|
2003-03-05 15:08:41 +00:00
|
|
|
nsresult
|
2001-12-12 07:59:31 +00:00
|
|
|
NS_NewSVGDocument(nsIDocument** aInstancePtrResult)
|
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<SVGDocument> doc = new SVGDocument();
|
Landing of SVG_20020806_BRANCH, Bug 182533. Refactoring of SVG backend, new GDI+ and Libart rendering
backends, text support on Windows (GDI+), rudimentary text support on Linux (libart/freetype2), presentation
attributes, lots of bug fixes (see bug 182533 for dependency list).
Not part of default build; code is #ifdef'ed out.
r=sicking, sr=jst for dom and htmlparser changes
r=bsmedberg, sr=tor for config changes
r=dbaron, sr=bzbarsky for content and layout changes
r=tor, sr=bzbarsky for gfx changes
2004-02-07 12:39:26 +00:00
|
|
|
|
|
|
|
nsresult rv = doc->Init();
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2013-04-13 07:08:49 +00:00
|
|
|
doc.forget(aInstancePtrResult);
|
Landing of SVG_20020806_BRANCH, Bug 182533. Refactoring of SVG backend, new GDI+ and Libart rendering
backends, text support on Windows (GDI+), rudimentary text support on Linux (libart/freetype2), presentation
attributes, lots of bug fixes (see bug 182533 for dependency list).
Not part of default build; code is #ifdef'ed out.
r=sicking, sr=jst for dom and htmlparser changes
r=bsmedberg, sr=tor for config changes
r=dbaron, sr=bzbarsky for content and layout changes
r=tor, sr=bzbarsky for gfx changes
2004-02-07 12:39:26 +00:00
|
|
|
return rv;
|
2001-12-12 07:59:31 +00:00
|
|
|
}
|