📄 213.html
字号:
<HTML><TITLE>The Browser Plugin and Safe-Tcl: Writing Tclets</TITLE><BODY BGCOLOR="#FFF0E0" VLINK="#0FBD0F" TEXT="#101000" LINK="#0F0FDD">
<A NAME="top"><H1>Writing Tclets</H1></A>
<P> This section brings together some bits of information about the interpreter
that runs tclets and the global variables available to them. Emphasis is on
what makes conditions different than with a normal Tk interpreter. Most of
what you need to know about writing a tclet is covered in the first twenty
chapters of this book. The actual mechanism for creating the interpreter that
runs a tclet is described in the next section.
<P> All tclets begin execution in the Safe Base interpreter which is a version
of Tk that lacks access to the following commands and library procedures.
<PRE>
bell cd clipboard exec fconfigure
glob grab history load menu
open pwd selection socket source
tcl_TraceProc tk_changeColor tk tk_getOpenFile tk_getSaveFile
tk_messageBox vwait
</PRE>
(This list includes some commands and procedures that are not discussed in
this book.)
<P> In addition, the Safe Base interpreter provides modified
versions of the following Tcl commands:
<PRE>
exit file load source tclPkgUnknown
</PRE>
The modifications remove potentially dangerous capabilities.
<P> Finally, the Safe Base interpreter contains a couple of extra commands:
<TT>getattr</TT> and <TT>policy</TT>.
<P>
<P> The <TT>getattr</TT> command can be used as follows.
<PRE>
getattr <CITE>VARIABLE_NAME</CITE>
</PRE>
It returns the value of <CITE>VARIABLE_NAME</CITE> which may be a browser-related
variable such as <TT>originURL</TT>, <TT>originHomeDirURL</TT>, <TT>originPath</TT>, or
<TT>originSocketHost</TT>. A list of such browser-related variables can be found
in the <TT>plugin</TT> page of the plugin's on-line manual. The four mentioned
give, respectively, the URL that actually fetched the tclet, the directory
part of that URL, the path part of that URL (that is, the part after the host
name/port and before the final file name), and the host name used for
connecting back to the tclet's host. Variables whose values are available
through <TT>getattr</TT> cannot be changed by a tclet.
<P> If a tclet is to use any of the resources made available by the features
described in the previous section, it must run under an appropriate security
policy. This it does by executing
<PRE>
policy <CITE>POLICY_NAME</CITE>
</PRE>
which will either terminate with an error or return <CITE>POLICY_NAME</CITE>. In the
latter case, the interpreter executing the tclet has been upgraded in a way
that is consistent with the named policy. This will happen if the tclet is
authorized to use the policy. If the tclet is already running under the
policy, then <CITE>POLICY_NAME</CITE> is also returned. If, however, the tclet is not
authorized to run under the policy or it is already running under a different
policy, an error is generated. Each tclet is permitted to run under at most
one policy per execution.
<P> As described above in
<A HREF="21.1.html" tppabs="http://www.mapfree.com/sbf/tcl/book/select/Html/21.1.html">The Tcl/Tk Plugin</A>, a tclet with the ability to use
persistent storage has a limited ability to modify the directory where its
files are stored. The particular storage directory that a tclet can use is a
function of a policy name and a URL path. The policy name is determined by
the security policy under which the tclet executes. The URL path is a prefix
of the URL from which the tclet was downloaded. This prefix is determined by
a global variable, <TT>embed_args(prefix)</TT>. This variable contains only the
part of the URL path which the tclet can change – that to the right of the
part identifying the server and port.
<P> For example, if the tclet is obtained from
<PRE>
http://www.mapfree.com:80/sbf/tcl/book/safeTk.tcl
</PRE>
then the default value of <TT>embed_args(prefix)</TT> initially will be
<PRE>
sbf/tcl/book/safeTk.tcl
</PRE>
<P> Changing <TT>embed_args(prefix)</TT> <CITE>before</CITE> requesting a
security policy will affect the directory used for persistent storage. The
value you assign to <TT>embed_args(prefix)</TT> must be a subpath of
<TT>originPath</TT>. If it is not, it will be ignored. If it is, then the
directory chosen by the plugin for persistent storage will be the same as for
any other tclet that successfully assigns the same value to
<TT>embed_args(prefix)</TT>.
<P> For example, assume that two tclets are loaded respectively from the
following URLs.
<PRE>
http://www.benign.org/a/b/c/tclet1.tcl
http://www.benign.org/a/b/tclet2.tcl
</PRE>
If both tclets begin this way
<PRE>
set embed_args(prefix) www.benign.org/a
policy home
</PRE>
then both will share the same directory for persistent storage. If one of
them ran under a policy different than <TT>home</TT>, this would not be
true.
<P> <!-- Linkbar -->
<P><CENTER><FONT SIZE=2><NOBR>
<STRONG>From</STRONG>
<A HREF="javascript:if(confirm('http://www.mapfree.com/sbf/tcl/book/home.html \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address. \n\nDo you want to open it from the server?'))window.location='http://www.mapfree.com/sbf/tcl/book/home.html'" tppabs="http://www.mapfree.com/sbf/tcl/book/home.html">Tcl/Tk For Programmers</A><WBR>
<STRONG>Previous</STRONG>
<A HREF="21.2.html" tppabs="http://www.mapfree.com/sbf/tcl/book/select/Html/21.2.html">section</A><WBR>
<STRONG>Next</STRONG>
<A HREF="21.4.html" tppabs="http://www.mapfree.com/sbf/tcl/book/select/Html/21.4.html">section</A><WBR>
<STRONG>All</STRONG>
<A HREF="21.html" tppabs="http://www.mapfree.com/sbf/tcl/book/select/Html/21.html">sections</A><WBR>
<STRONG>Author</STRONG>
<A HREF="javascript:if(confirm('http://www.mapfree.com/mp/jaz/home.html \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address. \n\nDo you want to open it from the server?'))window.location='http://www.mapfree.com/mp/jaz/home.html'" tppabs="http://www.mapfree.com/mp/jaz/home.html">J. A. Zimmer</A><WBR>
<STRONG>Copyright</STRONG>
<A HREF="copyright.html" tppabs="http://www.mapfree.com/sbf/tcl/book/select/Html/copyright.html">Notice</A><WBR>
<P>
<I>Jun 17, 1998</I>
</NOBR></FONT></CENTER></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -