From 15a02e49626e334edf46756e08e2359e778a10ee Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Thu, 14 Mar 2013 17:41:52 -0400 Subject: [PATCH 001/234] Bug 847971 - Make openURL select recent windows that match the current privacy state. r=dolske --HG-- rename : browser/modules/RecentWindow.jsm => toolkit/modules/RecentWindow.jsm --- browser/base/content/browser.js | 2 +- .../components/downloads/content/allDownloadsViewOverlay.js | 2 +- browser/components/downloads/src/DownloadsUI.js | 2 +- browser/components/nsBrowserContentHandler.js | 2 +- browser/components/nsBrowserGlue.js | 2 +- browser/modules/Makefile.in | 5 ----- toolkit/content/contentAreaUtils.js | 5 ++++- toolkit/modules/Makefile.in | 4 ++++ {browser => toolkit}/modules/RecentWindow.jsm | 0 9 files changed, 13 insertions(+), 11 deletions(-) rename {browser => toolkit}/modules/RecentWindow.jsm (100%) diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js index 5acee0950f3..4099c666c7f 100644 --- a/browser/base/content/browser.js +++ b/browser/base/content/browser.js @@ -7,7 +7,7 @@ let Ci = Components.interfaces; let Cu = Components.utils; Cu.import("resource://gre/modules/XPCOMUtils.jsm"); -Cu.import("resource:///modules/RecentWindow.jsm"); +Cu.import("resource://gre/modules/RecentWindow.jsm"); const nsIWebNavigation = Ci.nsIWebNavigation; diff --git a/browser/components/downloads/content/allDownloadsViewOverlay.js b/browser/components/downloads/content/allDownloadsViewOverlay.js index 6b28390b28d..2325864761f 100644 --- a/browser/components/downloads/content/allDownloadsViewOverlay.js +++ b/browser/components/downloads/content/allDownloadsViewOverlay.js @@ -23,7 +23,7 @@ Cu.import("resource://gre/modules/osfile.jsm"); XPCOMUtils.defineLazyModuleGetter(this, "PrivateBrowsingUtils", "resource://gre/modules/PrivateBrowsingUtils.jsm"); XPCOMUtils.defineLazyModuleGetter(this, "RecentWindow", - "resource:///modules/RecentWindow.jsm"); + "resource://gre/modules/RecentWindow.jsm"); XPCOMUtils.defineLazyModuleGetter(this, "FileUtils", "resource://gre/modules/FileUtils.jsm"); diff --git a/browser/components/downloads/src/DownloadsUI.js b/browser/components/downloads/src/DownloadsUI.js index 1234e10bc65..e5e3652bbbb 100644 --- a/browser/components/downloads/src/DownloadsUI.js +++ b/browser/components/downloads/src/DownloadsUI.js @@ -31,7 +31,7 @@ XPCOMUtils.defineLazyServiceGetter(this, "gBrowserGlue", "@mozilla.org/browser/browserglue;1", "nsIBrowserGlue"); XPCOMUtils.defineLazyModuleGetter(this, "RecentWindow", - "resource:///modules/RecentWindow.jsm"); + "resource://gre/modules/RecentWindow.jsm"); XPCOMUtils.defineLazyModuleGetter(this, "PrivateBrowsingUtils", "resource://gre/modules/PrivateBrowsingUtils.jsm"); diff --git a/browser/components/nsBrowserContentHandler.js b/browser/components/nsBrowserContentHandler.js index b489719cb35..96dc8743a54 100644 --- a/browser/components/nsBrowserContentHandler.js +++ b/browser/components/nsBrowserContentHandler.js @@ -8,7 +8,7 @@ Components.utils.import("resource://gre/modules/Services.jsm"); XPCOMUtils.defineLazyModuleGetter(this, "PrivateBrowsingUtils", "resource://gre/modules/PrivateBrowsingUtils.jsm"); XPCOMUtils.defineLazyModuleGetter(this, "RecentWindow", - "resource:///modules/RecentWindow.jsm"); + "resource://gre/modules/RecentWindow.jsm"); const nsISupports = Components.interfaces.nsISupports; diff --git a/browser/components/nsBrowserGlue.js b/browser/components/nsBrowserGlue.js index 112fc3fbb54..db381d46185 100644 --- a/browser/components/nsBrowserGlue.js +++ b/browser/components/nsBrowserGlue.js @@ -57,7 +57,7 @@ XPCOMUtils.defineLazyModuleGetter(this, "KeywordURLResetPrompter", "resource:///modules/KeywordURLResetPrompter.jsm"); XPCOMUtils.defineLazyModuleGetter(this, "RecentWindow", - "resource:///modules/RecentWindow.jsm"); + "resource://gre/modules/RecentWindow.jsm"); const PREF_PLUGINS_NOTIFYUSER = "plugins.update.notifyUser"; const PREF_PLUGINS_UPDATEURL = "plugins.update.url"; diff --git a/browser/modules/Makefile.in b/browser/modules/Makefile.in index ba3dbbab128..59990e4338d 100644 --- a/browser/modules/Makefile.in +++ b/browser/modules/Makefile.in @@ -25,11 +25,6 @@ EXTRA_JS_MODULES = \ SharedFrame.jsm \ $(NULL) -EXTRA_PP_JS_MODULES = \ - RecentWindow.jsm \ - $(NULL) - - ifeq ($(MOZ_WIDGET_TOOLKIT),windows) EXTRA_JS_MODULES += \ WindowsPreviewPerTab.jsm \ diff --git a/toolkit/content/contentAreaUtils.js b/toolkit/content/contentAreaUtils.js index 4a9ab268488..882ec5f98d7 100644 --- a/toolkit/content/contentAreaUtils.js +++ b/toolkit/content/contentAreaUtils.js @@ -5,6 +5,7 @@ Components.utils.import("resource://gre/modules/Services.jsm"); Components.utils.import("resource://gre/modules/PrivateBrowsingUtils.jsm"); +Components.utils.import("resource://gre/modules/RecentWindow.jsm"); var ContentAreaUtils = { @@ -1072,7 +1073,9 @@ function openURL(aURL) protocolSvc.loadUrl(uri); } else { - var recentWindow = Services.wm.getMostRecentWindow("navigator:browser"); + let isPrivate = PrivateBrowsingUtils.isWindowPrivate(window); + var recentWindow = RecentWindow.getMostRecentWindow({type: "navigator:browser", + private: isPrivate}); if (recentWindow) { var win = recentWindow.browserDOMWindow.openURI(uri, null, recentWindow.browserDOMWindow.OPEN_DEFAULTWINDOW, diff --git a/toolkit/modules/Makefile.in b/toolkit/modules/Makefile.in index 338effd08bf..d31a85889f9 100644 --- a/toolkit/modules/Makefile.in +++ b/toolkit/modules/Makefile.in @@ -16,4 +16,8 @@ EXTRA_JS_MODULES := \ Timer.jsm \ $(NULL) +EXTRA_PP_JS_MODULES = \ + RecentWindow.jsm \ + $(NULL) + include $(topsrcdir)/config/rules.mk diff --git a/browser/modules/RecentWindow.jsm b/toolkit/modules/RecentWindow.jsm similarity index 100% rename from browser/modules/RecentWindow.jsm rename to toolkit/modules/RecentWindow.jsm From 1f79f22adb034f8f1a521b696140df40828954e8 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Sun, 17 Mar 2013 12:33:37 -0400 Subject: [PATCH 002/234] Backed out changeset f85e650c1df7 (bug 847971) --HG-- rename : toolkit/modules/RecentWindow.jsm => browser/modules/RecentWindow.jsm --- browser/base/content/browser.js | 2 +- .../components/downloads/content/allDownloadsViewOverlay.js | 2 +- browser/components/downloads/src/DownloadsUI.js | 2 +- browser/components/nsBrowserContentHandler.js | 2 +- browser/components/nsBrowserGlue.js | 2 +- browser/modules/Makefile.in | 5 +++++ {toolkit => browser}/modules/RecentWindow.jsm | 0 toolkit/content/contentAreaUtils.js | 5 +---- toolkit/modules/Makefile.in | 4 ---- 9 files changed, 11 insertions(+), 13 deletions(-) rename {toolkit => browser}/modules/RecentWindow.jsm (100%) diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js index 4099c666c7f..5acee0950f3 100644 --- a/browser/base/content/browser.js +++ b/browser/base/content/browser.js @@ -7,7 +7,7 @@ let Ci = Components.interfaces; let Cu = Components.utils; Cu.import("resource://gre/modules/XPCOMUtils.jsm"); -Cu.import("resource://gre/modules/RecentWindow.jsm"); +Cu.import("resource:///modules/RecentWindow.jsm"); const nsIWebNavigation = Ci.nsIWebNavigation; diff --git a/browser/components/downloads/content/allDownloadsViewOverlay.js b/browser/components/downloads/content/allDownloadsViewOverlay.js index 2325864761f..6b28390b28d 100644 --- a/browser/components/downloads/content/allDownloadsViewOverlay.js +++ b/browser/components/downloads/content/allDownloadsViewOverlay.js @@ -23,7 +23,7 @@ Cu.import("resource://gre/modules/osfile.jsm"); XPCOMUtils.defineLazyModuleGetter(this, "PrivateBrowsingUtils", "resource://gre/modules/PrivateBrowsingUtils.jsm"); XPCOMUtils.defineLazyModuleGetter(this, "RecentWindow", - "resource://gre/modules/RecentWindow.jsm"); + "resource:///modules/RecentWindow.jsm"); XPCOMUtils.defineLazyModuleGetter(this, "FileUtils", "resource://gre/modules/FileUtils.jsm"); diff --git a/browser/components/downloads/src/DownloadsUI.js b/browser/components/downloads/src/DownloadsUI.js index e5e3652bbbb..1234e10bc65 100644 --- a/browser/components/downloads/src/DownloadsUI.js +++ b/browser/components/downloads/src/DownloadsUI.js @@ -31,7 +31,7 @@ XPCOMUtils.defineLazyServiceGetter(this, "gBrowserGlue", "@mozilla.org/browser/browserglue;1", "nsIBrowserGlue"); XPCOMUtils.defineLazyModuleGetter(this, "RecentWindow", - "resource://gre/modules/RecentWindow.jsm"); + "resource:///modules/RecentWindow.jsm"); XPCOMUtils.defineLazyModuleGetter(this, "PrivateBrowsingUtils", "resource://gre/modules/PrivateBrowsingUtils.jsm"); diff --git a/browser/components/nsBrowserContentHandler.js b/browser/components/nsBrowserContentHandler.js index 96dc8743a54..b489719cb35 100644 --- a/browser/components/nsBrowserContentHandler.js +++ b/browser/components/nsBrowserContentHandler.js @@ -8,7 +8,7 @@ Components.utils.import("resource://gre/modules/Services.jsm"); XPCOMUtils.defineLazyModuleGetter(this, "PrivateBrowsingUtils", "resource://gre/modules/PrivateBrowsingUtils.jsm"); XPCOMUtils.defineLazyModuleGetter(this, "RecentWindow", - "resource://gre/modules/RecentWindow.jsm"); + "resource:///modules/RecentWindow.jsm"); const nsISupports = Components.interfaces.nsISupports; diff --git a/browser/components/nsBrowserGlue.js b/browser/components/nsBrowserGlue.js index db381d46185..112fc3fbb54 100644 --- a/browser/components/nsBrowserGlue.js +++ b/browser/components/nsBrowserGlue.js @@ -57,7 +57,7 @@ XPCOMUtils.defineLazyModuleGetter(this, "KeywordURLResetPrompter", "resource:///modules/KeywordURLResetPrompter.jsm"); XPCOMUtils.defineLazyModuleGetter(this, "RecentWindow", - "resource://gre/modules/RecentWindow.jsm"); + "resource:///modules/RecentWindow.jsm"); const PREF_PLUGINS_NOTIFYUSER = "plugins.update.notifyUser"; const PREF_PLUGINS_UPDATEURL = "plugins.update.url"; diff --git a/browser/modules/Makefile.in b/browser/modules/Makefile.in index 59990e4338d..ba3dbbab128 100644 --- a/browser/modules/Makefile.in +++ b/browser/modules/Makefile.in @@ -25,6 +25,11 @@ EXTRA_JS_MODULES = \ SharedFrame.jsm \ $(NULL) +EXTRA_PP_JS_MODULES = \ + RecentWindow.jsm \ + $(NULL) + + ifeq ($(MOZ_WIDGET_TOOLKIT),windows) EXTRA_JS_MODULES += \ WindowsPreviewPerTab.jsm \ diff --git a/toolkit/modules/RecentWindow.jsm b/browser/modules/RecentWindow.jsm similarity index 100% rename from toolkit/modules/RecentWindow.jsm rename to browser/modules/RecentWindow.jsm diff --git a/toolkit/content/contentAreaUtils.js b/toolkit/content/contentAreaUtils.js index 882ec5f98d7..4a9ab268488 100644 --- a/toolkit/content/contentAreaUtils.js +++ b/toolkit/content/contentAreaUtils.js @@ -5,7 +5,6 @@ Components.utils.import("resource://gre/modules/Services.jsm"); Components.utils.import("resource://gre/modules/PrivateBrowsingUtils.jsm"); -Components.utils.import("resource://gre/modules/RecentWindow.jsm"); var ContentAreaUtils = { @@ -1073,9 +1072,7 @@ function openURL(aURL) protocolSvc.loadUrl(uri); } else { - let isPrivate = PrivateBrowsingUtils.isWindowPrivate(window); - var recentWindow = RecentWindow.getMostRecentWindow({type: "navigator:browser", - private: isPrivate}); + var recentWindow = Services.wm.getMostRecentWindow("navigator:browser"); if (recentWindow) { var win = recentWindow.browserDOMWindow.openURI(uri, null, recentWindow.browserDOMWindow.OPEN_DEFAULTWINDOW, diff --git a/toolkit/modules/Makefile.in b/toolkit/modules/Makefile.in index d31a85889f9..338effd08bf 100644 --- a/toolkit/modules/Makefile.in +++ b/toolkit/modules/Makefile.in @@ -16,8 +16,4 @@ EXTRA_JS_MODULES := \ Timer.jsm \ $(NULL) -EXTRA_PP_JS_MODULES = \ - RecentWindow.jsm \ - $(NULL) - include $(topsrcdir)/config/rules.mk From 04f1f14f19e7dd50ebc540d69ea1430d827a5632 Mon Sep 17 00:00:00 2001 From: Andrew McCreight Date: Sun, 17 Mar 2013 09:55:14 -0700 Subject: [PATCH 003/234] Bug 827486, part 1: add JSImplementation extended attribute. r=bz --- dom/bindings/Configuration.py | 10 ++++++---- dom/bindings/parser/WebIDL.py | 17 +++++++++++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/dom/bindings/Configuration.py b/dom/bindings/Configuration.py index c86f6d91d96..8e3e6888f4d 100644 --- a/dom/bindings/Configuration.py +++ b/dom/bindings/Configuration.py @@ -376,8 +376,11 @@ class Descriptor(DescriptorProvider): else: add('all', [config], attribute) - for attribute in ['implicitJSContext', 'resultNotAddRefed']: - addExtendedAttribute(attribute, desc.get(attribute, {})) + if self.interface.isJSImplemented(): + addExtendedAttribute('implicitJSContext', ['constructor']) + else: + for attribute in ['implicitJSContext', 'resultNotAddRefed']: + addExtendedAttribute(attribute, desc.get(attribute, {})) self.binaryNames = desc.get('binaryNames', {}) if '__legacycaller' not in self.binaryNames: @@ -420,9 +423,9 @@ class Descriptor(DescriptorProvider): attrs.append("infallible") name = member.identifier.name + throws = self.interface.isJSImplemented() or member.getExtendedAttribute("Throws") if member.isMethod(): attrs = self.extendedAttributes['all'].get(name, []) - throws = member.getExtendedAttribute("Throws") maybeAppendInfallibleToAttrs(attrs, throws) return attrs @@ -430,7 +433,6 @@ class Descriptor(DescriptorProvider): assert bool(getter) != bool(setter) key = 'getterOnly' if getter else 'setterOnly' attrs = self.extendedAttributes['all'].get(name, []) + self.extendedAttributes[key].get(name, []) - throws = member.getExtendedAttribute("Throws") if throws is None: throwsAttr = "GetterThrows" if getter else "SetterThrows" throws = member.getExtendedAttribute(throwsAttr) diff --git a/dom/bindings/parser/WebIDL.py b/dom/bindings/parser/WebIDL.py index cea8a4228b4..8d5ebd05a1d 100644 --- a/dom/bindings/parser/WebIDL.py +++ b/dom/bindings/parser/WebIDL.py @@ -475,6 +475,12 @@ class IDLExternalInterface(IDLObjectWithIdentifier): def resolve(self, parentScope): pass + def getJSImplementation(self): + return None + + def isJSImplemented(self): + return False + def _getDependentObjects(self): return set() @@ -956,6 +962,17 @@ class IDLInterface(IDLObjectWithScope): # Put the new members at the beginning self.members = members + self.members + def getJSImplementation(self): + classId = self.getExtendedAttribute("JSImplementation") + if not classId: + return classId + assert isinstance(classId, list) + assert len(classId) == 1 + return classId[0] + + def isJSImplemented(self): + return bool(self.getJSImplementation()) + def _getDependentObjects(self): deps = set(self.members) deps.union(self.implementedInterfaces) From 22dee5ecfb50f8fd4ea758c749798fb6dfa8795d Mon Sep 17 00:00:00 2001 From: Andrew McCreight Date: Sun, 17 Mar 2013 09:55:29 -0700 Subject: [PATCH 004/234] Bug 827486, part 2 - Refactor example class codegen into common base class. r=bz --- dom/bindings/Codegen.py | 73 +++++++++++++++++++++++++++-------------- 1 file changed, 48 insertions(+), 25 deletions(-) diff --git a/dom/bindings/Codegen.py b/dom/bindings/Codegen.py index 18671540586..e6ba2b1f7c0 100644 --- a/dom/bindings/Codegen.py +++ b/dom/bindings/Codegen.py @@ -7655,24 +7655,28 @@ class CGExampleSetter(CGNativeMember): def define(self, cgClass): return '' -class CGExampleClass(CGClass): +class CGBindingImplClass(CGClass): """ - Codegen for the actual example class implemenation for this descriptor + Common codegen for generating a C++ implementation of a WebIDL interface """ - def __init__(self, descriptor): + def __init__(self, descriptor, cgMethod, cgGetter, cgSetter): + """ + cgMethod, cgGetter and cgSetter are classes used to codegen methods, + getters and setters. + """ self.descriptor = descriptor iface = descriptor.interface - methodDecls = [] + self.methodDecls = [] def appendMethod(m): sigs = m.signatures() for s in sigs[:-1]: # Don't put an empty line after overloads, until we # get to the last one. - methodDecls.append(CGExampleMethod(descriptor, m, s, - breakAfter=False)) - methodDecls.append(CGExampleMethod(descriptor, m, sigs[-1])) + self.methodDecls.append(cgMethod(descriptor, m, s, + breakAfter=False)) + self.methodDecls.append(cgMethod(descriptor, m, sigs[-1])) if iface.ctor(): appendMethod(iface.ctor()) @@ -7684,9 +7688,9 @@ class CGExampleClass(CGClass): continue appendMethod(m) elif m.isAttr(): - methodDecls.append(CGExampleGetter(descriptor, m)) + self.methodDecls.append(cgGetter(descriptor, m)) if not m.readonly: - methodDecls.append(CGExampleSetter(descriptor, m)) + self.methodDecls.append(cgSetter(descriptor, m)) # Now do the special operations def appendSpecialOperation(name, op): @@ -7719,7 +7723,7 @@ class CGExampleClass(CGClass): else: # We already added this method return - methodDecls.append( + self.methodDecls.append( CGNativeMember(descriptor, op, name, (returnType, args), @@ -7732,7 +7736,7 @@ class CGExampleClass(CGClass): # If we support indexed properties, then we need a Length() # method so we know which indices are supported. if descriptor.supportsIndexedProperties(): - methodDecls.append( + self.methodDecls.append( CGNativeMember(descriptor, FakeMember(), "Length", (BuiltinTypes[IDLBuiltinType.Types.unsigned_long], @@ -7741,7 +7745,7 @@ class CGExampleClass(CGClass): # And if we support named properties we need to be able to # enumerate the supported names. if descriptor.supportsNamedProperties(): - methodDecls.append( + self.methodDecls.append( CGNativeMember( descriptor, FakeMember(), "GetSupportedNames", @@ -7752,18 +7756,37 @@ class CGExampleClass(CGClass): wrapArgs = [Argument('JSContext*', 'aCx'), Argument('JSObject*', 'aScope')] - methodDecls.insert(0, - ClassMethod("WrapObject", "JSObject*", - wrapArgs, virtual=descriptor.wrapperCache, - breakAfterReturnDecl=" ")) - getParentObjectReturnType = ( - "// TODO: return something sensible here, and change the return type\n" - "%s*" % descriptor.name) - methodDecls.insert(0, - ClassMethod("GetParentObject", - getParentObjectReturnType, - [], const=True, - breakAfterReturnDecl=" ")) + self.methodDecls.insert(0, + ClassMethod("WrapObject", "JSObject*", + wrapArgs, virtual=descriptor.wrapperCache, + breakAfterReturnDecl=" ", + body=self.getWrapObjectBody())) + self.methodDecls.insert(0, + ClassMethod("GetParentObject", + self.getGetParentObjectReturnType(), + [], const=True, + breakAfterReturnDecl=" ", + body=self.getGetParentObjectBody())) + + # Invoke CGClass.__init__ in any subclasses afterwards to do the actual codegen. + + def getWrapObjectBody(self): + return None + + def getGetParentObjectReturnType(self): + return ("// TODO: return something sensible here, and change the return type\n" + "%s*" % self.descriptor.name) + + def getGetParentObjectBody(self): + return None + +class CGExampleClass(CGBindingImplClass): + """ + Codegen for the actual example class implementation for this descriptor + """ + def __init__(self, descriptor): + CGBindingImplClass.__init__(self, descriptor, CGExampleMethod, CGExampleGetter, CGExampleSetter) + extradeclarations=( "public:\n" " NS_DECL_CYCLE_COLLECTING_ISUPPORTS\n" @@ -7776,7 +7799,7 @@ class CGExampleClass(CGClass): constructors=[ClassConstructor([], visibility="public")], destructor=ClassDestructor(visibility="public"), - methods=methodDecls, + methods=self.methodDecls, decorators="MOZ_FINAL", extradeclarations=extradeclarations) From 2c6f06baf36013eab83dc7b963219a86927156e3 Mon Sep 17 00:00:00 2001 From: Andrew McCreight Date: Sun, 17 Mar 2013 09:55:42 -0700 Subject: [PATCH 005/234] Bug 827486, part 3 - add dependencies for CGBindingImplClass. r=bz --- dom/bindings/Codegen.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/dom/bindings/Codegen.py b/dom/bindings/Codegen.py index e6ba2b1f7c0..bceb8512476 100644 --- a/dom/bindings/Codegen.py +++ b/dom/bindings/Codegen.py @@ -7665,6 +7665,7 @@ class CGBindingImplClass(CGClass): getters and setters. """ self.descriptor = descriptor + self._deps = descriptor.interface.getDeps() iface = descriptor.interface @@ -7780,6 +7781,10 @@ class CGBindingImplClass(CGClass): def getGetParentObjectBody(self): return None + def deps(self): + return self._deps + + class CGExampleClass(CGBindingImplClass): """ Codegen for the actual example class implementation for this descriptor From e7eae783a72ffac899e6d587fa15ba8563fe669a Mon Sep 17 00:00:00 2001 From: Andrew McCreight Date: Sun, 17 Mar 2013 09:55:55 -0700 Subject: [PATCH 006/234] Bug 827486, part 4: copy parts of example generator to JS impl generator. r=bz --- dom/bindings/Codegen.py | 57 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/dom/bindings/Codegen.py b/dom/bindings/Codegen.py index bceb8512476..af256d9237a 100644 --- a/dom/bindings/Codegen.py +++ b/dom/bindings/Codegen.py @@ -7897,6 +7897,63 @@ class CGExampleRoot(CGThing): def define(self): return self.root.define() + +class CGJSImplMethod(CGNativeMember): + def __init__(self, descriptor, method, signature, breakAfter=True): + CGNativeMember.__init__(self, descriptor, method, + CGSpecializedMethod.makeNativeName(descriptor, + method), + signature, + descriptor.getExtendedAttributes(method), + breakAfter=breakAfter, + variadicIsSequence=True) + def define(self, cgClass): + return '' + +class CGJSImplGetter(CGNativeMember): + def __init__(self, descriptor, attr): + CGNativeMember.__init__(self, descriptor, attr, + CGSpecializedGetter.makeNativeName(descriptor, + attr), + (attr.type, []), + descriptor.getExtendedAttributes(attr, + getter=True)) + def define(self, cgClass): + return '' + +class CGJSImplSetter(CGNativeMember): + def __init__(self, descriptor, attr): + CGNativeMember.__init__(self, descriptor, attr, + CGSpecializedSetter.makeNativeName(descriptor, + attr), + (BuiltinTypes[IDLBuiltinType.Types.void], + [FakeArgument(attr.type, attr)]), + descriptor.getExtendedAttributes(attr, + setter=True)) + def define(self, cgClass): + return '' + +class CGJSImplClass(CGBindingImplClass): + def __init__(self, descriptor): + CGBindingImplClass.__init__(self, descriptor, CGJSImplMethod, CGJSImplGetter, CGJSImplSetter) + + extradeclarations=( + "public:\n" + " NS_DECL_CYCLE_COLLECTING_ISUPPORTS\n" + " NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(%s)\n" + "\n" % descriptor.name) + + CGClass.__init__(self, descriptor.name, + bases=[ClassBase("nsISupports /* Change nativeOwnership in the binding configuration if you don't want this */"), + ClassBase("nsWrapperCache /* Change wrapperCache in the binding configuration if you don't want this */")], + constructors=[ClassConstructor([], + visibility="public")], + destructor=ClassDestructor(visibility="public"), + methods=self.methodDecls, + decorators="MOZ_FINAL", + extradeclarations=extradeclarations) + + class CGCallback(CGClass): def __init__(self, idlObject, descriptorProvider, baseName, methods, getters=[], setters=[]): From adc7071781e14a047b8c1c66be7c0457599ebd5d Mon Sep 17 00:00:00 2001 From: Andrew McCreight Date: Sun, 17 Mar 2013 09:56:05 -0700 Subject: [PATCH 007/234] Bug 827486, part 5: add the main JS impl code gen. r=bz --- dom/bindings/Codegen.py | 142 +++++++++++++++++++++++++++++++++------- 1 file changed, 119 insertions(+), 23 deletions(-) diff --git a/dom/bindings/Codegen.py b/dom/bindings/Codegen.py index af256d9237a..fff76939e63 100644 --- a/dom/bindings/Codegen.py +++ b/dom/bindings/Codegen.py @@ -7621,7 +7621,7 @@ class CGNativeMember(ClassMethod): class CGExampleMethod(CGNativeMember): - def __init__(self, descriptor, method, signature, breakAfter=True): + def __init__(self, descriptor, method, signature, isConstructor, breakAfter=True): CGNativeMember.__init__(self, descriptor, method, CGSpecializedMethod.makeNativeName(descriptor, method), @@ -7670,19 +7670,21 @@ class CGBindingImplClass(CGClass): iface = descriptor.interface self.methodDecls = [] - def appendMethod(m): + def appendMethod(m, isConstructor=False): sigs = m.signatures() for s in sigs[:-1]: # Don't put an empty line after overloads, until we # get to the last one. self.methodDecls.append(cgMethod(descriptor, m, s, + isConstructor, breakAfter=False)) - self.methodDecls.append(cgMethod(descriptor, m, sigs[-1])) + self.methodDecls.append(cgMethod(descriptor, m, sigs[-1], + isConstructor)) if iface.ctor(): - appendMethod(iface.ctor()) + appendMethod(iface.ctor(), isConstructor=True) for n in iface.namedConstructors: - appendMethod(n) + appendMethod(n, isConstructor=True) for m in iface.members: if m.isMethod(): if m.isIdentifierLess(): @@ -7898,8 +7900,11 @@ class CGExampleRoot(CGThing): return self.root.define() +def jsImplName(name): + return name + "JSImpl" + class CGJSImplMethod(CGNativeMember): - def __init__(self, descriptor, method, signature, breakAfter=True): + def __init__(self, descriptor, method, signature, isConstructor, breakAfter=True): CGNativeMember.__init__(self, descriptor, method, CGSpecializedMethod.makeNativeName(descriptor, method), @@ -7907,8 +7912,68 @@ class CGJSImplMethod(CGNativeMember): descriptor.getExtendedAttributes(method), breakAfter=breakAfter, variadicIsSequence=True) - def define(self, cgClass): - return '' + self.signature = signature + if isConstructor: + self.body = self.getConstructorImpl() + else: + self.body = self.getImpl() + + def getImpl(self): + callbackArgs = [arg.name for arg in self.getArgs(self.signature[0], self.signature[1])] + return 'return mImpl->%s(%s);' % (self.name, ", ".join(callbackArgs)) + + def getConstructorImpl(self): + assert self.descriptor.interface.isJSImplemented() + if self.name != 'Constructor': + raise TypeError("Named constructors are not supported for JS implemented WebIDL. See bug 851287.") + if len(self.signature[1]) != 0: + raise TypeError("Constructors with arguments are unsupported. See bug 851178.") + + return string.Template( +""" // Get the window to use as a parent. + nsCOMPtr window = do_QueryInterface(global.Get()); + if (!window) { + aRv.Throw(NS_ERROR_FAILURE); + return nullptr; + } + // Get the JS implementation for the WebIDL interface. + nsCOMPtr implISupports = do_CreateInstance("${contractId}"); + MOZ_ASSERT(implISupports, "Failed to get JS implementation instance from contract ID."); + if (!implISupports) { + aRv.Throw(NS_ERROR_FAILURE); + return nullptr; + } + nsCOMPtr implWrapped = do_QueryInterface(implISupports); + MOZ_ASSERT(implWrapped, "Failed to get wrapped JS from XPCOM component."); + if (!implWrapped) { + aRv.Throw(NS_ERROR_FAILURE); + return nullptr; + } + JSObject* jsImplObj; + if (NS_FAILED(implWrapped->GetJSObject(&jsImplObj))) { + aRv.Throw(NS_ERROR_FAILURE); + return nullptr; + } + // Construct the callback interface object. + bool initOk; + nsRefPtr<${callbackClass}> cbImpl = new ${callbackClass}(cx, nullptr, jsImplObj, &initOk); + if (!initOk) { + aRv.Throw(NS_ERROR_FAILURE); + return nullptr; + } + // Build the actual implementation. + nsRefPtr<${implClass}> impl = new ${implClass}(cbImpl, window); + return impl.forget();""").substitute({"implClass" : self.descriptor.name, + "callbackClass" : jsImplName(self.descriptor.name), + "contractId" : self.descriptor.interface.getJSImplementation() + }) + +# We're always fallible +def callbackGetterName(attr): + return "Get" + MakeNativeName(attr.identifier.name) + +def callbackSetterName(attr): + return "Set" + MakeNativeName(attr.identifier.name) class CGJSImplGetter(CGNativeMember): def __init__(self, descriptor, attr): @@ -7918,8 +7983,11 @@ class CGJSImplGetter(CGNativeMember): (attr.type, []), descriptor.getExtendedAttributes(attr, getter=True)) - def define(self, cgClass): - return '' + self.body = self.getImpl() + + def getImpl(self): + callbackArgs = [arg.name for arg in self.getArgs(self.member.type, [])] + return 'return mImpl->%s(%s);' % (callbackGetterName(self.member), ", ".join(callbackArgs)) class CGJSImplSetter(CGNativeMember): def __init__(self, descriptor, attr): @@ -7930,8 +7998,12 @@ class CGJSImplSetter(CGNativeMember): [FakeArgument(attr.type, attr)]), descriptor.getExtendedAttributes(attr, setter=True)) - def define(self, cgClass): - return '' + self.body = self.getImpl() + + def getImpl(self): + callbackArgs = [arg.name for arg in self.getArgs(BuiltinTypes[IDLBuiltinType.Types.void], + [FakeArgument(self.member.type, self.member)])] + return 'mImpl->%s(%s);' % (callbackSetterName(self.member), ", ".join(callbackArgs)) class CGJSImplClass(CGBindingImplClass): def __init__(self, descriptor): @@ -7941,18 +8013,43 @@ class CGJSImplClass(CGBindingImplClass): "public:\n" " NS_DECL_CYCLE_COLLECTING_ISUPPORTS\n" " NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(%s)\n" - "\n" % descriptor.name) + "\n" + "private:\n" + " nsRefPtr<%s> mImpl;\n" + " nsCOMPtr mParent;\n" + "\n" % (descriptor.name, jsImplName(descriptor.name))) + + extradefinitions= string.Template( + "NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_2(${ifaceName}, mImpl, mParent)\n" + "NS_IMPL_CYCLE_COLLECTING_ADDREF(${ifaceName})\n" + "NS_IMPL_CYCLE_COLLECTING_RELEASE(${ifaceName})\n" + "NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(${ifaceName})\n" + " NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY\n" + " NS_INTERFACE_MAP_ENTRY(nsISupports)\n" + "NS_INTERFACE_MAP_END\n").substitute({ "ifaceName": self.descriptor.name }) CGClass.__init__(self, descriptor.name, - bases=[ClassBase("nsISupports /* Change nativeOwnership in the binding configuration if you don't want this */"), - ClassBase("nsWrapperCache /* Change wrapperCache in the binding configuration if you don't want this */")], - constructors=[ClassConstructor([], - visibility="public")], - destructor=ClassDestructor(visibility="public"), + bases=[ClassBase("nsISupports"), + ClassBase("nsWrapperCache")], + constructors=[ClassConstructor([Argument(jsImplName(descriptor.name) + "*", "aImpl"), + Argument("nsISupports*", "aParent")], + visibility="public", + baseConstructors=["mImpl(aImpl)", + "mParent(aParent)"], + body="SetIsDOMBinding();")], methods=self.methodDecls, decorators="MOZ_FINAL", - extradeclarations=extradeclarations) + extradeclarations=extradeclarations, + extradefinitions=extradefinitions) + def getWrapObjectBody(self): + return "return %sBinding::Wrap(aCx, aScope, this);" % self.descriptor.name + + def getGetParentObjectReturnType(self): + return "nsISupports*" + + def getGetParentObjectBody(self): + return "return mParent;" class CGCallback(CGClass): def __init__(self, idlObject, descriptorProvider, baseName, methods, @@ -8124,7 +8221,7 @@ class CallbackMember(CGNativeMember): # will handle generating public versions that handle the "this" stuff. visibility = "private" if needThisHandling else "public" # We don't care, for callback codegen, whether our original member was - # a method or attribure or whatnot. Just always pass FakeMember() + # a method or attribute or whatnot. Just always pass FakeMember() # here. CGNativeMember.__init__(self, descriptorProvider, FakeMember(), name, (self.retvalType, args), @@ -8394,8 +8491,7 @@ class CallbackGetter(CallbackMember): self.attrName = attr.identifier.name CallbackMember.__init__(self, (attr.type, []), - # We're always fallible - "Get" + MakeNativeName(attr.identifier.name), + callbackGetterName(attr), descriptor, needThisHandling=False) @@ -8420,7 +8516,7 @@ class CallbackSetter(CallbackMember): CallbackMember.__init__(self, (BuiltinTypes[IDLBuiltinType.Types.void], [FakeArgument(attr.type, attr)]), - "Set" + MakeNativeName(attr.identifier.name), + callbackSetterName(attr), descriptor, needThisHandling=False) From 947a90e0ae4cfd33ea7b4441699d9968ce6f9719 Mon Sep 17 00:00:00 2001 From: Andrew McCreight Date: Sun, 17 Mar 2013 09:56:13 -0700 Subject: [PATCH 008/234] Bug 827486, part 6 - generate headers and code for JS implemented WebIDL classes. r=bz --- dom/bindings/Codegen.py | 22 ++++++++++++++++------ dom/bindings/Configuration.py | 4 +++- dom/bindings/parser/WebIDL.py | 2 +- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/dom/bindings/Codegen.py b/dom/bindings/Codegen.py index fff76939e63..7938e10cca5 100644 --- a/dom/bindings/Codegen.py +++ b/dom/bindings/Codegen.py @@ -10,7 +10,7 @@ import re import string from WebIDL import BuiltinTypes, IDLBuiltinType, IDLNullValue, IDLSequenceType, IDLType -from Configuration import NoSuchDescriptorError, getTypesFromDescriptor, getTypesFromDictionary, getTypesFromCallback +from Configuration import NoSuchDescriptorError, getTypesFromDescriptor, getTypesFromDictionary, getTypesFromCallback, Descriptor AUTOGENERATED_WARNING_COMMENT = \ "/* THIS FILE IS AUTOGENERATED - DO NOT EDIT */\n\n" @@ -476,8 +476,9 @@ class CGHeaders(CGWrapper): Generates the appropriate include statements. """ def __init__(self, descriptors, dictionaries, callbacks, - callbackDescriptors, declareIncludes, defineIncludes, child, - config=None): + callbackDescriptors, + declareIncludes, defineIncludes, child, + config=None, anyJSImplemented=False): """ Builds a set of includes to cover |descriptors|. @@ -586,7 +587,7 @@ class CGHeaders(CGWrapper): # And we need BindingUtils.h so we can wrap "this" objects declareIncludes.add("mozilla/dom/BindingUtils.h") - if len(callbackDescriptors) != 0: + if len(callbackDescriptors) != 0 or anyJSImplemented: # We need CallbackInterface to serve as our parent class declareIncludes.add("mozilla/dom/CallbackInterface.h") # And we need BindingUtils.h so we can wrap "this" objects @@ -7075,7 +7076,8 @@ class CGBindingRoot(CGThing): workers=True) callbackDescriptors = config.getDescriptors(webIDLFile=webIDLFile, isCallback=True) - + jsImplemented = config.getDescriptors(webIDLFile=webIDLFile, + isJSImplemented=True) forwardDeclares = [CGClassForwardDeclare('XPCWrappedNativeScope')] descriptorsForForwardDeclaration = list(descriptors) @@ -7229,6 +7231,11 @@ class CGBindingRoot(CGThing): # Do codegen for all the callback interfaces cgthings.extend([CGCallbackInterface(x) for x in callbackDescriptors]) + # Do codegen for JS implemented classes + for x in jsImplemented: + cgthings.append(CGCallbackInterface(x)) + cgthings.append(CGJSImplClass(x)) + # And make sure we have the right number of newlines at the end curr = CGWrapper(CGList(cgthings, "\n\n"), post="\n\n") @@ -7267,7 +7274,8 @@ class CGBindingRoot(CGThing): 'nsDOMQS.h' ], curr, - config) + config, + anyJSImplemented = len(jsImplemented) != 0) # Add include guards. curr = CGIncludeGuard(prefix, curr) @@ -8059,6 +8067,8 @@ class CGCallback(CGClass): name = idlObject.identifier.name if descriptorProvider.workers: name += "Workers" + if isinstance(descriptorProvider, Descriptor) and descriptorProvider.interface.isJSImplemented(): + name = jsImplName(name) # For our public methods that needThisHandling we want most of the # same args and the same return type as what CallbackMember # generates. So we want to take advantage of all its diff --git a/dom/bindings/Configuration.py b/dom/bindings/Configuration.py index 8e3e6888f4d..49aedea0eae 100644 --- a/dom/bindings/Configuration.py +++ b/dom/bindings/Configuration.py @@ -113,6 +113,8 @@ class Configuration: getter = lambda x: x.interface.isCallback() elif key == 'isExternal': getter = lambda x: x.interface.isExternal() + elif key == 'isJSImplemented': + getter = lambda x: x.interface.isJSImplemented() else: getter = lambda x: getattr(x, key) curr = filter(lambda x: getter(x) == val, curr) @@ -213,7 +215,7 @@ class Descriptor(DescriptorProvider): # Do something sane for JSObject if self.nativeType == "JSObject": headerDefault = "jsapi.h" - elif self.interface.isCallback(): + elif self.interface.isCallback() or self.interface.isJSImplemented(): # A copy of CGHeaders.getDeclarationFilename; we can't # import it here, sadly. # Use our local version of the header, not the exported one, so that diff --git a/dom/bindings/parser/WebIDL.py b/dom/bindings/parser/WebIDL.py index 8d5ebd05a1d..f334ad34cc1 100644 --- a/dom/bindings/parser/WebIDL.py +++ b/dom/bindings/parser/WebIDL.py @@ -779,7 +779,7 @@ class IDLInterface(IDLObjectWithScope): return self._callback def isSingleOperationInterface(self): - assert self.isCallback() + assert self.isCallback() or self.isJSImplemented() return ( # Not inheriting from another interface not self.parent and From 72d64db0b26dc4d31c33047975bb63480b1e4b18 Mon Sep 17 00:00:00 2001 From: Andrew McCreight Date: Sun, 17 Mar 2013 09:58:10 -0700 Subject: [PATCH 009/234] Bug 827486, part 7 - add basic code gen test. r=bz --- CLOBBER | 2 +- dom/bindings/Bindings.conf | 18 + dom/bindings/test/TestCodeGen.webidl | 2 +- dom/bindings/test/TestExampleGen.webidl | 2 +- dom/bindings/test/TestJSImplGen.webidl | 430 ++++++++++++++++++++++++ dom/webidl/WebIDL.mk | 1 + 6 files changed, 452 insertions(+), 3 deletions(-) create mode 100644 dom/bindings/test/TestJSImplGen.webidl diff --git a/CLOBBER b/CLOBBER index f2bb81875ee..102d08ebe4f 100644 --- a/CLOBBER +++ b/CLOBBER @@ -15,4 +15,4 @@ # # Note: The description below will be part of the error message shown to users. # -Bug 648407 - Fold NSPR, NSS and SQLite libraries all together on B2G, Android, OSX and Windows +Bug 851908 - The WebIDL build system has some problems picking up dependencies. diff --git a/dom/bindings/Bindings.conf b/dom/bindings/Bindings.conf index 454309c1081..2a1d1cbfcf7 100644 --- a/dom/bindings/Bindings.conf +++ b/dom/bindings/Bindings.conf @@ -1114,6 +1114,24 @@ DOMInterfaces = { 'register': False, }, +'TestJSImplInterface' : { + # Keep this in sync with TestExampleInterface + 'headerFile': 'TestJSImplGenBinding.h', + 'register': False, + 'resultNotAddRefed': [ 'receiveWeakSelf', 'receiveWeakNullableSelf', + 'receiveWeakOther', 'receiveWeakNullableOther', + 'receiveWeakExternal', 'receiveWeakNullableExternal', + 'ReceiveWeakCallbackInterface', + 'ReceiveWeakNullableCallbackInterface', + 'receiveWeakCastableObjectSequence', + 'receiveWeakNullableCastableObjectSequence', + 'receiveWeakCastableObjectNullableSequence', + 'receiveWeakNullableCastableObjectNullableSequence' ], + 'binaryNames': { 'methodRenamedFrom': 'methodRenamedTo', + 'attributeGetterRenamedFrom': 'attributeGetterRenamedTo', + 'attributeRenamedFrom': 'attributeRenamedTo' } + }, + 'TestExternalInterface' : { 'nativeType': 'mozilla::dom::TestExternalInterface', 'headerFile': 'TestBindingHeader.h', diff --git a/dom/bindings/test/TestCodeGen.webidl b/dom/bindings/test/TestCodeGen.webidl index 1d65c606f88..692c2381993 100644 --- a/dom/bindings/test/TestCodeGen.webidl +++ b/dom/bindings/test/TestCodeGen.webidl @@ -510,7 +510,7 @@ interface TestInterface { [SetterThrows] attribute boolean throwingSetterAttr; legacycaller short(unsigned long arg1, TestInterface arg2); - // If you add things here, add them to TestExampleGen as well + // If you add things here, add them to TestExampleGen and TestJSImplGen as well }; interface TestParentInterface { diff --git a/dom/bindings/test/TestExampleGen.webidl b/dom/bindings/test/TestExampleGen.webidl index d1e6b917f2e..a687c94ca49 100644 --- a/dom/bindings/test/TestExampleGen.webidl +++ b/dom/bindings/test/TestExampleGen.webidl @@ -424,7 +424,7 @@ interface TestExampleInterface { [SetterThrows] attribute boolean throwingSetterAttr; legacycaller short(unsigned long arg1, TestInterface arg2); - // If you add things here, add them to TestCodeGen as well + // If you add things here, add them to TestCodeGen and TestJSImplGen as well }; interface TestExampleProxyInterface { diff --git a/dom/bindings/test/TestJSImplGen.webidl b/dom/bindings/test/TestJSImplGen.webidl new file mode 100644 index 00000000000..dff0d628c00 --- /dev/null +++ b/dom/bindings/test/TestJSImplGen.webidl @@ -0,0 +1,430 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* 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/. + */ + +typedef TestJSImplInterface AnotherNameForTestJSImplInterface; +typedef TestJSImplInterface YetAnotherNameForTestJSImplInterface; +typedef TestJSImplInterface? NullableTestJSImplInterface; + +callback MyTestCallback = void(); + +TestInterface implements ImplementedInterface; + +enum MyTestEnum { + "a", + "b" +}; + +[Constructor, JSImplementation="@mozilla.org/test-js-impl-interface;1"] +interface TestJSImplInterface { + // Integer types + // XXXbz add tests for throwing versions of all the integer stuff + readonly attribute byte readonlyByte; + attribute byte writableByte; + void passByte(byte arg); + byte receiveByte(); + void passOptionalByte(optional byte arg); + // Callback interface limitation. See bug 841429. + // void passOptionalByteWithDefault(optional byte arg = 0); + void passNullableByte(byte? arg); + void passOptionalNullableByte(optional byte? arg); + void passVariadicByte(byte... arg); + + readonly attribute short readonlyShort; + attribute short writableShort; + void passShort(short arg); + short receiveShort(); + void passOptionalShort(optional short arg); + // Callback interface limitation. See bug 841429. + //void passOptionalShortWithDefault(optional short arg = 5); + + readonly attribute long readonlyLong; + attribute long writableLong; + void passLong(long arg); + long receiveLong(); + void passOptionalLong(optional long arg); + // Callback interface limitation. See bug 841429. + //void passOptionalLongWithDefault(optional long arg = 7); + + readonly attribute long long readonlyLongLong; + attribute long long writableLongLong; + void passLongLong(long long arg); + long long receiveLongLong(); + void passOptionalLongLong(optional long long arg); + // Callback interface limitation. See bug 841429. + //void passOptionalLongLongWithDefault(optional long long arg = -12); + + readonly attribute octet readonlyOctet; + attribute octet writableOctet; + void passOctet(octet arg); + octet receiveOctet(); + void passOptionalOctet(optional octet arg); + // Callback interface limitation. See bug 841429. + //void passOptionalOctetWithDefault(optional octet arg = 19); + + readonly attribute unsigned short readonlyUnsignedShort; + attribute unsigned short writableUnsignedShort; + void passUnsignedShort(unsigned short arg); + unsigned short receiveUnsignedShort(); + void passOptionalUnsignedShort(optional unsigned short arg); + // Callback interface limitation. See bug 841429. + //void passOptionalUnsignedShortWithDefault(optional unsigned short arg = 2); + + readonly attribute unsigned long readonlyUnsignedLong; + attribute unsigned long writableUnsignedLong; + void passUnsignedLong(unsigned long arg); + unsigned long receiveUnsignedLong(); + void passOptionalUnsignedLong(optional unsigned long arg); + // Callback interface limitation. See bug 841429. + //void passOptionalUnsignedLongWithDefault(optional unsigned long arg = 6); + + readonly attribute unsigned long long readonlyUnsignedLongLong; + attribute unsigned long long writableUnsignedLongLong; + void passUnsignedLongLong(unsigned long long arg); + unsigned long long receiveUnsignedLongLong(); + void passOptionalUnsignedLongLong(optional unsigned long long arg); + // Callback interface limitation. See bug 841429. + //void passOptionalUnsignedLongLongWithDefault(optional unsigned long long arg = 17); + + attribute float writableFloat; + attribute unrestricted float writableUnrestrictedFloat; + attribute float? writableNullableFloat; + attribute unrestricted float? writableNullableUnrestrictedFloat; + attribute double writableDouble; + attribute unrestricted double writableUnrestrictedDouble; + attribute double? writableNullableDouble; + attribute unrestricted double? writableNullableUnrestrictedDouble; + void passFloat(float arg1, unrestricted float arg2, + float? arg3, unrestricted float? arg4, + double arg5, unrestricted double arg6, + double? arg7, unrestricted double? arg8, + sequence arg9, sequence arg10, + sequence arg11, sequence arg12, + sequence arg13, sequence arg14, + sequence arg15, sequence arg16); + [LenientFloat] + void passLenientFloat(float arg1, unrestricted float arg2, + float? arg3, unrestricted float? arg4, + double arg5, unrestricted double arg6, + double? arg7, unrestricted double? arg8, + sequence arg9, + sequence arg10, + sequence arg11, + sequence arg12, + sequence arg13, + sequence arg14, + sequence arg15, + sequence arg16); + [LenientFloat] + attribute float lenientFloatAttr; + [LenientFloat] + attribute double lenientDoubleAttr; + + // Castable interface types + // XXXbz add tests for throwing versions of all the castable interface stuff + TestJSImplInterface receiveSelf(); + TestJSImplInterface? receiveNullableSelf(); + + // Callback interface ignores 'resultNotAddRefed'. See bug 843272. + //TestJSImplInterface receiveWeakSelf(); + //TestJSImplInterface? receiveWeakNullableSelf(); + + // A version to test for casting to TestJSImplInterface& + void passSelf(TestJSImplInterface arg); + // A version we can use to test for the exact type passed in + void passSelf2(TestJSImplInterface arg); + void passNullableSelf(TestJSImplInterface? arg); + attribute TestJSImplInterface nonNullSelf; + attribute TestJSImplInterface? nullableSelf; + // Optional arguments + void passOptionalSelf(optional TestJSImplInterface? arg); + void passOptionalNonNullSelf(optional TestJSImplInterface arg); + // Callback interface limitation. See bug 841429. + //void passOptionalSelfWithDefault(optional TestJSImplInterface? arg = null); + + // Non-wrapper-cache interface types + [Creator] + TestNonWrapperCacheInterface receiveNonWrapperCacheInterface(); + [Creator] + TestNonWrapperCacheInterface? receiveNullableNonWrapperCacheInterface(); + + // Can't return sequences of interfaces from callback interface methods. See bug 843264. + //[Creator] + //sequence receiveNonWrapperCacheInterfaceSequence(); + //[Creator] + //sequence receiveNullableNonWrapperCacheInterfaceSequence(); + //[Creator] + //sequence? receiveNonWrapperCacheInterfaceNullableSequence(); + //[Creator] + //sequence? receiveNullableNonWrapperCacheInterfaceNullableSequence(); + + // Non-castable interface types + IndirectlyImplementedInterface receiveOther(); + IndirectlyImplementedInterface? receiveNullableOther(); + // Callback interface ignores 'resultNotAddRefed'. See bug 843272. + //IndirectlyImplementedInterface receiveWeakOther(); + //IndirectlyImplementedInterface? receiveWeakNullableOther(); + + // A verstion to test for casting to IndirectlyImplementedInterface& + void passOther(IndirectlyImplementedInterface arg); + // A version we can use to test for the exact type passed in + void passOther2(IndirectlyImplementedInterface arg); + void passNullableOther(IndirectlyImplementedInterface? arg); + attribute IndirectlyImplementedInterface nonNullOther; + attribute IndirectlyImplementedInterface? nullableOther; + // Optional arguments + void passOptionalOther(optional IndirectlyImplementedInterface? arg); + void passOptionalNonNullOther(optional IndirectlyImplementedInterface arg); + // Callback interface limitation. See bug 841429. + //void passOptionalOtherWithDefault(optional IndirectlyImplementedInterface? arg = null); + + // External interface types + TestExternalInterface receiveExternal(); + TestExternalInterface? receiveNullableExternal(); + // Callback interface ignores 'resultNotAddRefed'. See bug 843272. + //TestExternalInterface receiveWeakExternal(); + //TestExternalInterface? receiveWeakNullableExternal(); + // A verstion to test for casting to TestExternalInterface& + void passExternal(TestExternalInterface arg); + // A version we can use to test for the exact type passed in + void passExternal2(TestExternalInterface arg); + void passNullableExternal(TestExternalInterface? arg); + attribute TestExternalInterface nonNullExternal; + attribute TestExternalInterface? nullableExternal; + // Optional arguments + void passOptionalExternal(optional TestExternalInterface? arg); + void passOptionalNonNullExternal(optional TestExternalInterface arg); + // Callback interface limitation. See bug 841429. + //void passOptionalExternalWithDefault(optional TestExternalInterface? arg = null); + + // Callback interface types + TestCallbackInterface receiveCallbackInterface(); + TestCallbackInterface? receiveNullableCallbackInterface(); + // Callback interface ignores 'resultNotAddRefed'. See bug 843272. + //TestCallbackInterface receiveWeakCallbackInterface(); + //TestCallbackInterface? receiveWeakNullableCallbackInterface(); + // A verstion to test for casting to TestCallbackInterface& + void passCallbackInterface(TestCallbackInterface arg); + // A version we can use to test for the exact type passed in + void passCallbackInterface2(TestCallbackInterface arg); + void passNullableCallbackInterface(TestCallbackInterface? arg); + attribute TestCallbackInterface nonNullCallbackInterface; + attribute TestCallbackInterface? nullableCallbackInterface; + // Optional arguments + void passOptionalCallbackInterface(optional TestCallbackInterface? arg); + void passOptionalNonNullCallbackInterface(optional TestCallbackInterface arg); + // Callback interface limitation. See bug 841429. + //void passOptionalCallbackInterfaceWithDefault(optional TestCallbackInterface? arg = null); + + // Miscellaneous interface tests + IndirectlyImplementedInterface receiveConsequentialInterface(); + void passConsequentialInterface(IndirectlyImplementedInterface arg); + + // Sequence types + sequence receiveSequence(); + sequence? receiveNullableSequence(); + sequence receiveSequenceOfNullableInts(); + sequence? receiveNullableSequenceOfNullableInts(); + void passSequence(sequence arg); + void passNullableSequence(sequence? arg); + void passSequenceOfNullableInts(sequence arg); + void passOptionalSequenceOfNullableInts(optional sequence arg); + void passOptionalNullableSequenceOfNullableInts(optional sequence? arg); + // Can't return sequences of interfaces from callback interface methods. See bug 843264. + //sequence receiveCastableObjectSequence(); + //sequence receiveCallbackObjectSequence(); + //sequence receiveNullableCastableObjectSequence(); + //sequence receiveNullableCallbackObjectSequence(); + //sequence? receiveCastableObjectNullableSequence(); + //sequence? receiveNullableCastableObjectNullableSequence(); + // Callback interface ignores 'resultNotAddRefed'. See bug 843272. + //sequence receiveWeakCastableObjectSequence(); + //sequence receiveWeakNullableCastableObjectSequence(); + //sequence? receiveWeakCastableObjectNullableSequence(); + //sequence? receiveWeakNullableCastableObjectNullableSequence(); + void passCastableObjectSequence(sequence arg); + void passNullableCastableObjectSequence(sequence arg); + void passCastableObjectNullableSequence(sequence? arg); + void passNullableCastableObjectNullableSequence(sequence? arg); + void passOptionalSequence(optional sequence arg); + void passOptionalNullableSequence(optional sequence? arg); + // Callback interface limitation. See bug 841429. + //void passOptionalNullableSequenceWithDefaultValue(optional sequence? arg = null); + void passOptionalObjectSequence(optional sequence arg); + void passExternalInterfaceSequence(sequence arg); + void passNullableExternalInterfaceSequence(sequence arg); + + // Can't return sequences of interfaces from callback interface methods. See bug 843264. + //sequence receiveStringSequence(); + // Callback interface problem. See bug 843261. + //void passStringSequence(sequence arg); + // "Can't handle sequence member 'any'; need to sort out rooting issues" + //sequence receiveAnySequence(); + //sequence? receiveNullableAnySequence(); + + // ArrayBuffer is handled differently in callback interfaces and the example generator. + // Need to figure out what should be done there. Seems like other typed array stuff is + // similarly not working in the JS implemented generator. Probably some other issues + // here as well. + // Typed array types + //void passArrayBuffer(ArrayBuffer arg); + //void passNullableArrayBuffer(ArrayBuffer? arg); + //void passOptionalArrayBuffer(optional ArrayBuffer arg); + //void passOptionalNullableArrayBuffer(optional ArrayBuffer? arg); + //void passOptionalNullableArrayBufferWithDefaultValue(optional ArrayBuffer? arg= null); + //void passArrayBufferView(ArrayBufferView arg); + //void passInt8Array(Int8Array arg); + //void passInt16Array(Int16Array arg); + //void passInt32Array(Int32Array arg); + //void passUint8Array(Uint8Array arg); + //void passUint16Array(Uint16Array arg); + //void passUint32Array(Uint32Array arg); + //void passUint8ClampedArray(Uint8ClampedArray arg); + //void passFloat32Array(Float32Array arg); + //void passFloat64Array(Float64Array arg); + //Uint8Array receiveUint8Array(); + + // String types + void passString(DOMString arg); + void passNullableString(DOMString? arg); + void passOptionalString(optional DOMString arg); + // Callback interface limitation. See bug 841429. + //void passOptionalStringWithDefaultValue(optional DOMString arg = "abc"); + void passOptionalNullableString(optional DOMString? arg); + // Callback interface limitation. See bug 841429. + //void passOptionalNullableStringWithDefaultValue(optional DOMString? arg = null); + void passVariadicString(DOMString... arg); + + // Enumerated types + void passEnum(MyTestEnum arg); + // No support for nullable enums yet + // void passNullableEnum(MyTestEnum? arg); + // Optional enum arg doesn't work with callback interfaces. See bug 843355. + //void passOptionalEnum(optional MyTestEnum arg); + // Callback interface limitation. See bug 841429. + //void passEnumWithDefault(optional MyTestEnum arg = "a"); + // void passOptionalNullableEnum(optional MyTestEnum? arg); + // void passOptionalNullableEnumWithDefaultValue(optional MyTestEnum? arg = null); + MyTestEnum receiveEnum(); + attribute MyTestEnum enumAttribute; + readonly attribute MyTestEnum readonlyEnumAttribute; + + // Callback types + void passCallback(MyTestCallback arg); + void passNullableCallback(MyTestCallback? arg); + void passOptionalCallback(optional MyTestCallback arg); + void passOptionalNullableCallback(optional MyTestCallback? arg); + // Callback interface limitation. See bug 841429. + //void passOptionalNullableCallbackWithDefaultValue(optional MyTestCallback? arg = null); + MyTestCallback receiveCallback(); + MyTestCallback? receiveNullableCallback(); + // Hmm. These two don't work, I think because I need a locally modified version of TestTreatAsNullCallback. + //void passNullableTreatAsNullCallback(TestTreatAsNullCallback? arg); + //void passOptionalNullableTreatAsNullCallback(optional TestTreatAsNullCallback? arg); + // Callback interface limitation. See bug 841429. + //void passOptionalNullableTreatAsNullCallbackWithDefaultValue(optional TestTreatAsNullCallback? arg = null); + +/* The rest of these are untested. + // Any types + void passAny(any arg); + void passOptionalAny(optional any arg); + void passAnyDefaultNull(optional any arg = null); + any receiveAny(); + + // object types + void passObject(object arg); + void passNullableObject(object? arg); + void passOptionalObject(optional object arg); + void passOptionalNullableObject(optional object? arg); + void passOptionalNullableObjectWithDefaultValue(optional object? arg = null); + object receiveObject(); + object? receiveNullableObject(); + + // Union types + void passUnion((object or long) arg); + void passUnionWithNullable((object? or long) arg); + void passNullableUnion((object or long)? arg); + void passOptionalUnion(optional (object or long) arg); + void passOptionalNullableUnion(optional (object or long)? arg); + void passOptionalNullableUnionWithDefaultValue(optional (object or long)? arg = null); + //void passUnionWithInterfaces((TestJSImplInterface or TestExternalInterface) arg); + //void passUnionWithInterfacesAndNullable((TestJSImplInterface? or TestExternalInterface) arg); + //void passUnionWithSequence((sequence or long) arg); + void passUnionWithArrayBuffer((ArrayBuffer or long) arg); + void passUnionWithString((DOMString or object) arg); + //void passUnionWithEnum((MyTestEnum or object) arg); + // Trying to use a callback in a union won't include the test + // headers, unfortunately, so won't compile. + // void passUnionWithCallback((MyTestCallback or long) arg); + void passUnionWithObject((object or long) arg); + //void passUnionWithDict((Dict or long) arg); + + // binaryNames tests + void methodRenamedFrom(); + void methodRenamedFrom(byte argument); + readonly attribute byte attributeGetterRenamedFrom; + attribute byte attributeRenamedFrom; + + void passDictionary(optional Dict x); + //UNSUPPORTED Dict receiveDictionary(); + void passOtherDictionary(optional GrandparentDict x); + void passSequenceOfDictionaries(sequence x); + void passDictionaryOrLong(optional Dict x); + void passDictionaryOrLong(long x); + + void passDictContainingDict(optional DictContainingDict arg); + void passDictContainingSequence(optional DictContainingSequence arg); + //UNSUPPORTED DictContainingSequence receiveDictContainingSequence(); + + // EnforceRange/Clamp tests + void dontEnforceRangeOrClamp(byte arg); + void doEnforceRange([EnforceRange] byte arg); + void doClamp([Clamp] byte arg); + + // Typedefs + const myLong myLongConstant = 5; + // ???? What + void exerciseTypedefInterfaces1(AnotherNameForTestJSImplInterface arg); + AnotherNameForTestJSImplInterface exerciseTypedefInterfaces2(NullableTestJSImplInterface arg); + void exerciseTypedefInterfaces3(YetAnotherNameForTestJSImplInterface arg); + + // Static methods and attributes + static attribute boolean staticAttribute; + static void staticMethod(boolean arg); + static void staticMethodWithContext(any arg); + + // Overload resolution tests + //void overload1(DOMString... strs); + boolean overload1(TestJSImplInterface arg); + TestJSImplInterface overload1(DOMString strs, TestJSImplInterface arg); + void overload2(TestJSImplInterface arg); + void overload2(optional Dict arg); + void overload2(DOMString arg); + void overload3(TestJSImplInterface arg); + void overload3(MyTestCallback arg); + void overload3(DOMString arg); + void overload4(TestJSImplInterface arg); + void overload4(TestCallbackInterface arg); + void overload4(DOMString arg); + + // Variadic handling + void passVariadicThirdArg(DOMString arg1, long arg2, TestJSImplInterface... arg3); + + // Miscellania + [LenientThis] attribute long attrWithLenientThis; + [Unforgeable] readonly attribute long unforgeableAttr; + [Unforgeable, ChromeOnly] readonly attribute long unforgeableAttr2; + stringifier; + void passRenamedInterface(TestRenamedInterface arg); + [PutForwards=writableByte] readonly attribute TestJSImplInterface putForwardsAttr; + [PutForwards=writableByte, LenientThis] readonly attribute TestJSImplInterface putForwardsAttr2; + [PutForwards=writableByte, ChromeOnly] readonly attribute TestJSImplInterface putForwardsAttr3; + [Throws] void throwingMethod(); + [Throws] attribute boolean throwingAttr; + [GetterThrows] attribute boolean throwingGetterAttr; + [SetterThrows] attribute boolean throwingSetterAttr; +*/ + // If you add things here, add them to TestCodeGen as well +}; diff --git a/dom/webidl/WebIDL.mk b/dom/webidl/WebIDL.mk index 812a27eb341..1a3c8d673c7 100644 --- a/dom/webidl/WebIDL.mk +++ b/dom/webidl/WebIDL.mk @@ -292,6 +292,7 @@ test_webidl_files := \ TestCodeGen.webidl \ TestDictionary.webidl \ TestExampleGen.webidl \ + TestJSImplGen.webidl \ TestTypedef.webidl \ $(NULL) else From 9c8d806447866c13b64078ac5be31e249866be82 Mon Sep 17 00:00:00 2001 From: Ethan Hugg Date: Thu, 15 Nov 2012 10:38:27 -0800 Subject: [PATCH 010/234] Bug 805533 Patch 2 - Pass SDP parsing errors up to PeerConnection r=jesup --- .../signaling/src/media/VcmSIPCCBinding.cpp | 19 +++++++++++ .../src/peerconnection/PeerConnectionImpl.cpp | 24 ++++++++++++++ .../src/peerconnection/PeerConnectionImpl.h | 12 +++++++ .../signaling/src/sipcc/core/sdp/sdp_main.c | 10 ++++-- .../src/sipcc/cpr/common/cpr_string.c | 32 +++++++++++++++---- .../src/sipcc/cpr/include/cpr_string.h | 9 ++++++ .../webrtc/signaling/src/sipcc/include/vcm.h | 9 ++++++ 7 files changed, 106 insertions(+), 9 deletions(-) diff --git a/media/webrtc/signaling/src/media/VcmSIPCCBinding.cpp b/media/webrtc/signaling/src/media/VcmSIPCCBinding.cpp index 96fe0a2ca59..c4e6e19e189 100644 --- a/media/webrtc/signaling/src/media/VcmSIPCCBinding.cpp +++ b/media/webrtc/signaling/src/media/VcmSIPCCBinding.cpp @@ -2700,3 +2700,22 @@ vcmCreateTransportFlow(sipcc::PeerConnectionImpl *pc, int level, bool rtcp, } return flow; } + + +/** + * vcmOnSdpParseError + * + * This method is called for each parsing error of SDP. It does not necessarily + * mean the SDP read was fatal and can be called many times for the same SDP. + * + */ +int vcmOnSdpParseError(const char *peerconnection, const char *message) { + + sipcc::PeerConnectionWrapper pc(peerconnection); + ENSURE_PC(pc, VCM_ERROR); + + pc.impl()->OnSdpParseError(message); + + return 0; +} + diff --git a/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp b/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp index 039dca9bd01..46015177002 100644 --- a/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp +++ b/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp @@ -160,18 +160,30 @@ public: break; case SETLOCALDESC: + // TODO: The SDP Parse error list should be copied out and sent up + // to the Javascript layer before being cleared here. + mPC->ClearSdpParseErrorMessages(); mObserver->OnSetLocalDescriptionSuccess(mCode); break; case SETREMOTEDESC: + // TODO: The SDP Parse error list should be copied out and sent up + // to the Javascript layer before being cleared here. + mPC->ClearSdpParseErrorMessages(); mObserver->OnSetRemoteDescriptionSuccess(mCode); break; case SETLOCALDESCERROR: + // TODO: The SDP Parse error list should be copied out and sent up + // to the Javascript layer before being cleared here. + mPC->ClearSdpParseErrorMessages(); mObserver->OnSetLocalDescriptionError(mCode); break; case SETREMOTEDESCERROR: + // TODO: The SDP Parse error list should be copied out and sent up + // to the Javascript layer before being cleared here. + mPC->ClearSdpParseErrorMessages(); mObserver->OnSetRemoteDescriptionError(mCode); break; @@ -1388,6 +1400,18 @@ PeerConnectionImpl::IceStreamReady(NrIceMediaStream *aStream) CSFLogDebug(logTag, "%s: %s", __FUNCTION__, aStream->name().c_str()); } +void +PeerConnectionImpl::OnSdpParseError(const char *message) { + CSFLogError(logTag, "%s SDP Parse Error: %s", __FUNCTION__, message); + // Save the parsing errors in the PC to be delivered with OnSuccess or OnError + mSDPParseErrorMessages.push_back(message); +} + +void +PeerConnectionImpl::ClearSdpParseErrorMessages() { + mSDPParseErrorMessages.clear(); +} + #ifdef MOZILLA_INTERNAL_API static nsresult diff --git a/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.h b/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.h index f4d0d41afb5..d060f6bb5e2 100644 --- a/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.h +++ b/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.h @@ -222,6 +222,15 @@ public: NS_IMETHODIMP CreateOffer(MediaConstraints& aConstraints); NS_IMETHODIMP CreateAnswer(MediaConstraints& aConstraints); + // Called whenever something is unrecognized by the parser + // May be called more than once and does not necessarily mean + // that parsing was stopped, only that something was unrecognized. + void OnSdpParseError(const char* errorMessage); + + // Called when OnLocal/RemoteDescriptionSuccess/Error + // is called to start the list over. + void ClearSdpParseErrorMessages(); + private: PeerConnectionImpl(const PeerConnectionImpl&rhs); PeerConnectionImpl& operator=(PeerConnectionImpl); @@ -313,6 +322,9 @@ private: int mNumAudioStreams; int mNumVideoStreams; + // Holder for error messages from parsing SDP + std::vector mSDPParseErrorMessages; + public: //these are temporary until the DataChannel Listen/Connect API is removed unsigned short listenPort; diff --git a/media/webrtc/signaling/src/sipcc/core/sdp/sdp_main.c b/media/webrtc/signaling/src/sipcc/core/sdp/sdp_main.c index c11c7c89d54..0a47b0587cc 100644 --- a/media/webrtc/signaling/src/sipcc/core/sdp/sdp_main.c +++ b/media/webrtc/signaling/src/sipcc/core/sdp/sdp_main.c @@ -1453,11 +1453,17 @@ sdp_result_e sdp_free_description (sdp_t *sdp_p) * Send SDP parsing errors to log and up to peerconnection */ void sdp_parse_error(const char *peerconnection, const char *format, ...) { + flex_string fs; va_list ap; - /* TODO - report error up to PeerConnection here */ + flex_string_init(&fs); va_start(ap, format); - CSFLogErrorV("SDP Parse", format, ap); + flex_string_vsprintf(&fs, format, ap); va_end(ap); + + CSFLogError("SDP Parse", "SDP Parse Error %s, pc %s", fs.buffer, peerconnection); + vcmOnSdpParseError(peerconnection, fs.buffer); + + flex_string_free(&fs); } diff --git a/media/webrtc/signaling/src/sipcc/cpr/common/cpr_string.c b/media/webrtc/signaling/src/sipcc/cpr/common/cpr_string.c index 13276e91354..18fe182285e 100644 --- a/media/webrtc/signaling/src/sipcc/cpr/common/cpr_string.c +++ b/media/webrtc/signaling/src/sipcc/cpr/common/cpr_string.c @@ -2,7 +2,6 @@ * 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 #include #include "mozilla/Assertions.h" @@ -166,22 +165,29 @@ void flex_string_append(flex_string *fs, const char *more) { } /* - * flex_string_sprintf + * va_copy is part of the C99 spec but MSVC doesn't have it. + */ +#ifndef va_copy +#define va_copy(d,s) ((d) = (s)) +#endif + +/* + * flex_string_vsprintf * * Not thread-safe */ -void flex_string_sprintf(flex_string *fs, const char *format, ...) { +void flex_string_vsprintf(flex_string *fs, const char *format, va_list original_ap) { va_list ap; int vsnprintf_result; - va_start(ap, format); + va_copy(ap, original_ap); vsnprintf_result = vsnprintf(fs->buffer + fs->string_length, fs->buffer_length - fs->string_length, format, ap); va_end(ap); /* Special case just for Windows where vsnprintf is broken and returns -1 if buffer too large unless you size it 0. */ if (vsnprintf_result < 0) { - va_start(ap, format); + va_copy(ap, original_ap); vsnprintf_result = vsnprintf(NULL, 0, format, ap); va_end(ap); } @@ -191,10 +197,10 @@ void flex_string_sprintf(flex_string *fs, const char *format, ...) { flex_string_check_alloc(fs, fs->string_length + vsnprintf_result + 1); /* Try again with new buffer */ - va_start(ap, format); + va_copy(ap, original_ap); vsnprintf_result = vsnprintf(fs->buffer + fs->string_length, fs->buffer_length - fs->string_length, format, ap); - MOZ_ASSERT(vsnprintf_result > 0 && vsnprintf_result < (fs->buffer_length - fs->string_length)); va_end(ap); + MOZ_ASSERT(vsnprintf_result > 0 && vsnprintf_result < (fs->buffer_length - fs->string_length)); } if (vsnprintf_result > 0) { @@ -202,4 +208,16 @@ void flex_string_sprintf(flex_string *fs, const char *format, ...) { } } +/* + * flex_string_sprintf + * + * Not thread-safe + */ +void flex_string_sprintf(flex_string *fs, const char *format, ...) { + va_list ap; + + va_start(ap, format); + flex_string_vsprintf(fs, format, ap); + va_end(ap); +} diff --git a/media/webrtc/signaling/src/sipcc/cpr/include/cpr_string.h b/media/webrtc/signaling/src/sipcc/cpr/include/cpr_string.h index 3b981b08971..aa76e1d50b6 100644 --- a/media/webrtc/signaling/src/sipcc/cpr/include/cpr_string.h +++ b/media/webrtc/signaling/src/sipcc/cpr/include/cpr_string.h @@ -5,6 +5,8 @@ #ifndef _CPR_STRING_H_ #define _CPR_STRING_H_ +#include + #include "cpr_types.h" #include "cpr_strings.h" @@ -104,6 +106,13 @@ void flex_string_check_alloc(flex_string *fs, size_t new_min_length); */ void flex_string_append(flex_string *fs, const char *more); +/* + * flex_string_sprintf + * + * Not thread-safe + */ +void flex_string_vsprintf(flex_string *fs, const char *format, va_list original_ap); + /* * flex_string_sprintf * diff --git a/media/webrtc/signaling/src/sipcc/include/vcm.h b/media/webrtc/signaling/src/sipcc/include/vcm.h index ef607559c9a..6db623087b9 100755 --- a/media/webrtc/signaling/src/sipcc/include/vcm.h +++ b/media/webrtc/signaling/src/sipcc/include/vcm.h @@ -1003,6 +1003,15 @@ int vcmDtmfBurst(int digit, int duration, int direction); */ int vcmGetILBCMode(); +/** + * vcmOnSdpParseError + * + * This method is called for each parsing error of SDP. It does not necessarily + * mean the SDP read was fatal and can be called many times for the same SDP. + * + */ +int vcmOnSdpParseError(const char *peercconnection, const char *message); + //Using C++ for gips. This is the end of extern "C" above. #ifdef __cplusplus } From 8bfd3a128f387048195a8087966b9b865fde9d44 Mon Sep 17 00:00:00 2001 From: Frank Yan Date: Tue, 5 Mar 2013 14:58:07 -0800 Subject: [PATCH 011/234] Bug 848150 - Update about:home favicons. r=dolske ui-r=shorlander ui-r=limi --- browser/base/content/abouthome/aboutHome.xhtml | 2 +- browser/branding/aurora/content/jar.mn | 1 + browser/branding/nightly/content/jar.mn | 1 + browser/branding/official/content/jar.mn | 1 + browser/branding/unofficial/content/jar.mn | 1 + browser/themes/osx/searchbar.css | 5 +++++ 6 files changed, 10 insertions(+), 1 deletion(-) diff --git a/browser/base/content/abouthome/aboutHome.xhtml b/browser/base/content/abouthome/aboutHome.xhtml index 1cb8b6d1802..3a2d6546657 100644 --- a/browser/base/content/abouthome/aboutHome.xhtml +++ b/browser/base/content/abouthome/aboutHome.xhtml @@ -22,7 +22,7 @@ &abouthome.pageTitle; + href="chrome://branding/content/icon32.png"/> diff --git a/browser/branding/aurora/content/jar.mn b/browser/branding/aurora/content/jar.mn index 310063280bd..abe651b98c8 100644 --- a/browser/branding/aurora/content/jar.mn +++ b/browser/branding/aurora/content/jar.mn @@ -11,4 +11,5 @@ browser.jar: content/branding/icon48.png (icon48.png) content/branding/icon64.png (icon64.png) content/branding/icon16.png (../default16.png) + content/branding/icon32.png (../default32.png) content/branding/aboutDialog.css (aboutDialog.css) diff --git a/browser/branding/nightly/content/jar.mn b/browser/branding/nightly/content/jar.mn index 310063280bd..abe651b98c8 100644 --- a/browser/branding/nightly/content/jar.mn +++ b/browser/branding/nightly/content/jar.mn @@ -11,4 +11,5 @@ browser.jar: content/branding/icon48.png (icon48.png) content/branding/icon64.png (icon64.png) content/branding/icon16.png (../default16.png) + content/branding/icon32.png (../default32.png) content/branding/aboutDialog.css (aboutDialog.css) diff --git a/browser/branding/official/content/jar.mn b/browser/branding/official/content/jar.mn index 8e99c940e53..5794ae2e76d 100644 --- a/browser/branding/official/content/jar.mn +++ b/browser/branding/official/content/jar.mn @@ -10,4 +10,5 @@ browser.jar: content/branding/icon48.png (icon48.png) content/branding/icon64.png (icon64.png) content/branding/icon16.png (../default16.png) + content/branding/icon32.png (../default32.png) content/branding/aboutDialog.css (aboutDialog.css) diff --git a/browser/branding/unofficial/content/jar.mn b/browser/branding/unofficial/content/jar.mn index 310063280bd..abe651b98c8 100644 --- a/browser/branding/unofficial/content/jar.mn +++ b/browser/branding/unofficial/content/jar.mn @@ -11,4 +11,5 @@ browser.jar: content/branding/icon48.png (icon48.png) content/branding/icon64.png (icon64.png) content/branding/icon16.png (../default16.png) + content/branding/icon32.png (../default32.png) content/branding/aboutDialog.css (aboutDialog.css) diff --git a/browser/themes/osx/searchbar.css b/browser/themes/osx/searchbar.css index 50343915f6b..d79ff9fc749 100644 --- a/browser/themes/osx/searchbar.css +++ b/browser/themes/osx/searchbar.css @@ -48,6 +48,11 @@ } @media (min-resolution: 2dppx) { + .searchbar-engine-image, + .searchbar-engine-menuitem > .menu-iconic-left > .menu-iconic-icon { + image-rendering: -moz-crisp-edges; + } + .searchbar-engine-image { list-style-image: url("chrome://mozapps/skin/places/defaultFavicon@2x.png"); } From 686da379b86ef0c5c91bee08770363785eab7196 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Sun, 17 Mar 2013 10:42:01 -0400 Subject: [PATCH 012/234] Bug 843627 part 1. Rename nsHTMLSharedObjectElement to HTMLSharedObjectElement. r=peterv --HG-- rename : content/html/content/src/nsHTMLSharedObjectElement.cpp => content/html/content/src/HTMLSharedObjectElement.cpp rename : content/html/content/src/nsHTMLSharedObjectElement.cpp => content/html/content/src/HTMLSharedObjectElement.h --- .../content/src/HTMLSharedObjectElement.cpp | 365 +++++++++++++ .../content/src/HTMLSharedObjectElement.h | 144 +++++ content/html/content/src/Makefile.in | 3 +- .../content/src/nsHTMLSharedObjectElement.cpp | 490 ------------------ 4 files changed, 511 insertions(+), 491 deletions(-) create mode 100644 content/html/content/src/HTMLSharedObjectElement.cpp create mode 100644 content/html/content/src/HTMLSharedObjectElement.h delete mode 100644 content/html/content/src/nsHTMLSharedObjectElement.cpp diff --git a/content/html/content/src/HTMLSharedObjectElement.cpp b/content/html/content/src/HTMLSharedObjectElement.cpp new file mode 100644 index 00000000000..974886d0ff5 --- /dev/null +++ b/content/html/content/src/HTMLSharedObjectElement.cpp @@ -0,0 +1,365 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +// vim:set et sw=2 sts=2 cin: +/* 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/HTMLSharedObjectElement.h" +#include "mozilla/Util.h" + +#include "nsIDocument.h" +#include "nsIPluginDocument.h" +#include "nsIDOMDocument.h" +#include "nsThreadUtils.h" +#include "nsIDOMSVGDocument.h" +#include "nsIScriptError.h" +#include "nsIWidget.h" +#include "nsContentUtils.h" + +NS_IMPL_NS_NEW_HTML_ELEMENT_CHECK_PARSER(SharedObject) + +DOMCI_DATA(HTMLAppletElement, mozilla::dom::HTMLSharedObjectElement) +DOMCI_DATA(HTMLEmbedElement, mozilla::dom::HTMLSharedObjectElement) + +namespace mozilla { +namespace dom { + +HTMLSharedObjectElement::HTMLSharedObjectElement(already_AddRefed aNodeInfo, + FromParser aFromParser) + : nsGenericHTMLElement(aNodeInfo), + mIsDoneAddingChildren(mNodeInfo->Equals(nsGkAtoms::embed) || !aFromParser) +{ + RegisterFreezableElement(); + SetIsNetworkCreated(aFromParser == FROM_PARSER_NETWORK); + + // By default we're in the loading state + AddStatesSilently(NS_EVENT_STATE_LOADING); +} + +void +HTMLSharedObjectElement::GetItemValueText(nsAString& aValue) +{ + if (mNodeInfo->Equals(nsGkAtoms::applet)) { + nsGenericHTMLElement::GetItemValueText(aValue); + } else { + GetSrc(aValue); + } +} + +void +HTMLSharedObjectElement::SetItemValueText(const nsAString& aValue) +{ + if (mNodeInfo->Equals(nsGkAtoms::applet)) { + nsGenericHTMLElement::SetItemValueText(aValue); + } else { + SetSrc(aValue); + } +} + +HTMLSharedObjectElement::~HTMLSharedObjectElement() +{ + UnregisterFreezableElement(); + DestroyImageLoadingContent(); +} + +bool +HTMLSharedObjectElement::IsDoneAddingChildren() +{ + return mIsDoneAddingChildren; +} + +void +HTMLSharedObjectElement::DoneAddingChildren(bool aHaveNotified) +{ + if (!mIsDoneAddingChildren) { + mIsDoneAddingChildren = true; + + // If we're already in a document, we need to trigger the load + // Otherwise, BindToTree takes care of that. + if (IsInDoc()) { + StartObjectLoad(aHaveNotified); + } + } +} + +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(HTMLSharedObjectElement, + nsGenericHTMLElement) + nsObjectLoadingContent::Traverse(tmp, cb); +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END + +NS_IMPL_ADDREF_INHERITED(HTMLSharedObjectElement, Element) +NS_IMPL_RELEASE_INHERITED(HTMLSharedObjectElement, Element) + +nsIClassInfo* +HTMLSharedObjectElement::GetClassInfoInternal() +{ + if (mNodeInfo->Equals(nsGkAtoms::applet)) { + return NS_GetDOMClassInfoInstance(eDOMClassInfo_HTMLAppletElement_id); + } + if (mNodeInfo->Equals(nsGkAtoms::embed)) { + return NS_GetDOMClassInfoInstance(eDOMClassInfo_HTMLEmbedElement_id); + } + return nullptr; +} + +NS_INTERFACE_TABLE_HEAD_CYCLE_COLLECTION_INHERITED(HTMLSharedObjectElement) + NS_HTML_CONTENT_INTERFACE_TABLE_AMBIGUOUS_BEGIN(HTMLSharedObjectElement, + nsIDOMHTMLAppletElement) + NS_INTERFACE_TABLE_ENTRY(HTMLSharedObjectElement, nsIRequestObserver) + NS_INTERFACE_TABLE_ENTRY(HTMLSharedObjectElement, nsIStreamListener) + NS_INTERFACE_TABLE_ENTRY(HTMLSharedObjectElement, nsIFrameLoaderOwner) + NS_INTERFACE_TABLE_ENTRY(HTMLSharedObjectElement, nsIObjectLoadingContent) + NS_INTERFACE_TABLE_ENTRY(HTMLSharedObjectElement, imgINotificationObserver) + NS_INTERFACE_TABLE_ENTRY(HTMLSharedObjectElement, nsIImageLoadingContent) + NS_INTERFACE_TABLE_ENTRY(HTMLSharedObjectElement, imgIOnloadBlocker) + NS_INTERFACE_TABLE_ENTRY(HTMLSharedObjectElement, nsIInterfaceRequestor) + NS_INTERFACE_TABLE_ENTRY(HTMLSharedObjectElement, nsIChannelEventSink) + NS_OFFSET_AND_INTERFACE_TABLE_END + NS_HTML_CONTENT_INTERFACE_TABLE_TO_MAP_SEGUE_AMBIGUOUS(HTMLSharedObjectElement, + nsGenericHTMLElement, + nsIDOMHTMLAppletElement) + NS_INTERFACE_MAP_ENTRY_IF_TAG(nsIDOMHTMLAppletElement, applet) + NS_INTERFACE_MAP_ENTRY_IF_TAG(nsIDOMHTMLEmbedElement, embed) + NS_INTERFACE_MAP_ENTRY_IF_TAG(nsIDOMGetSVGDocument, embed) + NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO_GETTER(GetClassInfoInternal) +NS_HTML_CONTENT_INTERFACE_MAP_END + +NS_IMPL_ELEMENT_CLONE(HTMLSharedObjectElement) + +nsresult +HTMLSharedObjectElement::BindToTree(nsIDocument *aDocument, + nsIContent *aParent, + nsIContent *aBindingParent, + bool aCompileEventHandlers) +{ + nsresult rv = nsGenericHTMLElement::BindToTree(aDocument, aParent, + aBindingParent, + aCompileEventHandlers); + NS_ENSURE_SUCCESS(rv, rv); + + rv = nsObjectLoadingContent::BindToTree(aDocument, aParent, + aBindingParent, + aCompileEventHandlers); + 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 pluginDoc = do_QueryInterface(aDocument); + + // If we already have all the children, start the load. + if (mIsDoneAddingChildren && !pluginDoc) { + void (HTMLSharedObjectElement::*start)() = + &HTMLSharedObjectElement::StartObjectLoad; + nsContentUtils::AddScriptRunner(NS_NewRunnableMethod(this, start)); + } + + return NS_OK; +} + +void +HTMLSharedObjectElement::UnbindFromTree(bool aDeep, + bool aNullParent) +{ + nsObjectLoadingContent::UnbindFromTree(aDeep, aNullParent); + nsGenericHTMLElement::UnbindFromTree(aDeep, aNullParent); +} + + +nsresult +HTMLSharedObjectElement::SetAttr(int32_t aNameSpaceID, nsIAtom *aName, + nsIAtom *aPrefix, const nsAString &aValue, + bool aNotify) +{ + nsresult rv = nsGenericHTMLElement::SetAttr(aNameSpaceID, aName, aPrefix, + aValue, aNotify); + NS_ENSURE_SUCCESS(rv, rv); + + // 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 && IsInDoc() && mIsDoneAddingChildren && + aNameSpaceID == kNameSpaceID_None && aName == URIAttrName()) { + return LoadObject(aNotify, true); + } + + return NS_OK; +} + +bool +HTMLSharedObjectElement::IsHTMLFocusable(bool aWithMouse, + bool *aIsFocusable, + int32_t *aTabIndex) +{ + if (mNodeInfo->Equals(nsGkAtoms::embed) || Type() == eType_Plugin) { + // Has plugin content: let the plugin decide what to do in terms of + // internal focus from mouse clicks + if (aTabIndex) { + GetTabIndex(aTabIndex); + } + + *aIsFocusable = true; + + // Let the plugin decide, so override. + return true; + } + + return nsGenericHTMLElement::IsHTMLFocusable(aWithMouse, aIsFocusable, aTabIndex); +} + +nsIContent::IMEState +HTMLSharedObjectElement::GetDesiredIMEState() +{ + if (Type() == eType_Plugin) { + return IMEState(IMEState::PLUGIN); + } + + return nsGenericHTMLElement::GetDesiredIMEState(); +} + +NS_IMPL_STRING_ATTR(HTMLSharedObjectElement, Align, align) +NS_IMPL_STRING_ATTR(HTMLSharedObjectElement, Alt, alt) +NS_IMPL_STRING_ATTR(HTMLSharedObjectElement, Archive, archive) +NS_IMPL_STRING_ATTR(HTMLSharedObjectElement, Code, code) +NS_IMPL_URI_ATTR(HTMLSharedObjectElement, CodeBase, codebase) +NS_IMPL_STRING_ATTR(HTMLSharedObjectElement, Height, height) +NS_IMPL_INT_ATTR(HTMLSharedObjectElement, Hspace, hspace) +NS_IMPL_STRING_ATTR(HTMLSharedObjectElement, Name, name) +NS_IMPL_URI_ATTR_WITH_BASE(HTMLSharedObjectElement, Object, object, codebase) +NS_IMPL_URI_ATTR(HTMLSharedObjectElement, Src, src) +NS_IMPL_STRING_ATTR(HTMLSharedObjectElement, Type, type) +NS_IMPL_INT_ATTR(HTMLSharedObjectElement, Vspace, vspace) +NS_IMPL_STRING_ATTR(HTMLSharedObjectElement, Width, width) + +int32_t +HTMLSharedObjectElement::TabIndexDefault() +{ + return -1; +} + +NS_IMETHODIMP +HTMLSharedObjectElement::GetSVGDocument(nsIDOMDocument **aResult) +{ + NS_ENSURE_ARG_POINTER(aResult); + + *aResult = nullptr; + + if (!IsInDoc()) { + return NS_OK; + } + + // XXXbz should this use GetCurrentDoc()? sXBL/XBL2 issue! + nsIDocument *sub_doc = OwnerDoc()->GetSubDocumentFor(this); + if (!sub_doc) { + return NS_OK; + } + + return CallQueryInterface(sub_doc, aResult); +} + +bool +HTMLSharedObjectElement::ParseAttribute(int32_t aNamespaceID, + nsIAtom *aAttribute, + const nsAString &aValue, + nsAttrValue &aResult) +{ + 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, + aResult); +} + +static void +MapAttributesIntoRule(const nsMappedAttributes *aAttributes, + nsRuleData *aData) +{ + nsGenericHTMLElement::MapImageBorderAttributeInto(aAttributes, aData); + nsGenericHTMLElement::MapImageMarginAttributeInto(aAttributes, aData); + nsGenericHTMLElement::MapImageSizeAttributesInto(aAttributes, aData); + nsGenericHTMLElement::MapImageAlignAttributeInto(aAttributes, aData); + nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aData); +} + +NS_IMETHODIMP_(bool) +HTMLSharedObjectElement::IsAttributeMapped(const nsIAtom *aAttribute) const +{ + static const MappedAttributeEntry* const map[] = { + sCommonAttributeMap, + sImageMarginSizeAttributeMap, + sImageBorderAttributeMap, + sImageAlignAttributeMap, + }; + + return FindAttributeDependence(aAttribute, map); +} + + +nsMapRuleToAttributesFunc +HTMLSharedObjectElement::GetAttributeMappingFunction() const +{ + return &MapAttributesIntoRule; +} + +void +HTMLSharedObjectElement::StartObjectLoad(bool aNotify) +{ + // BindToTree can call us asynchronously, and we may be removed from the tree + // in the interim + if (!IsInDoc() || !OwnerDoc()->IsActive()) { + return; + } + + LoadObject(aNotify); + SetIsNetworkCreated(false); +} + +nsEventStates +HTMLSharedObjectElement::IntrinsicState() const +{ + return nsGenericHTMLElement::IntrinsicState() | ObjectState(); +} + +uint32_t +HTMLSharedObjectElement::GetCapabilities() const +{ + uint32_t capabilities = eSupportPlugins | eAllowPluginSkipChannel; + if (mNodeInfo->Equals(nsGkAtoms::embed)) { + capabilities |= eSupportSVG | eSupportImages; + } + + return capabilities; +} + +void +HTMLSharedObjectElement::DestroyContent() +{ + nsObjectLoadingContent::DestroyContent(); + nsGenericHTMLElement::DestroyContent(); +} + +nsresult +HTMLSharedObjectElement::CopyInnerTo(Element* aDest) +{ + nsresult rv = nsGenericHTMLElement::CopyInnerTo(aDest); + NS_ENSURE_SUCCESS(rv, rv); + + if (aDest->OwnerDoc()->IsStaticDocument()) { + CreateStaticClone(static_cast(aDest)); + } + + return rv; +} + +} // namespace dom +} // namespace mozilla diff --git a/content/html/content/src/HTMLSharedObjectElement.h b/content/html/content/src/HTMLSharedObjectElement.h new file mode 100644 index 00000000000..3e88a9bd1f4 --- /dev/null +++ b/content/html/content/src/HTMLSharedObjectElement.h @@ -0,0 +1,144 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +// vim:set et sw=2 sts=2 cin: +/* 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/. */ + +#ifndef mozilla_dom_HTMLSharedObjectElement_h +#define mozilla_dom_HTMLSharedObjectElement_h + +#include "nsGenericHTMLElement.h" +#include "nsObjectLoadingContent.h" +#include "nsGkAtoms.h" +#include "nsError.h" +#include "nsIDOMHTMLAppletElement.h" +#include "nsIDOMHTMLEmbedElement.h" +#include "nsIDOMGetSVGDocument.h" + +namespace mozilla { +namespace dom { + +class HTMLSharedObjectElement : public nsGenericHTMLElement + , public nsObjectLoadingContent + , public nsIDOMHTMLAppletElement + , public nsIDOMHTMLEmbedElement + , public nsIDOMGetSVGDocument +{ +public: + HTMLSharedObjectElement(already_AddRefed aNodeInfo, + mozilla::dom::FromParser aFromParser = mozilla::dom::NOT_FROM_PARSER); + virtual ~HTMLSharedObjectElement(); + + // nsISupports + NS_DECL_ISUPPORTS_INHERITED + + // nsIDOMNode + NS_FORWARD_NSIDOMNODE_TO_NSINODE + + // nsIDOMElement + NS_FORWARD_NSIDOMELEMENT_TO_GENERIC + + // nsIDOMHTMLElement + NS_FORWARD_NSIDOMHTMLELEMENT_TO_GENERIC + + virtual int32_t TabIndexDefault() MOZ_OVERRIDE; + + // nsIDOMHTMLAppletElement + NS_DECL_NSIDOMHTMLAPPLETELEMENT + + // Can't use macro for nsIDOMHTMLEmbedElement because it has conflicts with + // NS_DECL_NSIDOMHTMLAPPLETELEMENT. + + // nsIDOMHTMLEmbedElement + NS_IMETHOD GetSrc(nsAString &aSrc); + NS_IMETHOD SetSrc(const nsAString &aSrc); + NS_IMETHOD GetType(nsAString &aType); + NS_IMETHOD SetType(const nsAString &aType); + + // nsIDOMGetSVGDocument + NS_DECL_NSIDOMGETSVGDOCUMENT + + virtual nsresult BindToTree(nsIDocument *aDocument, nsIContent *aParent, + nsIContent *aBindingParent, + bool aCompileEventHandlers); + virtual void UnbindFromTree(bool aDeep = true, + bool aNullParent = true); + virtual nsresult SetAttr(int32_t aNameSpaceID, nsIAtom *aName, + nsIAtom *aPrefix, const nsAString &aValue, + bool aNotify); + + virtual bool IsHTMLFocusable(bool aWithMouse, bool *aIsFocusable, int32_t *aTabIndex); + virtual IMEState GetDesiredIMEState(); + + virtual void DoneAddingChildren(bool aHaveNotified); + virtual bool IsDoneAddingChildren(); + + virtual bool ParseAttribute(int32_t aNamespaceID, + nsIAtom *aAttribute, + const nsAString &aValue, + nsAttrValue &aResult); + virtual nsMapRuleToAttributesFunc GetAttributeMappingFunction() const; + NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom *aAttribute) const; + virtual nsEventStates IntrinsicState() const; + virtual void DestroyContent(); + + // nsObjectLoadingContent + virtual uint32_t GetCapabilities() const; + + virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const; + + nsresult CopyInnerTo(Element* aDest); + + void StartObjectLoad() { StartObjectLoad(true); } + + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_NO_UNLINK(HTMLSharedObjectElement, + nsGenericHTMLElement) + + virtual nsXPCClassInfo* GetClassInfo() + { + return static_cast(GetClassInfoInternal()); + } + nsIClassInfo* GetClassInfoInternal(); + + virtual nsIDOMNode* AsDOMNode() + { + return static_cast(this); + } +private: + /** + * Calls LoadObject with the correct arguments to start the plugin load. + */ + NS_HIDDEN_(void) StartObjectLoad(bool aNotify); + + void GetTypeAttrValue(nsCString &aValue) const + { + if (mNodeInfo->Equals(nsGkAtoms::applet)) { + aValue.AppendLiteral("application/x-java-vm"); + } + else { + nsAutoString type; + GetAttr(kNameSpaceID_None, nsGkAtoms::type, type); + + CopyUTF16toUTF8(type, aValue); + } + } + + nsIAtom *URIAttrName() const + { + return mNodeInfo->Equals(nsGkAtoms::applet) ? + nsGkAtoms::code : + nsGkAtoms::src; + } + + // mIsDoneAddingChildren is only really used for . This boolean is + // always true for , per the documentation in nsIContent.h. + bool mIsDoneAddingChildren; + + virtual void GetItemValueText(nsAString& text); + virtual void SetItemValueText(const nsAString& text); +}; + +} // namespace dom +} // namespace mozilla + +#endif // mozilla_dom_HTMLSharedObjectElement_h diff --git a/content/html/content/src/Makefile.in b/content/html/content/src/Makefile.in index fde753ac7e7..5ece96e1171 100644 --- a/content/html/content/src/Makefile.in +++ b/content/html/content/src/Makefile.in @@ -65,6 +65,7 @@ EXPORTS_mozilla/dom = \ HTMLScriptElement.h \ HTMLSharedElement.h \ HTMLSharedListElement.h \ + HTMLSharedObjectElement.h \ HTMLSpanElement.h \ HTMLStyleElement.h \ HTMLTableCaptionElement.h \ @@ -121,7 +122,7 @@ CPPSRCS = \ HTMLMeterElement.cpp \ HTMLModElement.cpp \ HTMLObjectElement.cpp \ - nsHTMLSharedObjectElement.cpp \ + HTMLSharedObjectElement.cpp \ HTMLOptionElement.cpp \ HTMLOptionsCollection.cpp \ HTMLOptGroupElement.cpp \ diff --git a/content/html/content/src/nsHTMLSharedObjectElement.cpp b/content/html/content/src/nsHTMLSharedObjectElement.cpp deleted file mode 100644 index 60f476eb198..00000000000 --- a/content/html/content/src/nsHTMLSharedObjectElement.cpp +++ /dev/null @@ -1,490 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -// vim:set et sw=2 sts=2 cin: -/* 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/Util.h" - -#include "nsGenericHTMLElement.h" -#include "nsObjectLoadingContent.h" -#include "nsGkAtoms.h" -#include "nsError.h" -#include "nsIDocument.h" -#include "nsIPluginDocument.h" -#include "nsIDOMDocument.h" -#include "nsIDOMHTMLAppletElement.h" -#include "nsIDOMHTMLEmbedElement.h" -#include "nsThreadUtils.h" -#include "nsIDOMGetSVGDocument.h" -#include "nsIDOMSVGDocument.h" -#include "nsIScriptError.h" -#include "nsIWidget.h" -#include "nsContentUtils.h" - -using namespace mozilla; -using namespace mozilla::dom; - -class nsHTMLSharedObjectElement : public nsGenericHTMLElement - , public nsObjectLoadingContent - , public nsIDOMHTMLAppletElement - , public nsIDOMHTMLEmbedElement - , public nsIDOMGetSVGDocument -{ -public: - nsHTMLSharedObjectElement(already_AddRefed aNodeInfo, - mozilla::dom::FromParser aFromParser = mozilla::dom::NOT_FROM_PARSER); - virtual ~nsHTMLSharedObjectElement(); - - // nsISupports - NS_DECL_ISUPPORTS_INHERITED - - // nsIDOMNode - NS_FORWARD_NSIDOMNODE_TO_NSINODE - - // nsIDOMElement - NS_FORWARD_NSIDOMELEMENT_TO_GENERIC - - // nsIDOMHTMLElement - NS_FORWARD_NSIDOMHTMLELEMENT_TO_GENERIC - - virtual int32_t TabIndexDefault() MOZ_OVERRIDE; - - // nsIDOMHTMLAppletElement - NS_DECL_NSIDOMHTMLAPPLETELEMENT - - // Can't use macro for nsIDOMHTMLEmbedElement because it has conflicts with - // NS_DECL_NSIDOMHTMLAPPLETELEMENT. - - // nsIDOMHTMLEmbedElement - NS_IMETHOD GetSrc(nsAString &aSrc); - NS_IMETHOD SetSrc(const nsAString &aSrc); - NS_IMETHOD GetType(nsAString &aType); - NS_IMETHOD SetType(const nsAString &aType); - - // nsIDOMGetSVGDocument - NS_DECL_NSIDOMGETSVGDOCUMENT - - virtual nsresult BindToTree(nsIDocument *aDocument, nsIContent *aParent, - nsIContent *aBindingParent, - bool aCompileEventHandlers); - virtual void UnbindFromTree(bool aDeep = true, - bool aNullParent = true); - virtual nsresult SetAttr(int32_t aNameSpaceID, nsIAtom *aName, - nsIAtom *aPrefix, const nsAString &aValue, - bool aNotify); - - virtual bool IsHTMLFocusable(bool aWithMouse, bool *aIsFocusable, int32_t *aTabIndex); - virtual IMEState GetDesiredIMEState(); - - virtual void DoneAddingChildren(bool aHaveNotified); - virtual bool IsDoneAddingChildren(); - - virtual bool ParseAttribute(int32_t aNamespaceID, - nsIAtom *aAttribute, - const nsAString &aValue, - nsAttrValue &aResult); - virtual nsMapRuleToAttributesFunc GetAttributeMappingFunction() const; - NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom *aAttribute) const; - virtual nsEventStates IntrinsicState() const; - virtual void DestroyContent(); - - // nsObjectLoadingContent - virtual uint32_t GetCapabilities() const; - - virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const; - - nsresult CopyInnerTo(Element* aDest); - - void StartObjectLoad() { StartObjectLoad(true); } - - NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_NO_UNLINK(nsHTMLSharedObjectElement, - nsGenericHTMLElement) - - virtual nsXPCClassInfo* GetClassInfo() - { - return static_cast(GetClassInfoInternal()); - } - nsIClassInfo* GetClassInfoInternal(); - - virtual nsIDOMNode* AsDOMNode() - { - return static_cast(this); - } -private: - /** - * Calls LoadObject with the correct arguments to start the plugin load. - */ - NS_HIDDEN_(void) StartObjectLoad(bool aNotify); - - void GetTypeAttrValue(nsCString &aValue) const - { - if (mNodeInfo->Equals(nsGkAtoms::applet)) { - aValue.AppendLiteral("application/x-java-vm"); - } - else { - nsAutoString type; - GetAttr(kNameSpaceID_None, nsGkAtoms::type, type); - - CopyUTF16toUTF8(type, aValue); - } - } - - nsIAtom *URIAttrName() const - { - return mNodeInfo->Equals(nsGkAtoms::applet) ? - nsGkAtoms::code : - nsGkAtoms::src; - } - - // mIsDoneAddingChildren is only really used for . This boolean is - // always true for , per the documentation in nsIContent.h. - bool mIsDoneAddingChildren; - - virtual void GetItemValueText(nsAString& text); - virtual void SetItemValueText(const nsAString& text); -}; - - -NS_IMPL_NS_NEW_HTML_ELEMENT_CHECK_PARSER(SharedObject) - - -nsHTMLSharedObjectElement::nsHTMLSharedObjectElement(already_AddRefed aNodeInfo, - FromParser aFromParser) - : nsGenericHTMLElement(aNodeInfo), - mIsDoneAddingChildren(mNodeInfo->Equals(nsGkAtoms::embed) || !aFromParser) -{ - RegisterFreezableElement(); - SetIsNetworkCreated(aFromParser == FROM_PARSER_NETWORK); - - // By default we're in the loading state - AddStatesSilently(NS_EVENT_STATE_LOADING); -} - -void -nsHTMLSharedObjectElement::GetItemValueText(nsAString& aValue) -{ - if (mNodeInfo->Equals(nsGkAtoms::applet)) { - nsGenericHTMLElement::GetItemValueText(aValue); - } else { - GetSrc(aValue); - } -} - -void -nsHTMLSharedObjectElement::SetItemValueText(const nsAString& aValue) -{ - if (mNodeInfo->Equals(nsGkAtoms::applet)) { - nsGenericHTMLElement::SetItemValueText(aValue); - } else { - SetSrc(aValue); - } -} - -nsHTMLSharedObjectElement::~nsHTMLSharedObjectElement() -{ - UnregisterFreezableElement(); - DestroyImageLoadingContent(); -} - -bool -nsHTMLSharedObjectElement::IsDoneAddingChildren() -{ - return mIsDoneAddingChildren; -} - -void -nsHTMLSharedObjectElement::DoneAddingChildren(bool aHaveNotified) -{ - if (!mIsDoneAddingChildren) { - mIsDoneAddingChildren = true; - - // If we're already in a document, we need to trigger the load - // Otherwise, BindToTree takes care of that. - if (IsInDoc()) { - StartObjectLoad(aHaveNotified); - } - } -} - -NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsHTMLSharedObjectElement, - nsGenericHTMLElement) - nsObjectLoadingContent::Traverse(tmp, cb); -NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END - -NS_IMPL_ADDREF_INHERITED(nsHTMLSharedObjectElement, Element) -NS_IMPL_RELEASE_INHERITED(nsHTMLSharedObjectElement, Element) - -DOMCI_DATA(HTMLAppletElement, nsHTMLSharedObjectElement) -DOMCI_DATA(HTMLEmbedElement, nsHTMLSharedObjectElement) - -nsIClassInfo* -nsHTMLSharedObjectElement::GetClassInfoInternal() -{ - if (mNodeInfo->Equals(nsGkAtoms::applet)) { - return NS_GetDOMClassInfoInstance(eDOMClassInfo_HTMLAppletElement_id); - } - if (mNodeInfo->Equals(nsGkAtoms::embed)) { - return NS_GetDOMClassInfoInstance(eDOMClassInfo_HTMLEmbedElement_id); - } - return nullptr; -} - -NS_INTERFACE_TABLE_HEAD_CYCLE_COLLECTION_INHERITED(nsHTMLSharedObjectElement) - NS_HTML_CONTENT_INTERFACE_TABLE_AMBIGUOUS_BEGIN(nsHTMLSharedObjectElement, - nsIDOMHTMLAppletElement) - NS_INTERFACE_TABLE_ENTRY(nsHTMLSharedObjectElement, nsIRequestObserver) - NS_INTERFACE_TABLE_ENTRY(nsHTMLSharedObjectElement, nsIStreamListener) - NS_INTERFACE_TABLE_ENTRY(nsHTMLSharedObjectElement, nsIFrameLoaderOwner) - NS_INTERFACE_TABLE_ENTRY(nsHTMLSharedObjectElement, nsIObjectLoadingContent) - NS_INTERFACE_TABLE_ENTRY(nsHTMLSharedObjectElement, imgINotificationObserver) - NS_INTERFACE_TABLE_ENTRY(nsHTMLSharedObjectElement, nsIImageLoadingContent) - NS_INTERFACE_TABLE_ENTRY(nsHTMLSharedObjectElement, imgIOnloadBlocker) - NS_INTERFACE_TABLE_ENTRY(nsHTMLSharedObjectElement, nsIInterfaceRequestor) - NS_INTERFACE_TABLE_ENTRY(nsHTMLSharedObjectElement, nsIChannelEventSink) - NS_OFFSET_AND_INTERFACE_TABLE_END - NS_HTML_CONTENT_INTERFACE_TABLE_TO_MAP_SEGUE_AMBIGUOUS(nsHTMLSharedObjectElement, - nsGenericHTMLElement, - nsIDOMHTMLAppletElement) - NS_INTERFACE_MAP_ENTRY_IF_TAG(nsIDOMHTMLAppletElement, applet) - NS_INTERFACE_MAP_ENTRY_IF_TAG(nsIDOMHTMLEmbedElement, embed) - NS_INTERFACE_MAP_ENTRY_IF_TAG(nsIDOMGetSVGDocument, embed) - NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO_GETTER(GetClassInfoInternal) -NS_HTML_CONTENT_INTERFACE_MAP_END - -NS_IMPL_ELEMENT_CLONE(nsHTMLSharedObjectElement) - -nsresult -nsHTMLSharedObjectElement::BindToTree(nsIDocument *aDocument, - nsIContent *aParent, - nsIContent *aBindingParent, - bool aCompileEventHandlers) -{ - nsresult rv = nsGenericHTMLElement::BindToTree(aDocument, aParent, - aBindingParent, - aCompileEventHandlers); - NS_ENSURE_SUCCESS(rv, rv); - - rv = nsObjectLoadingContent::BindToTree(aDocument, aParent, - aBindingParent, - aCompileEventHandlers); - 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 pluginDoc = do_QueryInterface(aDocument); - - // If we already have all the children, start the load. - if (mIsDoneAddingChildren && !pluginDoc) { - void (nsHTMLSharedObjectElement::*start)() = - &nsHTMLSharedObjectElement::StartObjectLoad; - nsContentUtils::AddScriptRunner(NS_NewRunnableMethod(this, start)); - } - - return NS_OK; -} - -void -nsHTMLSharedObjectElement::UnbindFromTree(bool aDeep, - bool aNullParent) -{ - nsObjectLoadingContent::UnbindFromTree(aDeep, aNullParent); - nsGenericHTMLElement::UnbindFromTree(aDeep, aNullParent); -} - - -nsresult -nsHTMLSharedObjectElement::SetAttr(int32_t aNameSpaceID, nsIAtom *aName, - nsIAtom *aPrefix, const nsAString &aValue, - bool aNotify) -{ - nsresult rv = nsGenericHTMLElement::SetAttr(aNameSpaceID, aName, aPrefix, - aValue, aNotify); - NS_ENSURE_SUCCESS(rv, rv); - - // 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 && IsInDoc() && mIsDoneAddingChildren && - aNameSpaceID == kNameSpaceID_None && aName == URIAttrName()) { - return LoadObject(aNotify, true); - } - - return NS_OK; -} - -bool -nsHTMLSharedObjectElement::IsHTMLFocusable(bool aWithMouse, - bool *aIsFocusable, - int32_t *aTabIndex) -{ - if (mNodeInfo->Equals(nsGkAtoms::embed) || Type() == eType_Plugin) { - // Has plugin content: let the plugin decide what to do in terms of - // internal focus from mouse clicks - if (aTabIndex) { - GetTabIndex(aTabIndex); - } - - *aIsFocusable = true; - - // Let the plugin decide, so override. - return true; - } - - return nsGenericHTMLElement::IsHTMLFocusable(aWithMouse, aIsFocusable, aTabIndex); -} - -nsIContent::IMEState -nsHTMLSharedObjectElement::GetDesiredIMEState() -{ - if (Type() == eType_Plugin) { - return IMEState(IMEState::PLUGIN); - } - - return nsGenericHTMLElement::GetDesiredIMEState(); -} - -NS_IMPL_STRING_ATTR(nsHTMLSharedObjectElement, Align, align) -NS_IMPL_STRING_ATTR(nsHTMLSharedObjectElement, Alt, alt) -NS_IMPL_STRING_ATTR(nsHTMLSharedObjectElement, Archive, archive) -NS_IMPL_STRING_ATTR(nsHTMLSharedObjectElement, Code, code) -NS_IMPL_URI_ATTR(nsHTMLSharedObjectElement, CodeBase, codebase) -NS_IMPL_STRING_ATTR(nsHTMLSharedObjectElement, Height, height) -NS_IMPL_INT_ATTR(nsHTMLSharedObjectElement, Hspace, hspace) -NS_IMPL_STRING_ATTR(nsHTMLSharedObjectElement, Name, name) -NS_IMPL_URI_ATTR_WITH_BASE(nsHTMLSharedObjectElement, Object, object, codebase) -NS_IMPL_URI_ATTR(nsHTMLSharedObjectElement, Src, src) -NS_IMPL_STRING_ATTR(nsHTMLSharedObjectElement, Type, type) -NS_IMPL_INT_ATTR(nsHTMLSharedObjectElement, Vspace, vspace) -NS_IMPL_STRING_ATTR(nsHTMLSharedObjectElement, Width, width) - -int32_t -nsHTMLSharedObjectElement::TabIndexDefault() -{ - return -1; -} - -NS_IMETHODIMP -nsHTMLSharedObjectElement::GetSVGDocument(nsIDOMDocument **aResult) -{ - NS_ENSURE_ARG_POINTER(aResult); - - *aResult = nullptr; - - if (!IsInDoc()) { - return NS_OK; - } - - // XXXbz should this use GetCurrentDoc()? sXBL/XBL2 issue! - nsIDocument *sub_doc = OwnerDoc()->GetSubDocumentFor(this); - if (!sub_doc) { - return NS_OK; - } - - return CallQueryInterface(sub_doc, aResult); -} - -bool -nsHTMLSharedObjectElement::ParseAttribute(int32_t aNamespaceID, - nsIAtom *aAttribute, - const nsAString &aValue, - nsAttrValue &aResult) -{ - 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, - aResult); -} - -static void -MapAttributesIntoRule(const nsMappedAttributes *aAttributes, - nsRuleData *aData) -{ - nsGenericHTMLElement::MapImageBorderAttributeInto(aAttributes, aData); - nsGenericHTMLElement::MapImageMarginAttributeInto(aAttributes, aData); - nsGenericHTMLElement::MapImageSizeAttributesInto(aAttributes, aData); - nsGenericHTMLElement::MapImageAlignAttributeInto(aAttributes, aData); - nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aData); -} - -NS_IMETHODIMP_(bool) -nsHTMLSharedObjectElement::IsAttributeMapped(const nsIAtom *aAttribute) const -{ - static const MappedAttributeEntry* const map[] = { - sCommonAttributeMap, - sImageMarginSizeAttributeMap, - sImageBorderAttributeMap, - sImageAlignAttributeMap, - }; - - return FindAttributeDependence(aAttribute, map); -} - - -nsMapRuleToAttributesFunc -nsHTMLSharedObjectElement::GetAttributeMappingFunction() const -{ - return &MapAttributesIntoRule; -} - -void -nsHTMLSharedObjectElement::StartObjectLoad(bool aNotify) -{ - // BindToTree can call us asynchronously, and we may be removed from the tree - // in the interim - if (!IsInDoc() || !OwnerDoc()->IsActive()) { - return; - } - - LoadObject(aNotify); - SetIsNetworkCreated(false); -} - -nsEventStates -nsHTMLSharedObjectElement::IntrinsicState() const -{ - return nsGenericHTMLElement::IntrinsicState() | ObjectState(); -} - -uint32_t -nsHTMLSharedObjectElement::GetCapabilities() const -{ - uint32_t capabilities = eSupportPlugins | eAllowPluginSkipChannel; - if (mNodeInfo->Equals(nsGkAtoms::embed)) { - capabilities |= eSupportSVG | eSupportImages; - } - - return capabilities; -} - -void -nsHTMLSharedObjectElement::DestroyContent() -{ - nsObjectLoadingContent::DestroyContent(); - nsGenericHTMLElement::DestroyContent(); -} - -nsresult -nsHTMLSharedObjectElement::CopyInnerTo(Element* aDest) -{ - nsresult rv = nsGenericHTMLElement::CopyInnerTo(aDest); - NS_ENSURE_SUCCESS(rv, rv); - - if (aDest->OwnerDoc()->IsStaticDocument()) { - CreateStaticClone(static_cast(aDest)); - } - - return rv; -} From 50ddafc30ddd61f98c41b3e5ff3c36dc59af6858 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Sun, 17 Mar 2013 10:42:03 -0400 Subject: [PATCH 013/234] Bug 843627 part 2. Implement the WebIDL API for and . r=peterv --- .../content/src/HTMLSharedObjectElement.h | 108 ++++++++++++++++++ dom/bindings/Bindings.conf | 8 ++ dom/bindings/parser/WebIDL.py | 2 +- dom/webidl/HTMLAppletElement.webidl | 43 +++++++ dom/webidl/HTMLEmbedElement.webidl | 45 ++++++++ 5 files changed, 205 insertions(+), 1 deletion(-) create mode 100644 dom/webidl/HTMLAppletElement.webidl create mode 100644 dom/webidl/HTMLEmbedElement.webidl diff --git a/content/html/content/src/HTMLSharedObjectElement.h b/content/html/content/src/HTMLSharedObjectElement.h index 3e88a9bd1f4..82724ec0c7b 100644 --- a/content/html/content/src/HTMLSharedObjectElement.h +++ b/content/html/content/src/HTMLSharedObjectElement.h @@ -104,6 +104,114 @@ public: { return static_cast(this); } + + // WebIDL API for + void GetAlign(DOMString& aValue) + { + GetHTMLAttr(nsGkAtoms::align, aValue); + } + void SetAlign(const nsAString& aValue, ErrorResult& aRv) + { + SetHTMLAttr(nsGkAtoms::align, aValue, aRv); + } + void GetAlt(DOMString& aValue) + { + GetHTMLAttr(nsGkAtoms::alt, aValue); + } + void SetAlt(const nsAString& aValue, ErrorResult& aRv) + { + SetHTMLAttr(nsGkAtoms::alt, aValue, aRv); + } + void GetArchive(DOMString& aValue) + { + GetHTMLAttr(nsGkAtoms::archive, aValue); + } + void SetArchive(const nsAString& aValue, ErrorResult& aRv) + { + SetHTMLAttr(nsGkAtoms::archive, aValue, aRv); + } + void GetCode(DOMString& aValue) + { + GetHTMLAttr(nsGkAtoms::code, aValue); + } + void SetCode(const nsAString& aValue, ErrorResult& aRv) + { + SetHTMLAttr(nsGkAtoms::code, aValue, aRv); + } + // XPCOM GetCodebase is ok; note that it's a URI attribute + void SetCodeBase(const nsAString& aValue, ErrorResult& aRv) + { + SetHTMLAttr(nsGkAtoms::codebase, aValue, aRv); + } + void GetHeight(DOMString& aValue) + { + GetHTMLAttr(nsGkAtoms::height, aValue); + } + void SetHeight(const nsAString& aValue, ErrorResult& aRv) + { + SetHTMLAttr(nsGkAtoms::height, aValue, aRv); + } + uint32_t Hspace() + { + return GetHTMLUnsignedIntAttr(nsGkAtoms::hspace, 0); + } + void SetHspace(uint32_t aValue, ErrorResult& aRv) + { + SetHTMLUnsignedIntAttr(nsGkAtoms::hspace, aValue, aRv); + } + void GetName(DOMString& aValue) + { + GetHTMLAttr(nsGkAtoms::name, aValue); + } + void SetName(const nsAString& aValue, ErrorResult& aRv) + { + SetHTMLAttr(nsGkAtoms::name, aValue, aRv); + } + // XPCOM GetObject is ok; note that it's a URI attribute with a weird base URI + void SetObject(const nsAString& aValue, ErrorResult& aRv) + { + SetHTMLAttr(nsGkAtoms::object, aValue, aRv); + } + uint32_t Vspace() + { + return GetHTMLUnsignedIntAttr(nsGkAtoms::vspace, 0); + } + void SetVspace(uint32_t aValue, ErrorResult& aRv) + { + SetHTMLUnsignedIntAttr(nsGkAtoms::vspace, aValue, aRv); + } + void GetWidth(DOMString& aValue) + { + GetHTMLAttr(nsGkAtoms::width, aValue); + } + void SetWidth(const nsAString& aValue, ErrorResult& aRv) + { + SetHTMLAttr(nsGkAtoms::width, aValue, aRv); + } + + // WebIDL api + // XPCOM GetSrc is ok; note that it's a URI attribute + void SetSrc(const nsAString& aValue, ErrorResult& aRv) + { + SetHTMLAttr(nsGkAtoms::src, aValue, aRv); + } + void GetType(DOMString& aValue) + { + GetHTMLAttr(nsGkAtoms::type, aValue); + } + void SetType(const nsAString& aValue, ErrorResult& aRv) + { + SetHTMLAttr(nsGkAtoms::type, aValue, aRv); + } + // width covered by + // height covered by + // align covered by + // name covered by + nsIDocument* GetSVGDocument() + { + return GetContentDocument(); + } + private: /** * Calls LoadObject with the correct arguments to start the plugin load. diff --git a/dom/bindings/Bindings.conf b/dom/bindings/Bindings.conf index 8d5a924d9ef..9d77d5e1af3 100644 --- a/dom/bindings/Bindings.conf +++ b/dom/bindings/Bindings.conf @@ -345,6 +345,10 @@ DOMInterfaces = { 'wrapperCache': False }, +'HTMLAppletElement': { + 'nativeType': 'mozilla::dom::HTMLSharedObjectElement' +}, + 'HTMLBaseElement': { 'nativeType': 'mozilla::dom::HTMLSharedElement' }, @@ -386,6 +390,10 @@ DOMInterfaces = { ] }, +'HTMLEmbedElement': { + 'nativeType': 'mozilla::dom::HTMLSharedObjectElement' +}, + 'HTMLHeadElement': { 'nativeType': 'mozilla::dom::HTMLSharedElement' }, diff --git a/dom/bindings/parser/WebIDL.py b/dom/bindings/parser/WebIDL.py index 8a001b42fa4..cea8a4228b4 100644 --- a/dom/bindings/parser/WebIDL.py +++ b/dom/bindings/parser/WebIDL.py @@ -319,7 +319,7 @@ class IDLUnresolvedIdentifier(IDLObject): [location]) if name[0] == '_' and not allowDoubleUnderscore: name = name[1:] - if name in ["constructor", "toString"] and not allowForbidden: + if name in ["constructor", "iterator", "toString", "toJSON"] and not allowForbidden: raise WebIDLError("Cannot use reserved identifier '%s'" % (name), [location]) diff --git a/dom/webidl/HTMLAppletElement.webidl b/dom/webidl/HTMLAppletElement.webidl new file mode 100644 index 00000000000..d2805989583 --- /dev/null +++ b/dom/webidl/HTMLAppletElement.webidl @@ -0,0 +1,43 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* 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/. + * + * The origin of this IDL file is + * http://www.whatwg.org/specs/web-apps/current-work/#the-applet-element + * + * © Copyright 2004-2011 Apple Computer, Inc., Mozilla Foundation, and + * Opera Software ASA. You are granted a license to use, reproduce + * and create derivative works of this document. + */ + +// http://www.whatwg.org/specs/web-apps/current-work/#the-applet-element +[NeedNewResolve] +interface HTMLAppletElement : HTMLElement { + [Pure, SetterThrows] + attribute DOMString align; + [Pure, SetterThrows] + attribute DOMString alt; + [Pure, SetterThrows] + attribute DOMString archive; + [Pure, SetterThrows] + attribute DOMString code; + [Pure, SetterThrows] + attribute DOMString codeBase; + [Pure, SetterThrows] + attribute DOMString height; + [Pure, SetterThrows] + attribute unsigned long hspace; + [Pure, SetterThrows] + attribute DOMString name; + [Pure, SetterThrows] + attribute DOMString _object; + [Pure, SetterThrows] + attribute unsigned long vspace; + [Pure, SetterThrows] + attribute DOMString width; +}; + +HTMLAppletElement implements MozImageLoadingContent; +HTMLAppletElement implements MozFrameLoaderOwner; +HTMLAppletElement implements MozObjectLoadingContent; diff --git a/dom/webidl/HTMLEmbedElement.webidl b/dom/webidl/HTMLEmbedElement.webidl new file mode 100644 index 00000000000..313b4fa201d --- /dev/null +++ b/dom/webidl/HTMLEmbedElement.webidl @@ -0,0 +1,45 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* 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/. + * + * The origin of this IDL file is + * http://www.whatwg.org/specs/web-apps/current-work/#the-embed-element + * http://www.whatwg.org/specs/web-apps/current-work/#HTMLEmbedElement-partial + * + * © Copyright 2004-2011 Apple Computer, Inc., Mozilla Foundation, and + * Opera Software ASA. You are granted a license to use, reproduce + * and create derivative works of this document. + */ + +// http://www.whatwg.org/specs/web-apps/current-work/#the-embed-element +[NeedNewResolve] +interface HTMLEmbedElement : HTMLElement { + [Pure, SetterThrows] + attribute DOMString src; + [Pure, SetterThrows] + attribute DOMString type; + [Pure, SetterThrows] + attribute DOMString width; + [Pure, SetterThrows] + attribute DOMString height; + [Throws] + legacycaller any (any... arguments); +}; + +// http://www.whatwg.org/specs/web-apps/current-work/#HTMLEmbedElement-partial +partial interface HTMLEmbedElement { + [Pure, SetterThrows] + attribute DOMString align; + [Pure, SetterThrows] + attribute DOMString name; +}; + +partial interface HTMLEmbedElement { + // nsIDOMGetSVGDocument + Document? getSVGDocument(); +}; + +HTMLEmbedElement implements MozImageLoadingContent; +HTMLEmbedElement implements MozFrameLoaderOwner; +HTMLEmbedElement implements MozObjectLoadingContent; From 7984f39d39ee5a088138345a647265b7aa0937e1 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Sun, 17 Mar 2013 10:42:05 -0400 Subject: [PATCH 014/234] Bug 843627 part 3. Enable WebIDL bindings for and . r=peterv --- browser/base/content/test/test_bug787619.html | 2 +- .../content/src/HTMLSharedObjectElement.cpp | 31 +++++++++++++++++++ .../content/src/HTMLSharedObjectElement.h | 4 +++ dom/bindings/BindingUtils.cpp | 18 +++++++++-- .../test/mochitest/test_bug751809.html | 4 +-- dom/webidl/WebIDL.mk | 2 ++ 6 files changed, 56 insertions(+), 5 deletions(-) diff --git a/browser/base/content/test/test_bug787619.html b/browser/base/content/test/test_bug787619.html index 93d7a84aa83..ba1b3c034e8 100644 --- a/browser/base/content/test/test_bug787619.html +++ b/browser/base/content/test/test_bug787619.html @@ -24,7 +24,7 @@ function test1() { let plugin = document.getElementById('plugin'); ok(plugin, 'got plugin element'); - let objLC = plugin.QueryInterface(Ci.nsIObjectLoadingContent); + let objLC = SpecialPowers.wrap(plugin); ok(!objLC.activated, 'plugin should not be activated'); synthesizeMouseAtCenter(plugin, {}); diff --git a/content/html/content/src/HTMLSharedObjectElement.cpp b/content/html/content/src/HTMLSharedObjectElement.cpp index 974886d0ff5..f7327d12261 100644 --- a/content/html/content/src/HTMLSharedObjectElement.cpp +++ b/content/html/content/src/HTMLSharedObjectElement.cpp @@ -5,6 +5,8 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "mozilla/dom/HTMLSharedObjectElement.h" +#include "mozilla/dom/HTMLEmbedElementBinding.h" +#include "mozilla/dom/HTMLAppletElementBinding.h" #include "mozilla/Util.h" #include "nsIDocument.h" @@ -34,6 +36,8 @@ HTMLSharedObjectElement::HTMLSharedObjectElement(already_AddRefed a // By default we're in the loading state AddStatesSilently(NS_EVENT_STATE_LOADING); + + SetIsDOMBinding(); } void @@ -361,5 +365,32 @@ HTMLSharedObjectElement::CopyInnerTo(Element* aDest) return rv; } +JSObject* +HTMLSharedObjectElement::WrapNode(JSContext* aCx, JSObject* aScope) +{ + JSObject* obj; + if (mNodeInfo->Equals(nsGkAtoms::applet)) { + obj = HTMLAppletElementBinding::Wrap(aCx, aScope, this); + } else { + MOZ_ASSERT(mNodeInfo->Equals(nsGkAtoms::embed)); + obj = HTMLEmbedElementBinding::Wrap(aCx, aScope, this); + } + if (!obj) { + return nullptr; + } + SetupProtoChain(aCx, obj); + return obj; +} + +JSObject* +HTMLSharedObjectElement::GetCanonicalPrototype(JSContext* aCx, JSObject* aGlobal) +{ + if (mNodeInfo->Equals(nsGkAtoms::applet)) { + return HTMLAppletElementBinding::GetProtoObject(aCx, aGlobal); + } + MOZ_ASSERT(mNodeInfo->Equals(nsGkAtoms::embed)); + return HTMLEmbedElementBinding::GetProtoObject(aCx, aGlobal); +} + } // namespace dom } // namespace mozilla diff --git a/content/html/content/src/HTMLSharedObjectElement.h b/content/html/content/src/HTMLSharedObjectElement.h index 82724ec0c7b..2266226f7b9 100644 --- a/content/html/content/src/HTMLSharedObjectElement.h +++ b/content/html/content/src/HTMLSharedObjectElement.h @@ -244,6 +244,10 @@ private: virtual void GetItemValueText(nsAString& text); virtual void SetItemValueText(const nsAString& text); + + virtual JSObject* WrapNode(JSContext *aCx, JSObject *aScope) MOZ_OVERRIDE; + virtual JSObject* GetCanonicalPrototype(JSContext* aCx, + JSObject* aGlobal) MOZ_OVERRIDE; }; } // namespace dom diff --git a/dom/bindings/BindingUtils.cpp b/dom/bindings/BindingUtils.cpp index 0139724da72..9cbcd383ef6 100644 --- a/dom/bindings/BindingUtils.cpp +++ b/dom/bindings/BindingUtils.cpp @@ -22,6 +22,9 @@ #include "mozilla/dom/HTMLObjectElement.h" #include "mozilla/dom/HTMLObjectElementBinding.h" +#include "mozilla/dom/HTMLSharedObjectElement.h" +#include "mozilla/dom/HTMLEmbedElementBinding.h" +#include "mozilla/dom/HTMLAppletElementBinding.h" namespace mozilla { namespace dom { @@ -1533,9 +1536,20 @@ ReparentWrapper(JSContext* aCx, JSObject* aObj) MOZ_CRASH(); } - HTMLObjectElement* htmlobject; + nsObjectLoadingContent* htmlobject; nsresult rv = UnwrapObject(aCx, aObj, htmlobject); - if (NS_SUCCEEDED(rv)) { + if (NS_FAILED(rv)) { + rv = UnwrapObject(aCx, aObj, htmlobject); + if (NS_FAILED(rv)) { + rv = UnwrapObject(aCx, aObj, htmlobject); + if (NS_FAILED(rv)) { + htmlobject = nullptr; + } + } + } + if (htmlobject) { htmlobject->SetupProtoChain(aCx, aObj); } diff --git a/dom/plugins/test/mochitest/test_bug751809.html b/dom/plugins/test/mochitest/test_bug751809.html index b851b14c6bf..b6348bd752a 100644 --- a/dom/plugins/test/mochitest/test_bug751809.html +++ b/dom/plugins/test/mochitest/test_bug751809.html @@ -39,7 +39,7 @@ function go() { var plugin = document.getElementById('plugin'); - var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); + var objLoadingContent = SpecialPowers.wrap(plugin); ok(!objLoadingContent.activated, "plugin should not be activated"); SimpleTest.waitForFocus(afterWindowFocus); @@ -55,7 +55,7 @@ function afterPluginActivation() { var plugin = document.getElementById('plugin'); - var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); + var objLoadingContent = SpecialPowers.wrap(plugin); ok(objLoadingContent.activated, "plugin should be activated now"); // Triggering a paint and waiting for it to be flushed makes sure diff --git a/dom/webidl/WebIDL.mk b/dom/webidl/WebIDL.mk index faabf5339b7..cb65cb21ee2 100644 --- a/dom/webidl/WebIDL.mk +++ b/dom/webidl/WebIDL.mk @@ -66,6 +66,7 @@ webidl_files = \ Function.webidl \ GainNode.webidl \ HTMLAnchorElement.webidl \ + HTMLAppletElement.webidl \ HTMLAreaElement.webidl \ HTMLBaseElement.webidl \ HTMLBodyElement.webidl \ @@ -79,6 +80,7 @@ webidl_files = \ HTMLDListElement.webidl \ HTMLDocument.webidl \ HTMLElement.webidl \ + HTMLEmbedElement.webidl \ HTMLFieldSetElement.webidl \ HTMLFontElement.webidl \ HTMLFrameElement.webidl \ From e192a8450c69bc10784c2c3d6e127b07946a6553 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Sun, 17 Mar 2013 10:42:07 -0400 Subject: [PATCH 015/234] Bug 843627 part 4. Add IDL attribute reflection tests for , , . r=peterv --- content/html/content/test/Makefile.in | 3 + content/html/content/test/reflect.js | 39 +++--- .../test_applet_attributes_reflection.html | 86 +++++++++++++ .../test_embed_attributes_reflection.html | 57 +++++++++ .../test_object_attributes_reflection.html | 117 ++++++++++++++++++ 5 files changed, 288 insertions(+), 14 deletions(-) create mode 100644 content/html/content/test/test_applet_attributes_reflection.html create mode 100644 content/html/content/test/test_embed_attributes_reflection.html create mode 100644 content/html/content/test/test_object_attributes_reflection.html diff --git a/content/html/content/test/Makefile.in b/content/html/content/test/Makefile.in index 5171634a74d..77b796a85d0 100644 --- a/content/html/content/test/Makefile.in +++ b/content/html/content/test/Makefile.in @@ -247,6 +247,9 @@ MOCHITEST_FILES = \ file_fullscreen-multiple-inner.html \ test_li_attributes_reflection.html \ test_link_attributes_reflection.html \ + test_object_attributes_reflection.html \ + test_embed_attributes_reflection.html \ + test_applet_attributes_reflection.html \ test_ol_attributes_reflection.html \ test_dl_attributes_reflection.html \ test_ul_attributes_reflection.html \ diff --git a/content/html/content/test/reflect.js b/content/html/content/test/reflect.js index 68cd3f15874..3b290bb10a3 100644 --- a/content/html/content/test/reflect.js +++ b/content/html/content/test/reflect.js @@ -21,6 +21,7 @@ * OR * attribute Object object containing two attributes, 'content' and 'idl' * - otherValues Array [optional] other values to test in addition of the default ones + * - extendedAttributes Object object which can have 'TreatNullAs': "EmptyString" */ function reflectString(aParameters) { @@ -31,11 +32,13 @@ function reflectString(aParameters) ? aParameters.attribute : aParameters.attribute.idl; var otherValues = aParameters.otherValues !== undefined ? aParameters.otherValues : []; + var treatNullAs = aParameters.extendedAttributes ? + aParameters.extendedAttributes.TreatNullAs : null; ok(idlAttr in element, idlAttr + " should be an IDL attribute of this element"); is(typeof element[idlAttr], "string", - idlAttr + " IDL attribute should be a string"); + "'" + idlAttr + "' IDL attribute should be a string"); // Tests when the attribute isn't set. is(element.getAttribute(contentAttr), null, @@ -49,9 +52,9 @@ function reflectString(aParameters) */ element.setAttribute(contentAttr, null); is(element.getAttribute(contentAttr), "null", - "null should have been stringified to 'null'"); + "null should have been stringified to 'null' for '" + contentAttr + "'"); is(element[idlAttr], "null", - "null should have been stringified to 'null'"); + "null should have been stringified to 'null' for '" + idlAttr + "'"); element.removeAttribute(contentAttr); element[idlAttr] = null; @@ -61,15 +64,23 @@ function reflectString(aParameters) input: [ "accept", "alt", "formTarget", "max", "min", "name", "pattern", "placeholder", "step", "defaultValue" ] }; if (!(element.localName in todoAttrs) || todoAttrs[element.localName].indexOf(idlAttr) == -1) { - is(element.getAttribute(contentAttr), "null", - "null should have been stringified to 'null'"); - is(element[idlAttr], "null", "null should have been stringified to 'null'"); + if (treatNullAs == "EmptyString") { + is(element.getAttribute(contentAttr), "", + "null should have been stringified to '' for '" + contentAttr + "'"); + is(element[idlAttr], "", + "null should have been stringified to '' for '" + idlAttr + "'"); + } else { + is(element.getAttribute(contentAttr), "null", + "null should have been stringified to 'null' for '" + contentAttr + "'"); + is(element[idlAttr], "null", + "null should have been stringified to 'null' for '" + contentAttr + "'"); + } element.removeAttribute(contentAttr); } else { todo_is(element.getAttribute(contentAttr), "null", - "null should have been stringified to 'null'"); + "null should have been stringified to 'null' for '" + contentAttr + "'"); todo_is(element[idlAttr], "null", - "null should have been stringified to 'null'"); + "null should have been stringified to 'null' for '" + contentAttr + "'"); element.removeAttribute(contentAttr); } @@ -106,16 +117,16 @@ function reflectString(aParameters) stringsToTest.forEach(function([v, r]) { element.setAttribute(contentAttr, v); is(element[idlAttr], r, - "IDL attribute should return the value it has been set to."); + "IDL attribute '" + idlAttr + "' should return the value it has been set to."); is(element.getAttribute(contentAttr), r, - "Content attribute should return the value it has been set to."); + "Content attribute '" + contentAttr + "'should return the value it has been set to."); element.removeAttribute(contentAttr); element[idlAttr] = v; is(element[idlAttr], r, - "IDL attribute should return the value it has been set to."); + "IDL attribute '" + idlAttr + "' should return the value it has been set to."); is(element.getAttribute(contentAttr), r, - "Content attribute should return the value it has been set to."); + "Content attribute '" + contentAttr + "' should return the value it has been set to."); element.removeAttribute(contentAttr); }); @@ -270,7 +281,7 @@ function reflectLimitedEnumerated(aParameters) ? aParameters.unsupportedValues : []; ok(idlAttr in element, idlAttr + " should be an IDL attribute of this element"); - is(typeof element[idlAttr], "string", idlAttr + " IDL attribute should be a string"); + is(typeof element[idlAttr], "string", "'" + idlAttr + "' IDL attribute should be a string"); // Explicitly check the default value. element.removeAttribute(contentAttr); @@ -598,7 +609,7 @@ function reflectURL(aParameters) { var element = aParameters.element; var contentAttr = typeof aParameters.attribute === "string" - ? aParameters.attribute : aParameters.attribute.content; + ? aParameters.attribute : aParameters.attribute.content; var idlAttr = typeof aParameters.attribute === "string" ? aParameters.attribute : aParameters.attribute.idl; diff --git a/content/html/content/test/test_applet_attributes_reflection.html b/content/html/content/test/test_applet_attributes_reflection.html new file mode 100644 index 00000000000..dd04a2022ee --- /dev/null +++ b/content/html/content/test/test_applet_attributes_reflection.html @@ -0,0 +1,86 @@ + + + + Test for HTMLAppletElement attributes reflection + + + + + +

+ +
+
+
+ + diff --git a/content/html/content/test/test_embed_attributes_reflection.html b/content/html/content/test/test_embed_attributes_reflection.html new file mode 100644 index 00000000000..85001598a39 --- /dev/null +++ b/content/html/content/test/test_embed_attributes_reflection.html @@ -0,0 +1,57 @@ + + + + Test for HTMLEmbedElement attributes reflection + + + + + +

+ +
+
+
+ + diff --git a/content/html/content/test/test_object_attributes_reflection.html b/content/html/content/test/test_object_attributes_reflection.html new file mode 100644 index 00000000000..5a417c289c4 --- /dev/null +++ b/content/html/content/test/test_object_attributes_reflection.html @@ -0,0 +1,117 @@ + + + + Test for HTMLObjectElement attributes reflection + + + + + +

+ +
+
+
+ + From bd34362e96fab6c3e251d77d5359bbe6a523a781 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Sun, 17 Mar 2013 10:42:09 -0400 Subject: [PATCH 016/234] Bug 846972 part 1. Make nsCSSStyleSheet wrappercached. r=mccr8 --- layout/style/nsCSSStyleSheet.cpp | 5 ++++- layout/style/nsCSSStyleSheet.h | 8 +++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/layout/style/nsCSSStyleSheet.cpp b/layout/style/nsCSSStyleSheet.cpp index a3760fee83f..8db8bdfe950 100644 --- a/layout/style/nsCSSStyleSheet.cpp +++ b/layout/style/nsCSSStyleSheet.cpp @@ -1175,6 +1175,7 @@ DOMCI_DATA(CSSStyleSheet, nsCSSStyleSheet) // QueryInterface implementation for nsCSSStyleSheet NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsCSSStyleSheet) + NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY NS_INTERFACE_MAP_ENTRY(nsIStyleSheet) NS_INTERFACE_MAP_ENTRY(nsIDOMStyleSheet) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSStyleSheet) @@ -1199,6 +1200,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsCSSStyleSheet) tmp->DropRuleCollection(); tmp->UnlinkInner(); tmp->mScopeElement = nullptr; + NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER NS_IMPL_CYCLE_COLLECTION_UNLINK_END NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsCSSStyleSheet) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMedia) @@ -1207,8 +1209,9 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsCSSStyleSheet) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mRuleCollection) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mScopeElement) tmp->TraverseInner(cb); + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END - +NS_IMPL_CYCLE_COLLECTION_TRACE_WRAPPERCACHE(nsCSSStyleSheet) nsresult nsCSSStyleSheet::AddRuleProcessor(nsCSSRuleProcessor* aProcessor) diff --git a/layout/style/nsCSSStyleSheet.h b/layout/style/nsCSSStyleSheet.h index d4544522598..0af5c90fd46 100644 --- a/layout/style/nsCSSStyleSheet.h +++ b/layout/style/nsCSSStyleSheet.h @@ -23,6 +23,7 @@ #include "nsString.h" #include "mozilla/CORSMode.h" #include "nsCycleCollectionParticipant.h" +#include "nsWrapperCache.h" class nsXMLNameSpaceMap; class nsCSSRuleProcessor; @@ -104,14 +105,15 @@ class CSSRuleListImpl; class nsCSSStyleSheet MOZ_FINAL : public nsIStyleSheet, public nsIDOMCSSStyleSheet, - public nsICSSLoaderObserver + public nsICSSLoaderObserver, + public nsWrapperCache { public: nsCSSStyleSheet(mozilla::CORSMode aCORSMode); NS_DECL_CYCLE_COLLECTING_ISUPPORTS - NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsCSSStyleSheet, - nsIStyleSheet) + NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsCSSStyleSheet, + nsIStyleSheet) NS_DECLARE_STATIC_IID_ACCESSOR(NS_CSS_STYLE_SHEET_IMPL_CID) From 9482e7c07aec97cd76377c24c22b2e5fac7c6923 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Sun, 17 Mar 2013 10:42:59 -0400 Subject: [PATCH 017/234] Bug 846972 part 2. Add the WebIDL APIs for StyleSheet and CSSStyleSheet. r=peterv --- .../base/public/nsIStyleSheetLinkingElement.h | 3 +- content/base/src/nsStyleLinkElement.cpp | 34 +++------ content/base/src/nsStyleLinkElement.h | 8 +-- content/html/content/src/HTMLLinkElement.cpp | 35 ++++------ content/html/content/src/HTMLLinkElement.h | 4 +- content/html/content/src/HTMLStyleElement.cpp | 33 +++------ content/html/content/src/HTMLStyleElement.h | 2 +- dom/bindings/BindingDeclarations.h | 52 ++++++++++++++ dom/bindings/BindingUtils.h | 50 -------------- dom/interfaces/html/nsIDOMHTMLLinkElement.idl | 1 + .../html/nsIDOMHTMLStyleElement.idl | 1 + dom/webidl/CSSStyleSheet.webidl | 22 ++++++ dom/webidl/HTMLLinkElement.webidl | 2 +- dom/webidl/HTMLStyleElement.webidl | 8 +-- dom/webidl/StyleSheet.webidl | 30 ++++++++ layout/style/Loader.cpp | 2 +- layout/style/nsCSSStyleSheet.cpp | 69 ++++++++++--------- layout/style/nsCSSStyleSheet.h | 53 ++++++++++++-- 18 files changed, 239 insertions(+), 170 deletions(-) create mode 100644 dom/webidl/CSSStyleSheet.webidl create mode 100644 dom/webidl/StyleSheet.webidl diff --git a/content/base/public/nsIStyleSheetLinkingElement.h b/content/base/public/nsIStyleSheetLinkingElement.h index f6077b002b1..dc455dfdc78 100644 --- a/content/base/public/nsIStyleSheetLinkingElement.h +++ b/content/base/public/nsIStyleSheetLinkingElement.h @@ -16,6 +16,7 @@ class nsIURI; { 0xb2, 0xe9, 0x63, 0x52, 0x8c, 0x87, 0x99, 0x7a } } class nsIStyleSheet; +class nsCSSStyleSheet; class nsIStyleSheetLinkingElement : public nsISupports { public: @@ -28,7 +29,7 @@ public: * @param aStyleSheet the style sheet associated with this * element. */ - NS_IMETHOD SetStyleSheet(nsIStyleSheet* aStyleSheet) = 0; + NS_IMETHOD SetStyleSheet(nsCSSStyleSheet* aStyleSheet) = 0; /** * Used to obtain the style sheet linked in by this element. diff --git a/content/base/src/nsStyleLinkElement.cpp b/content/base/src/nsStyleLinkElement.cpp index a52b7b602cf..44b87b53ce7 100644 --- a/content/base/src/nsStyleLinkElement.cpp +++ b/content/base/src/nsStyleLinkElement.cpp @@ -56,21 +56,17 @@ nsStyleLinkElement::Traverse(nsCycleCollectionTraversalCallback &cb) } NS_IMETHODIMP -nsStyleLinkElement::SetStyleSheet(nsIStyleSheet* aStyleSheet) +nsStyleLinkElement::SetStyleSheet(nsCSSStyleSheet* aStyleSheet) { - nsRefPtr cssSheet = do_QueryObject(mStyleSheet); - if (cssSheet) { - cssSheet->SetOwningNode(nullptr); + if (mStyleSheet) { + mStyleSheet->SetOwningNode(nullptr); } mStyleSheet = aStyleSheet; - cssSheet = do_QueryObject(mStyleSheet); - if (cssSheet) { - nsCOMPtr node; - CallQueryInterface(this, - static_cast(getter_AddRefs(node))); + if (mStyleSheet) { + nsCOMPtr node = do_QueryObject(this); if (node) { - cssSheet->SetOwningNode(node); + mStyleSheet->SetOwningNode(node); } } @@ -97,15 +93,7 @@ nsStyleLinkElement::InitStyleLinkElement(bool aDontLoadStyle) NS_IMETHODIMP nsStyleLinkElement::GetSheet(nsIDOMStyleSheet** aSheet) { - NS_ENSURE_ARG_POINTER(aSheet); - *aSheet = nullptr; - - if (mStyleSheet) { - CallQueryInterface(mStyleSheet, aSheet); - } - - // Always return NS_OK to avoid throwing JS exceptions if mStyleSheet - // is not a nsIDOMStyleSheet + NS_IF_ADDREF(*aSheet = mStyleSheet); return NS_OK; } @@ -416,14 +404,10 @@ nsStyleLinkElement::UpdateStyleSheetScopedness(bool aIsNowScoped) return; } - nsRefPtr cssStyleSheet = do_QueryObject(mStyleSheet); - NS_ASSERTION(cssStyleSheet, "should only call UpdateStyleSheetScope for " - "an nsCSSStyleSheet"); - nsCOMPtr thisContent; CallQueryInterface(this, getter_AddRefs(thisContent)); - Element* oldScopeElement = cssStyleSheet->GetScopeElement(); + Element* oldScopeElement = mStyleSheet->GetScopeElement(); Element* newScopeElement = aIsNowScoped ? thisContent->GetParentElement() : nullptr; @@ -437,7 +421,7 @@ nsStyleLinkElement::UpdateStyleSheetScopedness(bool aIsNowScoped) document->BeginUpdate(UPDATE_STYLE); document->RemoveStyleSheet(mStyleSheet); - cssStyleSheet->SetScopeElement(newScopeElement); + mStyleSheet->SetScopeElement(newScopeElement); document->AddStyleSheet(mStyleSheet); document->EndUpdate(UPDATE_STYLE); diff --git a/content/base/src/nsStyleLinkElement.h b/content/base/src/nsStyleLinkElement.h index c9fe3ba1b32..aaf83eefb8b 100644 --- a/content/base/src/nsStyleLinkElement.h +++ b/content/base/src/nsStyleLinkElement.h @@ -16,7 +16,7 @@ #include "nsCOMPtr.h" #include "nsIDOMLinkStyle.h" #include "nsIStyleSheetLinkingElement.h" -#include "nsIStyleSheet.h" +#include "nsCSSStyleSheet.h" #include "nsIURI.h" #include "nsTArray.h" #include "mozilla/CORSMode.h" @@ -41,10 +41,10 @@ public: // nsIDOMLinkStyle NS_DECL_NSIDOMLINKSTYLE - nsIStyleSheet* GetSheet() { return mStyleSheet; } + nsCSSStyleSheet* GetSheet() const { return mStyleSheet; } // nsIStyleSheetLinkingElement - NS_IMETHOD SetStyleSheet(nsIStyleSheet* aStyleSheet); + NS_IMETHOD SetStyleSheet(nsCSSStyleSheet* aStyleSheet); NS_IMETHOD GetStyleSheet(nsIStyleSheet*& aStyleSheet); NS_IMETHOD InitStyleLinkElement(bool aDontLoadStyle); NS_IMETHOD UpdateStyleSheet(nsICSSLoaderObserver* aObserver, @@ -105,7 +105,7 @@ private: bool* aIsAlternate, bool aForceUpdate); - nsCOMPtr mStyleSheet; + nsRefPtr mStyleSheet; protected: bool mDontLoadStyle; bool mUpdatesEnabled; diff --git a/content/html/content/src/HTMLLinkElement.cpp b/content/html/content/src/HTMLLinkElement.cpp index 65ae7e6def8..fe3e3adff18 100644 --- a/content/html/content/src/HTMLLinkElement.cpp +++ b/content/html/content/src/HTMLLinkElement.cpp @@ -69,43 +69,34 @@ NS_HTML_CONTENT_INTERFACE_MAP_END NS_IMPL_ELEMENT_CLONE(HTMLLinkElement) bool -HTMLLinkElement::GetDisabled(ErrorResult& aRv) +HTMLLinkElement::Disabled() { - nsCOMPtr ss = do_QueryInterface(GetSheet()); - if (!ss) { - return false; - } - - bool disabled = false; - aRv = ss->GetDisabled(&disabled); - return disabled; + nsCSSStyleSheet* ss = GetSheet(); + return ss && ss->Disabled(); } NS_IMETHODIMP -HTMLLinkElement::GetDisabled(bool* aDisabled) +HTMLLinkElement::GetMozDisabled(bool* aDisabled) { - ErrorResult rv; - *aDisabled = GetDisabled(rv); - return rv.ErrorCode(); + *aDisabled = Disabled(); + return NS_OK; } void -HTMLLinkElement::SetDisabled(bool aDisabled, ErrorResult& aRv) +HTMLLinkElement::SetDisabled(bool aDisabled) { - nsCOMPtr ss = do_QueryInterface(GetSheet()); - if (!ss) { - return; + nsCSSStyleSheet* ss = GetSheet(); + if (ss) { + ss->SetDisabled(aDisabled); } - aRv = ss->SetDisabled(aDisabled); } NS_IMETHODIMP -HTMLLinkElement::SetDisabled(bool aDisabled) +HTMLLinkElement::SetMozDisabled(bool aDisabled) { - ErrorResult rv; - SetDisabled(aDisabled, rv); - return rv.ErrorCode(); + SetDisabled(aDisabled); + return NS_OK; } diff --git a/content/html/content/src/HTMLLinkElement.h b/content/html/content/src/HTMLLinkElement.h index 43524f53704..9c3378cda05 100644 --- a/content/html/content/src/HTMLLinkElement.h +++ b/content/html/content/src/HTMLLinkElement.h @@ -92,8 +92,8 @@ public: void CreateAndDispatchEvent(nsIDocument* aDoc, const nsAString& aEventName); // WebIDL - bool GetDisabled(ErrorResult& aRv); - void SetDisabled(bool aDisabled, ErrorResult& aRv); + bool Disabled(); + void SetDisabled(bool aDisabled); // XPCOM GetHref is fine. void SetHref(const nsAString& aHref, ErrorResult& aRv) { diff --git a/content/html/content/src/HTMLStyleElement.cpp b/content/html/content/src/HTMLStyleElement.cpp index 92465271cf6..3af346dc437 100644 --- a/content/html/content/src/HTMLStyleElement.cpp +++ b/content/html/content/src/HTMLStyleElement.cpp @@ -61,7 +61,7 @@ NS_IMPL_ELEMENT_CLONE(HTMLStyleElement) NS_IMETHODIMP -HTMLStyleElement::GetDisabled(bool* aDisabled) +HTMLStyleElement::GetMozDisabled(bool* aDisabled) { NS_ENSURE_ARG_POINTER(aDisabled); @@ -72,36 +72,23 @@ HTMLStyleElement::GetDisabled(bool* aDisabled) bool HTMLStyleElement::Disabled() { - nsCOMPtr ss = do_QueryInterface(GetSheet()); - if (!ss) { - return false; - } - - bool disabled = false; - ss->GetDisabled(&disabled); - - return disabled; + nsCSSStyleSheet* ss = GetSheet(); + return ss && ss->Disabled(); } NS_IMETHODIMP -HTMLStyleElement::SetDisabled(bool aDisabled) +HTMLStyleElement::SetMozDisabled(bool aDisabled) { - ErrorResult error; - SetDisabled(aDisabled, error); - return error.ErrorCode(); + SetDisabled(aDisabled); + return NS_OK; } void -HTMLStyleElement::SetDisabled(bool aDisabled, ErrorResult& aError) +HTMLStyleElement::SetDisabled(bool aDisabled) { - nsCOMPtr ss = do_QueryInterface(GetSheet()); - if (!ss) { - return; - } - - nsresult result = ss->SetDisabled(aDisabled); - if (NS_FAILED(result)) { - aError.Throw(result); + nsCSSStyleSheet* ss = GetSheet(); + if (ss) { + ss->SetDisabled(aDisabled); } } diff --git a/content/html/content/src/HTMLStyleElement.h b/content/html/content/src/HTMLStyleElement.h index 50fa3ba8194..bea4382e7d1 100644 --- a/content/html/content/src/HTMLStyleElement.h +++ b/content/html/content/src/HTMLStyleElement.h @@ -74,7 +74,7 @@ public: NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED bool Disabled(); - void SetDisabled(bool aDisabled, ErrorResult& aError); + void SetDisabled(bool aDisabled); void SetMedia(const nsAString& aMedia, ErrorResult& aError) { SetHTMLAttr(nsGkAtoms::media, aMedia, aError); diff --git a/dom/bindings/BindingDeclarations.h b/dom/bindings/BindingDeclarations.h index 3b3d9f277c4..9c480829937 100644 --- a/dom/bindings/BindingDeclarations.h +++ b/dom/bindings/BindingDeclarations.h @@ -21,6 +21,12 @@ #include "nsStringBuffer.h" #include "nsTArray.h" +class nsWrapperCache; + +// nsGlobalWindow implements nsWrapperCache, but doesn't always use it. Don't +// try to use it without fixing that first. +class nsGlobalWindow; + namespace mozilla { namespace dom { @@ -379,6 +385,52 @@ private: JSContext* mCx; }; +inline nsWrapperCache* +GetWrapperCache(nsWrapperCache* cache) +{ + return cache; +} + +inline nsWrapperCache* +GetWrapperCache(nsGlobalWindow* not_allowed); + +inline nsWrapperCache* +GetWrapperCache(void* p) +{ + return NULL; +} + +// Helper template for smart pointers to resolve ambiguity between +// GetWrappeCache(void*) and GetWrapperCache(const ParentObject&). +template