talk about JS components, remove gratuitous 'netscape' from progID

git-svn-id: svn://10.0.0.236/trunk@48626 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
shaver%netscape.com
1999-09-21 21:23:02 +00:00
parent 75d7a96f19
commit e913ee5946
4 changed files with 31 additions and 20 deletions

View File

@@ -39,4 +39,5 @@ include $(topsrcdir)/config/rules.mk
install:: $(TARGETS)
$(INSTALL) $(srcdir)/xpconnect-sample.html $(DIST)/bin/res/samples
$(INSTALL) $(srcdir)/nsSample.js $(DIST)/bin/components

View File

@@ -45,5 +45,6 @@ include <$(DEPTH)\config\rules.mak>
install:: $(DLL)
$(MAKE_INSTALL) $(DLL) $(DIST)\bin\components
$(MAKE_INSTALL) nsSample.js $(DIST)\bin\components
$(MAKE_INSTALL) xpconnect-sample.html $(DIST)\bin\res\samples

View File

@@ -297,7 +297,7 @@ NSRegisterSelf(nsISupports* aServMgr , const char* aPath)
rv = compMgr->RegisterComponent(kSampleCID,
"Sample World Component",
"component://netscape/sample/sample-world",
"component://mozilla/sample/sample-world",
aPath, PR_TRUE, PR_TRUE);
if (NS_FAILED(rv)) return rv;

View File

@@ -30,7 +30,7 @@ using the <tt>Components</tt> object, then accesses it through
the <a href="http://lxr.mozilla.org/seamonkey/source/xpcom/sample/nsISample.idl">nsISample</a> interface by calling <tt>QueryInterface</tt>:
<br>
<pre>
var sample = Components.classes["component://netscape/sample/sample-world"].createInstance();
var sample = Components.classes["component://mozilla/sample/sample-world"].createInstance();
sample = sample.QueryInterface(Components.interfaces.nsISample);
</pre>
@@ -39,26 +39,30 @@ The buttons on the form are connected to JavaScript event handlers which
call the methods defined in C++.
<p><b>nsISample.idl</b>
<p><b><a href="http://lxr.mozilla.org/mozilla/source/xpcom/sample/nsSample.idl">nsISample.idl</a></b>
<p>This is the interface declaration for the XPCOM object. It defines
two functions, their parameters, and one attribute. It also defines
the interface's id. The idl file is compiled by the xpidl compiler
into a C++ header, nsISample.h and a .xpt file which is a binary representation
of the interface used at runtime.
<br><tt>attribute string Value;</tt>
<br><tt>void WriteValue(in string aPrefix);</tt>
<br><tt>void Poke(in string aValue);</tt><b></b>
<p><b>nsSample.cpp</b>
<br><tt>attribute string value;</tt>
<br><tt>void writeValue(in string aPrefix);</tt>
<br><tt>void poke(in string aValue);</tt><b></b>
<p><b><a href="http://lxr.mozilla.org/mozilla/source/xpcom/sample/nsSample.cpp">nsSample.cpp</a></b>
<p>This contains the implementation of nsISample.idl. SampleImpl
inherits from nsISample.h, the header dynamically created by the xpidl
compiler. The attribute Value has been expanded into a get and set
and the return values have been modified to NS_IMETHOD, a success status
for the method. The macro NS_DECL_ISUPPORTS, defined in mozilla/xpcom/public/nsISupportsUtils.h
for the method. The macro NS_DECL_ISUPPORTS, defined in <a href="http://lxr.mozilla.org/mozilla/source/mozilla/xpcom/public/nsISupportsUtils.h">mozilla/xpcom/public/nsISupportsUtils.h</a>
defines the inherited methods from nsISupports.h.
<br><tt>NS_IMPL_ISUPPORTS(SampleImpl, nsISample::GetIID());</tt>
<br>In the constructor, the macro NS_INIT_REFCNT is called which sets the
reference count to 0.
<p><b>nsSampleFactory.cpp</b>
reference count to 0.<p>
Note that the methods in the C++ bindings use InterCaps style, while the IDL
and JavaScript versions should use interCaps naming. The JavaScript binding
matches the case of the IDL, <b>except</b> <a
href="http://bugzilla.mozilla.org/show_bug.cgi?id=14460">QueryInterface</a>.
<p><b><a href="http://lxr.mozilla.org/mozilla/source/xpcom/sample/nsSampleFactory.cpp">nsSampleFactory.cpp</a></b>
<p>This is the class which builds the instance of the nsSample class.
The COM framework uses factories to create instance of implementations
rather than having the implementations instatiate themselves in order to
@@ -67,6 +71,9 @@ which is also an XPCOM object. To gain more knowledge of factories
see the <a href="http://www.mozilla.org/projects/xpcom/generic-factory.html">generic
factory document</a> or the<a href="http://www.mozilla.org/docs/tplist/catFlow/modunote.htm#Basics">
Modularization techniques document</a>.
<p><b><a href="http://lxr.mozilla.org/mozilla/source/xpcom/sample/nsSample.js">nsSample.js</a></b>
<p>This file implements the nsISample interface, and associated factory glue,
in JavaScript.
<p><b>Compiling the idl</b>
@@ -108,31 +115,32 @@ printed is calculated in C++ code defined in <a href="http://lxr.mozilla.org/sea
<!-- XXX keep in sync with stuff in pre tag below -->
<script>
var sample = Components.classes["component://netscape/sample/sample-world"].createInstance();
/* to use nsSample.js version, use "mozilla.jssample.1" */
var sample = Components.classes["component://mozilla/sample/sample-world"].createInstance();
sample = sample.QueryInterface(Components.interfaces.nsISample);
dump("sample = " + sample + "\n");
function get()
{
var field = document.getElementById('Value');
field.value = sample.Value;
field.value = sample.value;
}
function set()
{
var field = document.getElementById('Value');
sample.Value = field.value;
sample.value = field.value;
}
function poke()
{
var field = document.getElementById('Value');
sample.Poke(field.value);
sample.poke(field.value);
}
function write()
{
sample.WriteValue("here is what I'm writing!");
sample.writeValue("here is what I'm writing: ");
}
</script>
@@ -153,31 +161,32 @@ JavaScript and form source:
<!-- XXX keep in sync with actual script -->
<pre>
&lt;script&gt;
var sample = Components.classes["component://netscape/sample/sample-world"].createInstance();
/* to use nsSample.js version, use "mozilla.jssample.1" */
var sample = Components.classes["component://mozilla/sample/sample-world"].createInstance();
sample = sample.QueryInterface(Components.interfaces.nsISample);
dump("sample = " + sample + "\n");
function get()
{
var field = document.getElementById('Value');
field.value = sample.Value;
field.value = sample.value;
}
function set()
{
var field = document.getElementById('Value');
sample.Value = field.value;
sample.value = field.value;
}
function poke()
{
var field = document.getElementById('Value');
sample.Poke(field.value);
sample.poke(field.value);
}
function write()
{
sample.WriteValue("here is what I'm writing!" + Components.interfaces.nsISample.MY_CONST_THINGIE);
sample.writeValue("here is what I'm writing: ");
}
&lt;/script&gt;