基础学习
-
Getting started with extension development - MozillaZine Knowledge Base
- In particular, you must set the javascript.options.showInConsole pref to true.
- The folders are traditionally named "content", "locale" and "skin", and you should follow the tradition.
- This means you should use unique names for global identifiers in your extensions to avoid clashing with other extensions. It's usually accomplished by prefixing all global identifiers with the name of your extension or by putting most/all of your variables and functions in an object with an unique name.
- An important issue you should be aware of is that all scripts that are loaded for a given document (the scripts used by the window itself, and scripts loaded from overlays to that document) share the same scope.
- DTD files are used to make XUL/XBL/XHTML and other XML files in Mozilla chrome localizable. Basically, instead of hard-coding the strings in your XUL file, you use XML entities, which expand to the values declared in the DTD file referenced at the top of the XUL file.
-
-
- In Mozilla, XUL is handled much in the same way that HTML or other types of content are handled.
- This means that the same CSS properties may be used to style both HTML and XUL, and many of the features can be shared between both.
- In fact, in Mozilla, all document types, whether they are HTML or XUL, or even SVG are all handled by the same underlying code
- Since XUL and HTML are handled in the same way, you can load both from either your local file system, from a web page, or from an extension or standalone XULRunner application.
- Mozilla provides a method of installing content locally and registering the installed files as part of its chrome system. This allows a special URL form to be used called a chrome URL. By accessing a file using a chrome URL, the files receive elevated privileges to access local files, access preferences and bookmarks and perform other privileged operations. Obviously, web pages do not get these privileges, unless they are signed with a digital certificate and the user has granted permission to perform these operations.
- Registered packages are not required to use overlays, of course. If they don't, you won't be able to access them via the main browser interface, but you can still access them via the chrome URL, if you know what it is.
- It is worth noting that the Mozilla browser itself is actually just a set of packages containing XUL files, JavaScript and style sheets. These files are accessed via a chrome URL and have enhanced privileges and work just like any other package
- Mozilla does not use the file extension, unless reading files from the file system, but you should use the .xul extension for all XUL files
- XUL may be loaded from a remote site, the local file system, or installed as a package and accessed using a chrome URL. This is what browser extensions do.
-
-
A Brief Guide to Mozilla Preferences - MDC
- A preference is any value or defined behavior that can be set (presumably, one setting is
preferable
to another). Preference changes via user interface usually take effect immediately. The values are are saved to the user profile (inprefs.js
). (Firefox confirmed). - A preference is read from a file, and is a can call up to three methods:
pref()
,user_pref()
andlock_pref()
. All preferences files may callpref()
anduser_pref()
, while the config file in addition may calllock_pref()
. - To protect privacy by preventing inadvertent loading of a preferences file in the browser, the first line of the file is made un-parseable and skipped on loading. The only exception to this is
user.js
. -
- Default pref. files
In the
defaults/pref/
directory of the application install directory are default preferences files with.js
file extension. On application launch these files initialize preferences with default values. -
- Config. file
A configuration file, usually with
.cfg
extension, may be called from a default pref file via thegeneral.config.filename
preference. This file allows preference locking via thelock_pref()
function. -
- User pref. files js
In the profile directory are two user pref files:
prefs.js
anduser.js
.prefs.js
is automatically generated by the application and should not be edited manually, whereasuser.js
is an optional file the user can create to override preferences initialized by other preferences files. -
-
Load all default pref files. Non-platform-specific
.js
files are loaded first, in reverse alphabetical order. Then the platform-specific file is loaded. -
Optionally load the config file.
-
Load user pref files, first
prefs.js
, thenuser.js
.
On application launch, the application loads preferences in the following order:
Preference conflicts are resolved in favor of the last entry; for example,
user.js
takes precedence overprefs.js
. -
- any error during loading of a default pref file, the application will issue a warning that a configuration file has failed to load and then quit.
- an error when loading user pref files, the application will issue a warning but will continue running
- Usually when the user specifically commits a preference change via user interface such as the Preferences dialog, the application saves the change by overwriting
prefs.js
. On application exit, all user-set preferences are saved toprefs.js
. This also means that preferences initially set byuser.js
will also be saved toprefs.js
. - Do NOT edit
prefs.js
directly - Note the application never changes
user.js
- You can set user preferences via the advanced preferences editor, accessible by typing
about:config
in the Location Bar. - If you want to manually change preference values for a given profile, you should do so by creating
user.js
in your profile directory. - preference names are case-sensitive.
- pref files are loaded in reverse alphabetical order
-
-
- Preferences API allows you to save and read strings, numbers, booleans, and references to files to the preferences store.
- The preferences API is exposed as a set of frozen XPCOM components and interfaces:
nsIPrefService
,nsIPrefBranch
,nsIPrefBranch2
.
-
-
Mozilla支持模块化。
Common JS Modules- Here you'll find a collection of modules which you can import into your extension. The goal is to make extension development easier by implementing common functionality as reusable libraries. If you would like to contribute a new module
一些有用的模块 - Logging
- Observers
- Preferences
- The URI module
-
-
Using JavaScript code modules - MDC
- JavaScript code modules are a concept introduced in Firefox 3 (Gecko 1.9) and can be used for sharing code between different privileged scopes. Modules can also be used to create global JavaScript singletons that previously required using JavaScript XPCOM objects.
- A JavaScript code module is simply some JavaScript code located in registered location. The module is loaded into a specific JavaScript scope, such as XUL script or JavaScript XPCOM script, using Components.utils.import.
- An extremely important behavior of Components.utils.import is that modules are cached when loaded and subsequent imports do not reload a new version of the module, but instead use the previously cached version. This means that a given module will be shared when imported multiple times. Any modifications to data, objects or functions will be available in any scope that has imported the module. For example, if the simple module were imported into two different JavaScript scopes, changes in one scope can be observed in the other scope.
- This sharing behavior can be used to create singleton objects that can share data across windows and between XUL script and XPCOM components.
- Each scope which imports a module receives a by-value copy of the exported symbols in that module. Changes to the symbol's value will not propagate to other scopes.
- That's to say the exported symbols work like reference in java. Import a module cause create new references defined in the EXPORTED_SYMBOLS and let them reference to corepsonding variables. To different import, these references are different, mutable and having nothing to do with each other, but their target are same. - post by ericwangqing
-
"resource://" protocol. The basic syntax of a resource URL is as follows:
resource://
/ / The
is an alias to a location, usually a physical location relative to the application or XUL runtime. There are several pre-defined aliases setup by the XUL runtime:app
- Alias to the location of the XUL application.gre
- Alias to the location of the XUL runtime.
The
can be multiple levels deep and is always relative to the location defined by the
. The common relative path is "modules" and is used by XUL Runner and Firefox. Code modules are simple JavaScript files with a .js or .jsm extension. -
The easiest way for extensions and XUL applications to add custom aliases is by registering an alias in the chrome manifest using a line like this:
resource aliasname uri/to/files/
-
Programmatically adding aliases
Custom aliases can be programmatically added to the resource protocol as well
-
-
- Chrome is the set of user interface elements of the application window that are outside of a window's content area. Toolbars, menu bars, progress bars, and window title bars are all examples of elements that are typically part of the chrome.
- A supplier of chrome for a given window type (e.g. for the browser window) is called a chrome provider. The providers work together to supply a complete set of chrome for a particular window, from the images on the toolbar buttons to the files that describe the text, content and appearance of the window itself.
- The main source file for a window description comes from the content provider, and it can be any file type viewable from within Mozilla. It will typically be a XUL file, since XUL is designed for describing the contents of windows and dialogs. The JavaScript files that define the user interface are also contained within the content packages, as well as most XBL binding files
- The two main types of localizable files are DTD files and Java-style properties files.
-
A skin provider is responsible for providing a complete set of files that describe the visual appearance of the chrome. Typically a skin provider will provide CSS files and images.
Note: Scripts (including those found in XBL) loaded from skin packages will not execute.
- The Gecko runtime maintains a service known as the chrome registry that provides mappings from chrome package names to the physical location of chrome packages on disk.
- This chrome registry is configurable and persistent, and thus a user can install different chrome providers, and select a preferred skin and locale. This is accomplished through xpinstall and the extension manager.
- Firefox 2 will not find the chrome when packagename is mixed case.
-
comments
A line is a comment if it begins with the character '#'; any other characters on the line are ignored.
-
content
A content package is registered with the line
content packagename uri/to/files/ [flags]
- This will register a location to use when resolving the URI chrome://packagename/content/.... The URI may be absolute or relative to the location of the manifest file. Note, that it must end with an '/'.
-
A locale package is registered with the line
locale packagename localename uri/to/files/ [flags]
This will register a locale package when resolving the URI chrome://packagename/locale/... . The localename is usually a plain language identifier "en" or a language-country identifier "en-US". If more than one locale is registered for a package, the chrome registry will select the best-fit locale using the user's preferences
-
skin
A skin package is registered with the line
skin packagename skinname uri/to/files/ [flags]
This will register a skin package when resolving the URI chrome://packagename/skin/... . The skinname is an opaque string identifying an installed skin. If more than one skin is registered for a package, the chrome registry will select the best-fit skin using the user's preferences.
-
override
In some cases an extension or embedder may wish to override a chrome file provided by the application or XULRunner. In order to allow for this, the chrome registration manifest allows for "override" instructions:
override chrome://package/type/original-uri.whatever new-resolved-URI [flags]
Note: overrides are not recursive (so overriding chrome://foo/content/bar/ with file:///home/john/blah/ will not usually do what you want or expect it to do).
There was a bug in Gecko 1.8.1.5 (Firefox 2.0.0.5) and earlier where you could not use a relative URL for the new-resolved-URI parameter. You needed to provide an absolute URL. See bug 323455 .
-
resource
New in Firefox 3
When using JavaScript code modules it may be necessary to create resource protocol aliases so extensions and applications can load modules using Components.utils.import. Aliases can be created using the
resource
instruction:resource aliasname uri/to/files/ [flags]
This will create an mapping for the
res://
to the path given./ Note that there are no security restrictions preventing web content from including content at resource uris so take care with what you make visible there.
-
-
Creating a C++ XPCOM component
Creating a C++ XPCOM component
-
Development resources - MozillaZine Knowledge Base
Good resources for Javascript, xpcom, and dom.
tags: javascript, xpcom, dom
Posted from Diigo. The rest of my favorite links are here.
没有评论:
发表评论