File: SimpleScriptableTest.html

package info (click to toggle)
iceweasel 2.0.0.19-0etch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 298,784 kB
  • ctags: 317,912
  • sloc: cpp: 1,796,902; ansic: 987,677; xml: 109,036; makefile: 47,777; asm: 35,201; perl: 26,983; sh: 20,879; cs: 6,232; java: 5,513; python: 3,249; pascal: 459; lex: 306; php: 244; csh: 132; objc: 97; yacc: 79; ada: 49; awk: 14; sql: 4; sed: 4
file content (108 lines) | stat: -rw-r--r-- 2,686 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<HTML>
<H1> Simple XPConnect Scriptable Sample Plug-in </H1>

<p> 

This sample plug-in demonstrates how to write a XPConnect-enabled plug-in. You
should see in the plug-in rectangle below with the text "Hello World". The text
box and buttons demostrate calling the scriptable xpcom interfaces of the plugin
from JavaScript.

<HR>

<center>

<EMBED type=application/x-simple name="simple1" width=400 height=300>

<script>

function GetText()
{
    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
    
    document.the_form.the_text.value = 
        document.simple1.nsISimplePluginInstance.text;
}

function SetText()
{
    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
    
    document.simple1.nsISimplePluginInstance.text = 
        document.the_form.the_text.value;
}

/*
// For JS evaluator below; unused.

var it = undefined; // persistent last special value.
function EvalIt() {
    var inText = document.eval_form.eval_text.value;

    dump(document.simple1);

    try {
        var result = eval(inText);
        result = result ? result : "";
        document.eval_form.result_text.value = result;
        if (it)
            document.eval_form.it_text.value = "it: " + it;
        document.eval_form.eval_text.value = "";
    } catch (err) {
        document.eval_form.result_text.value = "Exn: " + err.toString();
    }
    return true;
}
*/
</script>


<form name ="the_form">
<INPUT TYPE="text" NAME="the_text" VALUE="some text" SIZE="25">
<input	type=button value="Set Text" onclick='SetText()'>
<input	type=button value="Get Text" onclick='GetText()'>
</form>

<!--
<hr>
<form name ="eval_form">
JavaScript evaluation for poking at the plugin ('document.simple1').<br>
input:<br>
<INPUT TYPE="text" NAME="eval_text" onchange = "EvalIt()" SIZE="80"><br>
result:<br>
<INPUT TYPE="text" NAME="result_text" SIZE="80"><br>
contents of 'it':<br>
<INPUT TYPE="text" NAME="it_text" SIZE="80">
<p>
<input type=button value="eval" onclick="EvalIt()">
</form>
-->


<hr>

</center>

<h4>Problems?</h4>

<ul>

<p><li><b>Can't load pluign</b>:
Copy the compiled plugin to your plugins directory 

<p><li><b>JavaScript error in the Error console talking about how 
XPConnect can't build a wrapper</b>: 
Copy the type library (nsISimplePluginInstance.xpt) to the mozilla components
directory.

<p><li><b>Plugin loads, but when I push the 'Set Text' button the plugin text 
is not updated</b>: 
Are you not running Windows? Only the Windows version updates text the plugin 
draws. But the calls from JS to the plugin should work on all platforms.
[We welcome fixes to the samples if you'd like to submit them]

</ul>

<HR>

</HTML>