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: */
|
2012-05-21 15:12:37 +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/. */
|
2001-12-12 10:59:31 +03:00
|
|
|
|
2013-03-20 20:22:26 +04:00
|
|
|
#include "mozilla/dom/SVGDocument.h"
|
2014-05-25 00:37:48 +04:00
|
|
|
|
|
|
|
#include "mozilla/css/Loader.h"
|
|
|
|
#include "nsICategoryManager.h"
|
|
|
|
#include "nsISimpleEnumerator.h"
|
|
|
|
#include "nsIStyleSheetService.h"
|
|
|
|
#include "nsISupportsPrimitives.h"
|
2014-05-24 23:29:11 +04:00
|
|
|
#include "nsLayoutStylesheetCache.h"
|
2014-05-25 00:37:48 +04:00
|
|
|
#include "nsNetUtil.h"
|
|
|
|
#include "nsServiceManagerUtils.h"
|
2002-03-21 04:43:51 +03:00
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsLiteralString.h"
|
2013-02-08 23:55:07 +04:00
|
|
|
#include "nsIDOMSVGElement.h"
|
2010-05-05 22:18:05 +04:00
|
|
|
#include "mozilla/dom/Element.h"
|
2013-03-20 20:22:26 +04:00
|
|
|
#include "nsSVGElement.h"
|
|
|
|
#include "mozilla/dom/SVGDocumentBinding.h"
|
2010-04-30 17:12:05 +04:00
|
|
|
|
2014-05-25 00:37:48 +04:00
|
|
|
using namespace mozilla::css;
|
2010-04-30 17:12:05 +04:00
|
|
|
using namespace mozilla::dom;
|
2004-11-19 02:32:06 +03:00
|
|
|
|
2013-03-20 20:22:26 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2004-11-19 02:32:06 +03:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsISupports methods:
|
2001-12-12 10:59:31 +03:00
|
|
|
|
2013-03-20 20:22:26 +04:00
|
|
|
void
|
|
|
|
SVGDocument::GetDomain(nsAString& aDomain, ErrorResult& aRv)
|
2004-11-19 02:32:06 +03:00
|
|
|
{
|
|
|
|
SetDOMStringToNull(aDomain);
|
2003-06-21 04:26:28 +04:00
|
|
|
|
2004-01-10 02:54:21 +03:00
|
|
|
if (mDocumentURI) {
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString domain;
|
2004-01-10 02:54:21 +03:00
|
|
|
nsresult rv = mDocumentURI->GetHost(domain);
|
2013-03-20 20:22:26 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (domain.IsEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
2004-11-19 02:32:06 +03:00
|
|
|
CopyUTF8toUTF16(domain, aDomain);
|
2001-12-12 10:59:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-20 20:22:26 +04:00
|
|
|
nsSVGElement*
|
|
|
|
SVGDocument::GetRootElement(ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
Element* root = nsDocument::GetRootElement();
|
|
|
|
if (!root) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2015-03-03 14:08:59 +03:00
|
|
|
if (!root->IsSVGElement()) {
|
2013-03-20 20:22:26 +04:00
|
|
|
aRv.Throw(NS_NOINTERFACE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return static_cast<nsSVGElement*>(root);
|
2001-12-12 10:59:31 +03:00
|
|
|
}
|
|
|
|
|
2014-06-05 04:01:39 +04:00
|
|
|
nsresult
|
|
|
|
SVGDocument::InsertChildAt(nsIContent* aKid, uint32_t aIndex, bool aNotify)
|
|
|
|
{
|
2015-04-14 02:36:57 +03:00
|
|
|
if (aKid->IsElement() && !aKid->IsSVGElement()) {
|
2014-06-05 04:01:39 +04: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-14 02:36:57 +03: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 04:01:39 +04:00
|
|
|
EnsureNonSVGUserAgentStyleSheetsLoaded();
|
|
|
|
}
|
|
|
|
|
2015-04-14 02:36:57 +03:00
|
|
|
return XMLDocument::InsertChildAt(aKid, aIndex, aNotify);
|
2014-06-05 04:01:39 +04:00
|
|
|
}
|
|
|
|
|
2009-12-11 07:02:13 +03:00
|
|
|
nsresult
|
2014-06-20 06:01:40 +04:00
|
|
|
SVGDocument::Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult) const
|
2009-12-11 07:02:13 +03:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aNodeInfo->NodeInfoManager() == mNodeInfoManager,
|
|
|
|
"Can't import this document into another document!");
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<SVGDocument> clone = new SVGDocument();
|
2009-12-11 07:02:13 +03:00
|
|
|
nsresult rv = CloneDocHelper(clone.get());
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return CallQueryInterface(clone.get(), aResult);
|
|
|
|
}
|
|
|
|
|
2014-05-24 23:29:11 +04:00
|
|
|
void
|
|
|
|
SVGDocument::EnsureNonSVGUserAgentStyleSheetsLoaded()
|
|
|
|
{
|
|
|
|
if (mHasLoadedNonSVGUserAgentStyleSheets) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-20 00:59:37 +03: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 23:29:11 +04:00
|
|
|
mHasLoadedNonSVGUserAgentStyleSheets = true;
|
|
|
|
|
2015-06-16 04:34:47 +03:00
|
|
|
BeginUpdate(UPDATE_STYLE);
|
|
|
|
|
2014-05-25 00:37:48 +04:00
|
|
|
if (IsBeingUsedAsImage()) {
|
|
|
|
// nsDocumentViewer::CreateStyleSet skipped loading all user-agent/user
|
2015-04-23 22:10:30 +03:00
|
|
|
// style sheets in this case, but we'll need B2G/Fennec's
|
2014-05-25 00:37:48 +04: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 22:10:30 +03:00
|
|
|
// EnsureOnDemandBuiltInUASheet prepends, and B2G/Fennec's
|
2014-05-25 00:37:48 +04: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 08:24:48 +03:00
|
|
|
RefPtr<CSSStyleSheet> cssSheet;
|
2015-10-14 00:43:16 +03:00
|
|
|
cssLoader->LoadSheetSync(uri,
|
|
|
|
mozilla::css::eAgentSheetFeatures,
|
|
|
|
true, getter_AddRefs(cssSheet));
|
2014-05-25 00:37:48 +04:00
|
|
|
if (cssSheet) {
|
|
|
|
EnsureOnDemandBuiltInUASheet(cssSheet);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet* sheet = nsLayoutStylesheetCache::NumberControlSheet();
|
2014-05-28 17:28:34 +04:00
|
|
|
if (sheet) {
|
|
|
|
// number-control.css can be behind a pref
|
|
|
|
EnsureOnDemandBuiltInUASheet(sheet);
|
|
|
|
}
|
2014-05-24 23:29:11 +04:00
|
|
|
EnsureOnDemandBuiltInUASheet(nsLayoutStylesheetCache::FormsSheet());
|
2014-06-12 05:12:00 +04:00
|
|
|
EnsureOnDemandBuiltInUASheet(nsLayoutStylesheetCache::CounterStylesSheet());
|
2014-05-24 23:29:11 +04:00
|
|
|
EnsureOnDemandBuiltInUASheet(nsLayoutStylesheetCache::HTMLSheet());
|
2015-06-16 04:34:47 +03:00
|
|
|
if (nsLayoutUtils::ShouldUseNoFramesSheet(this)) {
|
|
|
|
EnsureOnDemandBuiltInUASheet(nsLayoutStylesheetCache::NoFramesSheet());
|
|
|
|
}
|
2015-06-16 04:34:47 +03:00
|
|
|
if (nsLayoutUtils::ShouldUseNoScriptSheet(this)) {
|
|
|
|
EnsureOnDemandBuiltInUASheet(nsLayoutStylesheetCache::NoScriptSheet());
|
|
|
|
}
|
2014-05-24 23:29:11 +04:00
|
|
|
EnsureOnDemandBuiltInUASheet(nsLayoutStylesheetCache::UASheet());
|
2015-06-16 04:34:47 +03:00
|
|
|
|
|
|
|
EndUpdate(UPDATE_STYLE);
|
2014-05-24 23:29:11 +04:00
|
|
|
}
|
|
|
|
|
2013-03-20 20:22:26 +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
|
|
|
SVGDocument::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-03-20 20:22:26 +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 SVGDocumentBinding::Wrap(aCx, this, aGivenProto);
|
2013-03-20 20:22:26 +04:00
|
|
|
}
|
|
|
|
|
2013-03-20 20:22:26 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2004-11-19 02:32:06 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// Exported creation functions
|
|
|
|
|
2003-03-05 18:08:41 +03:00
|
|
|
nsresult
|
2001-12-12 10:59:31 +03:00
|
|
|
NS_NewSVGDocument(nsIDocument** aInstancePtrResult)
|
|
|
|
{
|
2015-10-18 08:24:48 +03: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 15:39:26 +03:00
|
|
|
|
|
|
|
nsresult rv = doc->Init();
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2013-04-13 11:08:49 +04: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 15:39:26 +03:00
|
|
|
return rv;
|
2001-12-12 10:59:31 +03:00
|
|
|
}
|