-
Notifications
You must be signed in to change notification settings - Fork 13
Using Omaha OneClick plugin
Dmitry A. Shashkin edited this page Jan 19, 2015
·
5 revisions
If Omaha is already installed on user's machine, Omaha OneClick plugin allows users to install new applications without downloading tagged metainstallers. In short, the plugin launches Omaha, which is already installed, and passes the tag (the one which tagged metainstaller contains) within command line arguments. In this case, when user clicks link/button on the webpage, the actual installation process will be started instead of metainstaller downloading process.
To be able to use Omaha OneClick plugin on your server's webpage, the following changes are required:
- Update
kSiteLockPatternStrings
constant array inbase\constants.h
file to contain pattern matches your webpage (where OneClick plugin is working) domain- Developers can use one additional pattern. It can be defined in
OneClickHostPattern
variable underHKEY_LOCAL_MACHINE\Software\{OmahaCompanyName}\UpdateDev
registry path.
- Developers can use one additional pattern. It can be defined in
- (optional) Change
kPluginDomain
constant inbase\const_addresses.h
file to identify your company. Using your company domain is the common practice. - Make sure all the constants inside the
omaha
JavaScript object (see below) have the same values as defined in respective Omaha source files
Below is the sample code which illustrates how Omaha OneClick plugin can be used via JavaScript:
var appguid = "{AAAAAAAA-BBBB-CCCC-DDDD-EEEEEEEEEEEE}";
var appname = "Application";
var needsadmin = "prefers";
var extraParameters = "&lang=en&usagestats=1";
// create omaha object with necessary constants
// make sure all the constants have the same values
// as defined in respective Omaha source files
var omaha = {};
omaha.oneClickVersion = 9; // defined in VERSION file
omaha.domainName = "google"; // defined in main.scons
omaha.oneClickMimeType = // defined in base\const_config.h
"application/x-vnd." + omaha.domainName +
".oneclickctrl." + omaha.oneClickVersion;
omaha.companyName = "Google"; // defined in main.scons
omaha.oneClickProgId = // defined in plugins\update\config.cc
omaha.companyName + ".OneClickCtrl." + omaha.oneClickVersion;
// set up OneClick
function createOneClickObject() {
var obj = document.createElement("object");
obj.type = omaha.oneClickMimeType;
obj.id = "OneClickCtrl";
obj.style.position = "absolute";
obj.style.top = "-5000px";
obj.style.left = "-5000px";
document.body.appendChild(obj);
return obj;
}
try {
new ActiveXObject(omaha.oneClickProgId);
omaha.oneclickPlugin_ = createOneClickObject();
} catch (e) {
var mimeType = navigator.mimeTypes[omaha.oneClickMimeType];
if (mimeType && mimeType.enabledPlugin) {
omaha.oneclickPlugin_ = createOneClickObject();
}
}
omaha.oneclickPlugin_ && (omaha.oneclick = {
getOneClickVersion: function() {
try {
return omaha.oneclickPlugin_.GetOneClickVersion();
} catch (e) {
return -1;
}
},
install: function(tag, successCallback, failureCallback) {
try {
omaha.oneclickPlugin_.Install("/install " + tag,
successCallback, failureCallback);
} catch (e) {
var errorCode = 0;
var errorMessage;
try {
errorCode = e.number;
if (!errorCode) {
errorMessage = e.message ? e.message : e;
errorCode = parseInt(errorMessage,
"0x" == errorMessage.substring(0, 2) ? 16 : 10);
}
} catch (e2) {}
if (isNaN(errorCode) || 0 == errorCode)
errorCode = -2;
failureCallback(errorCode);
}
},
launchAppCommand: function(guid, isMachine, cmdId) {
if (9 > omaha.oneclick.getOneClickVersion())
return false;
try {
omaha.oneclickPlugin_.LaunchAppCommand(guid, isMachine, cmdId);
return true;
} catch (e) {
return false;
}
},
getInstalledVersion: function(guid, isMachine) {
var version = "";
try {
version = omaha.oneclickPlugin_.GetInstalledVersion(guid, isMachine);
} catch (e) {}
return version;
}
});
// install application using OneClick
function onSuccess() {
// ...
}
function onFail(errorCode) {
// ...
}
if (!omaha.oneclick) {
// OneClick is not available
} else {
var tag = "appguid=" + appguid;
tag += "&appname=" + appname;
tag += "&needsadmin=" + needsadmin;
tag += extraParameters;
omaha.oneclick.install(tag, onSuccess, onFail);
}