зеркало из https://github.com/mozilla/pjs.git
bug 77073, wallet checks slows creation of edit and context menus, r=sgehani, sr=alecf
This commit is contained in:
Родитель
0af6b707b9
Коммит
74d9c1cdb0
|
@ -1,89 +0,0 @@
|
|||
<?xml version="1.0"?>
|
||||
|
||||
<!--
|
||||
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 Communicator client code, released
|
||||
March 31, 1998.
|
||||
|
||||
The Initial Developer of the Original Code is Netscape
|
||||
Communications Corporation. Portions created by Netscape are
|
||||
Copyright (C) 1998-1999 Netscape Communications Corporation. All
|
||||
Rights Reserved.
|
||||
|
||||
Contributor(s):
|
||||
-->
|
||||
|
||||
<!DOCTYPE window SYSTEM "chrome://wallet/locale/walletContextOverlay.dtd">
|
||||
|
||||
<overlay id="walletContextOverlay"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
|
||||
|
||||
<script type="application/x-javascript" src="chrome://wallet/content/walletOverlay.js"/>
|
||||
|
||||
<script type="application/x-javascript">
|
||||
<![CDATA[
|
||||
|
||||
function initContextItems() {
|
||||
|
||||
// Determine if capture should be displayed and enabled.
|
||||
var captureState = getState(capture, 0);
|
||||
showItem("context-capture", (captureState != hide));
|
||||
setDisabledAttr("context-capture", (captureState == disable));
|
||||
|
||||
// Determine if prefill should be displayed and enabled.
|
||||
var prefillState = getState(prefill, 0);
|
||||
showItem("context-prefill", (prefillState != hide));
|
||||
setDisabledAttr("context-prefill", (prefillState == disable));
|
||||
|
||||
// Display show-saved-dat if either prefill or capture is being displayed
|
||||
showItem("context-formshow", captureState != hide || prefillState != hide);
|
||||
|
||||
// Display separator if either prefill or capture is being displayed
|
||||
showItem("context-separator", captureState != hide || prefillState != hide);
|
||||
}
|
||||
|
||||
// For some unexplainable reason, this overlay is loaded twice as can be demonstrated
|
||||
// by uncommenting the following "dump" statement which will get displayed twice
|
||||
// dump("$$$$$$$$$$ HERE WE ARE IN walletContextOverlay.xul $$$$$$$$$$\n");
|
||||
// As a consequence, the block-image item appears twice in the context menu. To
|
||||
// prevent that from happening, the "display:none" was added to the menuitem below
|
||||
|
||||
]]>
|
||||
</script>
|
||||
|
||||
<!-- context menu -->
|
||||
<popupset id="contentAreaContextSet" onpopupshowing="initContextItems();"/>
|
||||
|
||||
<popup id="contentAreaContextMenu">
|
||||
<menuitem id="context-formshow"
|
||||
label="&formshowCmd.label;"
|
||||
accesskey=""
|
||||
oncommand="formShow();"
|
||||
style="display:none;"
|
||||
insertafter="context-copyimage"/>
|
||||
<menuitem id="context-capture"
|
||||
label="&captureCmd.label;"
|
||||
accesskey=""
|
||||
oncommand="formCapture();"
|
||||
style="display:none;"
|
||||
insertafter="context-copyimage"/>
|
||||
<menuitem id="context-prefill"
|
||||
label="&prefillCmd.label;"
|
||||
accesskey=""
|
||||
oncommand="formPrefill();"
|
||||
style="display:none;"
|
||||
insertafter="context-copyimage"/>
|
||||
<menuseparator id="context-separator"
|
||||
style="display:none;"
|
||||
insertafter="context-copyimage"/>
|
||||
</popup>
|
||||
</overlay>
|
|
@ -33,15 +33,11 @@
|
|||
<![CDATA[
|
||||
|
||||
function initEditItems() {
|
||||
var state;
|
||||
|
||||
// Determine if capture should be displayed and enabled.
|
||||
state = getState(capture, 0);
|
||||
setDisabledAttr("edit_capture", (state != enable));
|
||||
|
||||
// Determine if prefill should be displayed and enabled.
|
||||
state = getState(prefill, 0);
|
||||
setDisabledAttr("edit_prefill", (state != enable));
|
||||
// Determine if capture/prefill should be displayed and enabled.
|
||||
var state = getState(0);
|
||||
setDisabledAttr("edit_capture", (state.capture != enable));
|
||||
setDisabledAttr("edit_prefill", (state.prefill != enable));
|
||||
}
|
||||
|
||||
/* form toolbar is out
|
||||
|
|
|
@ -17,9 +17,22 @@
|
|||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
var gIsEncrypted = -1;
|
||||
var gWalletService = -1;
|
||||
|
||||
var gIsEncrypted = -1;
|
||||
var gWalletService = -1;
|
||||
|
||||
// states that the capture and prefill menu items can be in
|
||||
const hide = -1; // don't show menu item
|
||||
const disable = 0; // show menu item but gray it out
|
||||
const enable = 1; // show menu item normally
|
||||
|
||||
// useful values for an array giving the state of the two menu item
|
||||
const bothHide = {capture: hide, prefill: hide};
|
||||
const bothEnable = {capture: enable, prefill: enable};
|
||||
|
||||
// useful values for an array indicating if state was determined for the two menu items
|
||||
const bothTrue = {capture: true, prefill: true};
|
||||
const bothFalse = {capture: false, prefill: false};
|
||||
|
||||
// Set the disabled attribute of specified item.
|
||||
// If the value is false, then it removes the attribute
|
||||
|
@ -105,11 +118,11 @@
|
|||
}
|
||||
|
||||
// hide form toolbar if three or less text elements in form
|
||||
var prefillState = getState(prefill, 3);
|
||||
showItem("formToolbar", (prefillState != hide));
|
||||
var state = getState(3);
|
||||
showItem("formToolbar", (state.prefill != hide));
|
||||
|
||||
// enable prefill button if there is at least one saved value for the form
|
||||
setDisabledAttr("formPrefill", (prefillState == disable));
|
||||
setDisabledAttr("formPrefill", (state.prefill == disable));
|
||||
}
|
||||
*/
|
||||
|
||||
|
@ -147,27 +160,18 @@
|
|||
}
|
||||
*/
|
||||
|
||||
var hide = -1;
|
||||
var disable = 0;
|
||||
var enable = 1;
|
||||
|
||||
var capture = 0;
|
||||
var prefill = 1;
|
||||
|
||||
var elementCount;
|
||||
|
||||
// Walk through the DOM to determine how a capture or prefill item is to appear.
|
||||
// arguments:
|
||||
// captureOrPrefill = capture, prefill
|
||||
// returned value:
|
||||
// hide, disable, enable
|
||||
function getStateFromFormsArray(formsArray, captureOrPrefill, threshhold) {
|
||||
// hide, disable, enable for .capture and .prefill
|
||||
function getStateFromFormsArray(formsArray, threshhold) {
|
||||
if (!formsArray) {
|
||||
return hide;
|
||||
return bothHide;
|
||||
}
|
||||
|
||||
var form;
|
||||
var bestState = hide;
|
||||
var bestState = bothHide;
|
||||
|
||||
for (form=0; form<formsArray.length; form++) {
|
||||
var elementsArray = formsArray[form].elements;
|
||||
|
@ -193,16 +197,22 @@
|
|||
// if (locked) { -- there's currently no way to make such a test
|
||||
// it's encrypted and locked, we lose
|
||||
elementCount = threshhold+1;
|
||||
return enable;
|
||||
return bothEnable;
|
||||
// }
|
||||
}
|
||||
} catch(e) {
|
||||
// there is no crypto pref so database could not possible be encrypted
|
||||
}
|
||||
|
||||
if (bestState == hide) {
|
||||
bestState = disable;
|
||||
|
||||
// since we know there is at least one text or select element, we can unhide
|
||||
// the menu items. That means doing nothing if state is already "enable" but
|
||||
// changing state to "disable" if it is currently "hide".
|
||||
for (var j in bestState) {
|
||||
if (bestState[j] == hide) {
|
||||
bestState[j] = disable;
|
||||
}
|
||||
}
|
||||
|
||||
var value;
|
||||
|
||||
// obtain saved values if any and store in array called valueList
|
||||
|
@ -216,32 +226,35 @@
|
|||
valueList = valueSequence.substring(1, valueSequence.length).split(separator);
|
||||
}
|
||||
|
||||
// see if there's a value on screen (capture case) or a saved value (prefill case)
|
||||
if (captureOrPrefill == capture) {
|
||||
// in capture case, see if element has a value on the screen which is not saved
|
||||
value = elementsArray[element].value;
|
||||
if (valueSequence && value) {
|
||||
for (var i=0; i<valueList.length; i++) {
|
||||
if (value == valueList[i]) {
|
||||
value = null;
|
||||
break;
|
||||
}
|
||||
// in capture case, see if element has a value on the screen which is not saved
|
||||
value = elementsArray[element].value;
|
||||
if (valueSequence && value) {
|
||||
for (var i=0; i<valueList.length; i++) {
|
||||
if (value == valueList[i]) {
|
||||
value = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// in prefill case, see if element has a saved value
|
||||
if (valueSequence) {
|
||||
value = valueList[0];
|
||||
}
|
||||
if (value) {
|
||||
// at least one text (or select) element has a value,
|
||||
// in which case the capture item is to appear in menu
|
||||
bestState.capture = enable;
|
||||
}
|
||||
|
||||
// in prefill case, see if element has a saved value
|
||||
if (valueSequence) {
|
||||
value = valueList[0];
|
||||
if (value) {
|
||||
// at least one text (or select) element has a value,
|
||||
// in which case the prefill item is to appear in menu
|
||||
bestState.prefill = enable;
|
||||
}
|
||||
}
|
||||
|
||||
if (value) {
|
||||
// at least one text (or select) element has a value,
|
||||
// in which case the capture or prefill item is to appear in menu
|
||||
bestState = enable;
|
||||
if (elementCount > threshhold) {
|
||||
return enable;
|
||||
}
|
||||
// see if we've gone far enough
|
||||
if ((bestState == bothEnable) && (elementCount > threshhold)) {
|
||||
return bestState;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -252,40 +265,42 @@
|
|||
|
||||
var bestState;
|
||||
|
||||
function stateFoundInFormsArray(formsArray, captureOrPrefill, threshhold) {
|
||||
var state =
|
||||
getStateFromFormsArray(formsArray, captureOrPrefill, threshhold);
|
||||
if (state == enable) {
|
||||
bestState = enable;
|
||||
if (elementCount > threshhold) {
|
||||
return true;
|
||||
function stateFoundInFormsArray(formsArray, threshhold) {
|
||||
var rv = bothFalse;
|
||||
var state = getStateFromFormsArray(formsArray, threshhold);
|
||||
for (var i in state) {
|
||||
if (state[i] == enable) {
|
||||
bestState[i] = enable;
|
||||
if (elementCount > threshhold) {
|
||||
rv[i] = true;
|
||||
}
|
||||
} else if (state[i] == disable && bestState[i] == hide) {
|
||||
bestState[i] = disable;
|
||||
}
|
||||
} else if (state == disable && bestState == hide) {
|
||||
bestState = disable;
|
||||
}
|
||||
return false;
|
||||
return rv;
|
||||
}
|
||||
|
||||
// Walk through the DOM to determine how capture or prefill item is to appear.
|
||||
// arguments:
|
||||
// captureOrPrefill = capture, prefill
|
||||
// returned value:
|
||||
// hide, disable, enable
|
||||
// hide, disable, enable for .capture and .prefill
|
||||
|
||||
function getState(captureOrPrefill, threshhold) {
|
||||
stateFound(window.content, captureOrPrefill, threshhold);
|
||||
function getState(threshhold) {
|
||||
stateFound(window.content, threshhold);
|
||||
return bestState;
|
||||
}
|
||||
|
||||
function stateFound(content, captureOrPrefill, threshhold) {
|
||||
bestState = hide;
|
||||
function stateFound(content, threshhold) {
|
||||
var captureStateFound = false;
|
||||
var prefillStateFound = false;
|
||||
bestState = bothHide;
|
||||
if (!content || !content.document) {
|
||||
return false;
|
||||
return bothFalse;
|
||||
}
|
||||
var document = content.document;
|
||||
if (!("forms" in document)) {
|
||||
// this will occur if document is xul document instead of html document for example
|
||||
return false;
|
||||
return bothFalse;
|
||||
}
|
||||
|
||||
// test for wallet service being available
|
||||
|
@ -293,31 +308,35 @@
|
|||
gWalletService = Components.classes["@mozilla.org/wallet/wallet-service;1"]
|
||||
.getService(Components.interfaces.nsIWalletService);
|
||||
if (!gWalletService) {
|
||||
return true;
|
||||
return bothTrue;
|
||||
}
|
||||
|
||||
var state;
|
||||
elementCount = 0;
|
||||
|
||||
// process frames if any
|
||||
var formsArray;
|
||||
var framesArray = content.frames;
|
||||
var rv;
|
||||
if (framesArray.length != 0) {
|
||||
var frame;
|
||||
for (frame=0; frame<framesArray.length; ++frame) {
|
||||
|
||||
// recursively process each frame for additional documents
|
||||
if (stateFound(framesArray[frame], captureOrPrefill, threshhold)) {
|
||||
return true;
|
||||
rv = stateFound(framesArray[frame], threshhold);
|
||||
captureStateFound |= rv.capture; prefillStateFound |= rv.prefill;
|
||||
if (captureStateFound && prefillStateFound) {
|
||||
return bothTrue;
|
||||
}
|
||||
|
||||
// process the document of this frame
|
||||
var frameDocument = framesArray[frame].document;
|
||||
if (frameDocument) {
|
||||
|
||||
if (stateFoundInFormsArray(frameDocument.forms, captureOrPrefill, threshhold)) {
|
||||
rv = stateFoundInFormsArray(frameDocument.forms, threshhold);
|
||||
captureStateFound |= rv.capture; prefillStateFound |= rv.prefill;
|
||||
if (captureStateFound && prefillStateFound) {
|
||||
gIsEncrypted = -1;
|
||||
return true;
|
||||
return bothTrue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -325,18 +344,20 @@
|
|||
|
||||
// process top-level document
|
||||
gIsEncrypted = -1;
|
||||
if (stateFoundInFormsArray(document.forms, captureOrPrefill, threshhold)) {
|
||||
return true;
|
||||
rv = stateFoundInFormsArray(document.forms, threshhold);
|
||||
captureStateFound |= rv.capture; prefillStateFound |= rv.prefill;
|
||||
if (captureStateFound && prefillStateFound) {
|
||||
return bothTrue;
|
||||
}
|
||||
|
||||
// if we got here, then there was no text (or select) element with a value
|
||||
// or there were too few text (or select) elements
|
||||
if (elementCount > threshhold) {
|
||||
// no text (or select) element with a value
|
||||
return false;
|
||||
return bothFalse;
|
||||
}
|
||||
|
||||
// too few text (or select) elements
|
||||
bestState = hide;
|
||||
return false;
|
||||
return bothFalse;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче