DOM extensions

The Opera browser can extend the traditional Document Object Model (DOM) with Opera-specific features. These extensions are added to the Opera DOM object.

The following extensions are currently available:

disableorigincheck Enable or disable XMLHttpRequest origin checking in a document
lockImage Lock an image in the decoded image cache
unlockImage Unlock a locked image so it can be thrown out of the image cache

You can control the use of these extensions using the security policy file domaddons.ini, which should be located in the OPERA_HOME directory. In this file, you specify which hosts are allowed to use certain DOM extensions.

Allow cross-domain XMLHttpRequest - disableorigincheck

This allows you to run a cross-domain XMLHttpRequest from certain URLs that would otherwise be blocked (as prescribed by the standard). This can be useful if you want to simulate the behaviour of some embedded browser configurations in a walled-garden environment, where XHR requests to certain trusted hosts are allowed.

Technically, this disables the origin-check mechanism, which is basically the verification that the source and destination of the request are allowed to use each other in this way.

How it works

The procedure for performing a cross-domain XMLHttpRequest is:

  1. Add a disable_origin_check directive to domaddons.ini for each host you want to allow cross-domain XMLHttpReqeuests from (see the example configuration below)
  2. In the "Tools" menu, check "Allow Cross Origin XHR" (this will disable origin check)
  3. In the JavaScript code of your web application, disable origin checking by calling:

    opera.disableorigincheck(document, true);

  4. Perform the cross-domain XMLHttpRequest(s).
  5. Re-enable origin checking by making another JavaScript call:

    opera.disableorigincheck(document, false);

  6. If you want to disable cross-domain requests again, uncheck "Allow Cross Origin XHR" in the "Tools" menu

Example configuration

The following is an example configuration for this extension.

keywordprotocolURLport
disable_origin_check:file,localhost,0
disable_origin_check:https,[ALL].foo.com,0
disable_origin_check:http,bar.com,80

This example configuration allows cross-domain XMLHttpRequests from:

Control images in image cache

This extension locks or unlocks images in the decoded image cache. It is useful to lock critical images in memory, so that they do not need to be redecoded if they are temporarily removed from the screen.

These locks are stored on a per-document basis, for example a GOGI Window, or an iframe. The locks are additive, so as long as at least one document has a reference to an image, it can not be removed. A document may not hold more than one lock to a single image. When the document is unloaded, for example when the user navigates away from it, or when the window is closed, all locks held by that document are removed.

How it works

The following two functions are exposed on the Opera DOM object:

boolean opera.lockImage(string url)

This function creates a lock from the current document to the image with the URL passed as parameter. The image can not be thrown out of the image cache as long as the lock is maintained. The URL must be the absolute path to the image. The function will return true if the image was found, and false if the image was not found. The function will also return false if the document already has a lock to the specified image or if the function is not allowed to execute according to the rules in the domaddons.ini file.

boolean opera.unlockImage(string url)

This function unlocks the image with the URL passed as parameter. Unless the image is locked by other documents, or locked by Opera core (for example if the image is visible or currently being decoded) it may be thrown out of the image cache. Just as with lockImage(), the URL must be the absolute path to the image. The function will return true if the image was found, and the document retained a lock to it. The function will return false if the image was not found, if the document did not hold a lock to it or if the function is not allowed to execute according to the rules in the domaddons.ini file.

Example configuration

The following is an example configuration for this extension.

keywordprotocolurlport
image_cache_lock:file,localhost,0
image_cache_lock:http,[All].opera.com,0
image_cache_lock:http,myhost.mydomain.org,4711
image_cache_lock:https,myhost.mydomain.org,0

Known issues

This extension is still in an early stage and a few bugs may still be present.