Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(180)

Side by Side Diff: chrome/common/extensions/docs/overview.html

Issue 179068: Extension Doc Changes (no building or testable changes): minor changes for tab & windows doc (Closed)
Patch Set: touch grd. rendered docs Created 11 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 <!DOCTYPE html><!-- This page is a placeholder for generated extensions api doc. Note: 1) The <head> information in this page is significant, should be uniform across api docs and should be edited only with knowledge of the templating mecha nism. 2) The <body> tag *must* retain id="body" 3) All <body>.innerHTML is gener eated as an rendering step. If viewed in a browser, it will be re-generated from the template, json schema and authored overview content. 4) The <body>.innerHTM L is also generated by an offline step so that this page may easily be indexed b y search engines. TODO(rafaelw): Abstract this into a "pageshell" that becomes t he single version of page template shell and the "instance" pages (bookmarks.htm l, etc...) can be generated with a build step. --><!-- <html> must retain id="te mplate --><html xmlns="http://www.w3.org/1999/xhtml" jstcache="0"><!-- <head> da ta is significant and loads the needed libraries and styles --><head jstcache="0 "> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" jstcache=" 0"> <title jscontent="getPageTitle()" jstcache="1">Overview</title> <link href=" css/ApiRefStyles.css" rel="stylesheet" type="text/css" jstcache="0"> <script typ e="text/javascript" src="../../../third_party/jstemplate/jstemplate_compiled.js" jstcache="0"> </script> <script type="text/javascript" src="js/api_page_generat or.js" jstcache="0"></script> <script type="text/javascript" src="js/bootstrap.j s" jstcache="0"></script> </head><!-- <body> content is completely generated. Do not edit, as it will be and rewritten. --><body jstcache="0"> <div id="containe r" jstcache="0"> <a name="top" jstcache="0"> </a> <!-- API HEADER --> <div id="p ageHeader" jstcache="0"> <div id="searchbox" jstcache="0"> <form action="http:// www.google.com/cse" id="cse-search-box" jstcache="0"> <div jstcache="0"> <input type="hidden" name="cx" value="002967670403910741006:61_cvzfqtno" jstcache="0"> <input type="hidden" name="ie" value="UTF-8" jstcache="0"> <input type="text" na me="q" size="31" jstcache="0"> <input type="submit" name="sa" value="Search" jst cache="0"> </div> </form> <script type="text/javascript" src="http://www.google. com/jsapi" jstcache="0"></script> <script type="text/javascript" jstcache="0">go ogle.load("elements", "1", {packages: "transliteration"});</script> <script type ="text/javascript" src="http://www.google.com/coop/cse/t13n?form=cse-search-box& amp;t13n_langs=en" jstcache="0"></script> <script type="text/javascript" src="ht tp://www.google.com/coop/cse/brand?form=cse-search-box&amp;lang=en" jstcache="0" ></script> </div> <div id="pageTitle" jstcache="0"> <h1 jscontent="getPageTitle( )" jstcache="1">Overview</h1> </div> </div> <!-- /pageHeader --> <div id="pageCo ntent" jstcache="0"> <!-- SIDENAV --> <div id="leftNav" jstcache="0"> <ul jstcac he="0"> <li jstcache="0"> <a href="index.html" jstcache="0">Home</a></li> <li js tcache="0"> <a href="getstarted.html" jstcache="0">Getting Started</a></li> <li jstcache="0" class="leftNavSelected">Overview </li> <li jstcache="0"> <a href="d evguide.html" jstcache="0"><div jstcache="0">Developer's Guide</div></a> <ul jst cache="0"> <li jstcache="0"><a href="toolstrip.html" jstcache="0">Toolstrips</a> </li> <li jstcache="0"><a href="pageActions.html" jstcache="0">Page Actions</a>< /li> <li jstcache="0"><a href="background_pages.html" jstcache="0">Background Pa ges</a></li> <li jstcache="0"><a href="content_scripts.html" jstcache="0">Conten t Scripts</a></li> <li jstcache="0">Events</li> <li jstcache="0"><a href="tabs.h tml" jstcache="0">Tabs</a></li> <li jstcache="0"><a href="windows.html" jstcache ="0">Windows</a></li> <li jstcache="0"><a href="bookmarks.html" jstcache="0">Boo kmarks</a></li> <li jstcache="0">Themes</li> <li jstcache="0"><a href="npapi.htm l" jstcache="0">NPAPI Plugins</a></li> <li jstcache="0"><a href="packaging.html" jstcache="0">Packaging</a></li> <li jstcache="0">Autoupdate</li> </ul> </li> <l i jstcache="0"><a href="tutorials.html" jstcache="0"><div jstcache="0">Tutorials </div></a> <ul jstcache="0"> <li jstcache="0"><a href="tut_debugging.html" jstca che="0">Debugging</a></li> </ul> </li> <li jstcache="0">Reference <ul jstcache=" 0"> <li jstcache="0"> Formats <ul jstcache="0"> <li jstcache="0"><a href="manife st.html" jstcache="0">Manifest Files</a></li> <li jstcache="0">Match Patterns</l i> <li jstcache="0">Packages (.crx)</li> </ul> </li> <li jstcache="0"> <a href=" api_index.html" jstcache="0">chrome.* APIs</a> </li> <li jstcache="0"> <a href=" api_other.html" jstcache="0">Other APIs</a> </li> </ul> </li> <li jstcache="0">< a href="http://dev.chromium.org/developers/design-documents/extensions/samples" jstcache="0">Samples</a></li> </ul> </div> <div id="mainColumn" jstcache="0"> <! -- TABLE OF CONTENTS --> <div id="toc" jsdisplay="showPageTOC()" jstcache="2"> < p jstcache="0">Contents</p> <ol jstcache="0"> <li jsselect="getStaticTOC()" jstc ache="9" jsinstance="0"> <a jscontent="name" jsvalues=".href:'#' + href" jstcach e="14" href="#H2-0">The basics</a> <ol jstcache="0"> <li jsselect="$this.childre n" jstcache="22" jsinstance="*0" style="display: none; "> <a jscontent="name" js values=".href:'#' + href" jstcache="14">h3Name</a> </li> </ol> </li><li jsselect ="getStaticTOC()" jstcache="9" jsinstance="1"> <a jscontent="name" jsvalues=".hr ef:'#' + href" jstcache="14" href="#H2-1">Files</a> <ol jstcache="0"> <li jssele ct="$this.children" jstcache="22" jsinstance="0"> <a jscontent="name" jsvalues=" .href:'#' + href" jstcache="14" href="#H3-2">Referring to files</a> </li><li jss elect="$this.children" jstcache="22" jsinstance="*1"> <a jscontent="name" jsvalu es=".href:'#' + href" jstcache="14" href="#H3-3">The manifest file</a> </li> </o l> </li><li jsselect="getStaticTOC()" jstcache="9" jsinstance="2"> <a jscontent= "name" jsvalues=".href:'#' + href" jstcache="14" href="#H2-4">Architecture</a> < ol jstcache="0"> <li jsselect="$this.children" jstcache="22" jsinstance="0"> <a jscontent="name" jsvalues=".href:'#' + href" jstcache="14" href="#H3-5">The back ground page</a> </li><li jsselect="$this.children" jstcache="22" jsinstance="*1" > <a jscontent="name" jsvalues=".href:'#' + href" jstcache="14" href="#H3-6">Con tent scripts</a> </li> </ol> </li><li jsselect="getStaticTOC()" jstcache="9" jsi nstance="3"> <a jscontent="name" jsvalues=".href:'#' + href" jstcache="14" href= "#H2-7">Communication </a> <ol jstcache="0"> <li jsselect="$this.children" jstca che="22" jsinstance="*0" style="display: none; "> <a jscontent="name" jsvalues=" .href:'#' + href" jstcache="14">h3Name</a> </li> </ol> </li><li jsselect="getSta ticTOC()" jstcache="9" jsinstance="*4"> <a jscontent="name" jsvalues=".href:'#' + href" jstcache="14" href="#H2-8"> Summary </a> <ol jstcache="0"> <li jsselect= "$this.children" jstcache="22" jsinstance="*0" style="display: none; "> <a jscon tent="name" jsvalues=".href:'#' + href" jstcache="14">h3Name</a> </li> </ol> </l i> <div jsselect="apiDefinition" jstcache="3" style="display: none; "> <li jstca che="0"> <a href="#apiReference" jscontent="'API reference: ' + getModuleName()" jstcache="4">API reference</a> <ol jstcache="0"> <li jsdisplay="$this.propertie s" jstcache="5"> <a href="#properties" jstcache="0">Properties</a> <ol jstcache= "0"> <li jsselect="getPropertyListFromObject($this)" jstcache="10"> <a jscontent ="name" jsvalues=".href:'#property-' + name" href="#property-anchor" jstcache="4 1">propertyName</a> </li> </ol> </li> <li jsdisplay="functions &amp;&amp; functi ons.length &gt; 0" jstcache="6"> <a href="#methods" jstcache="0">Methods</a> <ol jstcache="0"> <li jsselect="functions" jstcache="11"> <a jscontent="name" jsval ues=".href:'#method-' + name" href="#method-anchor" jstcache="42">methodName</a> </li> </ol> </li> <li jsdisplay="events &amp;&amp; events.length &gt; 0" jstcac he="7"> <a href="#events" jstcache="0">Events</a> <ol jstcache="0"> <li jsselect ="events" jstcache="12"> <a jscontent="name" jsvalues=".href:'#event-' + name" h ref="#event-anchor" jstcache="43">eventName</a> </li> </ol> </li> <li jsdisplay= "types &amp;&amp; types.length &gt; 0" jstcache="8"> <a href="#types" jstcache=" 0">Types</a> <ol jstcache="0"> <li jsselect="types" jstcache="13"> <a jscontent= "id" jsvalues=".href:'#type-' + id" href="#id-anchor" jstcache="44">id</a> </li> </ol> </li> </ol> </li> </div> </ol> </div> <!-- /TABLE OF CONTENTS --> <!-- ST ATIC CONTENT PLACEHOLDER --> <div id="static" jstcache="0"><div id="pageData-tit le" class="pageData" jstcache="0">Overview</div> <div id="pageData-showTOC" clas s="pageData" jstcache="0">true</div> <p jstcache="0"> Please read this page; it has vital information about the extension architecture. If you get bored or rest less, take a break! We suggest bouncing between this page and tutorials such as <a href="getstarted.html" jstcache="0">Getting Started</a> and <a href="tut_debu gging.html" jstcache="0">Debugging</a>. </p> <a name="H2-0" jstcache="0"></a><h2 id="what" jstcache="0">The basics</h2> <p jstcache="0"> An extension is a zippe d bundle of files — HTML, CSS, JavaScript, images, and anything else you need — that adds functionality to the Google Chrome browser. Because an extension is ju st a special kind of web page, it can use all the APIs that the browser provides to web pages and apps, from XMLHttpRequest to JSON to localStorage. </p> <p jst cache="0"> Extensions can add UI to Google Chrome, in the form of <a href="tools trip.html" jstcache="0">toolstrips</a> (toolbar additions) and <a href="pageActi ons.html" jstcache="0">page actions</a> (clickable badges in the address bar). E xtensions can also interact programmatically with browser features such as <a hr ef="bookmarks.html" jstcache="0">bookmarks</a> and <a href="tabs.html" jstcache= "0">tabs</a>. </p> <p jstcache="0"> To find a complete list of extension feature s, with implementation details for each one, see the <a href="devguide.html" jst cache="0">Developer's Guide</a>. </p> <a name="H2-1" jstcache="0"></a><h2 id="fi les" jstcache="0">Files</h2> <p jstcache="0"> Each extension has the following f iles: <!-- PENDING: This could use a picture --> </p> <ul jstcache="0"> <li jstc ache="0">A <b jstcache="0">manifest file</b></li> <li jstcache="0">One or more < b jstcache="0">HTML files</b> (unless the extension is a theme)</li> <li jstcach e="0"><em jstcache="0">Optional:</em> One or more <b jstcache="0">JavaScript fil es</b></li> <li jstcache="0"><em jstcache="0">Optional:</em> Any other files you r extension needs — for example, image files</li> </ul> <p jstcache="0"> While y ou're working on your extension, you put all these files into a single folder. W hen you distribute your extension, the contents of the folder are packaged into a special zipfile that has a <code jstcache="0">.crx</code> suffix, as described in <a href="packaging.html" jstcache="0">Packaging</a>. </p> <a name="H3-2" jst cache="0"></a><h3 jstcache="0">Referring to files</h3> <p jstcache="0"> You can put any file you like into an extension, but how do you use it? Usually, you can refer to the file using a relative URL, just as you would in an ordinary HTML p age. Here's an example of referring to a file named <code jstcache="0">myimage.p ng</code> that's in a subdirectory named <code jstcache="0">images</code>. </p> <pre jstcache="0">&lt;img <b jstcache="0">src="images/myimage.png"</b> style="wi dth:auto; height:auto"&gt; </pre> <p jstcache="0"> As you might notice while you use the Google Chrome debugger, every file in an extension is also accessible b y an absolute URL like this: </p> <blockquote jstcache="0"> <b jstcache="0">chro me-extension://</b><em jstcache="0">&lt;extensionID&gt;</em><b jstcache="0">/</b ><em jstcache="0">&lt;pathToFile&gt;</em> </blockquote> <p jstcache="0"> In that URL, the <em jstcache="0">&lt;extensionID&gt;</em> is a unique identifier that the extension system generates for each extension. You can see the IDs for all y our loaded extensions by going to the URL <b jstcache="0">chrome://extensions/</ b>. The <em jstcache="0">&lt;pathToFile&gt;</em> is the location of the file und er the extension's top directory; it's the same as the relative URL. </p> <p jst cache="0"> For example, assume your extension has the ID <b jstcache="0">aaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaa</b> and the files shown in the following figure: </p> <pre jstcache="0"><span class="comment" jstcache="0">[PENDING: convert this into a figure]</span> toolstrip.html styles.css images: myimage.png ... other: more. html morestyles.css ... </pre> <p jstcache="0"> Here's a table that shows the re lative and absolute URLs of these files. Keep in mind that the relative URL is t he same no matter where you're using it — the relative URL of <code jstcache="0" >myimage.png</code> is <b jstcache="0">images/myimage.png</b>, no matter whether it's being used by <code jstcache="0">toolstrip.html</code> or <code jstcache=" 0">other/more.html</code>. </p> <table jstcache="0"> <tbody jstcache="0"><tr jst cache="0"> <th jstcache="0"> File </th> <th jstcache="0"> Relative URL </th> <th jstcache="0"> Absolute URL </th> </tr> <tr jstcache="0"> <td jstcache="0"> tool strip.html </td> <td jstcache="0"> toolstrip.html </td> <td jstcache="0"> chrome -extension://aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/toolstrip.html </td> </tr> <tr jst cache="0"> <td jstcache="0"> styles.css </td> <td jstcache="0"> styles.css </td> <td jstcache="0"> chrome-extension://aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/styles.cs s </td> </tr> <tr jstcache="0"> <td jstcache="0"> myimage.png </td> <td jstcache ="0"> images/myimage.png </td> <td jstcache="0"> chrome-extension://aaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaa/images/myimage.png </td> </tr> <tr jstcache="0"> <td jstcac he="0"> more.html </td> <td jstcache="0"> other/more.html </td> <td jstcache="0" > chrome-extension://aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/other/more.html </td> </tr > <tr jstcache="0"> <td jstcache="0"> morestyles.css </td> <td jstcache="0"> oth er/morestyles.css </td> <td jstcache="0"> chrome-extension://aaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaa/other/morestyles.css </td> </tr> </tbody></table> <p class="commen t" jstcache="0"> [PENDING: Mention/reflect/link to <a href="http://dev.chromium. org/developers/design-documents/extensions/i18n" jstcache="0">internationalizati on</a>] </p> <a name="H3-3" jstcache="0"></a><h3 jstcache="0">The manifest file< /h3> <p jstcache="0"> The manifest file, called <code jstcache="0">manifest.json </code>, gives information about the extension, such as the most important files and the capabilities that the extension might use. Here's a typical manifest fi le for a toolstrip that uses information from google.com: </p> <pre jstcache="0" >{ "name": "My Extension", "version": "2.1", "description": "Gets information fr om Google.", "update_url": "http://example.com/mytestextension/updates.xml", "pe rmissions": ["http://*.google.com/", "https://*.google.com/"], "toolstrips": ["m y_toolstrip.html"] }</pre> <p jstcache="0"> For details, see <a href="manifest.h tml" jstcache="0">Manifest Files</a>. </p> <a name="H2-4" jstcache="0"></a><h2 i d="arch" jstcache="0">Architecture</h2> <p jstcache="0"> The following pictures shows the web pages associated with a typical extension (in this case, a simple toolstrip). The first figure shows what an extension might look like when there' s a single browser window. </p> <p class="comment" jstcache="0"> [PENDING: image goes here] </p> <p jstcache="0"> The next figure shows that all the code in the extension's main HTML file is duplicated each time you create a new window. In other words, each window has its own widgets for the extension, which means each window adds another web page for that extension. </p> <p class="comment" jstcac he="0"> [PENDING: image goes here] </p> <p jstcache="0"> To more easily coordina te all these web pages and to avoid duplication, you should design your extensio n so that most of the code — especially the state of the extension — is in a <em jstcache="0">background page</em>, as shown in the following figure. </p> <p cl ass="comment" jstcache="0"> [PENDING: image goes here.] </p> <a name="H3-5" jstc ache="0"></a><h3 id="background" jstcache="0">The background page</h3> <p jstcac he="0"> Any non-trivial extension can (and probably should) have a background pa ge. The background page is an invisible page where you put the main logic of the extension. The extension's other pages should have only the code that's necessa ry to show the state of the extension and to get input from the user.</p> <p jst cache="0"> An extension's background page exists before any of the extension's o ther pages exist. It continues to exist as long as the browser is running and th e extension is installed, even if other pages and windows go away. </p> <p jstca che="0"> Your extension's UI — its toolstrips, page actions, and so on — should be dumb views. When the view needs some state, it should request it from the bac kground page. When the background page notices some state change, it should upda te all the views. </p> <p jstcache="0"> For more information, see <a href="backg round_pages.html" jstcache="0">Background Pages</a>. </p> <a name="H3-6" jstcach e="0"></a><h3 id="contentScripts" jstcache="0">Content scripts</h3> <p jstcache= "0"> If you want your extension to interact with web pages, you need a content s cript. Content scripts are JavaScript files that run in the context of web pages . By using the standard Document Object Model (DOM), they can read details of th e web pages the browser visits, and they can make changes to the pages. </p> <p class="comment" jstcache="0"> [PENDING: add an architectural figure here, showin g the extension's pages, a web page, and the content script interacting with the web page. explain the figure.] </p> <p jstcache="0"> For more information, see <a href="content_scripts.html" jstcache="0">Content Scripts</a>. </p> <a name="H 2-7" jstcache="0"></a><h2 jstcache="0">Communication </h2> <p jstcache="0"> Two kinds of communication happen within an extension: </p> <ul jstcache="0"> <li js tcache="0"> Communication <b jstcache="0">between pages</b> in the extension. <b r jstcache="0"> For example, sometimes the background page needs to update all t he UI pages to reflect a change in the extension's state. </li> <li jstcache="0" > Communication <b jstcache="0">between content scripts and the extension</b>. < br jstcache="0"> For example, <span class="comment" jstcache="0">[PENDING: typic al use case goes here]</span>. See <a href="content_scripts.html" jstcache="0">C ontent Scripts</a> for information about this type of communication. </li> </ul> <p jstcache="0"> Here are some keys to communication between an extension's pag es: </p> <ul jstcache="0"> <li jstcache="0"> All the extension's pages execute i n same process, on the same thread. </li> <li jstcache="0"> Extension pages can use <a href="extension.html" jstcache="0"><code jstcache="0">chrome.extension</c ode></a> methods such as <code jstcache="0">getViews()</code>, <code jstcache="0 ">getBackgroundPage()</code>, and <code jstcache="0">getToolstrips()</code> to g et access to the extension's pages. </li> <li jstcache="0"> Once you have refere nces to an extension's pages, you can manipulate the DOM for each page. </li> <l i jstcache="0"> You can also make direct function calls to the pages, as shown i n the following example. </li> </ul> <p jstcache="0"> Here's an example of commu nication between toolstrips and the background page. </p> <pre jstcache="0">//In background_page.html: function updateUI(checked) { var toolstrips = chrome.exte nsion.getToolstrips(); for (var i in toolstrips) { if (toolstrips[i].enableCheck box) toolstrips[i].enableCheckbox(checked); } } //In toolstrip.html: function en ableCheckbox(checked) { var cb = document.getElementById('checkbox'); cb.checked = checked; } </pre> <p jstcache="0"> A good summary of communication mechanisms is at <a href="http://www.chromeplugins.org/google/plugins-development/communic ation-7883.html" jstcache="0">http://www.chromeplugins.org/google/plugins-develo pment/communication-7883.html</a>. </p> <a name="H2-8" jstcache="0"></a><h2 jstc ache="0"> Summary </h2> <p jstcache="0"> [ PENDING: wrap it up. suggest where to go next. Probably: <a href="getstarted.html" jstcache="0">Getting Started</a>, <a href="tut_debugging.html" jstcache="0">Debugging</a>, <a href="devguide.html" jstcache="0">Developer's Guide</a>. ] </p> </div> <!-- API PAGE --> <div class= "apiPage" jsselect="apiDefinition" jstcache="3" style="display: none; "> <a name ="apiReference" jstcache="0"></a> <h2 jscontent="'API reference: ' + getModuleNa me()" jstcache="4">API reference: chrome.apiname </h2> <!-- PROPERTIES --> <div jsdisplay="$this.properties" class="apiGroup" jstcache="5"> <a name="properties" jstcache="0"></a> <h3 id="properties" jstcache="0">Properties</h3> <div jsselec t="getPropertyListFromObject($this)" jstcache="10"> <a jsvalues=".name:'property -' + name" jstcache="15"></a> <h4 jscontent="name" jstcache="16">getLastError</h 4> <div class="summary" jstcache="0"> <!-- Note: intentionally longer 80 columns --> <span jscontent="getModuleName() + '.'" jstcache="23">chrome.extension</spa n><span jscontent="$this.name" jstcache="24">lastError</span> </div> <div transc lude="valueTemplate" jstcache="17"> </div> </div> </div> <!-- /apiGroup --> <!-- METHODS --> <div jsdisplay="functions &amp;&amp; functions.length &gt; 0" class ="apiGroup" id="methods" jstcache="6"> <a name="methods" jstcache="0"></a> <h3 j stcache="0">Methods</h3> <!-- iterates over all functions --> <div class="apiIte m" jsselect="functions" jstcache="11"> <a jsvalues=".name:'method-' + name" jstc ache="18"></a> <!-- method-anchor --> <h4 jscontent="name" jstcache="16">method name</h4> <div class="summary" jstcache="0"><span jsdisplay="returns" jscontent= "getTypeName(returns)" jstcache="25">void</span> <!-- Note: intentionally longer 80 columns --> <span jscontent="getFullyQualifiedFunctionName($this)" jstcache= "26">chrome.module.methodName</span>(<span jsselect="parameters" jsvalues="class :optional ? 'optional' : ''" jstcache="27"><span jsdisplay="$index" jstcache="33 ">, </span><span jscontent="getTypeName($this)" jstcache="34"></span> <var jstca che="0"><span jscontent="name" jstcache="16"></span></var></span>)</div> <div cl ass="description" jstcache="0"> <p class="todo" jsdisplay="!description" jstcach e="28">Undocumented.</p> <p jsdisplay="description" jsvalues=".innerHTML:descrip tion" jstcache="29"> A description from the json schema def of the function goes here. </p> <!-- PARAMETERS --> <h4 jstcache="0">Parameters</h4> <dl jstcache="0 "> <div jsselect="parameters" jstcache="35"> <!-- VALUE: This is a subtemplate t hat is used elsewhere via jsTemplate *transclude* --> <div id="valueTemplate" js tcache="0"> <dt jstcache="0"> <var jsdisplay="$this.name" jscontent="$this.name" jstcache="45">paramName</var> <em jstcache="0"> <!-- TYPE --> <div style="displ ay:inline" jstcache="0"> ( <span class="optional" jsdisplay="optional" jstcache= "46">optional</span> <span id="typeTemplate" jstcache="0"> <span jsdisplay="getT ypeRef($this)" jstcache="47"> <a jsvalues=".href: getTypeRefPage($this) + '#type -' + getTypeRef($this)" jscontent="getTypeRef($this)" jstcache="49"> Type</a> </ span> <span jsdisplay="!getTypeRef($this)" jstcache="48"> <span jsdisplay="isArr ay($this)" jstcache="50"> array of <span jsselect="items" jstcache="52"><span tr ansclude="typeTemplate" jstcache="53"></span></span> </span> <span jsdisplay="!i sArray($this)" jscontent="getTypeName($this)" jstcache="51">paramType</span> </s pan> </span> ) </div> </em> </dt> <dd class="todo" jsdisplay="!$this.description " jstcache="38"> Undocumented. </dd> <dd jsdisplay="$this.description" jsvalues= ".innerHTML:$this.description" jstcache="39"> Description of this parameter from the json schema. </dd> <!-- OBJECT PROPERTIES --> <dd jsdisplay="shouldExpandOb ject($this)" jstcache="40"> <dl jstcache="0"> <div jsselect="getPropertyListFrom Object($this)" jstcache="10"> <div transclude="valueTemplate" jstcache="17"> </d iv> </div> </dl> </dd> </div> <!-- /VALUE --> </div> </dl> <!-- RETURNS --> <h4 jsdisplay="returns" jstcache="30">Returns</h4> <dl jstcache="0"> <div jsselect=" returns" jstcache="36"> <div transclude="valueTemplate" jstcache="17"> </div> </ div> </dl> <!-- CALLBACK --> <div jsdisplay="hasCallback(parameters)" jstcac he="31"> <div jsselect="getCallbackParameters(parameters)" jstcache="37"> <h4 js tcache="0">Callback function</h4> <p jstcache="0"> If you specify the <em jstcac he="0">callback</em> parameter, it should specify a function that looks like thi s: </p> <!-- Note: intentionally longer 80 columns --> <pre jstcache="0">functio n(<span jscontent="getSignatureString(parameters)" jstcache="32">Type param1, Ty pe param2</span>) <span class="subdued" jstcache="0">{...}</span>);</pre> <dl js tcache="0"> <div jsselect="parameters" jstcache="35"> <div transclude="valueTemp late" jstcache="17"> </div> </div> </dl> </div> </div> </div> <!-- /description --> </div> <!-- /apiItem --> </div> <!-- /apiGroup --> <!-- EVENTS --> <div jsdi splay="events &amp;&amp; events.length &gt; 0" class="apiGroup" jstcache="7"> <a name="events" jstcache="0"></a> <h3 id="events" jstcache="0">Events</h3> <!-- i terates over all events --> <div jsselect="events" class="apiItem" jstcache="12" > <a jsvalues=".name:'event-' + name" jstcache="19"></a> <h4 jscontent="name" js tcache="16">event name</h4> <div class="summary" jstcache="0"> <!-- Note: intent ionally longer 80 columns --> <span jscontent="getModuleName() + '.'" class="sub dued" jstcache="23">chrome.bookmarks</span><span jscontent="name" jstcache="16"> onEvent</span><span class="subdued" jstcache="0">.addListener</span>(function(<s pan jscontent="getSignatureString(parameters)" jstcache="32">Type param1, Type p aram2</span>) <span class="subdued" jstcache="0">{...}</span>); </div> <div clas s="description" jstcache="0"> <p class="todo" jsdisplay="!description" jstcache= "28">Undocumented.</p> <p jsdisplay="description" jsvalues=".innerHTML:descripti on" jstcache="29"> A description from the json schema def of the event goes here . </p> <!-- PARAMETERS --> <h4 jstcache="0">Parameters</h4> <dl jstcache="0"> <d iv jsselect="parameters" jstcache="35"> <div transclude="valueTemplate" jstcache ="17"> </div> </div> </dl> </div> <!-- /decription --> </div> <!-- /apiItem --> </div> <!-- /apiGroup --> <!-- TYPES --> <div jsdisplay="types &amp;&amp; types. length &gt; 0" class="apiGroup" jstcache="8"> <a name="types" jstcache="0"></a> <h3 id="types" jstcache="0">Types</h3> <!-- iterates over all types --> <div jss elect="types" class="apiItem" jstcache="13"> <a jsvalues=".name:'type-' + id" js tcache="20"></a> <h4 jscontent="id" jstcache="21">type name</h4> <div transclude ="valueTemplate" jstcache="17"> </div> </div> <!-- /apiItem --> </div> <!-- /api Group --> </div> <!-- /apiPage --> </div> <!-- /mainColumn --> </div> <!-- /page Content --> <div id="pageFooter" --="" jstcache="0"> <p jstcache="0"> Except as otherwise <a href="http://code.google.com/policies.html#restrictions" jstcache=" 0">noted</a>, the content of this page is licensed under the <a rel="license" hr ef="http://creativecommons.org/licenses/by/3.0/" jstcache="0">Creative Commons A ttribution 3.0 License</a>, and code samples are licensed under the <a rel="lice nse" href="http://code.google.com/google_bsd_license.html" jstcache="0">BSD Lice nse</a>. </p> <p jstcache="0"> ©2009 Google </p> </div> <!-- /pageFooter --> </d iv> <!-- /container --> </body></html> 1 <!DOCTYPE html><!-- This page is a placeholder for generated extensions api doc. Note:
2 1) The <head> information in this page is significant, should be uniform
3 across api docs and should be edited only with knowledge of the
4 templating mechanism.
5 2) The <body> tag *must* retain id="body"
6 3) All <body>.innerHTML is genereated as an rendering step. If viewed in a
7 browser, it will be re-generated from the template, json schema and
8 authored overview content.
9 4) The <body>.innerHTML is also generated by an offline step so that this
10 page may easily be indexed by search engines.
11
12 TODO(rafaelw): Abstract this into a "pageshell" that becomes the single
13 version of page template shell and the "instance" pages (bookmarks.html,
14 etc...) can be generated with a build step.
15 --><!-- <html> must retain id="template --><html xmlns="http://www.w3.org/1999/x html" jstcache="0"><!-- <head> data is significant and loads the needed librarie s and styles --><head jstcache="0">
16 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" jstcache= "0">
17 <title jscontent="getPageTitle()" jstcache="1">Overview</title>
18 <link href="css/ApiRefStyles.css" rel="stylesheet" type="text/css" jstcache= "0">
19 <script type="text/javascript" src="../../../third_party/jstemplate/jstempla te_compiled.js" jstcache="0">
20 </script>
21 <script type="text/javascript" src="js/api_page_generator.js" jstcache="0">< /script>
22 <script type="text/javascript" src="js/bootstrap.js" jstcache="0"></script>
23 </head><!-- <body> content is completely generated. Do not edit, as it will be
24 and rewritten. --><body jstcache="0"> <div id="container" jstcache="0">
25 <a name="top" jstcache="0"> </a>
26 <!-- API HEADER -->
27 <div id="pageHeader" jstcache="0">
28 <div id="searchbox" jstcache="0">
29 <form action="http://www.google.com/cse" id="cse-search-box" jstcache="0 ">
30 <div jstcache="0">
31 <input type="hidden" name="cx" value="002967670403910741006:61_cvzfq tno" jstcache="0">
32 <input type="hidden" name="ie" value="UTF-8" jstcache="0">
33 <input type="text" name="q" size="31" jstcache="0">
34 <input type="submit" name="sa" value="Search" jstcache="0">
35 </div>
36 </form>
37
38 <script type="text/javascript" src="http://www.google.com/jsapi" jstcach e="0"></script>
39 <script type="text/javascript" jstcache="0">google.load("elements", "1", {packages: "transliteration"});</script>
40 <script type="text/javascript" src="http://www.google.com/coop/cse/t13n? form=cse-search-box&amp;t13n_langs=en" jstcache="0"></script>
41 <script type="text/javascript" src="http://www.google.com/coop/cse/brand ?form=cse-search-box&amp;lang=en" jstcache="0"></script>
42 </div>
43 <div id="pageTitle" jstcache="0">
44 <h1 jscontent="getPageTitle()" jstcache="1">Overview</h1>
45 </div>
46 </div> <!-- /pageHeader -->
47
48 <div id="pageContent" jstcache="0">
49 <!-- SIDENAV -->
50 <div id="leftNav" jstcache="0">
51 <ul jstcache="0">
52 <li jstcache="0"> <a href="index.html" jstcache="0">Home</a></li>
53 <li jstcache="0"> <a href="getstarted.html" jstcache="0">Getting Start ed</a></li>
54 <li jstcache="0" class="leftNavSelected">Overview </li>
55 <li jstcache="0"> <a href="devguide.html" jstcache="0"><div jstcache=" 0">Developer's Guide</div></a>
56 <ul jstcache="0">
57 <li jstcache="0"><a href="toolstrip.html" jstcache="0">Toolstrips< /a></li>
58 <li jstcache="0"><a href="pageActions.html" jstcache="0">Page Acti ons</a></li>
59 <li jstcache="0"><a href="background_pages.html" jstcache="0">Back ground Pages</a></li>
60 <li jstcache="0"><a href="content_scripts.html" jstcache="0">Conte nt Scripts</a></li>
61 <li jstcache="0"><a href="events.html" jstcache="0">Events</a></li >
62 <li jstcache="0"><a href="tabs.html" jstcache="0">Tabs</a></li>
63 <li jstcache="0"><a href="windows.html" jstcache="0">Windows</a></ li>
64 <li jstcache="0"><a href="bookmarks.html" jstcache="0">Bookmarks</ a></li>
65 <li jstcache="0"><a href="themes.html" jstcache="0">Themes</a></li >
66 <li jstcache="0"><a href="npapi.html" jstcache="0">NPAPI Plugins</ a></li>
67 <li jstcache="0"><a href="packaging.html" jstcache="0">Packaging</ a></li>
68 <li jstcache="0">Autoupdate</li>
69 </ul>
70 </li>
71 <li jstcache="0"><a href="tutorials.html" jstcache="0"><div jstcache=" 0">Tutorials</div></a>
72 <ul jstcache="0">
73 <li jstcache="0"><a href="tut_debugging.html" jstcache="0">Debuggi ng</a></li>
74 </ul>
75 </li>
76 <li jstcache="0">Reference
77 <ul jstcache="0">
78 <li jstcache="0"> Formats
79 <ul jstcache="0">
80 <li jstcache="0"><a href="manifest.html" jstcache="0">Manifest Files</a></li>
81 <li jstcache="0"><a href="match_patterns.html" jstcache="0">Ma tch Patterns</a></li>
82 <li jstcache="0">Packages (.crx)</li>
83 </ul>
84 </li>
85 <li jstcache="0"> <a href="api_index.html" jstcache="0">chrome.* A PIs</a> </li>
86 <li jstcache="0"> <a href="api_other.html" jstcache="0">Other APIs </a> </li>
87 </ul>
88 </li>
89 <li jstcache="0"><a href="http://dev.chromium.org/developers/design-doc uments/extensions/samples" jstcache="0">Samples</a></li>
90 </ul>
91 </div>
92
93 <div id="mainColumn" jstcache="0">
94 <!-- TABLE OF CONTENTS -->
95 <div id="toc" jsdisplay="showPageTOC()" jstcache="2">
96 <p jstcache="0">Contents</p>
97 <ol jstcache="0">
98 <li jsselect="getStaticTOC()" jstcache="9" jsinstance="0">
99 <a jscontent="name" jsvalues=".href:'#' + href" jstcache="14" href ="#what">The basics</a>
100 <ol jstcache="0">
101 <li jsselect="$this.children" jstcache="22" jsinstance="*0" styl e="display: none; ">
102 <a jscontent="name" jsvalues=".href:'#' + href" jstcache="14"> h3Name</a>
103 </li>
104 </ol>
105 </li><li jsselect="getStaticTOC()" jstcache="9" jsinstance="1">
106 <a jscontent="name" jsvalues=".href:'#' + href" jstcache="14" href ="#files">Files</a>
107 <ol jstcache="0">
108 <li jsselect="$this.children" jstcache="22" jsinstance="0">
109 <a jscontent="name" jsvalues=".href:'#' + href" jstcache="14" href="#H3-2">Referring to files</a>
110 </li><li jsselect="$this.children" jstcache="22" jsinstance="*1" >
111 <a jscontent="name" jsvalues=".href:'#' + href" jstcache="14" href="#H3-3">The manifest file</a>
112 </li>
113 </ol>
114 </li><li jsselect="getStaticTOC()" jstcache="9" jsinstance="2">
115 <a jscontent="name" jsvalues=".href:'#' + href" jstcache="14" href ="#arch">Architecture</a>
116 <ol jstcache="0">
117 <li jsselect="$this.children" jstcache="22" jsinstance="0">
118 <a jscontent="name" jsvalues=".href:'#' + href" jstcache="14" href="#background">The background page</a>
119 </li><li jsselect="$this.children" jstcache="22" jsinstance="*1" >
120 <a jscontent="name" jsvalues=".href:'#' + href" jstcache="14" href="#contentScripts">Content scripts</a>
121 </li>
122 </ol>
123 </li><li jsselect="getStaticTOC()" jstcache="9" jsinstance="3">
124 <a jscontent="name" jsvalues=".href:'#' + href" jstcache="14" href ="#H2-7">Communication </a>
125 <ol jstcache="0">
126 <li jsselect="$this.children" jstcache="22" jsinstance="*0" styl e="display: none; ">
127 <a jscontent="name" jsvalues=".href:'#' + href" jstcache="14"> h3Name</a>
128 </li>
129 </ol>
130 </li><li jsselect="getStaticTOC()" jstcache="9" jsinstance="*4">
131 <a jscontent="name" jsvalues=".href:'#' + href" jstcache="14" href ="#H2-8"> Summary </a>
132 <ol jstcache="0">
133 <li jsselect="$this.children" jstcache="22" jsinstance="*0" styl e="display: none; ">
134 <a jscontent="name" jsvalues=".href:'#' + href" jstcache="14"> h3Name</a>
135 </li>
136 </ol>
137 </li>
138 <div jsselect="apiDefinition" jstcache="3" style="display: none; ">
139 <li jstcache="0">
140 <a href="#apiReference" jscontent="'API reference: ' + getModule Name()" jstcache="4">API reference</a>
141 <ol jstcache="0">
142 <li jsdisplay="$this.properties" jstcache="5">
143 <a href="#properties" jstcache="0">Properties</a>
144 <ol jstcache="0">
145 <li jsselect="getPropertyListFromObject($this)" jstcache=" 10">
146 <a jscontent="name" jsvalues=".href:'#property-' + name" href="#property-anchor" jstcache="42">propertyName</a>
147 </li>
148 </ol>
149 </li>
150 <li jsdisplay="functions &amp;&amp; functions.length &gt; 0" j stcache="6">
151 <a href="#methods" jstcache="0">Methods</a>
152 <ol jstcache="0">
153 <li jsselect="functions.sort(sortByName)" jstcache="11">
154 <a jscontent="name" jsvalues=".href:'#method-' + name" h ref="#method-anchor" jstcache="43">methodName</a>
155 </li>
156 </ol>
157 </li>
158 <li jsdisplay="events &amp;&amp; events.length &gt; 0" jstcach e="7">
159 <a href="#events" jstcache="0">Events</a>
160 <ol jstcache="0">
161 <li jsselect="events.sort(sortByName)" jstcache="12">
162 <a jscontent="name" jsvalues=".href:'#event-' + name" hr ef="#event-anchor" jstcache="44">eventName</a>
163 </li>
164 </ol>
165 </li>
166 <li jsdisplay="types &amp;&amp; types.length &gt; 0" jstcache= "8">
167 <a href="#types" jstcache="0">Types</a>
168 <ol jstcache="0">
169 <li jsselect="types.sort(sortByName)" jstcache="38">
170 <a jscontent="id" jsvalues=".href:'#type-' + id" href="# id-anchor" jstcache="45">id</a>
171 </li>
172 </ol>
173 </li>
174 </ol>
175 </li>
176 </div>
177 </ol>
178 </div>
179 <!-- /TABLE OF CONTENTS -->
180
181 <!-- STATIC CONTENT PLACEHOLDER -->
182 <div id="static" jstcache="0"><div id="pageData-title" class="pageData" jstcache="0">Overview</div>
183 <div id="pageData-showTOC" class="pageData" jstcache="0">true</div>
184
185 <p jstcache="0">
186 Please read this page;
187 it has vital information about the extension architecture.
188 If you get bored or restless,
189 take a break!
190 We suggest bouncing between this page
191 and tutorials
192 such as <a href="getstarted.html" jstcache="0">Getting Started</a>
193 and <a href="tut_debugging.html" jstcache="0">Debugging</a>.
194 </p>
195
196
197 <h2 id="what" jstcache="0">The basics</h2>
198
199 <p jstcache="0">
200 An extension is a zipped bundle of files —
201 HTML, CSS, JavaScript, images, and anything else you need —
202 that adds functionality to the Google Chrome browser.
203 Because an extension is just a special kind of web page,
204 it can use all the APIs
205 that the browser provides
206 to web pages and apps,
207 from XMLHttpRequest to JSON to localStorage.
208 </p>
209
210 <p jstcache="0">
211 Extensions can add UI to Google Chrome,
212 in the form of
213 <a href="toolstrip.html" jstcache="0">toolstrips</a> (toolbar additions)
214 and <a href="pageActions.html" jstcache="0">page actions</a>
215 (clickable badges in the address bar).
216 Extensions can also interact programmatically
217 with browser features such as
218 <a href="bookmarks.html" jstcache="0">bookmarks</a>
219 and <a href="tabs.html" jstcache="0">tabs</a>.
220 </p>
221
222 <p jstcache="0">
223 To find a complete list of extension features,
224 with implementation details
225 for each one,
226 see the <a href="devguide.html" jstcache="0">Developer's Guide</a>.
227 </p>
228
229
230 <h2 id="files" jstcache="0">Files</h2>
231 <p jstcache="0">
232 Each extension has the following files:
233 <!-- PENDING: This could use a picture -->
234 </p>
235
236 <ul jstcache="0">
237 <li jstcache="0">A <b jstcache="0">manifest file</b></li>
238 <li jstcache="0">One or more <b jstcache="0">HTML files</b> (unless the extens ion is a theme)</li>
239 <li jstcache="0"><em jstcache="0">Optional:</em> One or more <b jstcache="0">J avaScript files</b></li>
240 <li jstcache="0"><em jstcache="0">Optional:</em> Any other files your extensio n needs — for example, image files</li>
241 </ul>
242
243 <p jstcache="0">
244 While you're working on your extension,
245 you put all these files into a single folder.
246 When you distribute your extension,
247 the contents of the folder are packaged into a special zipfile
248 that has a <code jstcache="0">.crx</code> suffix,
249 as described in <a href="packaging.html" jstcache="0">Packaging</a>.
250 </p>
251
252
253 <a name="H3-2" jstcache="0"></a><h3 jstcache="0">Referring to files</h3>
254
255 <p jstcache="0">
256 You can put any file you like into an extension,
257 but how do you use it?
258 Usually,
259 you can refer to the file using a relative URL,
260 just as you would in an ordinary HTML page.
261 Here's an example of referring to
262 a file named <code jstcache="0">myimage.png</code>
263 that's in a subdirectory named <code jstcache="0">images</code>.
264 </p>
265
266 <pre jstcache="0">&lt;img <b jstcache="0">src="images/myimage.png"</b> style="wi dth:auto; height:auto"&gt;
267 </pre>
268
269 <p jstcache="0">
270 As you might notice while you use the Google Chrome debugger,
271 every file in an extension is also accessible by an absolute URL like this:
272 </p>
273
274 <blockquote jstcache="0">
275 <b jstcache="0">chrome-extension://</b><em jstcache="0">&lt;extensionID&gt;</em> <b jstcache="0">/</b><em jstcache="0">&lt;pathToFile&gt;</em>
276 </blockquote>
277
278 <p jstcache="0">
279 In that URL, the <em jstcache="0">&lt;extensionID&gt;</em> is a unique identifie r
280 that the extension system generates for each extension.
281 You can see the IDs for all your loaded extensions
282 by going to the URL <b jstcache="0">chrome://extensions/</b>.
283 The <em jstcache="0">&lt;pathToFile&gt;</em> is the location of the file
284 under the extension's top directory;
285 it's the same as the relative URL.
286 </p>
287
288 <p jstcache="0">
289 For example, assume your extension has
290 the ID <b jstcache="0">aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</b>
291 and the files shown in the following figure:
292 </p>
293
294 <pre jstcache="0"><span class="comment" jstcache="0">[PENDING: convert this into a figure]</span>
295 toolstrip.html
296 styles.css
297 images:
298 myimage.png
299 ...
300 other:
301 more.html
302 morestyles.css
303 ...
304 </pre>
305
306 <p jstcache="0">
307 Here's a table that shows the relative and absolute URLs of these files.
308 Keep in mind that the relative URL is the same no matter where you're using it —
309 the relative URL of <code jstcache="0">myimage.png</code> is
310 <b jstcache="0">images/myimage.png</b>,
311 no matter whether it's being used by
312 <code jstcache="0">toolstrip.html</code> or <code jstcache="0">other/more.html</ code>.
313 </p>
314
315 <table jstcache="0">
316 <tbody jstcache="0"><tr jstcache="0">
317 <th jstcache="0"> File </th>
318 <th jstcache="0"> Relative URL </th>
319 <th jstcache="0"> Absolute URL </th>
320 </tr>
321 <tr jstcache="0">
322 <td jstcache="0"> toolstrip.html </td>
323 <td jstcache="0"> toolstrip.html </td>
324 <td jstcache="0"> chrome-extension://aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/toolstri p.html </td>
325 </tr>
326 <tr jstcache="0">
327 <td jstcache="0"> styles.css </td>
328 <td jstcache="0"> styles.css </td>
329 <td jstcache="0"> chrome-extension://aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/styles.c ss </td>
330 </tr>
331 <tr jstcache="0">
332 <td jstcache="0"> myimage.png </td>
333 <td jstcache="0"> images/myimage.png </td>
334 <td jstcache="0"> chrome-extension://aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/images/m yimage.png </td>
335 </tr>
336 <tr jstcache="0">
337 <td jstcache="0"> more.html </td>
338 <td jstcache="0"> other/more.html </td>
339 <td jstcache="0"> chrome-extension://aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/other/mo re.html </td>
340 </tr>
341 <tr jstcache="0">
342 <td jstcache="0"> morestyles.css </td>
343 <td jstcache="0"> other/morestyles.css </td>
344 <td jstcache="0"> chrome-extension://aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/other/mo restyles.css </td>
345 </tr>
346 </tbody></table>
347
348 <p class="comment" jstcache="0">
349 [PENDING: Mention/reflect/link to
350 <a href="http://dev.chromium.org/developers/design-documents/extensions/i18n" js tcache="0">internationalization</a>]
351 </p>
352
353
354 <a name="H3-3" jstcache="0"></a><h3 jstcache="0">The manifest file</h3>
355
356 <p jstcache="0">
357 The manifest file, called <code jstcache="0">manifest.json</code>,
358 gives information about the extension,
359 such as the most important files
360 and the capabilities that the extension might use.
361 Here's a typical manifest file for a toolstrip
362 that uses information from google.com:
363 </p>
364
365 <pre jstcache="0">{
366 "name": "My Extension",
367 "version": "2.1",
368 "description": "Gets information from Google.",
369 "update_url": "http://example.com/mytestextension/updates.xml",
370 "permissions": ["http://*.google.com/", "https://*.google.com/"],
371 "toolstrips": ["my_toolstrip.html"]
372 }</pre>
373
374 <p jstcache="0">
375 For details, see
376 <a href="manifest.html" jstcache="0">Manifest Files</a>.
377 </p>
378
379 <h2 id="arch" jstcache="0">Architecture</h2>
380
381 <p jstcache="0">
382 The following pictures shows the web pages associated with a typical extension
383 (in this case, a simple toolstrip).
384 The first figure shows what an extension might look like
385 when there's a single browser window.
386 </p>
387
388 <p class="comment" jstcache="0"> [PENDING: image goes here] </p>
389
390 <p jstcache="0">
391 The next figure shows that all the code in the extension's main HTML file
392 is duplicated each time you create a new window.
393 In other words, each window has its own widgets for the extension,
394 which means each window adds another web page for that extension.
395 </p>
396
397 <p class="comment" jstcache="0"> [PENDING: image goes here] </p>
398
399 <p jstcache="0">
400 To more easily coordinate all these web pages and to avoid duplication,
401 you should design your extension
402 so that most of the code —
403 especially the state of the extension —
404 is in a <em jstcache="0">background page</em>,
405 as shown in the following figure.
406 </p>
407
408 <p class="comment" jstcache="0">
409 [PENDING: image goes here.]
410 </p>
411
412
413 <h3 id="background" jstcache="0">The background page</h3>
414 <p jstcache="0">
415 Any non-trivial extension can (and probably should)
416 have a background page.
417 The background page is an invisible page
418 where you put the main logic of the extension.
419 The extension's other pages should have
420 only the code that's necessary
421 to show the state of the extension
422 and to get input from the user.</p>
423
424 <p jstcache="0">
425 An extension's background page exists
426 before any of the extension's other pages exist.
427 It continues to exist as long as the browser is running
428 and the extension is installed,
429 even if other pages and windows go away.
430 </p>
431
432 <p jstcache="0">
433 Your extension's UI —
434 its toolstrips, page actions, and so on —
435 should be dumb views.
436 When the view needs some state,
437 it should request it from the background page.
438 When the background page notices some state change,
439 it should update all the views.
440 </p>
441
442 <p jstcache="0">
443 For more information, see
444 <a href="background_pages.html" jstcache="0">Background Pages</a>.
445 </p>
446
447 <h3 id="contentScripts" jstcache="0">Content scripts</h3>
448
449 <p jstcache="0">
450 If you want your extension to interact with web pages,
451 you need a content script.
452 Content scripts are JavaScript files that run in the context of web pages.
453 By using the standard Document Object Model (DOM),
454 they can read details of the web pages the browser visits,
455 and they can make changes to the pages.
456 </p>
457
458 <p class="comment" jstcache="0">
459 [PENDING: add an architectural figure here,
460 showing the extension's pages, a web page, and the content script
461 interacting with the web page. explain the figure.]
462 </p>
463
464 <p jstcache="0">
465 For more information,
466 see <a href="content_scripts.html" jstcache="0">Content Scripts</a>.
467 </p>
468
469
470 <a name="H2-7" jstcache="0"></a><h2 jstcache="0">Communication </h2>
471
472 <p jstcache="0">
473 Two kinds of communication happen within an extension:
474 </p>
475
476 <ul jstcache="0">
477 <li jstcache="0">
478 Communication <b jstcache="0">between pages</b> in the extension.
479 <br jstcache="0">
480 For example, sometimes the background page
481 needs to update all the UI pages
482 to reflect a change in the extension's state.
483 </li>
484 <li jstcache="0">
485 Communication <b jstcache="0">between content scripts and the extension</b>.
486 <br jstcache="0">
487 For example,
488 <span class="comment" jstcache="0">[PENDING: typical use case goes here]</sp an>.
489 See <a href="content_scripts.html" jstcache="0">Content Scripts</a>
490 for information about this type of communication.
491 </li>
492 </ul>
493
494 <p jstcache="0">
495 Here are some keys to communication between an extension's pages:
496 </p>
497
498 <ul jstcache="0">
499 <li jstcache="0">
500 All the extension's pages execute in same process,
501 on the same thread.
502 </li>
503 <li jstcache="0">
504 Extension pages can use
505 <a href="extension.html" jstcache="0"><code jstcache="0">chrome.extension</c ode></a>
506 methods such as
507 <code jstcache="0">getViews()</code>,
508 <code jstcache="0">getBackgroundPage()</code>,
509 and <code jstcache="0">getToolstrips()</code>
510 to get access to the extension's pages.
511 </li>
512 <li jstcache="0">
513 Once you have references to an extension's pages,
514 you can manipulate the DOM for each page.
515 </li>
516 <li jstcache="0">
517 You can also make direct function calls to the pages,
518 as shown in the following example.
519 </li>
520 </ul>
521
522 <p jstcache="0">
523 Here's an example of
524 communication between toolstrips and the background page.
525 </p>
526
527 <pre jstcache="0">//In background_page.html:
528 function updateUI(checked) {
529 var toolstrips = chrome.extension.getToolstrips();
530 for (var i in toolstrips) {
531 if (toolstrips[i].enableCheckbox)
532 toolstrips[i].enableCheckbox(checked);
533 }
534 }
535
536 //In toolstrip.html:
537 function enableCheckbox(checked) {
538 var cb = document.getElementById('checkbox');
539 cb.checked = checked;
540 }
541 </pre>
542
543 <p jstcache="0">
544 A good summary of communication mechanisms is at
545 <a href="http://www.chromeplugins.org/google/plugins-development/communication-7 883.html" jstcache="0">http://www.chromeplugins.org/google/plugins-development/c ommunication-7883.html</a>.
546 </p>
547
548
549 <a name="H2-8" jstcache="0"></a><h2 jstcache="0"> Summary </h2>
550
551 <p jstcache="0">
552 [
553 PENDING: wrap it up. suggest where to go next. Probably:
554 <a href="getstarted.html" jstcache="0">Getting Started</a>,
555 <a href="tut_debugging.html" jstcache="0">Debugging</a>,
556 <a href="devguide.html" jstcache="0">Developer's Guide</a>.
557 ]
558 </p>
559 </div>
560
561 <!-- API PAGE -->
562 <div class="apiPage" jsselect="apiDefinition" jstcache="3" style="displa y: none; ">
563 <a name="apiReference" jstcache="0"></a>
564 <h2 jscontent="'API reference: ' + getModuleName()" jstcache="4">API ref erence: chrome.apiname </h2>
565
566 <!-- PROPERTIES -->
567 <div jsdisplay="$this.properties" class="apiGroup" jstcache="5">
568 <a name="properties" jstcache="0"></a>
569 <h3 id="properties" jstcache="0">Properties</h3>
570
571 <div jsselect="getPropertyListFromObject($this)" jstcache="10">
572 <a jsvalues=".name:'property-' + name" jstcache="15"></a>
573 <h4 jscontent="name" jstcache="16">getLastError</h4>
574 <div class="summary" jstcache="0">
575 <!-- Note: intentionally longer 80 columns -->
576 <span jscontent="getModuleName() + '.'" jstcache="23">chrome.ext ension</span><span jscontent="$this.name" jstcache="24">lastError</span>
577 </div>
578 <div transclude="valueTemplate" jstcache="17">
579 </div>
580 </div>
581
582 </div> <!-- /apiGroup -->
583
584 <!-- METHODS -->
585 <div jsdisplay="functions &amp;&amp; functions.length &gt; 0" class="a piGroup" id="methods" jstcache="6">
586 <a name="methods" jstcache="0"></a>
587 <h3 jstcache="0">Methods</h3>
588
589 <!-- iterates over all functions -->
590 <div class="apiItem" jsselect="functions.sort(sortByName)" jstcache= "11">
591 <a jsvalues=".name:'method-' + name" jstcache="18"></a> <!-- metho d-anchor -->
592 <h4 jscontent="name" jstcache="16">method name</h4>
593
594 <div class="summary" jstcache="0"><span jsdisplay="returns" jscont ent="getTypeName(returns)" jstcache="25">void</span>
595 <!-- Note: intentionally longer 80 columns -->
596 <span jscontent="getFullyQualifiedFunctionName($this)" jstcach e="26">chrome.module.methodName</span>(<span jsselect="parameters" jsvalues="cla ss:optional ? 'optional' : ''" jstcache="27"><span jsdisplay="$index" jstcache=" 33">, </span><span jscontent="getTypeName($this)" jstcache="34"></span>
597 <var jstcache="0"><span jscontent="name" jstcache="16"></s pan></var></span>)</div>
598
599 <div class="description" jstcache="0">
600 <p class="todo" jsdisplay="!description" jstcache="28">Undocumen ted.</p>
601 <p jsdisplay="description" jsvalues=".innerHTML:description" jst cache="29">
602 A description from the json schema def of the function goes he re.
603 </p>
604
605 <!-- PARAMETERS -->
606 <h4 jstcache="0">Parameters</h4>
607 <dl jstcache="0">
608 <div jsselect="parameters" jstcache="35">
609
610 <!-- VALUE: This is a subtemplate that is used elsewhere
611 via jsTemplate *transclude* -->
612 <div id="valueTemplate" jstcache="0">
613 <dt jstcache="0">
614 <var jsdisplay="$this.name" jscontent="$this.name" jstca che="46">paramName</var>
615 <em jstcache="0">
616
617 <!-- TYPE -->
618 <div style="display:inline" jstcache="0">
619 (
620 <span class="optional" jsdisplay="optional" jstc ache="47">optional</span>
621 <span id="typeTemplate" jstcache="0">
622 <span jsdisplay="getTypeRef($this)" jstcache=" 48">
623 <a jsvalues=".href: getTypeRefPage($this) + '#type-' + getTypeRef($this)" jscontent="getTypeRef($this)" jstcache="50"> Type< /a>
624 </span>
625 <span jsdisplay="!getTypeRef($this)" jstcache= "49">
626 <span jsdisplay="isArray($this)" jstcache="5 1">
627 array of <span jsselect="items" jstcache=" 53"><span transclude="typeTemplate" jstcache="54"></span></span>
628 </span>
629 <span jsdisplay="!isArray($this)" jscontent= "getTypeName($this)" jstcache="52">paramType</span>
630 </span>
631 </span>
632 )
633 </div>
634
635 </em>
636 </dt>
637 <dd class="todo" jsdisplay="!$this.description" jstcache=" 39">
638 Undocumented.
639 </dd>
640 <dd jsdisplay="$this.description" jsvalues=".innerHTML:$th is.description" jstcache="40">
641 Description of this parameter from the json schema.
642 </dd>
643
644 <!-- OBJECT PROPERTIES -->
645 <dd jsdisplay="shouldExpandObject($this)" jstcache="41">
646 <dl jstcache="0">
647 <div jsselect="getPropertyListFromObject($this)" jstca che="10">
648 <div transclude="valueTemplate" jstcache="17">
649 </div>
650 </div>
651 </dl>
652 </dd>
653 </div> <!-- /VALUE -->
654
655 </div>
656 </dl>
657
658 <!-- RETURNS -->
659 <h4 jsdisplay="returns" jstcache="30">Returns</h4>
660 <dl jstcache="0">
661 <div jsselect="returns" jstcache="36">
662 <div transclude="valueTemplate" jstcache="17">
663 </div>
664 </div>
665 </dl>
666
667 <!-- CALLBACK -->
668 <div jsdisplay="hasCallback(parameters)" jstcache="31">
669 <div jsselect="getCallbackParameters(parameters)" jstcache="37 ">
670 <h4 jstcache="0">Callback function</h4>
671 <p jstcache="0">
672 If you specify the <em jstcache="0">callback</em> parameter,
673 it should specify a function that looks like this:
674 </p>
675
676 <!-- Note: intentionally longer 80 columns -->
677 <pre jstcache="0">function(<span jscontent="getSignatureString (parameters)" jstcache="32">Type param1, Type param2</span>) <span class="subdue d" jstcache="0">{...}</span>);</pre>
678 <dl jstcache="0">
679 <div jsselect="parameters" jstcache="35">
680 <div transclude="valueTemplate" jstcache="17">
681 </div>
682 </div>
683 </dl>
684 </div>
685 </div>
686
687 </div> <!-- /description -->
688
689 </div> <!-- /apiItem -->
690
691 </div> <!-- /apiGroup -->
692
693 <!-- EVENTS -->
694 <div jsdisplay="events &amp;&amp; events.length &gt; 0" class="apiGrou p" jstcache="7">
695 <a name="events" jstcache="0"></a>
696 <h3 id="events" jstcache="0">Events</h3>
697
698 <!-- iterates over all events -->
699 <div jsselect="events.sort(sortByName)" class="apiItem" jstcache="12 ">
700 <a jsvalues=".name:'event-' + name" jstcache="19"></a>
701 <h4 jscontent="name" jstcache="16">event name</h4>
702
703 <div class="summary" jstcache="0">
704 <!-- Note: intentionally longer 80 columns -->
705 <span jscontent="getModuleName() + '.'" class="subdued" jstcache ="23">chrome.bookmarks</span><span jscontent="name" jstcache="16">onEvent</span> <span class="subdued" jstcache="0">.addListener</span>(function(<span jscontent= "getSignatureString(parameters)" jstcache="32">Type param1, Type param2</span>) <span class="subdued" jstcache="0">{...}</span>);
706 </div>
707
708 <div class="description" jstcache="0">
709 <p class="todo" jsdisplay="!description" jstcache="28">Undocumen ted.</p>
710 <p jsdisplay="description" jsvalues=".innerHTML:description" jst cache="29">
711 A description from the json schema def of the event goes here.
712 </p>
713
714 <!-- PARAMETERS -->
715 <h4 jstcache="0">Parameters</h4>
716 <dl jstcache="0">
717 <div jsselect="parameters" jstcache="35">
718 <div transclude="valueTemplate" jstcache="17">
719 </div>
720 </div>
721 </dl>
722
723 </div> <!-- /decription -->
724
725 </div> <!-- /apiItem -->
726
727 </div> <!-- /apiGroup -->
728
729 <!-- TYPES -->
730 <div jsdisplay="types &amp;&amp; types.length &gt; 0" class="apiGroup" jstcache="8">
731 <a name="types.sort(sortByName)" jstcache="0"></a>
732 <h3 id="types" jstcache="0">Types</h3>
733
734 <!-- iterates over all types -->
735 <div jsselect="types" class="apiItem" jstcache="13">
736 <a jsvalues=".name:'type-' + id" jstcache="20"></a>
737 <h4 jscontent="id" jstcache="21">type name</h4>
738
739 <div transclude="valueTemplate" jstcache="17">
740 </div>
741
742 </div> <!-- /apiItem -->
743
744 </div> <!-- /apiGroup -->
745
746 </div> <!-- /apiPage -->
747 </div> <!-- /mainColumn -->
748 </div> <!-- /pageContent -->
749 <div id="pageFooter" --="" jstcache="0">
750 <p jstcache="0">
751 Except as otherwise <a href="http://code.google.com/policies.html#restrictions " jstcache="0">noted</a>,
752 the content of this page is licensed under the <a rel="license" href="http://c reativecommons.org/licenses/by/3.0/" jstcache="0">Creative Commons
753 Attribution 3.0 License</a>, and code samples are licensed under the
754 <a rel="license" href="http://code.google.com/google_bsd_license.html" jstcach e="0">BSD License</a>.
755 </p>
756 <p jstcache="0">
757 ©2009 Google
758 </p>
759 </div> <!-- /pageFooter -->
760 </div> <!-- /container -->
761 </body></html>
762 #EOF
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698