diff options
Diffstat (limited to 'files/pt-br/construindo_um_complemento/index.html')
-rw-r--r-- | files/pt-br/construindo_um_complemento/index.html | 262 |
1 files changed, 262 insertions, 0 deletions
diff --git a/files/pt-br/construindo_um_complemento/index.html b/files/pt-br/construindo_um_complemento/index.html new file mode 100644 index 0000000000..825907784b --- /dev/null +++ b/files/pt-br/construindo_um_complemento/index.html @@ -0,0 +1,262 @@ +--- +title: Construindo um complemento +slug: Construindo_um_complemento +tags: + - Add-ons + - Complementos + - Tutorial +translation_of: Mozilla/Add-ons +--- +<h2 id="Introdução">Introdução</h2> +<p>This tutorial will take you through the steps required to build a very basic <a href="/en-US/docs/Extensions" title="/en-US/docs/Extensions">extension</a> - one which adds a status bar panel to the Firefox browser containing the text "Hello, World!".</p> +<div class="note"> + <strong>Note:</strong> The extension created by this tutorial won't work in Firefox versions that don't have a static status bar (that is, Firefox 4 and up). You can find a more up-to-date tutorial in the <a href="/en-US/docs/XUL_School" title="XUL School Tutorial">XUL School</a> tutorial <a href="/en-US/docs/XUL_School/The_Essentials_of_an_Extension" title="The Essentials of an Extension">The Essentials of an Extension</a>.</div> +<p>Since Firefox 4 (and other Mozilla 2 based applications) there are two types of extensions:</p> +<ul> + <li>Traditional, classic, or XUL extensions are more powerful, but more complicated to build and require a restart to install.</li> + <li>Restartless, or <a href="/en-US/docs/Extensions/Bootstrapped_extensions" title="/en-US/docs/Extensions/Bootstrapped_extensions">bootstrapped extensions</a> do not require a restart to install but are more limited than traditional extensions. The <a class="link-https" href="https://addons.mozilla.org/en-US/developers/tools/builder">Add-on SDK and the Add-on Builder</a> can be used to build restartless extensions with ease.</li> +</ul> +<p>This article explains how to build a traditional extension for Firefox. For information on bootstrapped or restartless extensions, see <a href="/en-US/docs/Extensions/Bootstrapped_extensions" title="/en-US/docs/Extensions/Bootstrapped_extensions">Bootstrapped extensions</a>.</p> +<p>For a tutorial on building an extension for Thunderbird, see <a href="/en-US/docs/Extensions/Thunderbird/Building_a_Thunderbird_extension" title="/en-US/docs/Building_a_Thunderbird_extension">Building a Thunderbird extension.</a></p> +<h2 id="Início_rápido">Início rápido</h2> +<p>A <a class="external" href="http://mozilla.doslash.org/stuff/helloworld.zip">Hello World extension</a> similar to what you can generate with the Extension Wizard is explained line-by-line in <a class="external" href="http://kb.mozillazine.org/Getting_started_with_extension_development">another tutorial from MozillaZine Knowledge Base</a>.</p> +<h2 id="Configurando_o_ambiente_de_desenvolvimento">Configurando o ambiente de desenvolvimento</h2> +<p>Extensions are packaged and distributed in ZIP files or <a href="/en-US/docs/Bundles" title="/en-US/docs/Bundles">Bundles</a>, with the <code>XPI</code> file extension.</p> +<p>An example of the content within a typical XPI file:</p> +<pre class="eval">my_extension.xpi: //Equal to a folder named <span style="font-weight: bold;">my_extension</span><strong>/</strong> + <a href="/en-US/docs/Install_Manifests" title="/en-US/docs/Install Manifests">/install.rdf </a> //General information about your extension + /<a href="/en-US/docs/Chrome_Registration" title="/en-US/docs/Chrome_Registration">chrome.manifest</a> //Registers your content with the <a href="/en-US/docs/Chrome_Registration" title="https://developer.mozilla.org/en-US/docs/chrome_registration">Chrome </a>engine + /chrome/ + /chrome/content/ //Contents of your extension such as XUL and JavaScript files + /<a href="/en-US/docs/Window_icons" title="/en-US/docs/Window_icons">chrome/icons/default/*</a> //Default Icons of the extension + /chrome/locale/* //Building an Extension# <a href="/en-US/docs/Building_an_Extension#Localization" title="https://developer.mozilla.org/en-US/docs/Building_an_Extension#Localization">Localization</a> + <a href="#Defaults_Files">/defaults/preferences/*.js</a> //Building an Extension# <a href="/en-US/docs/Building_an_Extension#Defaults_Files" title="https://developer.mozilla.org/en-US/docs/Building_an_Extension#Defaults_Files">Defaults Files</a> + /plugins/* +<a href="#XPCOM_Components"> /components/*</a> + <a href="#Application_Command_Line">/components/cmdline.js</a></pre> +<p>We'll want to create a file structure similar to the one above for our tutorial, so let's begin by creating a folder for your extension somewhere on your hard disk (e.g. <code>C:\extensions\my_extension\</code> or <code>~/extensions/my_extension/</code>). Inside your new extension folder, create another folder called <code>chrome</code>, and inside the <code>chrome</code> folder create a folder called <code>content</code>.</p> +<p>Inside the <strong>root</strong> directory of your extension folder, create two new empty text files, called <code>chrome.manifest<span style="font-family: Verdana,Tahoma,sans-serif;"> and</span></code> <code>install.rdf</code>. In the <strong>chrome/content</strong> directory, create a new empty text file called <code>sample.xul</code>.</p> +<p>You should end up with this directory structure:</p> +<ul> + <li>install.rdf</li> + <li>chrome.manifest</li> + <li>chrome\ + <ul> + <li>content\ + <ul> + <li>sample.xul</li> + </ul> + </li> + </ul> + </li> +</ul> +<p><span class="comment"><pre> #!/bin/sh h=$HOME/moExt mkdir -p $h/my_extension/chrome/content touch $h/my_extension/chrome.manifest $h/my_extension/install.rdf </pre></span> Please read the additional information about setting up your development environment in the article <a href="/en-US/docs/Setting_up_extension_development_environment" title="/en-US/docs/Setting_up_extension_development_environment">Setting up extension development environment</a>.</p> +<p>{{ gecko_minversion_note("1.9.2", "Starting in Gecko 1.9.2 (Firefox 3.6), you can also simply include an icon, named <code>icon.png</code>, in the base directory of the add-on. This allows your add-on's icon to be displayed even when the add-on is disabled, or if the manifest is missing an <code>iconURL</code> entry.") }}</p> +<h2 id="Criando_o_Manifesto_de_Instalação">Criando o Manifesto de Instalação</h2> +<p>Open the file called <code><a href="/en-US/docs/Install_Manifests" title="/en-US/docs/Install_Manifests">install.rdf</a></code> that you created at the top of your extension's folder hierarchy and put this inside:</p> +<pre class="brush: xml"><?xml version="1.0"?> + +<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:em="http://www.mozilla.org/2004/em-rdf#"> + + <Description about="urn:mozilla:install-manifest"> + <em:id>sample@example.net</em:id> + <em:version>1.0</em:version> + <em:type>2</em:type> + + <!-- Target Application this extension can install into, + with minimum and maximum supported versions. --> + <em:targetApplication> + <Description> + <em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id> + <em:minVersion>1.5</em:minVersion> + <em:maxVersion>4.0.*</em:maxVersion> + </Description> + </em:targetApplication> + + <!-- Front End MetaData --> + <em:name>sample</em:name> + <em:description>A test extension</em:description> + <em:creator>Your Name Here</em:creator> + <em:homepageURL>http://www.example.com/</em:homepageURL> + </Description> +</RDF> +</pre> +<ul> + <li><code><strong><span class="linkification-ext link-mailto">sample@example.net</span></strong></code> – the ID of the extension. This is a value you come up with to identify your extension in email address format (note that it should not be <em>your</em> email). Make it unique. You could also use a GUID. NOTE: This parameter MUST be in the format of an email address, although it does NOT have to be a valid email address. (<code><span class="link-mailto">example@example.example</span></code>)</li> + <li>Specify <code><em:type>2</em:type></code> – the 2 declares that it is installing an extension. If you were to install a theme it would be 4 (see <a href="/en-US/docs/Install_Manifests#type" title="/en-US/docs/Install_Manifests#type">Install Manifests#type</a> for other type codes).</li> + <li><code><strong>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</strong></code> – Firefox's application ID.</li> + <li><code><strong>1.5</strong></code> – the exact version number of the earliest version of Firefox you're saying this extension will work with. Never use a * in a minVersion; it almost certainly will not do what you expect it to.</li> + <li><code><strong>4.0.*</strong></code> – the maximum version of Firefox you're saying this extension will work with. In this case, "4.0.*" indicates that the extension works with Firefox 4.0 and any subsequent 4.0.x release. This number needs to be less than or equal to an <a class="external" href="http://wiki.mozilla.org/Releases" title="http://wiki.mozilla.org/Releases">announced version of Firefox</a>. By default, Firefox 10 and later do not enforce the constraint against <code>maxVersion</code> (although starting in Firefox 11, very old <code>maxVersion</code> values are still enforced). You can force the application to do it by using the <code><em:strictCompatibility></code>.</li> +</ul> +<div class="note"> + <strong>Note:</strong> If you get a message that the <code>install.rdf</code> is malformed, it is helpful to load it into Firefox using the File->Open File command and it will report XML errors to you.</div> +<p>Extensions designed to work with Firefox 2.0.0.x at the latest should set the maximum version to "2.0.0.*". Extensions designed to work with Firefox 1.5.0.x at the latest should set the maximum version to "1.5.0.*".</p> +<p>See <a href="/en-US/docs/Install_Manifests" title="/en-US/docs/Install_Manifests">Install Manifests</a> for a complete listing of the required and optional properties.</p> +<p>Save the file.</p> +<h2 id="Extendendo_o_navegador_com_XUL">Extendendo o navegador com XUL</h2> +<p>Firefox's user interface is written in XUL and JavaScript. <a href="/en-US/docs/XUL" title="/en-US/docs/XUL">XUL</a> is an XML grammar that provides user interface widgets like buttons, menus, toolbars, trees, etc. User actions are bound to functionality using JavaScript.</p> +<p>To extend the browser, we modify parts of the browser UI by adding or modifying widgets. We add widgets by inserting new XUL DOM elements into the browser window and modify them by using script and attaching event handlers.</p> +<p>The browser is implemented in a XUL file called <code>browser.xul</code> (<code>$FIREFOX_INSTALL_DIR/chrome/browser.jar</code> contains <code>content/browser/browser.xul</code>). In browser.xul we can find the status bar, which looks something like this:</p> +<pre class="eval"><statusbar id="status-bar"> + ... <statusbarpanel>s ... +</statusbar> +</pre> +<p><code><statusbar id="status-bar"></code> is a "merge point" for a XUL Overlay.</p> +<h3 id="XUL_Overlays">XUL Overlays</h3> +<p><a href="/en-US/docs/XUL_Overlays" title="/en-US/docs/XUL_Overlays">XUL Overlays</a> are a way of attaching other UI widgets to a XUL document at runtime. A XUL Overlay is a .xul file that specifies XUL fragments to insert at specific merge points within a "master" document. These fragments can specify widgets to be inserted, removed, or modified.</p> +<p><strong>Example XUL Overlay Document</strong></p> +<pre class="eval"><?xml version="1.0"?> +<overlay id="sample" + xmlns="<span class="nowiki"><a class="linkification-ext" href="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" title="Linkification: http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul</a></span>"> + <statusbar id="<strong>status-bar</strong>"> + <statusbarpanel id="my-panel" label="Hello, World" /> + </statusbar> +</overlay> +</pre> +<p>The <code><statusbar></code> called <code><strong>status-bar</strong></code> specifies the "merge point" within the browser window that we want to attach to.</p> +<p>The <code><statusbarpanel></code> child is a new widget that we want to insert within the merge point.</p> +<p>Take this sample code above and save it into your file called <code><strong>sample.xul</strong></code> inside the <code>chrome/content</code> folder you created.</p> +<p>For more information about merging widgets and modifying the user interface using Overlays, see below.</p> +<h2 id="Chrome_URIs">Chrome URIs</h2> +<p>XUL files are part of "<a href="/en-US/docs/Chrome_Registration" title="/en-US/docs/Chrome_Registration">Chrome Packages</a>" - bundles of user interface components which are loaded via <code>chrome://</code> URIs. Rather than load the browser from disk using a <code>file://</code> URI (since the location of Firefox on the system can change from platform to platform and system to system), Mozilla developers came up with a solution for creating URIs to XUL content that the installed application knows about.</p> +<p>The browser window is: <code><a class="external" rel="freelink">chrome://browser/content/browser.xul</a></code>. Try typing this URL into the location bar in Firefox!</p> +<p>Chrome URIs consist of several components:</p> +<ul> + <li>First, the <strong>URI scheme</strong> (<code>chrome</code>) which tells Firefox's networking library that this is a Chrome URI. It indicates that the content of the URI should be handled as a (<code>chrome</code>). Compare (<code>chrome</code>) to (<code>http</code>) which tells Firefox to treat the URI as a web page.</li> + <li>Second, a package name (in the example above, <code><strong>browser</strong></code>) which identifies the bundle of user interface components. This should be as unique to your application as possible to avoid collisions between extensions.</li> + <li>Third, the type of data being requested. There are three types: <code>content</code> (XUL, JavaScript, XBL bindings, etc. that form the structure and behavior of an application UI), <code>locale</code> (DTD, .properties files etc that contain strings for the UI's <a href="/en-US/docs/Localization" title="/en-US/docs/Localization">localization</a>), and <code>skin</code> (CSS and images that form the <a href="/en-US/docs/Themes" title="/en-US/docs/Themes">theme</a> of the UI).</li> + <li>Finally, the path of a file to load.</li> +</ul> +<p>So, <code><a class="external" rel="freelink">chrome://foo/skin/bar.png</a></code> loads the file <code>bar.png</code> from the <code>foo</code> theme's <code>skin</code> section.</p> +<p>When you load content using a Chrome URI, Firefox uses the Chrome Registry to translate these URIs into the actual source files on disk (or in JAR packages).</p> +<h2 id="Criando_um_Manifesto_Chrome">Criando um Manifesto Chrome</h2> +<p>For more information on Chrome Manifests and the properties they support, see the <a href="/en-US/docs/Chrome_Registration" title="/en-US/docs/Chrome_Registration">Chrome Manifest</a> Reference.</p> +<p>Open the file called <strong>chrome.manifest</strong> that you created alongside the <code>chrome</code> directory at the root of your extension's source folder hierarchy.</p> +<p>Add in this code:</p> +<pre class="eval">content sample chrome/content/ +</pre> +<p>(<strong>Don't forget the trailing slash, "<code>/</code>"!</strong> Without it, the package won't be registered.)</p> +<p>This specifies the:</p> +<ol> + <li>type of material within a chrome package</li> + <li>name of the chrome package (make sure you use all lowercase characters for the package name ("sample") as Firefox/Thunderbird doesn't support mixed/camel case in version 2 and earlier - {{ Bug("132183") }})</li> + <li>location of the chrome packages' files</li> +</ol> +<p>So, this line says that for a chrome package <strong>sample</strong>, we can find its <strong>content</strong> files at the location <code>chrome/content</code> which is a path relative to the location of <code>chrome.manifest</code>.</p> +<p>Note that content, locale, and skin files must be kept inside folders called content, locale, and skin within your <code>chrome</code> subdirectory.</p> +<p>Save the file. When you launch Firefox with your extension (later in this tutorial), this will register the chrome package.</p> +<h2 id="Register_an_Overlay">Register an Overlay</h2> +<p>You need Firefox to merge your overlay with the browser window whenever it displays one. So add this line to your <code>chrome.manifest</code> file:</p> +<pre class="eval">overlay <a class="external" rel="freelink">chrome://browser/content/browser.xul</a> <a class="external" rel="freelink">chrome://sample/content/sample.xul</a> +</pre> +<p>This tells Firefox to merge <code>sample.xul</code> into <code>browser.xul</code> when <code>browser.xul</code> loads.</p> +<h2 id="Teste">Teste</h2> +<p>First, we need to tell Firefox about your extension. During the development phase for Firefox versions 2.0 and higher, you can point Firefox to the folder where you are developing the extension, and it'll load it up every time you restart Firefox.</p> +<ol> + <li>Locate your <a class="external" href="http://kb.mozillazine.org/Profile_folder" title="http://kb.mozillazine.org/Profile_folder">profile folder</a> and beneath it the profile you want to work with (e.g., <code>Firefox/Profiles/<profile_id>.default/</code>).</li> + <li>Open the <code>extensions/</code> folder, creating it if need be.</li> + <li>Create a new text file and put the full path to your development folder inside (e.g., <code>C:\extensions\my_extension\</code> or <code>~/extensions/my_extension/)</code>. Windows users should retain the OS slash direction, and <em>everyone</em> should remember to <strong>include</strong> a closing slash and <strong>remove</strong> any trailing spaces.</li> + <li>Save the file with the id of your extension as its name (e.g., <code><a class="linkification-ext link-mailto" href="mailto:sample@example.net" title="Linkification: mailto:sample@example.net">sample@example.net</a></code>). No file extension.</li> +</ol> +<p>Now you should be ready to test your extension!</p> +<p>Start Firefox. Firefox will detect the text link to your extension directory and install the Extension. When the browser window appears you should see the text "Hello, World!" on the right side of the status bar panel.</p> +<p>You can now go back and make changes to the .xul file, close and restart Firefox, and they should appear.</p> +<h2 id="Empacotando">Empacotando</h2> +<p>Now that your extension works, you can <a href="/en-US/docs/Extension_Packaging" title="/en-US/docs/Extension_Packaging">package</a> it for deployment and installation.</p> +<p>Zip up the <strong>contents</strong> of your extension's folder (not the extension folder itself), and rename the zip file to have a .xpi extension. In Windows XP, you can do this easily by selecting all the files and subfolders in your extension folder, right click and choose "Send To -> Compressed (Zipped) Folder". A .zip file will be created for you. Just rename it and you're done!</p> +<p>On Mac OS X, you can right-click on the <strong>contents</strong> of the extension's folder and choose "Create Archive of..." to make the zip file. However, since Mac OS X adds hidden files to folders in order to track file metadata, you should instead use the Terminal, delete the hidden files (whose names begin with a period), and then use the <code>zip</code> command on the command line to create the zip file.</p> +<p>On Linux, you would likewise use the command-line zip tool.</p> +<p>If you have the 'Extension Builder' extension installed, it can compile the .xpi file for you (Tools -> Extension Developer -> Extension Builder). Merely navigate to the directory where your extension is (install.rdf, etc.), and hit the Build Extension button. This extension has a slew of tools to make development easier.</p> +<p>Now upload the .xpi file to your server, making sure it's served as <code>application/x-xpinstall</code>. You can link to it and allow people to download and install it. For the purposes of just testing our .xpi file we can just drag it into the extensions window via Tools -> Extensions in Firefox 1.5.0.x, or Tools -> Add-ons in later versions.</p> +<h3 id="Instalando_a_partir_de_uma_página_web">Instalando a partir de uma página web</h3> +<p>There are a variety of ways you can install extensions from web pages, including direct linking to the XPI files and using the InstallTrigger object. Extension and web authors are encouraged to use the <a href="/en-US/docs/Installing_Extensions_and_Themes_From_Web_Pages" title="/en-US/docs/Installing_Extensions_and_Themes_From_Web_Pages"> InstallTrigger method</a> to install XPIs, as it provides the best experience to users.</p> +<h3 id="Usando_addons.mozilla.org">Usando addons.mozilla.org</h3> +<p>Mozilla Add-ons is a distribution site where you can host your extension for free. Your extension will be hosted on Mozilla's mirror network to guarantee your download even though it might be very popular. Mozilla's site also provides users easier installation, and will automatically make your newer versions available to users of your existing versions when you upload them. In addition Mozilla Add-ons allows users to comment and provide feedback on your extension. It is highly recommended that you use Mozilla Add-ons to distribute your extensions!</p> +<p>Visit <a class="linkification-ext external" href="http://addons.mozilla.org/developers/" title="Linkification: http://addons.mozilla.org/developers/">http://addons.mozilla.org/developers/</a> to create an account and begin distributing your extensions!</p> +<p><em>Note:</em> Your Extension will be passed faster and downloaded more if you have a good description and some screenshots of the extension in action.</p> +<h3 id="Instalando_complementos_usando_uma_instalador_um_instalador_separado">Instalando complementos usando uma instalador um instalador separado</h3> +<p>It's possible to install an extension in a special directory and it will be installed the next time the application starts. The extension will be available to any profile. See <a class="internal" href="/en-US/docs/Installing_extensions" title="/en-US/docs/Installing extensions">Installing extensions</a> for more information.</p> +<p>On Windows, information about extensions can be added to the registry, and the extensions will automatically be picked up the next time the application starts. This allows application installers to easily add integration hooks as extensions. See <a href="/en-US/docs/Adding_Extensions_using_the_Windows_Registry" title="/en-US/docs/Adding_Extensions_using_the_Windows_Registry">Adding Extensions using the Windows Registry</a> for more information.</p> +<h2 id="Mais_sobre_XUL_Overlays">Mais sobre XUL Overlays</h2> +<p>In addition to appending UI widgets to the merge point, you can use XUL fragments within Overlays to:</p> +<ul> + <li>Modify attributes on the merge point, e.g., <code><statusbar id="status-bar" hidden="true" /></code> (hides the status bar)</li> + <li>Remove the merge point from the master document, e.g., <code><statusbar id="status-bar" removeelement="true" /></code></li> + <li>Control the position of the inserted widgets:</li> +</ul> +<pre class="eval"><statusbarpanel position="1" ... /> + +<statusbarpanel insertbefore="other-id" ... /> + +<statusbarpanel insertafter="other-id" ... /> +</pre> +<h2 id="Criando_novos_componentes_de_interface_com_o_usuário">Criando novos componentes de interface com o usuário</h2> +<p>You can create your own windows and dialog boxes as separate .xul files, provide functionality by implementing user actions in .js files, using DOM methods to manipulate UI widgets. You can use style rules in .css files to attach images, set colors, etc.</p> +<p>View the <a href="/en-US/docs/XUL" title="/en-US/docs/XUL">XUL</a> documentation for more resources for XUL developers.</p> +<h2 id="Arquivos_padrão">Arquivos padrão</h2> +<p>Defaults files that you use to seed a user's profile with should be placed in <code>defaults/</code> under the root of your extension's folder hierarchy. Default preferences .js files should be stored in <code>defaults/preferences/</code> - when you place them here they will be automatically loaded by Firefox's preferences system when it starts so that you can access them using the <a href="/en-US/docs/Preferences_API" title="/en-US/docs/Preferences_API">Preferences API</a>.</p> +<p>An example default preference file:</p> +<pre class="eval">pref("extensions.sample.username", "Joe"); //a string pref +pref("extensions.sample.sort", 2); //an int pref +pref("extensions.sample.showAdvanced", true); //a boolean pref +</pre> +<h2 id="Componentes_XPCOM">Componentes XPCOM</h2> +<p>Firefox supports <a href="/en-US/docs/XPCOM" title="/en-US/docs/XPCOM">XPCOM</a> components in extensions. You can create your own components easily in JavaScript or in C++ (using the <a href="/en-US/docs/Gecko_SDK" title="/en-US/docs/Gecko_SDK">Gecko SDK</a>).</p> +<p>Place all of your .js or .dll files in the <code>components/</code> directory - they are automatically registered the first time Firefox runs after your extension is installed.</p> +<p>For more information see <a href="/en-US/docs/How_to_Build_an_XPCOM_Component_in_Javascript" title="/en-US/docs/How_to_Build_an_XPCOM_Component_in_Javascript">How to Build an XPCOM Component in Javascript</a>, <a href="/en-US/docs/How_to_build_a_binary_XPCOM_component_using_Visual_Studio" title="/en-US/docs/How_to_build_a_binary_XPCOM_component_using_Visual_Studio">How to build a binary XPCOM component using Visual Studio,</a> and the <a href="/en-US/docs/Creating_XPCOM_Components" title="/en-US/docs/Creating_XPCOM_Components">Creating XPCOM Components</a> book.</p> +<h3 id="Aplicação_de_linha_de_comando">Aplicação de linha de comando</h3> +<p>One of the possible uses of custom XPCOM components is adding a command line handler to Firefox or Thunderbird. You can use this technique to run your extension as an application:</p> +<pre class="eval"> firefox.exe -myapp +</pre> +<p><span class="comment">I should move the useful parts of this to the Command Line page. -Nickolay This is done by adding a component containing the function... function NSGetModule(comMgr, fileSpec) { return myAppHandlerModule; } This function is run by firefox each time firefox is started. Firefox registers the myAppHandlerModule's by calling its 'registerSelf()'. Then it obtains the myAppHandlerModule's handler factory via 'getClassObject()'. The handler factory is then used to create the handle using its 'createInstance(). Finally, the handle's 'handle(cmdline)' processes the command line cmdline's handleFlagWithParam() and handleFlag().</span> See <a href="/en-US/docs/Chrome/Command_Line" title="/en-US/docs/Chrome/Command_Line">Chrome: Command Line</a> and a <a class="external" href="http://forums.mozillazine.org/viewtopic.php?t=365297">forum discussion</a> for details.</p> +<h2 id="Localização">Localização</h2> +<p>To support more than one language, you should separate strings from your content using <a href="/en-US/docs/XUL_Tutorial/Localization" title="/en-US/docs/XUL_Tutorial/Localization">entities</a> and <a href="/en-US/docs/XUL_Tutorial/Property_Files" title="/en-US/docs/XUL_Tutorial/Property_Files">string bundles</a>. It is much easier to do this while you are developing your extension, rather than come back and do it later!</p> +<p>Localization information is stored in the locale directory for the extension. For example, to add a locale to our sample extension, create two directories nested as "locale/en-US" in chrome (where the "content" directory is located) and add the following line to the chrome.manifest file:</p> +<pre class="eval">locale sample en-US chrome/locale/en-US/ +</pre> +<p>To create localizable attribute values in XUL, you can place the values in a <code>.dtd</code> file (sample.dtd for our sample extension). This file should be placed in the locale directory and looks like this:</p> +<pre class="eval"><!ENTITY my-panel.label "Hello, World"> +</pre> +<p>And then include it at the top of your XUL document (but underneath the "<?xml version"1.0"?>") like so:</p> +<pre class="eval"><?xml version="1.0"?> +<!DOCTYPE <strong>window</strong> SYSTEM "chrome://<strong>packagename</strong>/locale/<strong>filename.dtd</strong>"> +... +</pre> +<p>where <code><strong>window</strong></code> is the <code><a href="/en-US/docs/DOM/Node.localName" title="/en-US/docs/DOM/element.localName">localName</a></code> value of the root element of the XUL document, and the value of the <code>SYSTEM</code> property is the chrome URI to the entity file.</p> +<p>For our sample extension, replace <code><strong>window</strong></code> with <code><strong>overlay</strong></code> (root element), <code><strong>packagename</strong></code> with <code><strong>sample</strong></code>, and <code><strong>filename.dtd</strong></code> with <code><strong>sample.dtd</strong></code>.</p> +<p>To use the entities, modify your XUL to look like this:</p> +<pre class="eval"><statusbarpanel id="my-panel" label="&my-panel.label;" /> +</pre> +<p>The Chrome Registry will make sure the entity file is loaded from the localization bundle corresponding to the selected locale.</p> +<p>For strings that you use in script, create a .properties file, a text file that has a string on each line in this format:</p> +<pre class="eval">key=value +</pre> +<p>and then use {{ interface("nsIStringBundleService") }}/{{ interface("nsIStringBundle") }} or the {{ XULElem("stringbundle") }} tag to load the values into script.</p> +<h2 id="Entendendo_o_navegador">Entendendo o navegador</h2> +<p>Use the <a href="/en-US/docs/DOM_Inspector" title="/en-US/docs/DOM_Inspector">DOM Inspector</a> to inspect the browser window or any other XUL window you want to extend.</p> +<p><strong>Note:</strong> <strong>DOM Inspector</strong> is not part of the <strong>Standard</strong> Firefox installation. Since Firefox 3 Beta 4, the DOM Inspector has been available from <a class="link-https" href="https://addons.mozilla.org/en-US/firefox/addon/6622">Firefox Add-ons</a> as a standalone extension. For earlier versions, you must reinstall with the Custom install path and choose <strong>DOM Inspector</strong> (or <strong>Developer Tools</strong> in Firefox 1.5) if there is not a "DOM Inspector" item in your browser's Tools menu.</p> +<p>Use the point-and-click node finder button at the top left of the DOM Inspector's toolbar to click on a node in the XUL window visually to select it. When you do this, the DOM inspector's DOM hierarchy tree view will jump to the node you clicked on.</p> +<p>Use the DOM Inspector's right side panel to discover merge points with ids that you can use to insert your elements from overlays. If you cannot discover an element with an id that you can merge into, you may need to attach a script in your overlay and insert your elements when the <code>load</code> event fires on the master XUL window.</p> +<h2 id="Debugando_complementos">Debugando complementos</h2> +<p><strong>Analytical Tools for Debugging</strong></p> +<ul> + <li>The <a href="/en-US/docs/DOM_Inspector" title="/en-US/docs/DOM_Inspector">DOM Inspector</a> - inspect attributes, DOM structure, CSS style rules that are in effect (e.g., find out why your style rules don't seem to be working for an element - an invaluable tool!)</li> + <li><a href="/en-US/docs/Venkman" title="/en-US/docs/Venkman">Venkman</a> - set breakpoints in JavaScript and inspect call stacks</li> + <li><code>Components.stack.caller></code> in JavaScript - access a function's call stack</li> +</ul> +<p><strong>printf debugging</strong></p> +<ul> + <li>Use <code><a href="/en-US/docs/DOM/window.dump" title="/en-US/docs/DOM/window.dump">dump</a>("string")</code> (see the link for details; this requires a bit of configuration to work properly)</li> + <li>Use <code><a href="/en-US/docs/Components.utils.reportError" title="/en-US/docs/Components.utils.reportError">Components.utils.reportError()</a></code> or {{ interface("nsIConsoleService") }} to log to the JavaScript console</li> +</ul> +<p><strong>Advanced debugging</strong></p> +<ul> + <li>Run a debug Firefox build and set breakpoints in Firefox itself, or your C++ components. For the experienced developer, this is often the fastest way to diagnose a problem. See <a href="/en-US/docs/Developer_Guide/Build_Instructions" title="/en-US/docs/Build_Documentation">Build Documentation</a> and <a href="/en-US/docs/Developer_Guide" title="/en-US/docs/Developing_Mozilla">Developing Mozilla</a> for more information.</li> + <li>See <a href="/en-US/docs/Debugging_a_XULRunner_Application" title="/en-US/docs/Debugging_a_XULRunner_Application">Debugging a XULRunner Application</a> for more helpful tips.</li> +</ul> +<h2 id="Further_information">Further information</h2> +<ul> + <li><a href="/en-US/docs/Extension_Frequently_Asked_Questions" title="/en-US/docs/Extension_Frequently_Asked_Questions">Extension FAQ</a></li> + <li><a href="/en-US/docs/Extensions" title="/en-US/docs/Extensions">Extensions</a></li> +</ul> |