aboutsummaryrefslogtreecommitdiff
path: root/files/ko/creating_xpcom_components
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:42:17 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:42:17 -0500
commitda78a9e329e272dedb2400b79a3bdeebff387d47 (patch)
treee6ef8aa7c43556f55ddfe031a01cf0a8fa271bfe /files/ko/creating_xpcom_components
parent1109132f09d75da9a28b649c7677bb6ce07c40c0 (diff)
downloadtranslated-content-da78a9e329e272dedb2400b79a3bdeebff387d47.tar.gz
translated-content-da78a9e329e272dedb2400b79a3bdeebff387d47.tar.bz2
translated-content-da78a9e329e272dedb2400b79a3bdeebff387d47.zip
initial commit
Diffstat (limited to 'files/ko/creating_xpcom_components')
-rw-r--r--files/ko/creating_xpcom_components/an_overview_of_xpcom/index.html531
-rw-r--r--files/ko/creating_xpcom_components/index.html355
-rw-r--r--files/ko/creating_xpcom_components/preface/index.html78
3 files changed, 964 insertions, 0 deletions
diff --git a/files/ko/creating_xpcom_components/an_overview_of_xpcom/index.html b/files/ko/creating_xpcom_components/an_overview_of_xpcom/index.html
new file mode 100644
index 0000000000..03b5dbcba6
--- /dev/null
+++ b/files/ko/creating_xpcom_components/an_overview_of_xpcom/index.html
@@ -0,0 +1,531 @@
+---
+title: An Overview of XPCOM
+slug: Creating_XPCOM_Components/An_Overview_of_XPCOM
+tags:
+ - XPCOM
+translation_of: Mozilla/Tech/XPCOM/Guide/Creating_components/An_Overview_of_XPCOM
+---
+<p></p><div class="prevnext" style="text-align: right;">
+ <p><a href="/ko/docs/Creating_XPCOM_Components:Preface" style="float: left;">« 이전</a><a href="/ko/docs/Creating_XPCOM_Components:Using_XPCOM_Components">다음 »</a></p>
+</div> This is a book about XPCOM. The book is written in the form of a tutorial about creating XPCOM components, but it covers all major aspects, concepts, and terminology of the XPCOM component model along the way.<p></p>
+
+<p>This chapter starts with a quick tour of XPCOM - an introduction to the basic concepts and technologies in XPCOM and component development. The brief sections in this chapter introduce the concepts at a very high level, so that we can discuss and use them with more familiarity in the tutorial itself, which describes the creation of a Mozilla component called <strong>WebLock</strong>.</p>
+
+<h3 id="The_XPCOM_Solution" name="The_XPCOM_Solution">The XPCOM Solution</h3>
+
+<p>The Cross Platform Component Object Module (XPCOM) is a framework which allows developers to break up monolithic software projects into smaller modularized pieces. These pieces, known as<em>components</em> , are then assembled back together at runtime.</p>
+
+<p>The goal of XPCOM is to allow different pieces of software to be developed and built independently of one another. In order to allow interoperability between components within an application, XPCOM separates the<em>implementation</em> of a component from the<em>interface</em> , which we discuss in <a href="#Interfaces">Interfaces</a>. But XPCOM also provides several tools and libraries that enable the loading and manipulation of these components, services that help the developer write modular cross-platform code, and versioning support, so that components can be replaced or upgraded without breaking or having to recreate the application. Using XPCOM, developers create components that can be reused in different applications or that can be replaced to change the functionality of existing applications.</p>
+
+<p>XPCOM not only supports component software development, it also provides much of the functionality that a development platform provides, such as:</p>
+
+<ul>
+ <li>component management</li>
+ <li>file abstraction</li>
+ <li>object message passing</li>
+ <li>memory management</li>
+</ul>
+
+<p>We will discuss the above items in detail in the coming chapters, but for now, it can be useful to think of XPCOM as a<em>platform for component development</em> , in which features such as those listed above are provided.</p>
+
+<h3 id="Gecko" name="Gecko">Gecko</h3>
+
+<p>Although it is in some ways structurally similar to Microsoft COM, XPCOM is designed to be used principally at the application level. The most important use of XPCOM is within<em>Gecko</em> , an open source, standards compliant, embeddable web browser and toolkit for creating web browsers and other applications.</p>
+
+<p>XPCOM is the means of accessing Gecko library functionality and embedding or extending Gecko. This book focuses on the latter - extending Gecko - but the fundamental ideas in the book will be important to developers embedding Gecko as well.</p>
+
+<p>Gecko is used in many internet applications, mostly browsers. The list includes devices such as the Gateway/AOL Instant AOL device and the Nokia Media Terminal. Gecko is also used in the latest Compuserve client, AOL for Mac OS X, Netscape 7, and of course the Mozilla client. At this time, Gecko is the predominant open source web browser.</p>
+
+<h3 id="Components" name="Components">Components</h3>
+
+<p>XPCOM allows you to build a system in which large software projects can be broken up into smaller pieces. These pieces, known as components, are usually delivered in small, reusable binary libraries (a <abbr title="Dynamic Link Library">DLL</abbr> on Windows, for example, or a <abbr title="Distributed Shared Object">DSO</abbr> on Unix), which can include one or more components. When there are two or more related components together in a binary library, the library is referred to as a<em>module</em> .</p>
+
+<p>Breaking software into different components can help make it less difficult to develop and maintain. Beyond this, modular, component-based programming has some well-known advantages:</p>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <td class="header">Benefit</td>
+ <td class="header">Description</td>
+ </tr>
+ <tr>
+ <td>재사용</td>
+ <td>모듈화된 코드는 다른 응용프로그램들과 문맥들에서 재사용 될 수 있다.</td>
+ </tr>
+ <tr>
+ <td>갱신</td>
+ <td>전체 응용프로그램을 재컴파일하지 않고 컴포넌트들을 갱신할 수 있다.</td>
+ </tr>
+ <tr>
+ <td>성능</td>
+ <td>코드가 모듈화되면, 곧바로 필요하지 않은 모듈들은 메모리에 늦게 적재되거나(lazy loaded), 아예 적제되지 않아 응용프로그램의 성능을 향상시키는 효과를 가져올 수 있다.</td>
+ </tr>
+ <tr>
+ <td>관리</td>
+ <td>Even when you are not updating a component, designing your application in a modular way can make it easier for you to find and maintain the parts of the application that you are interested in.</td>
+ </tr>
+ </tbody>
+</table>
+
+<p>Mozilla has over four million lines of code, and no single individual understands the entire codebase. The best way to tackle a project of this size is to divide it into smaller, more managable pieces, use a component programming model, and to organize related sets of components into modules. The network library, for example, consists of components for each of the protocols, HTTP, FTP, and others, which are bundled together and linked into a single library. This library is the networking module, also known as "necko."</p>
+
+<p>But it's not always a good idea to divide things up. There are some things in the world that just go together, and others that shouldn't be apart. For example, one author's son will not eat a peanutbutter sandwich if there isn't jam on it, because in his world, peanut butter and jam form an indelible union. Some software is the same. In areas of code that are tightly-coupled-in classes that are only used internally, for example-the expensive work to divide things may not be worth the effort.</p>
+
+<p>The <abbr title="Hypertext Transfer Protocol">HTTP</abbr> component in Gecko doesn't expose private classes it uses as separate components. The "stuff" that's internal to the component stays internal, and isn't exposed to XPCOM. In the haste of early Mozilla development, components were created where they were inappropriate, but there's been an ongoing effort to remove XPCOM from places like this.</p>
+
+<h3 id=".EC.9D.B8.ED.84.B0.ED.8E.98.EC.9D.B4.EC.8A.A4" name=".EC.9D.B8.ED.84.B0.ED.8E.98.EC.9D.B4.EC.8A.A4">인터페이스</h3>
+
+<p>It's generally a good idea to break software into components, but how exactly do you do this? The basic idea is to identify the pieces of functionality that are related and understand how they communicate with each other. The communication channels between different component form boundaries between those components, and when those boundaries are formalized they are known as<em>interfaces</em> .</p>
+
+<p>Interfaces aren't a new idea in programming. We've all used interfaces since our first "HelloWorld" program, where the interface was between the code we actually wrote-the application code-and the printing code. The application code used an interface from a library, <code>stdio</code>, to print the "hello world" string out to the screen. The difference here is that a "HelloWorld" application in XPCOM finds this screen-printing functionality at runtime and never has to know about <code>stdio</code> when it's compiled.</p>
+
+<p>Interfaces allow developers to<em>encapsulate</em> the implementation and inner workings of their software, and allow clients to ignore how things are made and just use that software.</p>
+
+<div class="side-note">
+<p><span id="Interfaces_and_Programming_by_Contract"><a id="Interfaces_and_Programming_by_Contract"></a><strong>Interfaces and Programming by Contract</strong></span></p>
+
+<p>An interface forms a contractual agreement between components and clients. There is no code that enforces these agreements, but ignoring them can be fatal. In component-based programming, a component guarantees that the interfaces it provides will be<em>immutable</em> - that they will provide the same access to the same methods across different versions of the component - establishing a contract with the software clients that use it. In this respect, interface-based programming is often referred to as<em>programming by contract</em> .</p>
+</div>
+
+<h4 id="Interfaces_and_Encapsulation" name="Interfaces_and_Encapsulation">Interfaces and Encapsulation</h4>
+
+<p>Between component boundaries, abstraction is crucial for software maintainability and reusability. Consider, for example, a class that<em>isn't</em> well encapsulated. Using a freely available public initialization method, as the example below suggests, can cause problems.</p>
+
+<p><span id="SomeClass_Class_Initialization"><a id="SomeClass_Class_Initialization"></a><strong>SomeClass Class Initialization</strong></span></p>
+
+<pre>class SomeClass
+{
+ public:
+ // Constructor
+ SomeClass();
+
+ // Virtual Destructor
+ virtual ~SomeClass();
+
+ // init method
+ void Init();
+
+ void DoSomethingUseful();
+};
+</pre>
+
+<p>For this system to work properly, the client programmer must pay close attention to whatever rules the component programmer has established. This is the contractual agreement of this unencapsulated class: a set of rules that define when each method can be called and what it is expected to do. One rule might specify that <code>DoSomethingUseful</code> may only be called after a call to <code>Init()</code>. The <code>DoSomethingUseful</code> method may do some kind of checking to ensure that the condition - that <code>Init</code> has been called - has been satisfied.</p>
+
+<p>In addition to writing well-commented code that tells the client developer the rules about <code>Init()</code>, the developer can take a couple steps to make this contract even clearer. First, the construction of an object can be encapsulated, and a<em>virtual class</em> provided that defines the <code>DoSomethingUseful</code> method. In this way, construction and initialization can be completely hidden from clients of the class. In this "semi-encapsulated" situation, the only part of the class that is exposed is a well-defined list of callable methods (i.e., the interface). Once the class is encapsulated, the only interface the client will see is this:</p>
+
+<p><span id="Encapsulation_of_SomeInterface"><a id="Encapsulation_of_SomeInterface"></a><strong>Encapsulation of SomeInterface</strong></span></p>
+
+<pre>class SomeInterface
+{
+ public:
+ virtual void DoSomethingUseful() = 0;
+};
+</pre>
+
+<p>The implementation can then derive from this class and implement the virtual method. Clients of this code can then use a factory design pattern to create the object (see <a href="#Factories">Factories</a>) and further encapsulate the implementation. In XPCOM, clients are shielded from the inner workings of components in this way and rely on the interface to provide access to the needed functionality.</p>
+
+<h4 id="The_nsISupports_Base_Interface" name="The_nsISupports_Base_Interface">The <code>nsISupports</code> Base Interface</h4>
+
+<p>Two fundamental issues in component and interface-based programming are<em>component lifetime</em> , also called<em>object ownership</em> , and<em>interface querying</em> , or being able to identify which interfaces a component supports at runtime. This section introduces the base interface-the mother of all interfaces in XPCOM - <code>nsISupports</code>, which provides solutions to both of these issues for XPCOM developers.</p>
+
+<h5 id="Object_Ownership" name="Object_Ownership">Object Ownership</h5>
+
+<p>In XPCOM, since components may implement any number of different interfaces, interfaces must be<em>reference counted</em> . Components must keep track of how many references to it clients are maintaining and delete themselves when that number reaches zero.</p>
+
+<p>When a component gets created, an integer inside the component tracks this reference count. The reference count is incremented automatically when the client instantiates the component; over the course of the component's life, the reference count goes up and down, always staying above zero. At some point, all clients lose interest in the component, the reference count hits zero, and the component deletes itself.</p>
+
+<p>When clients use interfaces responsibly, this can be a very straightforward process. XPCOM has tools to make it even easier, as we describe later. It can raise some real housekeeping problems when, for example, a client uses an interface and forgets to decrement the reference count. When this happens, interfaces may never be released and will leak memory. The system of reference counting is, like many things in XPCOM, a contract between clients and implementations. It works when people agree to it, but when they don't, things can go wrong. It is the responsibility of the function that creates the interface pointer to add the initial reference, or<em>owning reference</em> , to the count.</p>
+
+<div class="side-note">
+<p><span id="Pointers_in_XPCOM"><a id="Pointers_in_XPCOM"></a><strong>Pointers in XPCOM</strong></span></p>
+
+<p>In XPCOM,<em>pointers</em> refer to interface pointers. The difference is a subtle one, since interface pointers and regular pointers are both just address in memory. But an interface pointer is known to implement the nsISupports base interface, and so can be used to call methods such as <code>AddRef</code>, <code>Release</code>, or <code>QueryInterface</code>.</p>
+</div>
+
+<p><code>nsISupports</code>, shown below, supplies the basic functionality for dealing with interface discovery and reference counting. The members of this interface, <code>QueryInterface</code>, <code>AddRef</code>, and <code>Release</code>, provide the basic means for getting the right interface from an object, incrementing the reference count, and releasing objects once they are not being used, respectively. The <code>nsISupports</code> interface is shown below:</p>
+
+<p><span id="The_%3Ccode%3EnsISupports%3C/code%3E_Interface"><a id="The_%3Ccode%3EnsISupports%3C/code%3E_Interface"></a><strong>The <code>nsISupports</code> Interface</strong></span></p>
+
+<pre>class Sample: public nsISupports
+{
+ private:
+ nsrefcnt mRefCnt;
+ public:
+ Sample();
+ virtual ~Sample();
+
+ NS_IMETHOD QueryInterface(const nsIID &amp;aIID, void **aResult);
+ NS_IMETHOD_(nsrefcnt) AddRef(void);
+ NS_IMETHOD_(nsrefcnt) Release(void);
+};
+</pre>
+
+<p>The various types used in the interface are described in the <a href="#XPCOM_Types">XPCOM Types</a> section below. A complete (if spare) implementation of the <code>nsISupports</code> interface is shown below:</p>
+
+<p><span id="Implementation_of_%3Ccode%3EnsISupports%3C/code%3E_Interface"><a id="Implementation_of_%3Ccode%3EnsISupports%3C/code%3E_Interface"></a><strong>Implementation of <code>nsISupports</code> Interface</strong></span></p>
+
+<pre>// initialize the reference count to 0
+Sample::Sample() : mRefCnt(0)
+{
+}
+Sample::~Sample()
+{
+}
+
+// typical, generic implementation of QI
+NS_IMETHODIMP Sample::QueryInterface(const nsIID &amp;aIID,
+ void **aResult)
+{
+ if (aResult == NULL) {
+ return NS_ERROR_NULL_POINTER;
+ }
+ *aResult = NULL;
+ if (aIID.Equals(kISupportsIID)) {
+ *aResult = (void *) this;
+ }
+ if (*aResult == NULL) {
+ return NS_ERROR_NO_INTERFACE;
+ }
+ // add a reference
+ AddRef();
+ return NS_OK;
+}
+
+NS_IMETHODIMP_(nsrefcnt) Sample::AddRef()
+{
+ return ++mRefCnt;
+}
+
+NS_IMETHODIMP_(nsrefcnt) Sample::Release()
+{
+ if (--mRefCnt == 0) {
+ delete this;
+ return 0;
+ }
+ // optional: return the reference count
+ return mRefCnt;
+}
+</pre>
+
+<h5 id="Object_Interface_Discovery" name="Object_Interface_Discovery">Object Interface Discovery</h5>
+
+<p><em>Inheritance</em>is another very important topic in object oriented programming. Inheritance is the means through which one class is derived from another. When a class inherits from another class, the inheriting class may<em>override</em> the default behaviors of the base class without having to copy all of that class's code, in effect creating a more specific class, as in the following example:</p>
+
+<p><span id="Simple_Class_Inheritance"><a id="Simple_Class_Inheritance"></a><strong>Simple Class Inheritance</strong></span></p>
+
+<pre>class Shape
+{
+ private:
+ int m_x;
+ int m_y;
+
+ public:
+ virtual void Draw() = 0;
+ Shape();
+ virtual ~Shape();
+};
+
+class Circle : public Shape
+{
+ private:
+ int m_radius;
+ public:
+ virtual Draw();
+ Circle(int x, int y, int radius);
+ virtual ~Circle();
+};
+</pre>
+
+<p><code>Circle</code> is a derived class of <code>Shape</code>. A <code>Circle</code> is a <code>Shape</code>, in other words, but a <code>Shape</code> is not necessarily a <code>Circle</code>. In this case, <code>Shape</code> is the<em>base class</em> and <code>Circle</code> is a<em>subclass</em> of <code>Shape</code>.</p>
+
+<p>In XPCOM, all classes derive from the <code>nsISupports</code> interface, so all objects are <code>nsISupports</code> but they are also other, more specific classes, which you need to be able to find out about at runtime. In <a href="#Simple_Class_Inheritance">Simple Class Inheritance</a>, for example, you'd like to be able ask the <code>Shape</code> if it's a <code>Circle</code> and to be able to use it like a circle if it is. In XPCOM, this is what the <code>QueryInterface</code> feature of the <code>nsISupports</code> interface is for: it allows clients to find and access different interfaces based on their needs.</p>
+
+<p>In C++, you can use a fairly advanced feature known as a <code>dynamic_cast&lt;&gt;</code>, which throws an exception if the <code>Shape</code> object is not able to be cast to a <code>Circle</code>. But enabling exceptions and <abbr title="Runtime Type Information">RTTI</abbr> may not be an option because of performance overhead and compatibility on many platforms, so XPCOM does things differently.</p>
+
+<div class="side-note">
+<p><span id="Exceptions_in_XPCOM"><a id="Exceptions_in_XPCOM"></a><strong>Exceptions in XPCOM</strong></span></p>
+
+<p>C++ exceptions are not supported directly by XPCOM. Instead all exceptions must be handled within a given component, before crossing interface boundaries. In XPCOM, all interface methods should return an <code>nsresult</code> error value (see the <a href="ko/XPCOM_API_Reference">XPCOM API Reference</a> for a listing of these error codes). These error code results become the "exceptions" that XPCOM handles.</p>
+</div>
+
+<p>Instead of leveraging C++ RTTI, XPCOM uses the special <code>QueryInterface</code> method that casts the object to the right interface if that interface is supported.</p>
+
+<p>Every interface is assigned an identifier that gets generated from a tool commonly named "uuidgen". This universally unique identifier (UUID) is a unique, 128-bit number. Used in the context of an interface (as opposed to a component, which is what the contract ID is for), this number is called an<em>IID</em> .</p>
+
+<p>When a client wants to discover if an object supports a given interface, the client passes the IID assigned to that interface into the <code>QueryInterface</code> method of that object. If the object supports the requested interface, it adds a reference to itself and passes back a pointer to that interface. If the object does not support the interface an error is returned.</p>
+
+<pre>class nsISupports {
+ public:
+ long QueryInterface(const nsIID &amp; uuid,
+ void **result) = 0;
+ long AddRef(void) = 0;
+ long Release(void) = 0;
+};
+</pre>
+
+<p>The first parameter of <code>QueryInterface</code> is a reference to a class named <code>nsIID</code>, which is a basic encapsulation of the IID. Of the three methods on the <code>nsIID</code> class, <code>Equals</code>, <code>Parse</code>, and <code>ToString</code>, <code>Equals</code> is by far the most important, because it is used to compare two <code>nsIID</code>s in this interface querying process.</p>
+
+<p>When you implement the <code>nsIID</code> class (and you'll see in the chapter <a href="ko/Creating_XPCOM_Components/Using_XPCOM_Utilities_to_Make_Things_Easier">Using XPCOM Utilities to Make Things Easier</a> how macros can make this process much easier), you must make sure the class methods return a valid result when the client calls <code>QueryInterface</code> with the <code>nsISupports</code> IID. <code>QueryInterface</code> should support all interfaces that the component supports.</p>
+
+<p>In implementations of <code>QueryInterface</code>, the IID argument is checked against the <code>nsIID</code> class. If there is a match, the object's <code>this</code> pointer is cast to <code>void</code>, the reference count is incremented, and the interface returned to the caller. If there isn't a match, the class returns an error and sets the out value to <code>null</code>.</p>
+
+<p>In the example above, it's easy enough to use a C-style cast. But casting can become more involved where you must first cast <code>void</code> then to the requested type, because you must return the interface pointer in the <abbr title="virtual table">vtable</abbr> corresponding to the requested interface. Casting can become a problem when there is an ambiguous inheritance hierarchy.</p>
+
+<h3 id="XPCOM_Identifiers" name="XPCOM_Identifiers">XPCOM Identifiers</h3>
+
+<p>In addition to the IID interface identifier discussed in the previous section, XPCOM uses two other very important identifiers to distinguish classes and components.</p>
+
+<div class="side-note">
+<p><span id="XPCOM_Identifier_Classes"><a id="XPCOM_Identifier_Classes"></a><strong>XPCOM Identifier Classes</strong></span></p>
+
+<p>The <code>nsIID</code> class is actually a typedef for the <code>nsID</code> class. The other typedefs of <code>nsID</code>, CID and IID, refer to specific implementations of a concrete class and to a specific interface, respectively.</p>
+
+<p>The <code>nsID</code> class provides methods like <code>Equals</code> for comparing identifiers in the code. See <a href="ko/Creating_XPCOM_Components/Creating_the_Component_Code#Identifiers_in_XPCOM">Identifiers in XPCOM</a> for more discussion of the <code>nsID</code> class.</p>
+</div>
+
+<h4 id="CID" name="CID">CID</h4>
+
+<p>A CID is a 128-bit number that uniquely identifies a class or component in much the same way that an IID uniquely identifies an interface. The CID for <code>nsISupports</code> looks like this:</p>
+
+<p><code>00000000-0000-0000-c000-000000000046</code></p>
+
+<p>The length of a CID can make it cumbersome to deal with in the code, so very often you see #defines for CIDs and other identifiers being used, as in this example:</p>
+
+<pre>#define SAMPLE_CID \
+{ 0x777f7150, 0x4a2b, 0x4301, \
+{ 0xad, 0x10, 0x5e, 0xab, 0x25, 0xb3, 0x22, 0xaa}}
+</pre>
+
+<p>You also see <code>NS_DEFINE_CID</code> used a lot. This simple macro declares a constant with the value of the CID:</p>
+
+<pre>static NS_DEFINE_CID(kWebShellCID, NS_WEB_SHELL_CID);
+</pre>
+
+<p>A CID is sometimes also referred to as a<em>class identifier</em> . If the class to which a CID refers implements more than one interface, that CID guarantees that the class implements that whole set of interfaces when it's published or frozen.</p>
+
+<h4 id="Contract_ID" name="Contract_ID">Contract ID</h4>
+
+<p>A contract ID is a human readable string used to access a component. A CID or a contract ID may be used to get a component from the component manager. This is the contract ID for the LDAP Operation component:</p>
+
+<pre>"@mozilla.org/network/ldap-operation;1"
+</pre>
+
+<p>The format of the contract ID is the<em>domain</em> of the component, the<em>module</em> , the<em>component name</em> , and the<em>version number</em> , separated by slashes.</p>
+
+<p>Like a CID, a contract ID refers to an implementation rather than an interface, as an IID does. But a contract ID is not bound to any specific implementation, as the CID is, and is thus more general. Instead, a contract ID only specifies a given set of interfaces that it wants implemented, and any number of different CIDs may step in and fill that request. This difference between a contract ID and a CID is what makes it possible to override components.</p>
+
+<h3 id="Factories" name="Factories">Factories</h3>
+
+<p>Once code is broken up into components, client code typically uses the <code>new</code> constructor to instantiate objects for use:</p>
+
+<pre>SomeClass* component = new SomeClass();
+</pre>
+
+<p>This pattern requires that the client know something about the component, however-how big it is at the very least. The<em>factory design pattern</em> can be used to encapsulate object construction. The goal of factories is create objects without exposing clients to the implementations and initializations of those objects. In the <code>SomeClass</code> example, the construction and initialization of <code>SomeClass</code>, which implements the <code>SomeInterface</code> abstract class, is contained within the <code>New_SomeInterface</code> function, which follows the factory design pattern:</p>
+
+<p><span id="Encapsulating_the_Constructor"><a id="Encapsulating_the_Constructor"></a><strong>Encapsulating the Constructor</strong></span></p>
+
+<pre>int New_SomeInterface(SomeInterface** ret)
+{
+ // create the object
+ SomeClass* out = new SomeClass();
+ if (!out) return -1;
+
+ // init the object
+ if (out-&gt;Init() == FALSE)
+ {
+ delete out;
+ return -1;
+ }
+
+ // cast to the interface
+ *ret = static_cast&lt;SomeInterface*&gt;(out);
+ return 0;
+}
+</pre>
+
+<p>The factory is the class that actually manages the creation of separate instances of a component for use. In XPCOM, factories are implementations of the <code>nsIFactory</code> interface, and they use a factory design pattern like the example above to abstract and encapsulate object construction and initialization.</p>
+
+<p>The example in <a href="#Encapsulating_the_Constructor">Encapsulating the Constructor</a> is a simple and stateless version of factories, but real world programming isn't usually so simple, and in general factories need to store state. At a minimum, the factory needs to preserve information about what objects it has created. When a factory manages instances of a class built in a dynamic shared library, for example, it needs to know when it can unload the library. When the factory preserves state, you can ask if there are outstanding references and find out if the factory created any objects.</p>
+
+<p>Another state that a factory can save is whether or not an object is a<em>singleton</em> . For example, if a factory creates an object that is supposed to be a singleton, then subsequent calls to the factory for the object should return the same object. Though there are tools and better ways to handle singletons (which we'll discuss when we talk about the <code>nsIServiceManager</code>), a developer may want to use this information to ensure that only one singleton object can exist despite what the callers do.</p>
+
+<p>The requirements of a factory class can be handled in a strictly functional way, with state being held by global variables, but there are benefits to using classes for factories. When you use a class to implement the functionality of a factory, for example, you derive from the <code>nsISupports</code> interface, which allows you to manage the lifetime of the factory objects themselves. This is important when you want to group sets of factories together and determine if they can be unloaded. Another benefit of using the <code>nsISupports</code> interface is that you can support other interfaces as they are introduced. As we'll show when we discuss <code>nsIClassInfo</code>, some factories support querying information about the underlying implementation, such as what language the object is written in, interfaces that the object supports, etc. This kind of "future-proofing" is a key advantage that comes along with deriving from <code>nsISupports</code>.</p>
+
+<h4 id="XPIDL_and_Type_Libraries" name="XPIDL_and_Type_Libraries">XPIDL and Type Libraries</h4>
+
+<p>An easy and powerful way to define an interface - indeed, a requirement for defining interfaces in a cross-platform, language neutral development environment - is to use an<em>interface definition language</em> (IDL). XPCOM uses its own variant of the CORBA OMG Interface Definition Language (IDL) called XPIDL, which allows you to specify methods, attributes and constants of a given interface, and also to define interface inheritance.</p>
+
+<p>There are some drawbacks to defining your interface using XPIDL. There is no support for multiple inheritance, for one thing. If you define a new interface, it cannot derive from more than one interface. Another limitation of interfaces in XPIDL is that method names must be unique. You can not have two methods with the same name that take different parameters, and the workaround - having multiple function names - isn't pretty:</p>
+
+<pre>void FooWithInt(in int x);
+void FooWithString(in string x);
+void FooWithURI(in nsIURI x);
+</pre>
+
+<p>However, these shortcomings pale in comparison to the functionality gained by using XPIDL. XPIDL allows you to generate<em>type libraries</em> , or typelibs, which are files with the extension<em>.xpt</em> . The type library is a binary representation of an interface or interfaces. It provides programmatic control and access of the interface, which is crucial for interfaces used in the non C++ world. When components are accessed from other languages, as they can be in XPCOM, they use the binary type library to access the interface, learn what methods it supports, and call those methods. This aspect of XPCOM is called<em>XPConnect</em> . XPConnect is the layer of XPCOM that provides access to XPCOM components from languages such as JavaScript. See <a href="ko/Creating_XPCOM_Components/Using_XPCOM_Components#Connecting_to_Components_from_the_Interface">Connecting to Components from the Interface</a> for more information about XPConnect.</p>
+
+<p>When a component is accessible from a language other than C++, such as JavaScript, its interface is said to be "reflected" into that language. Every reflected interface must have a corresponding type library. Currently you can write components in C, C++, or JavaScript (and sometimes Python or Java, depending on the state of the respective bindings), and there are efforts underway to build XPCOM bindings for Ruby and Perl as well.</p>
+
+<div class="side-note">
+<p><span id="Writing_Components_in_Other_Languages"><a id="Writing_Components_in_Other_Languages"></a><strong>Writing Components in Other Languages</strong></span></p>
+
+<p>Though you do not have access to some of the tools that XPCOM provides for C++ developers (such as macros, templates, smart pointers, and others) when you create components in other languages, you may be so comfortable with the language itself that you can eschew C++ altogether and build, for example, Python-based XPCOM components that can be used from JavaScript or vice versa.</p>
+
+<p>See <a href="ko/Creating_XPCOM_Components/Resources">Resources</a> for more information about Python and other languages for which support has been added in XPCOM.</p>
+</div>
+
+<p>All of the public interfaces in XPCOM are defined using the XPIDL syntax. Type libraries and C++ header files are generated from these IDL files, and the tool that generates these files is called the<em>xpidl compiler</em> . The section <a href="ko/Creating_XPCOM_Components/Starting_WebLock#Defining_the_WebLock_Interface_in_XPIDL">Defining the WebLock Interface in XPIDL</a> describes the XPIDL syntax in detail.</p>
+
+<h3 id="XPCOM_Services" name="XPCOM_Services">XPCOM Services</h3>
+
+<p>When clients use components, they typically<em>instantiate</em> a new object each time they need the functionality the component provides. This is the case when, for example, clients deal with files: each separate file is represented by a different object, and several file objects may be being used at any one time.</p>
+
+<p>But there is also a kind of object known as a<em>service</em> , of which there is always only one copy (though there may be many services running at any one time). Each time a client wants to access the functionality provided by a service, they talk to the same instance of that service. When a user looks up a phone number in a company database, for example, probably that database is being represented by an "object" that is the same for all co-workers. If it weren't, the application would need to keep two copies of a large database in memory, for one thing, and there might also be inconsistencies between records as the copies diverged.</p>
+
+<p>Providing this single point of access to functionality is what the singleton design pattern is for, and what services do in an application (and in a development environment like XPCOM).</p>
+
+<p>In XPCOM, in addition to the component support and management, there are a number of services that help the developer write cross platform components. These services include a cross platform file abstraction which provides uniform and powerful access to files, directory services which maintain the location of application- and system-specific locations, memory management to ensure everyone uses the same memory allocator, and an event notification system that allows passing of simple messages. The tutorial will show each of these component and services in use, and the <a href="ko/XPCOM_API_Reference">XPCOM API Reference</a> has a complete interface listing of these areas.</p>
+
+<h3 id="XPCOM_Types" name="XPCOM_Types">XPCOM Types</h3>
+
+<p>There are many XPCOM declared types and simple macros that we will use in the following samples. Most of these types are simple mappings. The most common types are described in the following sections.</p>
+
+<h4 id="Method_Types" name="Method_Types">Method Types</h4>
+
+<p>The following are a set of types for ensuring correct calling convention and return type of XPCOM methods.</p>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <td><code>NS_IMETHOD</code></td>
+ <td>Method declaration return type. XPCOM method declarations should use this as their return type.</td>
+ </tr>
+ <tr>
+ <td><code>NS_IMETHODIMP</code></td>
+ <td>Method Implementation return type. XPCOM method implementations should use this as their return time.</td>
+ </tr>
+ <tr>
+ <td><code>NS_IMETHODIMP_(type)</code></td>
+ <td>Special case implementation return type. Some methods such as <code>AddRef</code> and <code>Release</code> do not return the default return type. This exception is regrettable, but required for COM compliance.</td>
+ </tr>
+ <tr>
+ <td><code>NS_IMPORT</code></td>
+ <td>Forces the method to be resolved internally by the shared library.</td>
+ </tr>
+ <tr>
+ <td><code>NS_EXPORT</code></td>
+ <td>Forces the method to be exported by the shared library.</td>
+ </tr>
+ </tbody>
+</table>
+
+<h4 id="Reference_Counting" name="Reference_Counting">Reference Counting</h4>
+
+<p>These macros manage reference counting.</p>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <td><code>NS_ADDREF</code></td>
+ <td>Calls <code>AddRef</code> on an <code>nsISupports</code> object.</td>
+ </tr>
+ <tr>
+ <td><code>NS_IF_ADDREF</code></td>
+ <td>Same as above but checks for null before calling <code>AddRef</code>.</td>
+ </tr>
+ <tr>
+ <td><code>NS_RELEASE</code></td>
+ <td>Calls <code>Release</code> on an <code>nsISupports</code> object.</td>
+ </tr>
+ <tr>
+ <td><code>NS_IF_RELEASE</code></td>
+ <td>Same as above but check for null before calling <code>Release</code>.</td>
+ </tr>
+ </tbody>
+</table>
+
+<h3 id="Status_Codes" name="Status_Codes">Status Codes</h3>
+
+<p>These macros test status codes.</p>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <td><code>NS_FAILED</code></td>
+ <td>Return true if the passed status code was a failure.</td>
+ </tr>
+ <tr>
+ <td><code>NS_SUCCEEDED</code></td>
+ <td>Returns true is the passed status code was a success.</td>
+ </tr>
+ </tbody>
+</table>
+
+<h3 id="Variable_Mappings" name="Variable_Mappings">Variable Mappings</h3>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <td><code>nsrefcnt</code></td>
+ <td>Default reference count type. Maps to a 32-bit integer.</td>
+ </tr>
+ <tr>
+ <td><code>nsresult</code></td>
+ <td>Default error type. Maps to a 32-bit integer.</td>
+ </tr>
+ <tr>
+ <td><code>nsnull</code></td>
+ <td>Default null value.</td>
+ </tr>
+ </tbody>
+</table>
+
+<h3 id="Common_XPCOM_Error_Codes" name="Common_XPCOM_Error_Codes">Common XPCOM Error Codes</h3>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <td><code>NS_ERROR_NOT_INITIALIZED</code></td>
+ <td>Returned when an instance is not initialized.</td>
+ </tr>
+ <tr>
+ <td><code>NS_ERROR_ALREADY_INITIALIZED</code></td>
+ <td>Returned when an instance is already initialized.</td>
+ </tr>
+ <tr>
+ <td><code>NS_ERROR_NOT_IMPLEMENTED</code></td>
+ <td>Returned by an unimplemented method.</td>
+ </tr>
+ <tr>
+ <td><code>NS_ERROR_NO_INTERFACE</code></td>
+ <td>Returned when a given interface is not supported.</td>
+ </tr>
+ <tr>
+ <td><code>NS_ERROR_NULL_POINTER</code></td>
+ <td>Returned when a valid pointer is found to be <code>nsnull</code>.</td>
+ </tr>
+ <tr>
+ <td><code>NS_ERROR_FAILURE</code></td>
+ <td>Returned when a method fails. Generic error case.</td>
+ </tr>
+ <tr>
+ <td><code>NS_ERROR_UNEXPECTED</code></td>
+ <td>Returned when an unexpected error occurs.</td>
+ </tr>
+ <tr>
+ <td><code>NS_ERROR_OUT_OF_MEMORY</code></td>
+ <td>Returned when a memory allocation fails.</td>
+ </tr>
+ <tr>
+ <td><code>NS_ERROR_FACTORY_NOT_REGISTERED</code></td>
+ <td>Returned when a requested class is not registered.</td>
+ </tr>
+ </tbody>
+</table>
+
+<p></p><div class="prevnext" style="text-align: right;">
+ <p><a href="/ko/docs/Creating_XPCOM_Components:Preface" style="float: left;">« 이전</a><a href="/ko/docs/Creating_XPCOM_Components:Using_XPCOM_Components">다음 »</a></p>
+</div> <p></p><div class="licenseblock">
+<p>Copyright (c) 2003 by Doug Turner and Ian Oeschger. This material may be distributed only subject to the terms and conditions set forth in the <a class="external" href="http://www.opencontent.org/openpub/" rel="noopener">Open Publication License</a>, v1.02 or later. Distribution of substantively modified versions of this document is prohibited without the explicit permission of the copyright holder. Distribution of the work or derivative of the work in any standard (paper) book form is prohibited unless prior permission is obtained from the copyright holder.</p>
+</div><p></p>
diff --git a/files/ko/creating_xpcom_components/index.html b/files/ko/creating_xpcom_components/index.html
new file mode 100644
index 0000000000..3af1db1e92
--- /dev/null
+++ b/files/ko/creating_xpcom_components/index.html
@@ -0,0 +1,355 @@
+---
+title: Creating XPCOM Components
+slug: Creating_XPCOM_Components
+translation_of: Mozilla/Tech/XPCOM/Guide/Creating_components
+---
+<h3 id="Preface" name="Preface"><a href="ko/Creating_XPCOM_Components/Preface">Preface</a></h3>
+<dl>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Preface#Who_Should_Read_This_Book">Who Should Read This Book</a> 이 문서가 필요한 사람</dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Preface#Organization_of_the_Tutorial">Organization of the Tutorial</a> 튜토리얼 구조</dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Preface#Following_Along_with_the_Examples">Following Along with the Examples</a> 예제 따라하기</dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Preface#Conventions">Conventions</a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Preface#Acknowledgements">Acknowledgements</a></dd>
+</dl>
+<h3 id="An_Overview_of_XPCOM" name="An_Overview_of_XPCOM"><a href="ko/Creating_XPCOM_Components/An_Overview_of_XPCOM">An Overview of XPCOM</a></h3>
+<dl>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/An_Overview_of_XPCOM#The_XPCOM_Solution">The XPCOM Solution</a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/An_Overview_of_XPCOM#Gecko">Gecko</a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/An_Overview_of_XPCOM#Components">Components</a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/An_Overview_of_XPCOM#Interfaces">Interfaces</a>
+ <dl>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/An_Overview_of_XPCOM#Interfaces_and_Encapsulation">Interfaces and Encapsulation</a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/An_Overview_of_XPCOM#The_nsISupports_Base_Interface">The <code>nsISupports</code> Base Interface</a></dd>
+ </dl>
+ </dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/An_Overview_of_XPCOM#XPCOM_Identifiers">XPCOM Identifiers</a>
+ <dl>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/An_Overview_of_XPCOM#CID">CID</a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/An_Overview_of_XPCOM#Contract_ID">Contract ID</a></dd>
+ </dl>
+ </dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/An_Overview_of_XPCOM#Factories">Factories</a>
+ <dl>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/An_Overview_of_XPCOM#XPIDL_and_Type_Libraries">XPIDL and Type Libraries</a></dd>
+ </dl>
+ </dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/An_Overview_of_XPCOM#XPCOM_Services">XPCOM Services</a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/An_Overview_of_XPCOM#XPCOM_Types">XPCOM Types</a>
+ <dl>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/An_Overview_of_XPCOM#Method_Types">Method Types</a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/An_Overview_of_XPCOM#Reference_Counting">Reference Counting</a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/An_Overview_of_XPCOM#Status_Codes">Status Codes</a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/An_Overview_of_XPCOM#Variable_Mappings">Variable Mappings</a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/An_Overview_of_XPCOM#Common_XPCOM_Error_Codes">Common XPCOM Error Codes</a></dd>
+ </dl>
+ </dd>
+</dl>
+<h3 id="Using_XPCOM_Components" name="Using_XPCOM_Components"><a href="ko/Creating_XPCOM_Components/Using_XPCOM_Components">Using XPCOM Components</a></h3>
+<dl>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Using_XPCOM_Components#Component_Examples">Component Examples</a>
+ <dl>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Using_XPCOM_Components#Cookie_Manager">Cookie Manager</a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Using_XPCOM_Components#The_WebBrowserFind_Component">The <b>WebBrowserFind</b> Component</a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Using_XPCOM_Components#The_WebLock_Component">The <b>WebLock</b> Component</a></dd>
+ </dl>
+ </dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Using_XPCOM_Components#Component_Use_in_Mozilla">Component Use in Mozilla</a>
+ <dl>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Using_XPCOM_Components#Finding_Mozilla_Components">Finding Mozilla Components</a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Using_XPCOM_Components#Using_XPCOM_Components_in_Your_Cpp">Using XPCOM Components in Your Cpp</a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Using_XPCOM_Components#XPConnect:_Using_XPCOM_Components_From_Script">XPConnect: Using XPCOM Components From Script</a></dd>
+ </dl>
+ </dd>
+</dl>
+<h3 id="Component_Internals" name="Component_Internals"><a href="ko/Creating_XPCOM_Components/Component_Internals">Component Internals</a></h3>
+<dl>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Component_Internals#Creating_Components_in_Cpp">Creating Components in Cpp</a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Component_Internals#XPCOM_Initialization">XPCOM Initialization</a>
+ <dl>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Component_Internals#XPCOM_Registry_Manifests">XPCOM Registry Manifests</a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Component_Internals#Registration_Methods_in_XPCOM">Registration Methods in XPCOM</a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Component_Internals#Autoregistration">Autoregistration</a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Component_Internals#The_Shutdown_Process">The Shutdown Process</a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Component_Internals#Three_Parts_of_a_XPCOM_Component_Library">Three Parts of a XPCOM Component Library</a></dd>
+ </dl>
+ </dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Component_Internals#XPCOM_Glue">XPCOM Glue</a>
+ <dl>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Component_Internals#The_Glue_Library">The Glue Library</a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Component_Internals#XPCOM_String_Classes">XPCOM String Classes</a></dd>
+ </dl>
+ </dd>
+</dl>
+<h3 id="Creating_the_Component_Code" name="Creating_the_Component_Code"><a href="ko/Creating_XPCOM_Components/Creating_the_Component_Code">Creating the Component Code</a></h3>
+<dl>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Creating_the_Component_Code#What_We.27ll_Be_Working_On">What We'll Be Working On</a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Creating_the_Component_Code#Component_Registration">Component Registration</a>
+ <dl>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Creating_the_Component_Code#The_regxpcom_Program">The <code>regxpcom</code> Program</a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Creating_the_Component_Code#Registration_Alternatives">Registration Alternatives</a></dd>
+ </dl>
+ </dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Creating_the_Component_Code#Overview_of_the_WebLock_Module_Source">Overview of the <b>WebLock</b> Module Source</a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Creating_the_Component_Code#Digging_In:_Required_Includes_and_Constants">Digging In: Required Includes and Constants</a>
+ <dl>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Creating_the_Component_Code#Identifiers_in_XPCOM">Identifiers in XPCOM</a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Creating_the_Component_Code#Coding_for_the_Registration_Process">Coding for the Registration Process</a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Creating_the_Component_Code#The_Registration_Methods">The Registration Methods</a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Creating_the_Component_Code#Creating_an_Instance_of_Your_Component">Creating an Instance of Your Component</a></dd>
+ </dl>
+ </dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Creating_the_Component_Code#webLock1.cpp"><code>webLock1.cpp</code></a></dd>
+</dl>
+<h3 id="Using_XPCOM_Utilities_to_Make_Things_Easier" name="Using_XPCOM_Utilities_to_Make_Things_Easier"><a href="ko/Creating_XPCOM_Components/Using_XPCOM_Utilities_to_Make_Things_Easier">Using XPCOM Utilities to Make Things Easier</a></h3>
+<dl>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Using_XPCOM_Utilities_to_Make_Things_Easier#XPCOM_Macros">XPCOM Macros</a>
+ <dl>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Using_XPCOM_Utilities_to_Make_Things_Easier#Generic_XPCOM_Module_Macros">Generic XPCOM Module Macros</a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Using_XPCOM_Utilities_to_Make_Things_Easier#Common_Implementation_Macros">Common Implementation Macros</a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Using_XPCOM_Utilities_to_Make_Things_Easier#Declaration_Macros">Declaration Macros</a></dd>
+ </dl>
+ </dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Using_XPCOM_Utilities_to_Make_Things_Easier#webLock2.cpp"><code>webLock2.cpp</code></a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Using_XPCOM_Utilities_to_Make_Things_Easier#String_Classes_in_XPCOM">String Classes in XPCOM</a>
+ <dl>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Using_XPCOM_Utilities_to_Make_Things_Easier#Using_Strings">Using Strings</a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Using_XPCOM_Utilities_to_Make_Things_Easier#nsEmbedString_and_nsEmbedCString"><code>nsEmbedString</code> and <code>nsEmbedCString</code></a></dd>
+ </dl>
+ </dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Using_XPCOM_Utilities_to_Make_Things_Easier#Smart_Pointers">Smart Pointers</a></dd>
+</dl>
+<h3 id="Starting_WebLock" name="Starting_WebLock"><a href="ko/Creating_XPCOM_Components/Starting_WebLock">Starting <b>WebLock</b></a></h3>
+<dl>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Starting_WebLock#Getting_Called_at_Startup">Getting Called at Startup</a>
+ <dl>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Starting_WebLock#Registering_for_Notifications">Registering for Notifications</a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Starting_WebLock#Getting_Access_to_the_Category_Manager">Getting Access to the Category Manager</a></dd>
+ </dl>
+ </dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Starting_WebLock#Providing_Access_to_WebLock">Providing Access to <b>WebLock</b></a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Starting_WebLock#Creating_the_WebLock_Programming_Interface">Creating the <b>WebLock</b> Programming Interface</a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Starting_WebLock#Defining_the_WebLock_Interface_in_XPIDL">Defining the <b>WebLock</b> Interface in XPIDL</a>
+ <dl>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Starting_WebLock#The_XPIDL_Syntax">The XPIDL Syntax</a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Starting_WebLock#Scriptable_Interfaces">Scriptable Interfaces</a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Starting_WebLock#Subclassing_nsISupports">Subclassing <code>nsISupports</code></a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Starting_WebLock#The_Web_Locking_Interface">The Web Locking Interface</a></dd>
+ </dl>
+ </dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Starting_WebLock#Implementing_WebLock">Implementing <b>WebLock</b></a>
+ <dl>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Starting_WebLock#Declaration_Macros">Declaration Macros</a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Starting_WebLock#Representing_Return_Values_in_XPCOM">Representing Return Values in XPCOM</a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Starting_WebLock#XPIDL_Code_Generation">XPIDL Code Generation</a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Starting_WebLock#Getting_the_WebLock_Service_from_a_Client">Getting the <b>WebLock</b> Service from a Client</a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Starting_WebLock#Implementing_the_iWebLock_Interface">Implementing the <code>iWebLock</code> Interface</a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Starting_WebLock#The_Directory_Service">The Directory Service</a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Starting_WebLock#Modifying_Paths_with_nsIFile">Modifying Paths with <code>nsIFile</code></a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Starting_WebLock#Manipulating_Files_with_nsIFile">Manipulating Files with <code>nsIFile</code></a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Starting_WebLock#Using_nsILocalFile_for_Reading_Data">Using <code>nsILocalFile</code> for Reading Data</a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Starting_WebLock#Processing_the_White_List_Data">Processing the White List Data</a></dd>
+ </dl>
+ </dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Starting_WebLock#iWebLock_Method_By_Method"><code>iWebLock</code> Method By Method</a>
+ <dl>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Starting_WebLock#Lock_and_Unlock"><code>Lock</code> and <code>Unlock</code></a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Starting_WebLock#AddSite"><code>AddSite</code></a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Starting_WebLock#RemoveSite"><code>RemoveSite</code></a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Starting_WebLock#SetSites"><code>SetSites</code></a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Starting_WebLock#GetNext"><code>GetNext</code></a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Starting_WebLock#GetSites"><code>GetSites</code></a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Starting_WebLock#HasMoreElements"><code>HasMoreElements</code></a></dd>
+ </dl>
+ </dd>
+</dl>
+<h3 id="Finishing_the_Component" name="Finishing_the_Component"><a href="ko/Creating_XPCOM_Components/Finishing_the_Component">Finishing the Component</a></h3>
+<dl>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Finishing_the_Component#Using_Frozen_Interfaces">Using Frozen Interfaces</a>
+ <dl>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Finishing_the_Component#Copying_Interfaces_Into_Your_Build_Environment">Copying Interfaces Into Your Build Environment</a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Finishing_the_Component#Implementing_the_nsIContentPolicy_Interface">Implementing the <code>nsIContentPolicy</code> Interface</a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Finishing_the_Component#Receiving_Notifications">Receiving Notifications</a></dd>
+ </dl>
+ </dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Finishing_the_Component#Implementing_the_nsIContentPolicy">Implementing the <code>nsIContentPolicy</code></a>
+ <dl>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Finishing_the_Component#Uniform_Resource_Locators">Uniform Resource Locators</a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Finishing_the_Component#Checking_the_White_List">Checking the White List</a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Finishing_the_Component#Creating_nsIURI_Objects">Creating <code>nsIURI</code> Objects</a></dd>
+ </dl>
+ </dd>
+</dl>
+<h3 id="Building_the_WebLock_UI" name="Building_the_WebLock_UI"><a href="ko/Creating_XPCOM_Components/Building_the_WebLock_UI">Building the <b>WebLock</b> UI</a></h3>
+<dl>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Building_the_WebLock_UI#User_Interface_Package_List">User Interface Package List</a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Building_the_WebLock_UI#Client_Code_Overview">Client Code Overview</a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Building_the_WebLock_UI#XUL">XUL</a>
+ <dl>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Building_the_WebLock_UI#The_XUL_Document">The XUL Document</a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Building_the_WebLock_UI#The_Locking_UI">The Locking UI</a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Building_the_WebLock_UI#Site_Adding_UI">Site Adding UI</a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Building_the_WebLock_UI#weblock.xul"><code>weblock.xul</code></a></dd>
+ </dl>
+ </dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Building_the_WebLock_UI#Overlaying_New_User_Interface_Into_Mozilla">Overlaying New User Interface Into Mozilla</a>
+ <dl>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Building_the_WebLock_UI#webLockOverlay.xul"><code>webLockOverlay.xul</code></a></dd>
+ </dl>
+ </dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Building_the_WebLock_UI#Other_Resources">Other Resources</a>
+ <dl>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Building_the_WebLock_UI#weblock.css"><code>weblock.css</code></a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Building_the_WebLock_UI#Image_Resources">Image Resources</a></dd>
+ </dl>
+ </dd>
+</dl>
+<h3 id="Packaging_WebLock" name="Packaging_WebLock"><a href="ko/Creating_XPCOM_Components/Packaging_WebLock">Packaging WebLock</a></h3>
+<dl>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Packaging_WebLock#Component_Installation_Overview">Component Installation Overview</a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Packaging_WebLock#Archiving_Resources">Archiving Resources</a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Packaging_WebLock#The_WebLock_Installation_Script">The <b>WebLock</b> Installation Script</a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Packaging_WebLock#The_WebLock_Trigger_Script">The <b>WebLock</b> Trigger Script</a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Packaging_WebLock#Distributing_Your_Component">Distributing Your Component</a></dd>
+</dl>
+<h3 id="Appendix_A_-_Setting_up_the_Gecko_SDK" name="Appendix_A_-_Setting_up_the_Gecko_SDK"><a href="ko/Creating_XPCOM_Components/Setting_up_the_Gecko_SDK">Appendix A - Setting up the Gecko SDK</a></h3>
+<dl>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Setting_up_the_Gecko_SDK#Downloading_and_Setting_the_SDK">Downloading and Setting the SDK</a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Setting_up_the_Gecko_SDK#Building_a_Microsoft_Visual_Cpp_Project">Building a Microsoft Visual Cpp Project</a>
+ <dl>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Setting_up_the_Gecko_SDK#Creating_a_New_Project">Creating a New Project</a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Setting_up_the_Gecko_SDK#Adding_the_Gecko_SDK_to_the_Project_Settings">Adding the Gecko SDK to the Project Settings</a></dd>
+ </dl>
+ </dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Setting_up_the_Gecko_SDK#A_Makefile_for_Unix">A Makefile for Unix</a></dd>
+</dl>
+<h3 id="Appendix_B_-_Resources" name="Appendix_B_-_Resources"><a href="ko/Creating_XPCOM_Components/Resources">Appendix B - Resources</a></h3>
+<dl>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Resources#WebLock_Resources">WebLock Resources</a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Resources#Gecko_Resources">Gecko Resources</a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Resources#XPCOM_Resources">XPCOM Resources</a></dd>
+ <dd>
+ <a href="ko/Creating_XPCOM_Components/Resources#General_Development_Resources">General Development Resources</a></dd>
+</dl>
diff --git a/files/ko/creating_xpcom_components/preface/index.html b/files/ko/creating_xpcom_components/preface/index.html
new file mode 100644
index 0000000000..fa6c630b61
--- /dev/null
+++ b/files/ko/creating_xpcom_components/preface/index.html
@@ -0,0 +1,78 @@
+---
+title: Preface
+slug: Creating_XPCOM_Components/Preface
+tags:
+ - XPCOM
+translation_of: Mozilla/Tech/XPCOM/Guide/Creating_components/Preface
+---
+<p>이 문서는 Gecko 엔진과 이를 기반으로 하는 어플리케이션들을 위한 XPCOM 컴포넌트에 대한 설명을 담고 있습니다. 여기서 강조하고 있는 것은 Gecko 에서 사용 가능한 컴포넌트에 당신의 C++ 코드를 삽입하는</p>
+
+<p>Though the emphasis is on the practical steps you take to make your C++ code into a component that can be used in Gecko, we hope that these steps will also give us an occasion to discuss all of the tools, techniques, and technologies that make up XPCOM. Accordingly, the book is arranged so that you can follow along and create your own components or learn about different XPCOM topics individually, as in a reference work. For example, the introduction includes a discussion of components and what they are, and the first chapter - in which you compile the basic code and register it with Mozilla - prompts a discussion of the relationship between components and modules, of XPCOM interfaces, and of the registration process in general.</p>
+
+<p>The top of each chapter provides a list of the major topics covered. Sidebar sections are included to highlight technical details. By the end of the book, if we've done our job, you will have learned how to build a component and you will know something about the framework for these components in Gecko, which is XPCOM.</p>
+
+<h3 id="Who_Should_Read_This_Book" name="Who_Should_Read_This_Book">Who Should Read This Book</h3>
+
+<p><a href="ko/Creating_XPCOM_Components">Creating XPCOM Components</a> is meant for C++ developers. Though you can create XPCOM components in <a href="ko/JavaScript">JavaScript</a> and other languages, and though you might be able to follow along as a <a href="ko/C">C</a> programmer, the component implementation code is written in C++, and much of the discussion of how to make your code<em>into</em> an XPCOM component starts from C++. You don't need to be a C++ expert, however. Although basic ideas such as inheritance and encapsulation should be familar to you, wherever possible they are explained in the book as they are used. Also many of the examples are in JavaScript, which is used in Mozilla to access XPCOM components as scriptable objects, and so familiarity with that language is useful as well.</p>
+
+<p>XPCOM stands for the Cross Platform Component Object Model. As this name implies, XPCOM is similar to Microsoft COM. If you have any experience with this technology, much of it can be applied to XPCOM. However, this book does not assume any prior knowledge of COM - all of the basic COM ideas will be introduced.</p>
+
+<p>This book provides a tutorial about building an XPCOM component that controls browsing behavior. Although, XPCOM can be used in many environments which are unrelated to web browsing, XPCOM's main client is Gecko, an open source, standards compliant, embeddable web browser, where it's easiest and most practical to illustrate XPCOM's functionality. A full description of the component in this tutorial can be found in the <a href="ko/Creating_XPCOM_Components/Creating_the_Component_Code#What_We.27ll_Be_Working_On">What We'll Be Working On</a> section of the tutorial.</p>
+
+<h3 id="Organization_of_the_Tutorial" name="Organization_of_the_Tutorial">Organization of the Tutorial</h3>
+
+<p>The following list provides an overview of the steps that we will take to build an XPCOM component called <strong>WebLock</strong>, which provides site blocking functionality to Gecko-based browsers. Each one of these steps has its own chapter, in which a number of topics associated with the step are discussed.</p>
+
+<ul>
+ <li>Create the generic module code for the component.</li>
+ <li>Use C++ macros, special string classes and smart pointers to optimize your code.</li>
+ <li>Define the functionality for the component; create an <a href="ko/XPIDL">XPIDL</a> interface for that functionality; create the implementation code specific to the custom <strong>WebLock</strong> component interface.</li>
+ <li>Finish implementing the <strong>WebLock</strong> component: <code>nsIContentPolicy</code>, file I/O, locking, etc.</li>
+ <li>Creating the user interface for the WebLock component.</li>
+ <li>Packaging <strong>WebLock</strong> for distribution and installation.</li>
+</ul>
+
+<h3 id="Following_Along_with_the_Examples" name="Following_Along_with_the_Examples">Following Along with the Examples</h3>
+
+<p>There are a couple of different ways to get XPCOM onto your machine so you can begin to create components. If you already have a Mozilla build or the source from Mozilla 1.2 or later, then you can use the XPCOM framework available there. If you don't already have the Mozilla source, then an even easier way to get and use XPCOM is to download the Gecko SDK, which is a collection of libraries and tools that features the XPCOM component framework.</p>
+
+<p>Whether you compile your code in the Mozilla source tree or use the Gecko SDK, you can build your own components which leverage components that already exist in Gecko. The <strong>WebLock</strong> component we describe in this tutorial is a practical (and, we hope, genuinely useful) addition to the browser. In order to build it, your Gecko SDK or Mozilla source tree needs to be version 1.2 or later (XPCOM interfaces were not fully frozen in prior releases).</p>
+
+<p>This book assumes you are using the SDK rather than compiling in a Mozilla source tree, though the difference between these two approaches is minimal. Details about downloading the SDK, building, and getting programmatic access to Gecko components are provided in the appendix to this book, <a href="ko/Creating_XPCOM_Components/Setting_up_the_Gecko_SDK">Setting up the Gecko SDK</a>.</p>
+
+<h3 id="Conventions" name="Conventions">Conventions</h3>
+
+<p>The formatting conventions listed below are used to designate specific types of information in the book and make things easier to scan. The goal is to use as few formats as possible, but to distinguish the various different types of information clearly.</p>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <td class="header">Format</td>
+ <td class="header">Description</td>
+ </tr>
+ <tr>
+ <td><strong>bold</strong></td>
+ <td><strong>component names</strong> appear in bold in the text</td>
+ </tr>
+ <tr>
+ <td><code>monospace</code></td>
+ <td><code>code listings</code>, <code>interface names</code> and <code>members</code> of interfaces (e.g., <code>createInstance()</code>) appear in monospaced font. Lines of code are placed in separate boxes. Additionally, <code>filenames</code> and <code>directories</code> appear in monospaced font.</td>
+ </tr>
+ <tr>
+ <td><em>italic</em></td>
+ <td><em>variables</em>appear in italic. Important terms and new concepts are also italicized the first time they appear in the text. Those terms are either explained immediately after they are cited, or else the reader is referred to a section in the book where they are described in detail.</td>
+ </tr>
+ <tr>
+ <td>link</td>
+ <td>References to other sections and to figures and tables are links to those sections.</td>
+ </tr>
+ </tbody>
+</table>
+
+<h3 id="Acknowledgements" name="Acknowledgements">Acknowledgements</h3>
+
+<p>Thanks to Peter Lubczynski, John Gaunt, Ellen Evans, and Alec Flett for technical reviews. A special thanks goes to Darin Fisher for his very acute observations, close reading, and attention to detail.</p>
+
+<p></p><div class="licenseblock">
+<p>Copyright (c) 2003 by Doug Turner and Ian Oeschger. This material may be distributed only subject to the terms and conditions set forth in the <a class="external" href="http://www.opencontent.org/openpub/" rel="noopener">Open Publication License</a>, v1.02 or later. Distribution of substantively modified versions of this document is prohibited without the explicit permission of the copyright holder. Distribution of the work or derivative of the work in any standard (paper) book form is prohibited unless prior permission is obtained from the copyright holder.</p>
+</div><p></p>