зеркало из https://github.com/mozilla/pjs.git
Fix 182928: Add new set as wallpaper dialog (which acts as a confirmation dialog but also one-ups IE). Tiling preview is waiting on implementation of background-size. Also forks nsWindowsHooks in preparation for fixing fx to not totally take over every file association known to man.
This commit is contained in:
Родитель
d60de8d9fe
Коммит
8220c7395e
|
@ -0,0 +1,175 @@
|
|||
<?xml version="1.0"?> <!-- -*- Mode: HTML -*- -->
|
||||
|
||||
# ***** BEGIN LICENSE BLOCK *****
|
||||
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
#
|
||||
# The contents of this file are subject to the Mozilla Public License Version
|
||||
# 1.1 (the "License"); you may not use this file except in compliance with
|
||||
# the License. You may obtain a copy of the License at
|
||||
# http://www.mozilla.org/MPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
# for the specific language governing rights and limitations under the
|
||||
# License.
|
||||
#
|
||||
# The Original Code is Mozilla Firebird about dialog.
|
||||
#
|
||||
# The Initial Developer of the Original Code is
|
||||
# Blake Ross (blake@blakeross.com).
|
||||
# Portions created by the Initial Developer are Copyright (C) 2002
|
||||
# the Initial Developer. All Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
# Alternatively, the contents of this file may be used under the terms of
|
||||
# either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
# in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
# of those above. If you wish to allow use of your version of this file only
|
||||
# under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
# use your version of this file under the terms of the MPL, indicate your
|
||||
# decision by deleting the provisions above and replace them with the notice
|
||||
# and other provisions required by the LGPL or the GPL. If you do not delete
|
||||
# the provisions above, a recipient may use your version of this file under
|
||||
# the terms of any one of the MPL, the GPL or the LGPL.
|
||||
#
|
||||
# ***** END LICENSE BLOCK ***** -->
|
||||
|
||||
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
|
||||
|
||||
<!DOCTYPE dialog SYSTEM "chrome://browser/locale/setWallpaper.dtd">
|
||||
|
||||
<dialog xmlns:html="http://www.w3.org/1999/xhtml"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||
id="aboutDialog"
|
||||
buttons="accept,cancel"
|
||||
buttonlabelaccept="&setWallpaper.title;"
|
||||
onload="onLoad();"
|
||||
ondialogaccept="onAccept();"
|
||||
title="&setWallpaper.title;"
|
||||
style="width: 299px">
|
||||
|
||||
<script type="application/x-javascript">
|
||||
<![CDATA[
|
||||
const xulNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
|
||||
const winHooks = Components.interfaces.nsIWindowsHooks;
|
||||
var gMode = winHooks.WALLPAPER_STRETCH;
|
||||
var gMonitor;
|
||||
var gWidth, gHeight;
|
||||
|
||||
function HexToR(h) { return parseInt((cutHex(h)).substring(0,2),16) }
|
||||
function HexToG(h) { return parseInt((cutHex(h)).substring(2,4),16) }
|
||||
function HexToB(h) { return parseInt((cutHex(h)).substring(4,6),16) }
|
||||
function cutHex(h) { return (h.charAt(0)=="#") ? h.substring(1,7) : h}
|
||||
|
||||
function RGBToHex(r, g, b) {
|
||||
var rHex = r.toString(16).toUpperCase();
|
||||
var gHex = g.toString(16).toUpperCase();
|
||||
var bHex = b.toString(16).toUpperCase();
|
||||
|
||||
if (rHex.length == 1) rHex ='0' + rHex;
|
||||
if (gHex.length == 1) gHex ='0' + gHex;
|
||||
if (bHex.length == 1) bHex ='0' + bHex;
|
||||
|
||||
return '#' + rHex + gHex + bHex;
|
||||
}
|
||||
|
||||
function onLoad() {
|
||||
var winhooks = Components.classes["@mozilla.org/winhooks;1"].
|
||||
getService(Components.interfaces.nsIWindowsHooks);
|
||||
gMonitor = document.getElementById("monitor");
|
||||
var color = winhooks.getDesktopColor();
|
||||
const rMask = 4294901760;
|
||||
const gMask = 65280;
|
||||
const bMask = 255;
|
||||
var r = (color & rMask) >> 16;
|
||||
var g = (color & gMask) >> 8;
|
||||
var b = (color & bMask);
|
||||
gMonitor.style.backgroundColor = RGBToHex(r, g, b);
|
||||
gWidth = window.arguments[0].width;
|
||||
gHeight = window.arguments[0].height;
|
||||
var img = document.createElementNS(xulNS, "image");
|
||||
img.id = "wallpaperImg";
|
||||
img.setAttribute("src", window.arguments[0].src);
|
||||
gMonitor.appendChild(img);
|
||||
stretchImage();
|
||||
|
||||
var colorpicker = document.getElementById("desktopColor");
|
||||
colorpicker.color = RGBToHex(r, g, b);
|
||||
}
|
||||
|
||||
function stretchImage() {
|
||||
var img = gMonitor.firstChild.cloneNode(false);
|
||||
gMonitor.removeChild(gMonitor.firstChild);
|
||||
img.width = parseInt(gMonitor.style.width);
|
||||
img.height = parseInt(gMonitor.style.height);
|
||||
gMonitor.appendChild(img);
|
||||
}
|
||||
|
||||
function tileImage() {
|
||||
// XXXBlake Waiting on caillon to implement background-size
|
||||
}
|
||||
|
||||
function centerImage() {
|
||||
var img = gMonitor.firstChild.cloneNode(false);
|
||||
gMonitor.removeChild(gMonitor.firstChild);
|
||||
var width = gWidth*gMonitor.boxObject.width/screen.width;
|
||||
var height = gHeight*gMonitor.boxObject.height/screen.height;
|
||||
img.width = Math.floor(width);
|
||||
img.height = Math.floor(height);
|
||||
gMonitor.appendChild(img);
|
||||
}
|
||||
|
||||
function onAccept() {
|
||||
var pos = parseInt(document.getElementById("menuPosition").value);
|
||||
var winhooks = Components.classes["@mozilla.org/winhooks;1"].
|
||||
getService(Components.interfaces.nsIWindowsHooks);
|
||||
winhooks.setImageAsWallpaper(window.arguments[0], false, pos);
|
||||
|
||||
var colorpicker = document.getElementById("desktopColor");
|
||||
var r = HexToR(colorpicker.color);
|
||||
var g = HexToG(colorpicker.color);
|
||||
var b = HexToB(colorpicker.color);
|
||||
winhooks.setDesktopColor((r << 16) | (g << 8) | b);
|
||||
}
|
||||
|
||||
function updatePreviewColor(color) {
|
||||
gMonitor.style.backgroundColor = color;
|
||||
}
|
||||
|
||||
function onPositionChange(val) {
|
||||
gMode = parseInt(val);
|
||||
if (gMode == winHooks.WALLPAPER_TILE)
|
||||
tileImage();
|
||||
else if (gMode == winHooks.WALLPAPER_STRETCH)
|
||||
stretchImage();
|
||||
else
|
||||
centerImage();
|
||||
}
|
||||
]]>
|
||||
</script>
|
||||
|
||||
<hbox align="center" id="foo">
|
||||
<label value="&position.label;"/>
|
||||
<menulist id="menuPosition" label="&position.label;" oncommand="onPositionChange(this.value);">
|
||||
<menupopup>
|
||||
<menuitem label="¢er.label;" value="2"/>
|
||||
<menuitem label="&tile.label;" value="0"/>
|
||||
<menuitem label="&stretch.label;" value="1" selected="true"/>
|
||||
</menupopup>
|
||||
</menulist>
|
||||
<spacer flex="1"/>
|
||||
<label value="&color.label;"/>
|
||||
<colorpicker type="button" id="desktopColor" onchange="updatePreviewColor(this.color);"/>
|
||||
</hbox>
|
||||
<groupbox align="center">
|
||||
<caption label="&preview.label;"/>
|
||||
<stack>
|
||||
<vbox id="monitor" align="center" pack="center"
|
||||
style="width: 153px !important; height: 114px !important;"
|
||||
left="13" top="17"/>
|
||||
<image src="chrome://browser/content/monitor.png"/>
|
||||
</stack>
|
||||
</groupbox>
|
||||
</dialog>
|
|
@ -12,6 +12,7 @@ browser.jar:
|
|||
* content/browser/macBrowserOverlay.xul (content/macBrowserOverlay.xul)
|
||||
* content/browser/metaData.js (content/metaData.js)
|
||||
* content/browser/metaData.xul (content/metaData.xul)
|
||||
content/browser/monitor.png (content/monitor.png)
|
||||
* content/browser/openLocation.js (content/openLocation.js)
|
||||
* content/browser/openLocation.xul (content/openLocation.xul)
|
||||
* content/browser/pageInfo.js (content/pageInfo.js)
|
||||
|
@ -20,6 +21,7 @@ browser.jar:
|
|||
* content/browser/pageReport.xul (content/pageReport.xul)
|
||||
* content/browser/pageReportFirstTime.xul (content/pageReportFirstTime.xul)
|
||||
* content/browser/search.xml (content/search.xml)
|
||||
* content/browser/setWallpaper.xul (content/setWallpaper.xul)
|
||||
* content/browser/utilityOverlay.js (content/utilityOverlay.js)
|
||||
* content/browser/web-panels.js (content/web-panels.js)
|
||||
* content/browser/web-panels.xul (content/web-panels.xul)
|
||||
|
@ -40,6 +42,7 @@ en-US.jar:
|
|||
locale/en-US/browser/pageInfo.properties (locale/pageInfo.properties)
|
||||
locale/en-US/browser/pageReport.dtd (locale/pageReport.dtd)
|
||||
locale/en-US/browser/pageReportFirstTime.dtd (locale/pageReportFirstTime.dtd)
|
||||
locale/en-US/browser/setWallpaper.dtd (locale/setWallpaper.dtd)
|
||||
|
||||
US.jar:
|
||||
locale/US/browser-region/region.properties (locale/region.properties)
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
#
|
||||
# The contents of this file are subject to the Mozilla Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/MPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is mozilla.org code
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
|
||||
DEPTH = ../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = winhooks
|
||||
XPIDL_MODULE = winhooks
|
||||
LIBRARY_NAME = winhooks_s
|
||||
|
||||
XPIDLSRCS = nsIWindowsHooks.idl
|
||||
|
||||
CPPSRCS = nsWindowsHooks.cpp
|
||||
|
||||
REQUIRES = \
|
||||
xpcom \
|
||||
string \
|
||||
dom \
|
||||
windowwatcher \
|
||||
intl \
|
||||
appshell \
|
||||
necko \
|
||||
layout \
|
||||
content \
|
||||
widget \
|
||||
imglib2 \
|
||||
gfx \
|
||||
locale \
|
||||
$(NULL)
|
||||
|
||||
FORCE_STATIC_LIB = 1
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
JS_SET_BROWSER_COMPONENT = nsSetDefaultBrowser.js
|
||||
|
||||
libs::
|
||||
$(INSTALL) $(srcdir)/$(JS_SET_BROWSER_COMPONENT) $(DIST)/bin/components
|
||||
|
||||
clobber::
|
||||
rm -f $(DIST)/lib/$(LIBRARY_NAME).lib
|
||||
rm -f $(DIST)/bin/components/$(JS_SET_BROWSER_COMPONENT)
|
|
@ -0,0 +1,247 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.1 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Bill Law <law@netscape.com>
|
||||
* Aaron Kaluszka <ask@swva.net>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
|
||||
/* These interface provides support for integrating Mozilla into Windows.
|
||||
* This integration consists primarily of setting Mozilla as the "default
|
||||
* browser." Or more precisely, setting Mozilla as the executable to
|
||||
* handle certain file types.
|
||||
*
|
||||
* There are two subtly different types of desktop objects that Mozilla
|
||||
* can be configured to "handle:"
|
||||
* o File types (based on file extension)
|
||||
* o Internet shortcuts (based on URL protocol).
|
||||
*
|
||||
* While these are different types of objects, the mechanism by which
|
||||
* applications are matched with them is essentially the same.
|
||||
*
|
||||
* In the case of files, there is one more level of indirection. File
|
||||
* extensions are assigned a "file type" via a Windows registry entry.
|
||||
* For example, given the file extension ".foo", the file type is
|
||||
* determined by examing the value stored in the "default" value stored
|
||||
* at the registry key HKEY_LOCAL_MACHINE\Software\Classes\.foo.
|
||||
*
|
||||
* Once you have the "file type" then you use that the same way you use
|
||||
* Internet Shortcut protocol names to determine which application to
|
||||
* launch. The application is specified by the default value stored in
|
||||
* the registry key
|
||||
* HKEY_LOCAL_MACHINE\Software\Classes\<X>\shell\open\command, where
|
||||
* <X> is the "file type" or protocol name.
|
||||
*
|
||||
* If there are additional keys under "shell" then these appear on the
|
||||
* context menu for files/shortcuts of this type. Typically, there are
|
||||
* entries for "print." But Mozilla does not currently support a command
|
||||
* line option to print so we don't offer that.
|
||||
*
|
||||
* Previously, Netscape Communicator made itself the handler of standard
|
||||
* web things by creating a new file type "NetscapeMarkup" and mapping
|
||||
* extensions to that (.htm, .html, .shtml, .xbm), or, by setting itself
|
||||
* up as the "handler" for the file types of other web things (.jpg, .gif)
|
||||
* and Internet Shortcut protocols (ftp, gopher, http, https, mailto, news,
|
||||
* snews).
|
||||
*
|
||||
* In order to better enable Mozilla to co-exist with other browsers
|
||||
* (including Communicator), it will create yet another new file type,
|
||||
* "MozillaMarkup," that will be used to make Mozilla the default handler
|
||||
* for certain file extensions. This will be done by remapping those
|
||||
* extensions to this new type.
|
||||
*
|
||||
* Mozilla will attempt to remember the original mapping and restore it
|
||||
* when the user decides to no longer have Mozilla be the default handler
|
||||
* for that extension.
|
||||
*
|
||||
* Mozilla will drop support for some items that are no longer germane:
|
||||
* the .shtml file extension and the gopher: protocol. We will also, perhaps
|
||||
* only temporarily, drop support for protocols that aren't accessible from
|
||||
* the command line: mailto:, news:, and snews:.
|
||||
*
|
||||
* We will be adding support for the chrome: protocol (using the "-chrome"
|
||||
* command line option) and for .png, .xul and .xml file extensions.
|
||||
*
|
||||
* Missing Features:
|
||||
*
|
||||
* Currently, there is no way to extend the set of file types or protocols
|
||||
* that Mozilla can be associated with (save manually tweaking the Windows
|
||||
* registry). This is likely to be a problem for branded Mozilla browsers
|
||||
* that might support specialized file types or protocols (e.g., .aim files).
|
||||
*
|
||||
* The plan is to extend this interface so that such file types and protocols
|
||||
* can be set up using the implementation of the interfaces defined here.
|
||||
*/
|
||||
|
||||
interface nsIDOMWindowInternal;
|
||||
interface nsIDOMElement;
|
||||
|
||||
/* nsIWindowsHooksSettings
|
||||
*
|
||||
* This interface is used to get/set the user preferences relating to
|
||||
* "windows hooks" (aka "windows integration"). It is basically just
|
||||
* a conglomeration of a bunch of boolean attributes; it exists mainly
|
||||
* for historical reasons (it corresponds to the internal Prefs struct
|
||||
* that was in nsIDefaultBrowser.h in Mozilla Classic).
|
||||
*/
|
||||
[scriptable, uuid(4ce9aa90-0a6a-11d4-8076-00600811a9c3)]
|
||||
interface nsIWindowsHooksSettings : nsISupports {
|
||||
|
||||
// Internet shortcuts (based on "protocol").
|
||||
attribute boolean isHandlingHTTP;
|
||||
attribute boolean isHandlingHTTPS;
|
||||
attribute boolean isHandlingFTP;
|
||||
attribute boolean isHandlingCHROME;
|
||||
attribute boolean isHandlingGOPHER;
|
||||
|
||||
// File handling (based on extension).
|
||||
attribute boolean isHandlingHTML;
|
||||
attribute boolean isHandlingJPEG;
|
||||
attribute boolean isHandlingGIF;
|
||||
attribute boolean isHandlingPNG;
|
||||
attribute boolean isHandlingMNG;
|
||||
attribute boolean isHandlingXBM;
|
||||
attribute boolean isHandlingBMP;
|
||||
attribute boolean isHandlingICO;
|
||||
attribute boolean isHandlingXML;
|
||||
attribute boolean isHandlingXHTML;
|
||||
attribute boolean isHandlingXUL;
|
||||
|
||||
// Nag dialog flag. Set this so that dialog
|
||||
// appears on startup if there is a mismatch
|
||||
// between registry and these settings.
|
||||
attribute boolean showDialog;
|
||||
|
||||
// Registry mismatch indicator.
|
||||
// This is true if the Win32 registry is
|
||||
// currently set to match the preferences
|
||||
// in this object.
|
||||
readonly attribute boolean registryMatches;
|
||||
};
|
||||
|
||||
/* nsIWindowsHooks
|
||||
*
|
||||
* This interface describes the service that you can use to
|
||||
* get/set the various windows integration features specified
|
||||
* by the nsIWindowsHooksPrefs attributes.
|
||||
*/
|
||||
[scriptable, uuid(19c9fbb0-06a3-11d4-8076-00600811a9c3)]
|
||||
interface nsIWindowsHooks : nsISupports {
|
||||
|
||||
// settings
|
||||
// --------
|
||||
// Get/set this to query or modify them. The Windows
|
||||
// registry is updated when you set this attribute.
|
||||
attribute nsIWindowsHooksSettings settings;
|
||||
|
||||
// checkSettings
|
||||
// -------------
|
||||
// Check that registry matches settings and if not,
|
||||
// prompt user for whether to reset. This is
|
||||
// controlled by the showDialog setting. This will
|
||||
// perform the check only the first time the
|
||||
// service is called.
|
||||
// aParent - parent window for any dialogs that
|
||||
// will appear
|
||||
// Returns true if the windows integration dialog was shown
|
||||
boolean checkSettings( in nsIDOMWindowInternal aParent );
|
||||
|
||||
/**
|
||||
* Returns true if command is in the "(appname) QuickLaunch" value in the
|
||||
* HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run
|
||||
* key.
|
||||
*/
|
||||
boolean isOptionEnabled(in string option);
|
||||
|
||||
/**
|
||||
* Adds the option to the "(appname) QuickLaunch" value to the key mentioned above,
|
||||
* with data "(path\to\app.exe) option", if not done already.
|
||||
*/
|
||||
void startupAddOption(in string option);
|
||||
|
||||
/**
|
||||
* Removes the commnand from the "(appname) QuickLaunch" value from
|
||||
* the key mentioned above, if not done already. And deletes the
|
||||
* "(appname) QuickLaunch" value entirely if there are no options left
|
||||
*/
|
||||
void startupRemoveOption(in string option);
|
||||
|
||||
const PRInt32 WALLPAPER_TILE = 0;
|
||||
const PRInt32 WALLPAPER_STRETCH = 1;
|
||||
const PRInt32 WALLPAPER_CENTER = 2;
|
||||
|
||||
/**
|
||||
* Accepts an element, either an HTML img element or an element with
|
||||
* a background image, serializes the image to a bitmap file
|
||||
* in the windows directory, and sets it to be the desktop wallpaper.
|
||||
*/
|
||||
void setImageAsWallpaper(in nsIDOMElement aImageElement, in boolean useBackground, in PRInt32 position);
|
||||
PRUint32 getDesktopColor();
|
||||
void setDesktopColor(in PRUint32 color);
|
||||
|
||||
};
|
||||
|
||||
/* nsIWindowsRegistry
|
||||
*
|
||||
* This interface describes the service that you can use to
|
||||
* get/set Win32 registry entries.
|
||||
*
|
||||
* Notice: This interface is incomplete and should be used at your own risk!
|
||||
*/
|
||||
[scriptable, uuid(e07e7430-8d11-417c-83ee-c994400c452f)]
|
||||
interface nsIWindowsRegistry : nsISupports {
|
||||
/**
|
||||
* Returns a Win32 registry entry value. The returned string will be truncated
|
||||
* at 4096 bytes. The constants define the set of valid starting keys. You
|
||||
* pass in the subkey name and a value identifier (an empty string returns
|
||||
* the "default" value for that subkey).
|
||||
*/
|
||||
const long HKCR = 0; // HKEY_CLASSES_ROOT
|
||||
const long HKCC = 1; // HKEY_CURRENT_CONFIG
|
||||
const long HKCU = 2; // HKEY_CURRENT_USER
|
||||
const long HKLM = 3; // HKEY_LOCAL_MACHINE
|
||||
const long HKU = 4; // HKEY_USERS
|
||||
string getRegistryEntry( in long aHKeyConstant, in string aSubKeyName, in string aValueName );
|
||||
};
|
||||
|
||||
%{C++
|
||||
#define NS_IWINDOWSHOOKS_CONTRACTID "@mozilla.org/winhooks;1"
|
||||
#define NS_IWINDOWSHOOKS_CLASSNAME "Mozilla Windows Integration Hooks"
|
||||
|
||||
// The key that is used to write the quick launch appname in the windows registry
|
||||
#define NS_QUICKLAUNCH_RUN_KEY "Mozilla Quick Launch"
|
||||
%}
|
|
@ -0,0 +1,182 @@
|
|||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Mozilla Default Browser.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corp.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2002
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Bill Law <law@netscape.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
/* This file implements the nsICmdLineHandler interface. See nsICmdLineHandler.idl
|
||||
* at http://lxr.mozilla.org/seamonkey/source/xpfe/appshell/public/nsICmdLineHandler.idl.
|
||||
*
|
||||
* This component handles the startup command line argument of the form:
|
||||
* -setDefaultBrowser
|
||||
* by making the current executable the "default browser." It accomplishes
|
||||
* that via use of the nsIWindowsHooks interface (see implementation below).
|
||||
*
|
||||
* The module is registered under the contractid
|
||||
* "@mozilla.org/commandlinehandler/general-startup;1?type=setDefaultBrowser"
|
||||
*
|
||||
* The implementation consists of a JavaScript "class" named nsKillAll,
|
||||
* comprised of:
|
||||
* - a JS constructor function
|
||||
* - a prototype providing all the interface methods and implementation stuff
|
||||
*
|
||||
* In addition, this file implements an nsIModule object that registers the
|
||||
* nsSetDefaultBrowser component.
|
||||
*/
|
||||
|
||||
/* ctor
|
||||
*/
|
||||
function nsSetDefaultBrowser() {
|
||||
}
|
||||
|
||||
nsSetDefaultBrowser.prototype = {
|
||||
|
||||
// nsICmdLineHandler interface
|
||||
get commandLineArgument() { throw Components.results.NS_ERROR_NOT_IMPLEMENTED; },
|
||||
get prefNameForStartup() { throw Components.results.NS_ERROR_NOT_IMPLEMENTED; },
|
||||
|
||||
get chromeUrlForTask() {
|
||||
// First, get winhooks service.
|
||||
var winHooks = Components.classes[ "@mozilla.org/winhooks;1" ]
|
||||
.getService( Components.interfaces.nsIWindowsHooks );
|
||||
|
||||
// Next, extract current settings (these are what the user
|
||||
// had previously checked on the Advanced/System pref panel).
|
||||
var settings = winHooks.settings;
|
||||
|
||||
// Now, turn on all "default browser" settings.
|
||||
settings.isHandlingHTTP = true;
|
||||
settings.isHandlingHTTPS = true;
|
||||
settings.isHandlingFTP = true;
|
||||
settings.isHandlingHTML = true;
|
||||
settings.isHandlingXHTML = true;
|
||||
settings.isHandlingXML = true;
|
||||
|
||||
// Finally, apply the (new) settings.
|
||||
winHooks.settings = settings;
|
||||
|
||||
// Now, get the cmd line service.
|
||||
var cmdLineService = Components.classes[ "@mozilla.org/appshell/commandLineService;1" ]
|
||||
.getService( Components.interfaces.nsICmdLineService );
|
||||
|
||||
// See if "-setDefaultBrowser" was specified. The value will be "1" if
|
||||
// -setDefaultBrowser is in the service's list of cmd line arguments, and
|
||||
// null otherwise. -setDefaultBrowser will only be in the service's
|
||||
// arg list if the application was not already running. That's because
|
||||
// if it was already running, then the service reflects the arguments
|
||||
// that were specified when *that* process was started, *not* the ones
|
||||
// passed via IPC from the second instance.
|
||||
var option = cmdLineService.getCmdLineValue( "-setDefaultBrowser" );
|
||||
if (!option) {
|
||||
// Already running, so we don't have to worry about opening
|
||||
// another window, etc.
|
||||
throw Components.results.NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
// Return URL for dummy window that will auto-close. We do this rather
|
||||
// than throw NS_ERROR_NOT_AVAILABLE, which *should* work, because it
|
||||
// seems that if we don't open a window, we get a crash when trying to
|
||||
// release this (or some other) JS component during XPCOM shutdown.
|
||||
return "chrome://global/content/dummyWindow.xul";
|
||||
},
|
||||
|
||||
get helpText() { throw Components.results.NS_ERROR_NOT_IMPLEMENTED; },
|
||||
get handlesArgs() { return false; },
|
||||
get defaultArgs() { throw Components.results.NS_ERROR_NOT_IMPLEMENTED; },
|
||||
get openWindowWithArgs() { throw Components.results.NS_ERROR_NOT_IMPLEMENTED; },
|
||||
|
||||
// nsISupports interface
|
||||
|
||||
// This "class" supports nsICmdLineHandler and nsISupports.
|
||||
QueryInterface: function (iid) {
|
||||
if (!iid.equals(Components.interfaces.nsICmdLineHandler) &&
|
||||
!iid.equals(Components.interfaces.nsISupports)) {
|
||||
throw Components.results.NS_ERROR_NO_INTERFACE;
|
||||
}
|
||||
return this;
|
||||
},
|
||||
|
||||
// This Component's module implementation. All the code below is used to get this
|
||||
// component registered and accessible via XPCOM.
|
||||
module: {
|
||||
// registerSelf: Register this component.
|
||||
registerSelf: function (compMgr, fileSpec, location, type) {
|
||||
var compReg = compMgr.QueryInterface( Components.interfaces.nsIComponentRegistrar );
|
||||
compReg.registerFactoryLocation( this.cid,
|
||||
"Default Browser Component",
|
||||
this.contractId,
|
||||
fileSpec,
|
||||
location,
|
||||
type );
|
||||
},
|
||||
|
||||
// getClassObject: Return this component's factory object.
|
||||
getClassObject: function (compMgr, cid, iid) {
|
||||
if (!cid.equals(this.cid))
|
||||
throw Components.results.NS_ERROR_NO_INTERFACE;
|
||||
|
||||
if (!iid.equals(Components.interfaces.nsIFactory))
|
||||
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
|
||||
|
||||
return this.factory;
|
||||
},
|
||||
|
||||
/* CID for this class */
|
||||
cid: Components.ID("{C66E05DC-509C-4972-A1F2-EE5AC34B9800}"),
|
||||
|
||||
/* Contract ID for this class */
|
||||
contractId: "@mozilla.org/commandlinehandler/general-startup;1?type=setDefaultBrowser",
|
||||
|
||||
/* factory object */
|
||||
factory: {
|
||||
// createInstance: Return a new nsSetDefaultBrowser object.
|
||||
createInstance: function (outer, iid) {
|
||||
if (outer != null)
|
||||
throw Components.results.NS_ERROR_NO_AGGREGATION;
|
||||
|
||||
return (new nsSetDefaultBrowser()).QueryInterface(iid);
|
||||
}
|
||||
},
|
||||
|
||||
// canUnload: n/a (returns true)
|
||||
canUnload: function(compMgr) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// NSGetModule: Return the nsIModule object.
|
||||
function NSGetModule(compMgr, fileSpec) {
|
||||
return nsSetDefaultBrowser.prototype.module;
|
||||
}
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,136 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.1 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Aaron Kaluszka <ask@swva.net>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef nswindowshooks_h____
|
||||
#define nswindowshooks_h____
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nsIWindowsHooks.h"
|
||||
|
||||
#ifndef MAX_BUF
|
||||
#define MAX_BUF 4096
|
||||
#endif
|
||||
|
||||
/* c09bc130-0a71-11d4-8076-00600811a9c3 */
|
||||
#define NS_IWINDOWSHOOKS_CID \
|
||||
{ 0xc09bc130, 0x0a71, 0x11d4, {0x80, 0x76, 0x00, 0x60, 0x08, 0x11, 0xa9, 0xc3} }
|
||||
|
||||
class nsWindowsHooksSettings : public nsIWindowsHooksSettings {
|
||||
public:
|
||||
// ctor/dtor
|
||||
nsWindowsHooksSettings();
|
||||
virtual ~nsWindowsHooksSettings();
|
||||
|
||||
// Declare all interface methods we must implement.
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIWINDOWSHOOKSSETTINGS
|
||||
|
||||
// Typedef for nsIWindowsHooksSettings getter/setter member functions.
|
||||
typedef
|
||||
NS_STDCALL_FUNCPROTO(nsresult,
|
||||
getter,
|
||||
nsIWindowsHooksSettings, GetShowDialog,
|
||||
(PRBool*));
|
||||
|
||||
typedef
|
||||
NS_STDCALL_FUNCPROTO(nsresult,
|
||||
setter,
|
||||
nsIWindowsHooksSettings, SetShowDialog,
|
||||
(PRBool));
|
||||
|
||||
protected:
|
||||
// General purpose getter.
|
||||
NS_IMETHOD Get( PRBool *result, PRBool nsWindowsHooksSettings::*member );
|
||||
// General purpose setter.
|
||||
NS_IMETHOD Set( PRBool value, PRBool nsWindowsHooksSettings::*member );
|
||||
|
||||
private:
|
||||
// Internet shortcut protocols.
|
||||
PRBool mHandleHTTP;
|
||||
PRBool mHandleHTTPS;
|
||||
PRBool mHandleFTP;
|
||||
PRBool mHandleCHROME;
|
||||
PRBool mHandleGOPHER;
|
||||
// File types.
|
||||
PRBool mHandleHTML;
|
||||
PRBool mHandleJPEG;
|
||||
PRBool mHandleGIF;
|
||||
PRBool mHandlePNG;
|
||||
PRBool mHandleMNG;
|
||||
PRBool mHandleXBM;
|
||||
PRBool mHandleBMP;
|
||||
PRBool mHandleICO;
|
||||
PRBool mHandleXML;
|
||||
PRBool mHandleXHTML;
|
||||
PRBool mHandleXUL;
|
||||
// Dialog
|
||||
PRBool mShowDialog;
|
||||
|
||||
// Special member to handle initialization.
|
||||
PRBool mHaveBeenSet;
|
||||
NS_IMETHOD GetHaveBeenSet( PRBool * );
|
||||
NS_IMETHOD SetHaveBeenSet( PRBool );
|
||||
|
||||
// Give nsWindowsHooks full access.
|
||||
friend class nsWindowsHooks;
|
||||
}; // nsWindowsHooksSettings
|
||||
|
||||
class nsWindowsHooks : public nsIWindowsHooks, public nsIWindowsRegistry {
|
||||
public:
|
||||
// ctor/dtor
|
||||
nsWindowsHooks();
|
||||
virtual ~nsWindowsHooks();
|
||||
|
||||
// Declare all interface methods we must implement.
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIWINDOWSHOOKS
|
||||
NS_DECL_NSIWINDOWSREGISTRY
|
||||
|
||||
protected:
|
||||
// Internal flavor of GetPreferences.
|
||||
NS_IMETHOD GetSettings( nsWindowsHooksSettings ** );
|
||||
|
||||
// Set registry according to settings.
|
||||
NS_IMETHOD SetRegistry();
|
||||
char mShortcutPath[MAX_BUF];
|
||||
char mShortcutName[MAX_BUF];
|
||||
char mShortcutBase[MAX_BUF];
|
||||
char mShortcutProg[MAX_BUF];
|
||||
}; // nsWindowsHooksSettings
|
||||
|
||||
#endif // nswindowshooks_h____
|
|
@ -0,0 +1,829 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.1 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Bill Law <law@netscape.com>
|
||||
* Dean Tessman <dean_tessman@hotmail.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
#include <windows.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "nsString.h"
|
||||
#include "nsINativeAppSupportWin.h"
|
||||
#include "nsIStringBundle.h"
|
||||
#include "nsDirectoryService.h"
|
||||
#include "nsAppDirectoryServiceDefs.h"
|
||||
|
||||
#define MOZ_HWND_BROADCAST_MSG_TIMEOUT 5000
|
||||
#define MOZ_CLIENT_BROWSER_KEY "Software\\Clients\\StartMenuInternet"
|
||||
|
||||
// Where Mozilla stores its own registry values.
|
||||
const char * const mozillaKeyName = "Software\\Mozilla\\Desktop";
|
||||
|
||||
static const char shortcutSuffix[] = " -url \"%1\"";
|
||||
static const char chromeSuffix[] = " -chrome \"%1\"";
|
||||
static const char iconSuffix[] = ",0";
|
||||
|
||||
// Returns the (fully-qualified) name of this executable.
|
||||
static nsCString thisApplication() {
|
||||
static nsCAutoString result;
|
||||
|
||||
if ( result.IsEmpty() ) {
|
||||
char buffer[MAX_PATH] = { 0 };
|
||||
DWORD len = ::GetModuleFileName( NULL, buffer, sizeof buffer );
|
||||
len = ::GetShortPathName( buffer, buffer, sizeof buffer );
|
||||
|
||||
result = buffer;
|
||||
ToUpperCase(result);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Returns the "short" name of this application (in upper case). This is for
|
||||
// use as a StartMenuInternet value.
|
||||
static nsCString shortAppName() {
|
||||
static nsCAutoString result;
|
||||
|
||||
if ( result.IsEmpty() ) {
|
||||
// Find last backslash in thisApplication().
|
||||
nsCAutoString thisApp( thisApplication() );
|
||||
PRInt32 n = thisApp.RFind( "\\" );
|
||||
if ( n != kNotFound ) {
|
||||
// Use what comes after the last backslash.
|
||||
result = (const char*)thisApp.get() + n + 1;
|
||||
} else {
|
||||
// Use entire string.
|
||||
result = thisApp;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// RegistryEntry
|
||||
//
|
||||
// Generic registry entry (no saving of previous values). Each is comprised of:
|
||||
// o A base HKEY
|
||||
// o A subkey name.
|
||||
// o An optional value name (empty for the "default" value).
|
||||
// o The registry setting we'd like this entry to have when set.
|
||||
struct RegistryEntry {
|
||||
HKEY baseKey; // e.g., HKEY_CURRENT_USER
|
||||
PRBool isNull; // i.e., should use ::RegDeleteValue
|
||||
nsCString keyName; // Key name.
|
||||
nsCString valueName; // Value name (can be empty, which implies NULL).
|
||||
nsCString setting; // What we set it to.
|
||||
|
||||
RegistryEntry( HKEY baseKey, const char* keyName, const char* valueName, const char* setting )
|
||||
: baseKey( baseKey ), isNull( setting == 0 ), keyName( keyName ), valueName( valueName ), setting( setting ? setting : "" ) {
|
||||
}
|
||||
|
||||
PRBool isAlreadySet() const;
|
||||
nsresult set();
|
||||
nsresult reset();
|
||||
nsCString currentSetting( PRBool *currentUndefined = 0 ) const;
|
||||
|
||||
// Return value name in proper form for passing to ::Reg functions
|
||||
// (i.e., emptry string is converted to a NULL pointer).
|
||||
const char* valueNameArg() const {
|
||||
return valueName.IsEmpty() ? NULL : valueName.get();
|
||||
}
|
||||
|
||||
nsCString fullName() const;
|
||||
};
|
||||
|
||||
// BoolRegistryEntry
|
||||
//
|
||||
// These are used to store the "windows integration" preferences.
|
||||
// You can query the value via operator void* (i.e., if ( boolPref )... ).
|
||||
// These are stored under HKEY_LOCAL_MACHINE\Software\Mozilla\Desktop.
|
||||
// Set sets the stored value to "1". Reset deletes it (which implies 0).
|
||||
struct BoolRegistryEntry : public RegistryEntry {
|
||||
BoolRegistryEntry( const char *name )
|
||||
: RegistryEntry( HKEY_LOCAL_MACHINE, mozillaKeyName, name, "1" ) {
|
||||
}
|
||||
operator PRBool();
|
||||
};
|
||||
|
||||
// SavedRegistryEntry
|
||||
//
|
||||
// Like a plain RegistryEntry, but set/reset save/restore the
|
||||
// it had before we set it.
|
||||
struct SavedRegistryEntry : public RegistryEntry {
|
||||
SavedRegistryEntry( HKEY baseKey, const char *keyName, const char *valueName, const char *setting )
|
||||
: RegistryEntry( baseKey, keyName, valueName, setting ) {
|
||||
}
|
||||
nsresult set();
|
||||
nsresult reset();
|
||||
};
|
||||
|
||||
// ProtocolRegistryEntry
|
||||
//
|
||||
// For setting entries for a given Internet Shortcut protocol.
|
||||
// The key name is calculated as
|
||||
// HKEY_LOCAL_MACHINE\Software\Classes\protocol\shell\open\command.
|
||||
// The setting is this executable (with appropriate suffix).
|
||||
// Set/reset are trickier in this case.
|
||||
struct ProtocolRegistryEntry : public SavedRegistryEntry {
|
||||
nsCString protocol;
|
||||
ProtocolRegistryEntry( const char* protocol )
|
||||
: SavedRegistryEntry( HKEY_LOCAL_MACHINE, "", "", thisApplication().get() ),
|
||||
protocol( protocol ) {
|
||||
keyName = "Software\\Classes\\";
|
||||
keyName += protocol;
|
||||
keyName += "\\shell\\open\\command";
|
||||
|
||||
// Append appropriate suffix to setting.
|
||||
if ( this->protocol.Equals( "chrome" ) || this->protocol.Equals( "MozillaXUL" ) ) {
|
||||
// Use "-chrome" command line flag.
|
||||
setting += chromeSuffix;
|
||||
} else {
|
||||
// Use standard "-url" command line flag.
|
||||
setting += shortcutSuffix;
|
||||
}
|
||||
}
|
||||
nsresult set();
|
||||
nsresult reset();
|
||||
};
|
||||
|
||||
// ProtocolIconRegistryEntry
|
||||
//
|
||||
// For setting icon entries for a given Internet Shortcut protocol.
|
||||
// The key name is calculated as
|
||||
// HKEY_LOCAL_MACHINE\Software\Classes\protocol\DefaultIcon.
|
||||
// The setting is this executable (with appropriate suffix).
|
||||
struct ProtocolIconRegistryEntry : public SavedRegistryEntry {
|
||||
nsCString protocol;
|
||||
ProtocolIconRegistryEntry( const char* aprotocol )
|
||||
: SavedRegistryEntry( HKEY_LOCAL_MACHINE, "", "", thisApplication().get() ),
|
||||
protocol( aprotocol ) {
|
||||
keyName = NS_LITERAL_CSTRING("Software\\Classes\\") + protocol + NS_LITERAL_CSTRING("\\DefaultIcon");
|
||||
|
||||
// Append appropriate suffix to setting.
|
||||
setting += iconSuffix;
|
||||
}
|
||||
};
|
||||
|
||||
// DDERegistryEntry
|
||||
//
|
||||
// Like a protocol registry entry, but for the shell\open\ddeexec subkey.
|
||||
//
|
||||
// We need to remove this subkey entirely to ensure we work properly with
|
||||
// various programs on various platforms (see Bugzilla bugs 59078, 58770, etc.).
|
||||
//
|
||||
// We don't try to save everything, though. We do save the known useful info
|
||||
// under the ddeexec subkey:
|
||||
// ddeexec\@
|
||||
// ddeexec\NoActivateHandler
|
||||
// ddeexec\Application\@
|
||||
// ddeexec\Topic\@
|
||||
//
|
||||
// set/reset save/restore these values and remove/restore the ddeexec subkey
|
||||
struct DDERegistryEntry : public SavedRegistryEntry {
|
||||
DDERegistryEntry( const char *protocol )
|
||||
: SavedRegistryEntry( HKEY_LOCAL_MACHINE, "", "", 0 ),
|
||||
activate( HKEY_LOCAL_MACHINE, "", "NoActivateHandler", 0 ),
|
||||
app( HKEY_LOCAL_MACHINE, "", "", 0 ),
|
||||
topic( HKEY_LOCAL_MACHINE, "", "", 0 ) {
|
||||
// Derive keyName from protocol.
|
||||
keyName = "Software\\Classes\\";
|
||||
keyName += protocol;
|
||||
keyName += "\\shell\\open\\ddeexec";
|
||||
// Set subkey names.
|
||||
activate.keyName = keyName;
|
||||
app.keyName = keyName;
|
||||
app.keyName += "\\Application";
|
||||
topic.keyName = keyName;
|
||||
topic.keyName += "\\Topic";
|
||||
}
|
||||
nsresult set();
|
||||
nsresult reset();
|
||||
SavedRegistryEntry activate, app, topic;
|
||||
};
|
||||
|
||||
// FileTypeRegistryEntry
|
||||
//
|
||||
// For setting entries relating to a file extension (or extensions).
|
||||
// This object itself is for the "file type" associated with the extension.
|
||||
// Set/reset manage the mapping from extension to the file type, as well.
|
||||
// The description is taken from defDescKey if available. Otherwise desc
|
||||
// is used.
|
||||
struct FileTypeRegistryEntry : public ProtocolRegistryEntry {
|
||||
nsCString fileType;
|
||||
const char **ext;
|
||||
nsCString desc;
|
||||
nsCString defDescKey;
|
||||
nsCString iconFile;
|
||||
FileTypeRegistryEntry ( const char **ext, const char *fileType,
|
||||
const char *desc, const char *defDescKey, const char *iconFile )
|
||||
: ProtocolRegistryEntry( fileType ),
|
||||
fileType( fileType ),
|
||||
ext( ext ),
|
||||
desc( desc ),
|
||||
defDescKey(defDescKey),
|
||||
iconFile(iconFile) {
|
||||
}
|
||||
nsresult set();
|
||||
nsresult reset();
|
||||
};
|
||||
|
||||
// EditableFileTypeRegistryEntry
|
||||
//
|
||||
// Extends FileTypeRegistryEntry by setting an additional handler for an "edit" command.
|
||||
struct EditableFileTypeRegistryEntry : public FileTypeRegistryEntry {
|
||||
EditableFileTypeRegistryEntry( const char **ext, const char *fileType,
|
||||
const char *desc, const char *defDescKey, const char *iconFile )
|
||||
: FileTypeRegistryEntry( ext, fileType, desc, defDescKey, iconFile ) {
|
||||
}
|
||||
nsresult set();
|
||||
};
|
||||
|
||||
// Generate the "full" name of this registry entry.
|
||||
nsCString RegistryEntry::fullName() const {
|
||||
nsCString result;
|
||||
if ( baseKey == HKEY_CURRENT_USER ) {
|
||||
result = "HKEY_CURRENT_USER\\";
|
||||
} else if ( baseKey == HKEY_LOCAL_MACHINE ) {
|
||||
result = "HKEY_LOCAL_MACHINE\\";
|
||||
} else {
|
||||
result = "\\";
|
||||
}
|
||||
result += keyName;
|
||||
if ( !valueName.IsEmpty() ) {
|
||||
result += "[";
|
||||
result += valueName;
|
||||
result += "]";
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// Tests whether registry entry already has desired setting.
|
||||
PRBool RegistryEntry::isAlreadySet() const {
|
||||
PRBool result = FALSE;
|
||||
|
||||
nsCAutoString current( currentSetting() );
|
||||
|
||||
result = ( current == setting );
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Gives registry entry the desired setting.
|
||||
nsresult RegistryEntry::set() {
|
||||
#ifdef DEBUG_law
|
||||
if ( isNull && setting.IsEmpty() ) printf( "Deleting %s\n", fullName().get() );
|
||||
else printf( "Setting %s=%s\n", fullName().get(), setting.get() );
|
||||
#endif
|
||||
nsresult result = NS_ERROR_FAILURE;
|
||||
|
||||
HKEY key;
|
||||
LONG rc = ::RegOpenKey( baseKey, keyName.get(), &key );
|
||||
|
||||
// See if key doesn't exist yet...
|
||||
if ( rc == ERROR_FILE_NOT_FOUND ) {
|
||||
rc = ::RegCreateKey( baseKey, keyName.get(), &key );
|
||||
}
|
||||
if ( rc == ERROR_SUCCESS ) {
|
||||
if ( isNull && setting.IsEmpty() ) {
|
||||
// This means we need to actually remove the value, not merely set it to an
|
||||
// empty string.
|
||||
rc = ::RegDeleteValue( key, valueNameArg() );
|
||||
if ( rc == ERROR_SUCCESS ) {
|
||||
result = NS_OK;
|
||||
}
|
||||
} else {
|
||||
// Get current value to see if it is set properly already.
|
||||
char buffer[4096] = { 0 };
|
||||
DWORD len = sizeof buffer;
|
||||
rc = ::RegQueryValueEx( key, valueNameArg(), NULL, NULL, (LPBYTE)buffer, &len );
|
||||
if ( rc != ERROR_SUCCESS || strcmp( setting.get(), buffer ) != 0 ) {
|
||||
rc = ::RegSetValueEx( key, valueNameArg(), 0, REG_SZ, (LPBYTE)setting.get(), setting.Length() );
|
||||
#ifdef DEBUG_law
|
||||
NS_WARN_IF_FALSE( rc == ERROR_SUCCESS, fullName().get() );
|
||||
#endif
|
||||
if ( rc == ERROR_SUCCESS ) {
|
||||
result = NS_OK;
|
||||
}
|
||||
} else {
|
||||
// Already has desired setting.
|
||||
result = NS_OK;
|
||||
}
|
||||
}
|
||||
::RegCloseKey( key );
|
||||
} else {
|
||||
#ifdef DEBUG_law
|
||||
NS_WARN_IF_FALSE( rc == ERROR_SUCCESS, fullName().get() );
|
||||
#endif
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// Get current setting, set new one, then save the previous.
|
||||
nsresult SavedRegistryEntry::set() {
|
||||
nsresult rv = NS_OK;
|
||||
PRBool currentlyUndefined = PR_TRUE;
|
||||
nsCAutoString prev( currentSetting( ¤tlyUndefined ) );
|
||||
// See if value is changing.
|
||||
// We need an extra check for the case where we have an empty entry
|
||||
// and we need to remove it entirely.
|
||||
if ( setting != prev || ( !currentlyUndefined && isNull ) ) {
|
||||
// Set new.
|
||||
rv = RegistryEntry::set();
|
||||
if ( NS_SUCCEEDED( rv ) ) {
|
||||
// Save old.
|
||||
RegistryEntry tmp( HKEY_LOCAL_MACHINE, "Software\\Mozilla\\Desktop", fullName().get(), prev.get() );
|
||||
tmp.set();
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
// setWindowsXP
|
||||
//
|
||||
// We need to:
|
||||
// a. Make sure this application is registered as a "Start Menu
|
||||
// internet app" under HKLM\Software\Clients\StartMenuInternet.
|
||||
// b. Make this app the default "Start Menu internet app" for this
|
||||
// user.
|
||||
static void setWindowsXP() {
|
||||
// We test for the presence of this subkey as a WindowsXP test.
|
||||
// We do it this way so that vagueries of future Windows versions
|
||||
// are handled as best we can.
|
||||
HKEY key;
|
||||
nsCAutoString baseKey( NS_LITERAL_CSTRING( "Software\\Clients\\StartMenuInternet" ) );
|
||||
LONG rc = ::RegOpenKey( HKEY_LOCAL_MACHINE, baseKey.get(), &key );
|
||||
if ( rc == ERROR_SUCCESS ) {
|
||||
// OK, this is WindowsXP (or equivalent). Add this application to the
|
||||
// set registered as "Start Menu internet apps." These entries go
|
||||
// under the subkey MOZILLA.EXE (or whatever the name of this executable is),
|
||||
// that subkey name is generated by the utility function shortAppName.
|
||||
if ( rc == ERROR_SUCCESS ) {
|
||||
// The next 3 go under this subkey.
|
||||
nsCAutoString subkey( baseKey + NS_LITERAL_CSTRING( "\\" ) + shortAppName() );
|
||||
// Pretty name. This goes into the LocalizedString value. It is the
|
||||
// name of the executable (preceded by '@'), followed by ",-nnn" where
|
||||
// nnn is the resource identifier of the string in the .exe. That value
|
||||
// comes from nsINativeAppSupportWin.h.
|
||||
char buffer[ _MAX_PATH + 8 ]; // Path, plus '@', comma, minus, and digits (5)
|
||||
_snprintf( buffer, sizeof buffer, "@%s,-%d", thisApplication().get(), IDS_STARTMENU_APPNAME );
|
||||
RegistryEntry tmp_entry1( HKEY_LOCAL_MACHINE,
|
||||
subkey.get(),
|
||||
"LocalizedString",
|
||||
buffer );
|
||||
tmp_entry1.set();
|
||||
// Default icon (from .exe resource).
|
||||
RegistryEntry tmp_entry2( HKEY_LOCAL_MACHINE,
|
||||
nsCAutoString( subkey + NS_LITERAL_CSTRING( "\\DefaultIcon" ) ).get(),
|
||||
"",
|
||||
nsCAutoString( thisApplication() + NS_LITERAL_CSTRING( ",0" ) ).get() );
|
||||
tmp_entry2.set();
|
||||
// Command to open.
|
||||
RegistryEntry tmp_entry3( HKEY_LOCAL_MACHINE,
|
||||
nsCAutoString( subkey + NS_LITERAL_CSTRING( "\\shell\\open\\command" ) ).get(),
|
||||
"",
|
||||
thisApplication().get() );
|
||||
tmp_entry3.set();
|
||||
// "Properties" verb. The default value is the text that will appear in the menu.
|
||||
// The default value under the command subkey is the name of this application, with
|
||||
// arguments to cause the Preferences window to appear.
|
||||
nsCOMPtr<nsIStringBundleService> bundleService( do_GetService( "@mozilla.org/intl/stringbundle;1" ) );
|
||||
nsCOMPtr<nsIStringBundle> bundle;
|
||||
nsXPIDLString label;
|
||||
if ( bundleService &&
|
||||
NS_SUCCEEDED( bundleService->CreateBundle( "chrome://global-platform/locale/nsWindowsHooks.properties",
|
||||
getter_AddRefs( bundle ) ) ) &&
|
||||
NS_SUCCEEDED( bundle->GetStringFromName( NS_LITERAL_STRING( "prefsLabel" ).get(), getter_Copies( label ) ) ) ) {
|
||||
// Set the label that will appear in the start menu context menu.
|
||||
RegistryEntry tmp_entry4( HKEY_LOCAL_MACHINE,
|
||||
nsCAutoString( subkey + NS_LITERAL_CSTRING( "\\shell\\properties" ) ).get(),
|
||||
"",
|
||||
NS_ConvertUCS2toUTF8( label ).get() );
|
||||
tmp_entry4.set();
|
||||
}
|
||||
RegistryEntry tmp_entry5( HKEY_LOCAL_MACHINE,
|
||||
nsCAutoString( subkey + NS_LITERAL_CSTRING( "\\shell\\properties\\command" ) ).get(),
|
||||
"", nsCAutoString( thisApplication() +
|
||||
#ifndef MOZ_PHOENIX
|
||||
NS_LITERAL_CSTRING(" -chrome \"chrome://communicator/content/pref/pref.xul\"") ).get()
|
||||
#else
|
||||
NS_LITERAL_CSTRING(" -chrome \"chrome://browser/content/pref/pref.xul\"") ).get()
|
||||
#endif
|
||||
);
|
||||
tmp_entry5.set();
|
||||
|
||||
// Now we need to select our application as the default start menu internet application.
|
||||
// This is accomplished by first trying to store our subkey name in
|
||||
// HKLM\Software\Clients\StartMenuInternet's default value. See
|
||||
// http://support.microsoft.com/directory/article.asp?ID=KB;EN-US;Q297878 for detail.
|
||||
SavedRegistryEntry hklmAppEntry( HKEY_LOCAL_MACHINE, baseKey.get(), "", shortAppName().get() );
|
||||
hklmAppEntry.set();
|
||||
// That may or may not have worked (depending on whether we have sufficient access).
|
||||
if ( hklmAppEntry.currentSetting() == hklmAppEntry.setting ) {
|
||||
// We've set the hklm entry, so we can delete the one under hkcu.
|
||||
SavedRegistryEntry tmp_entry6( HKEY_CURRENT_USER, baseKey.get(), "", 0 );
|
||||
tmp_entry6.set();
|
||||
} else {
|
||||
// All we can do is set the default start menu internet app for this user.
|
||||
SavedRegistryEntry tmp_entry7( HKEY_CURRENT_USER, baseKey.get(), "", shortAppName().get() );
|
||||
}
|
||||
// Notify the system of the changes.
|
||||
::SendMessageTimeout( HWND_BROADCAST,
|
||||
WM_SETTINGCHANGE,
|
||||
0,
|
||||
(LPARAM)MOZ_CLIENT_BROWSER_KEY,
|
||||
SMTO_NORMAL|SMTO_ABORTIFHUNG,
|
||||
MOZ_HWND_BROADCAST_MSG_TIMEOUT,
|
||||
NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Set this entry and its corresponding DDE entry. The DDE entry
|
||||
// must be turned off to stop Windows from trying to use DDE.
|
||||
nsresult ProtocolRegistryEntry::set() {
|
||||
// If the protocol is http, then we have to do special stuff.
|
||||
// We must take care of this first because setting the "protocol entry"
|
||||
// for http will cause WindowsXP to do stuff automatically for us,
|
||||
// thereby making it impossible for us to propertly reset.
|
||||
if ( protocol == NS_LITERAL_CSTRING( "http" ) ) {
|
||||
setWindowsXP();
|
||||
}
|
||||
|
||||
// Set this entry.
|
||||
nsresult rv = SavedRegistryEntry::set();
|
||||
|
||||
// Save and set corresponding DDE entry(ies).
|
||||
DDERegistryEntry( protocol.get() ).set();
|
||||
// Set icon.
|
||||
ProtocolIconRegistryEntry( protocol.get() ).set();
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
// Not being a "saved" entry, we can't restore, so just delete it.
|
||||
nsresult RegistryEntry::reset() {
|
||||
HKEY key;
|
||||
LONG rc = ::RegOpenKey( baseKey, keyName.get(), &key );
|
||||
if ( rc == ERROR_SUCCESS ) {
|
||||
rc = ::RegDeleteValue( key, valueNameArg() );
|
||||
#ifdef DEBUG_law
|
||||
if ( rc == ERROR_SUCCESS ) printf( "Deleting key=%s\n", (const char*)fullName().get() );
|
||||
#endif
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Resets registry entry to the saved value (if there is one). We first
|
||||
// ensure that we still "own" that entry (by comparing its value to what
|
||||
// we would set it to).
|
||||
nsresult SavedRegistryEntry::reset() {
|
||||
nsresult result = NS_OK;
|
||||
|
||||
// Get current setting for this key/value.
|
||||
nsCAutoString current( currentSetting() );
|
||||
|
||||
// Test if we "own" it.
|
||||
if ( current == setting ) {
|
||||
// Unset it, then. First get saved value it had previously.
|
||||
PRBool noSavedValue = PR_TRUE;
|
||||
RegistryEntry saved = RegistryEntry( HKEY_LOCAL_MACHINE, mozillaKeyName, fullName().get(), "" );
|
||||
// There are 3 cases:
|
||||
// - no saved entry
|
||||
// - empty saved entry
|
||||
// - a non-empty saved entry
|
||||
// We delete the current entry in the first case, and restore
|
||||
// the saved entry (empty or otherwise) in the other two.
|
||||
setting = saved.currentSetting( &noSavedValue );
|
||||
if ( !setting.IsEmpty() || !noSavedValue ) {
|
||||
// Set to previous value.
|
||||
isNull = PR_FALSE; // Since we're resetting and the saved value may be empty, we
|
||||
// need to make sure set() doesn't mistakenly delete this entry.
|
||||
result = RegistryEntry::set();
|
||||
// Remove saved entry.
|
||||
saved.reset();
|
||||
} else {
|
||||
// No saved value, just delete this entry.
|
||||
result = RegistryEntry::reset();
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// resetWindowsXP
|
||||
//
|
||||
// This function undoes "setWindowsXP," more or less. It only needs to restore the selected
|
||||
// default Start Menu internet application. The registration of this application as one of
|
||||
// the start menu internet apps can remain. There is no check for the presence of anything
|
||||
// because the SaveRegistryEntry::reset calls will have no effect if there is no value at that
|
||||
// location (or, if that value has been changed by another application).
|
||||
static void resetWindowsXP() {
|
||||
NS_NAMED_LITERAL_CSTRING( baseKey, "Software\\Clients\\StartMenuInternet" );
|
||||
// First, try to restore the HKLM setting. This will fail if either we didn't
|
||||
// set that, or, if we don't have access).
|
||||
SavedRegistryEntry tmp_entry8( HKEY_LOCAL_MACHINE, baseKey.get(), "", shortAppName().get() );
|
||||
tmp_entry8.reset();
|
||||
|
||||
// The HKCU setting is trickier. We may have set it, but we may also have
|
||||
// removed it (see setWindowsXP(), above). We first try to reverse the
|
||||
// setting. If we had removed it, then this will fail.
|
||||
SavedRegistryEntry tmp_entry9( HKEY_CURRENT_USER, baseKey.get(), "", shortAppName().get() );
|
||||
tmp_entry9.reset();
|
||||
// Now, try to reverse the removal of this key. This will fail if there is a current
|
||||
// setting, and will only work if this key is unset, and, we have a saved value.
|
||||
SavedRegistryEntry tmp_entry10( HKEY_CURRENT_USER, baseKey.get(), "", 0 );
|
||||
tmp_entry10.reset();
|
||||
|
||||
// Notify the system of the changes.
|
||||
::SendMessageTimeout( HWND_BROADCAST,
|
||||
WM_SETTINGCHANGE,
|
||||
0,
|
||||
(LPARAM)MOZ_CLIENT_BROWSER_KEY,
|
||||
SMTO_NORMAL|SMTO_ABORTIFHUNG,
|
||||
MOZ_HWND_BROADCAST_MSG_TIMEOUT,
|
||||
NULL);
|
||||
}
|
||||
|
||||
// Restore this entry and corresponding DDE entry.
|
||||
nsresult ProtocolRegistryEntry::reset() {
|
||||
// Restore this entry.
|
||||
nsresult rv = SavedRegistryEntry::reset();
|
||||
|
||||
// Do same for corresponding DDE entry.
|
||||
DDERegistryEntry( protocol.get() ).reset();
|
||||
// Reset icon.
|
||||
ProtocolIconRegistryEntry( protocol.get() ).reset();
|
||||
|
||||
// For http:, on WindowsXP, we need to do some extra cleanup.
|
||||
if ( protocol == NS_LITERAL_CSTRING( "http" ) ) {
|
||||
resetWindowsXP();
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
static DWORD deleteKey( HKEY baseKey, const char *keyName ) {
|
||||
// Make sure input subkey isn't null.
|
||||
DWORD rc;
|
||||
if ( keyName && ::strlen(keyName) ) {
|
||||
// Open subkey.
|
||||
HKEY key;
|
||||
rc = ::RegOpenKeyEx( baseKey,
|
||||
keyName,
|
||||
0,
|
||||
KEY_ENUMERATE_SUB_KEYS | DELETE,
|
||||
&key );
|
||||
// Continue till we get an error or are done.
|
||||
while ( rc == ERROR_SUCCESS ) {
|
||||
char subkeyName[_MAX_PATH];
|
||||
DWORD len = sizeof subkeyName;
|
||||
// Get first subkey name. Note that we always get the
|
||||
// first one, then delete it. So we need to get
|
||||
// the first one next time, also.
|
||||
rc = ::RegEnumKeyEx( key,
|
||||
0,
|
||||
subkeyName,
|
||||
&len,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0 );
|
||||
if ( rc == ERROR_NO_MORE_ITEMS ) {
|
||||
// No more subkeys. Delete the main one.
|
||||
rc = ::RegDeleteKey( baseKey, keyName );
|
||||
break;
|
||||
} else if ( rc == ERROR_SUCCESS ) {
|
||||
// Another subkey, delete it, recursively.
|
||||
rc = deleteKey( key, subkeyName );
|
||||
}
|
||||
}
|
||||
// Close the key we opened.
|
||||
::RegCloseKey( key );
|
||||
} else {
|
||||
rc = ERROR_BADKEY;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
// Set the "dde" entry by deleting the main ddexec subkey
|
||||
// under HKLM\Software\Classes\<protocol>\shell\open.
|
||||
// We "set" the various subkeys in order to preserve useful
|
||||
// information.
|
||||
nsresult DDERegistryEntry::set() {
|
||||
nsresult rv = SavedRegistryEntry::set();
|
||||
rv = activate.set();
|
||||
rv = app.set();
|
||||
rv = topic.set();
|
||||
// We've saved what we can. Now recurse through this key and
|
||||
// subkeys. This is necessary due to the fact that
|
||||
// ::RegDeleteKey won't work on WinNT (and Win2k?) if there are
|
||||
// subkeys.
|
||||
if ( deleteKey( baseKey, keyName.get() ) != ERROR_SUCCESS ) {
|
||||
rv = NS_ERROR_FAILURE;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
// Reset the main (ddeexec) value but also the Application and Topic.
|
||||
// We reset the app/topic even though we no longer set them. This
|
||||
// handles cases where the user installed a prior version, and then
|
||||
// upgraded.
|
||||
nsresult DDERegistryEntry::reset() {
|
||||
nsresult rv = SavedRegistryEntry::reset();
|
||||
rv = activate.reset();
|
||||
rv = app.reset();
|
||||
rv = topic.reset();
|
||||
return rv;
|
||||
}
|
||||
|
||||
// Return current setting for this registry entry.
|
||||
// Optionally, the caller can ask that a boolean be set to indicate whether
|
||||
// the registry value is undefined. This flag can be used to distinguish
|
||||
// between not defined at all versus simply empty (both of which return an
|
||||
// empty string).
|
||||
nsCString RegistryEntry::currentSetting( PRBool *currentlyUndefined ) const {
|
||||
nsCString result;
|
||||
|
||||
if ( currentlyUndefined ) {
|
||||
*currentlyUndefined = PR_TRUE;
|
||||
}
|
||||
|
||||
HKEY key;
|
||||
LONG rc = ::RegOpenKey( baseKey, keyName.get(), &key );
|
||||
if ( rc == ERROR_SUCCESS ) {
|
||||
char buffer[4096] = { 0 };
|
||||
DWORD len = sizeof buffer;
|
||||
rc = ::RegQueryValueEx( key, valueNameArg(), NULL, NULL, (LPBYTE)buffer, &len );
|
||||
if ( rc == ERROR_SUCCESS ) {
|
||||
result = buffer;
|
||||
if ( currentlyUndefined ) {
|
||||
*currentlyUndefined = PR_FALSE; // Indicate entry is present.
|
||||
}
|
||||
}
|
||||
::RegCloseKey( key );
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// For each file extension, map it to this entry's file type.
|
||||
// Set the file type so this application opens files of that type.
|
||||
nsresult FileTypeRegistryEntry::set() {
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
// Set file extensions.
|
||||
for ( int i = 0; NS_SUCCEEDED( rv ) && ext[i]; i++ ) {
|
||||
nsCAutoString thisExt( "Software\\Classes\\" );
|
||||
thisExt += ext[i];
|
||||
rv = SavedRegistryEntry( HKEY_LOCAL_MACHINE, thisExt.get(), "", fileType.get() ).set();
|
||||
}
|
||||
|
||||
// If OK, set file type opener.
|
||||
if ( NS_SUCCEEDED( rv ) ) {
|
||||
rv = ProtocolRegistryEntry::set();
|
||||
|
||||
// If we just created this file type entry, set description and default icon.
|
||||
if ( NS_SUCCEEDED( rv ) ) {
|
||||
nsCAutoString iconFileToUse( "%1" );
|
||||
nsCAutoString descKey( "Software\\Classes\\" );
|
||||
descKey += protocol;
|
||||
RegistryEntry descEntry( HKEY_LOCAL_MACHINE, descKey.get(), NULL, "" );
|
||||
if ( descEntry.currentSetting().IsEmpty() ) {
|
||||
nsCAutoString defaultDescKey( "Software\\Classes\\" );
|
||||
defaultDescKey += defDescKey;
|
||||
RegistryEntry defaultDescEntry( HKEY_LOCAL_MACHINE, defaultDescKey.get(), NULL, "" );
|
||||
|
||||
descEntry.setting = defaultDescEntry.currentSetting();
|
||||
if ( descEntry.setting.IsEmpty() )
|
||||
descEntry.setting = desc;
|
||||
descEntry.set();
|
||||
}
|
||||
nsCAutoString iconKey( "Software\\Classes\\" );
|
||||
iconKey += protocol;
|
||||
iconKey += "\\DefaultIcon";
|
||||
|
||||
if ( !iconFile.Equals(iconFileToUse) ) {
|
||||
iconFileToUse = thisApplication() + NS_LITERAL_CSTRING( ",0" );
|
||||
|
||||
// Check to see if there's an icon file name associated with this extension.
|
||||
// If there is, then we need to use this icon file. If not, then we default
|
||||
// to the main app's icon.
|
||||
if ( !iconFile.IsEmpty() ) {
|
||||
nsCOMPtr<nsIFile> iconFileSpec;
|
||||
PRBool flagExists;
|
||||
|
||||
// Use the directory service to get the path to the chrome folder. The
|
||||
// icons will be located in [chrome dir]\icons\default.
|
||||
// The abs path to the icon has to be in the short filename
|
||||
// format, else it won't work under win9x systems.
|
||||
rv = NS_GetSpecialDirectory( NS_APP_CHROME_DIR, getter_AddRefs( iconFileSpec ) );
|
||||
if ( NS_SUCCEEDED( rv ) ) {
|
||||
iconFileSpec->AppendNative( NS_LITERAL_CSTRING( "icons" ) );
|
||||
iconFileSpec->AppendNative( NS_LITERAL_CSTRING( "default" ) );
|
||||
iconFileSpec->AppendNative( iconFile );
|
||||
|
||||
// Check to make sure that the icon file exists on disk.
|
||||
iconFileSpec->Exists( &flagExists );
|
||||
if ( flagExists ) {
|
||||
rv = iconFileSpec->GetNativePath( iconFileToUse );
|
||||
if ( NS_SUCCEEDED( rv ) ) {
|
||||
TCHAR buffer[MAX_PATH];
|
||||
DWORD len;
|
||||
|
||||
// Get the short path name (8.3) format for iconFileToUse
|
||||
// else it won't work under win9x.
|
||||
len = ::GetShortPathName( iconFileToUse.get(), buffer, sizeof buffer );
|
||||
NS_ASSERTION ( (len > 0) && ( len < sizeof buffer ), "GetShortPathName failed!" );
|
||||
iconFileToUse.Assign( buffer );
|
||||
iconFileToUse.Append( NS_LITERAL_CSTRING( ",0" ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RegistryEntry iconEntry( HKEY_LOCAL_MACHINE, iconKey.get(), NULL, iconFileToUse.get() );
|
||||
if( !iconEntry.currentSetting().Equals( iconFileToUse ) )
|
||||
iconEntry.set();
|
||||
}
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
// Basically, the inverse of set().
|
||||
// First, reset the opener for this entry's file type.
|
||||
// Then, reset the file type associated with each extension.
|
||||
nsresult FileTypeRegistryEntry::reset() {
|
||||
nsresult rv = ProtocolRegistryEntry::reset();
|
||||
|
||||
for ( int i = 0; ext[ i ]; i++ ) {
|
||||
nsCAutoString thisExt( "Software\\Classes\\" );
|
||||
thisExt += ext[i];
|
||||
(void)SavedRegistryEntry( HKEY_LOCAL_MACHINE, thisExt.get(), "", fileType.get() ).reset();
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
// Do inherited set() and also set key for edit (with -edit option).
|
||||
//
|
||||
// Note: We make the rash assumption that we "own" this filetype (aka "protocol").
|
||||
// If we ever start commandeering some other file type then this may have to be
|
||||
// rethought. The solution is to override reset() and undo this (and make the
|
||||
// "edit" entry a SavedRegistryEntry).
|
||||
nsresult EditableFileTypeRegistryEntry::set() {
|
||||
nsresult rv = FileTypeRegistryEntry::set();
|
||||
if ( NS_SUCCEEDED( rv ) ) {
|
||||
// only set this if we support "-edit" on the command-line
|
||||
nsCOMPtr<nsICmdLineHandler> editorService =
|
||||
do_GetService( "@mozilla.org/commandlinehandler/general-startup;1?type=edit", &rv );
|
||||
if ( NS_SUCCEEDED( rv) ) {
|
||||
nsCAutoString editKey( "Software\\Classes\\" );
|
||||
editKey += protocol;
|
||||
editKey += "\\shell\\edit\\command";
|
||||
nsCAutoString editor( thisApplication() );
|
||||
editor += " -edit \"%1\"";
|
||||
rv = RegistryEntry( HKEY_LOCAL_MACHINE, editKey.get(), "", editor.get() ).set();
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
// Convert current registry setting to boolean.
|
||||
BoolRegistryEntry::operator PRBool() {
|
||||
return currentSetting().Equals( "1" ) ? PR_TRUE : PR_FALSE;
|
||||
}
|
Загрузка…
Ссылка в новой задаче