From 39a2e833dc1983b78e9cf78df3d8f3cda3f150c9 Mon Sep 17 00:00:00 2001
From: "kathyw@google.com"
-For more information, see -Background Pages. +See the Browser Actions page and +the Communication between pages section +for example code and more details.
+If your extension needs to interact with web pages, then it needs a content script. -Content scripts are JavaScript files that run in the context of web pages. -Using the standard -Document Object Model -(DOM), -content scripts can read details of the web pages the browser visits, -and they can make changes to the pages. +A content script is some JavaScript +that executes in the context of a page +that's been loaded into the browser. +Think of a content script as part of that loaded page, +not as part of the extension it was packaged with +(its parent extension).
+Content scripts can read details of the web pages the browser visits, +and they can make changes to the pages. In the following figure, the content script can read and modify -the DOM for the web page displayed in Window 1. -If the toolstrip's UI needs to change -to reflect the web page's contents, -the content script can request that change -by sending a message to the parent extension. +the DOM for the displayed web page. +It cannot, however, modify the DOM of its parent extension's background page. +
+ ++Content scripts aren't completely cut off from their parent extensions. +A content script can exchange messages with its parent extension, +as the arrows in the following figure show. +For example, a content script might send a message +whenever it finds an RSS feed in a browser page. +Or a background page might send a message +asking a content script to change the appearance of its browser page.
The HTML pages within an extension often need to communicate.
-An example is when the background page tells
-UI pages (such as toolstrips)
-to update their appearance.
+
+[PENDING: For example, ...]
+
Because all of an extension's pages
execute in same process on the same thread,
the pages can make direct function calls to each other.
@@ -500,38 +527,17 @@ the pages can make direct function calls to each other.
To find pages in the extension, use
chrome.extension
methods such as
-getViews()
,
-getBackgroundPage()
,
-and getToolstrips()
.
+getViews()
and
+getBackgroundPage()
.
Once a page has a reference to other pages within the extension,
-the first page can invoke functions on the other pages.
-It can even manipulate their DOMs.
-
-Here's an example of -communication between toolstrips and the background page. +the first page can invoke functions on the other pages, +and it can manipulate their DOMs.
-//In background.html: -function updateUI(checked) { - var toolstrips = chrome.extension.getToolstrips(); - for (var i in toolstrips) { - if (toolstrips[i].enableCheckbox) - toolstrips[i].enableCheckbox(checked); - } -} - -//In toolstrip.html: -function enableCheckbox(checked) { - var cb = document.getElementById('checkbox'); - cb.checked = checked; -} -- -
-A good summary of communication mechanisms is at -http://www.chromeplugins.org/google/plugins-development/communication-7883.html. +
+[PENDING: Here's an example of +communication between xyz and the background page. +(code example goes here)]
diff --git a/chrome/common/extensions/docs/static/overview.html b/chrome/common/extensions/docs/static/overview.html index d29f2f8..072f767 100644 --- a/chrome/common/extensions/docs/static/overview.html +++ b/chrome/common/extensions/docs/static/overview.html @@ -2,8 +2,6 @@-Read this page! -It has vital information about the extension architecture. Once you've finished this page and the Getting Started tutorial, @@ -27,10 +25,8 @@ from XMLHttpRequest to JSON to HTML5 local storage.
Many extensions add UI to Google Chrome, in the form of -toolstrips (toolbar additions), -browser actions, -or page actions -(clickable badges in the address bar). +browser actions +or page actions. Extensions can also interact programmatically with browser features such as bookmarks @@ -42,13 +38,21 @@ extensions can use
+Note: +Each extension can have at most one browser action or page action. +Choose a browser action when the extension is relevant to most pages. +Choose a page action when the extension's icon +should appear or disappear, +depending on the page. +
+ +See the Developer's Guide for a complete list of extension features, with implementation details for each one.
-
Each extension has the following files:
@@ -103,7 +107,7 @@ every file in an extension is also accessible by an absolute URL like this:
In that URL, the <extensionID> is a unique identifier
that the extension system generates for each extension.
You can see the IDs for all your loaded extensions
-by going to the URL chrome://extensions/.
+by going to the URL chrome://extensions.
The <pathToFile> is the location of the file
under the extension's top folder;
it's the same as the relative URL.
@@ -123,7 +127,7 @@ The manifest file, called manifest.json
,
gives information about the extension,
such as the most important files
and the capabilities that the extension might use.
-Here's a typical manifest file for a toolstrip
+Here's a typical manifest file for a browser action
that uses information from google.com:
@@ -145,87 +154,105 @@ For details, see
-Remember that extensions are essentially web pages.
-The following figure shows what
-a simple extension with a toolstrip
-might look like
-when there's a single browser window.
-The toolstrip (T1) is at the bottom of the window.
-The HTML and JavaScript code for T1
-is in a web page
-(toolstrip.html
).
+Most extensions have a
+background page,
+an invisible page
+that holds the main logic of the extension.
+
+[PENDING: unnecessary?]
+No matter how many windows or tabs the user opens,
+there's only one copy of the background page.
+
-Each time the user creates a new window,
-the browser creates new toolstrips, page actions, and so on.
-Each new bit of UI gets its own web page,
-which means that toolstrips (for example)
-that are in different windows can have different states.
-In the following figure,
-the two toolstrips (T1 and T2)
-are associated with two separate web pages,
-both of which contain code from toolstrip.html
.
-This means that although both toolstrips use the same code,
-one can be blue while the other is green.
+The preceding figure shows a browser
+that has at least two extensions installed:
+a browser action (yellow icon)
+and a page action (blue icon).
+The background page,
+which is defined by an HTML file
+(background.html
),
+has JavaScript code that controls both
+the browser action and the page action.
-If your extension's web pages need to communicate
-or otherwise share information —
-for example, if a browser event
-can affect more than just one window's toolstrip —
-the extension can use a background page.
-The following figure shows a background page
-(background.html
)
-that controls
-the toolstrips in an extension.
+The background page isn't the only HTML page
+that an extension can have.
+For example, a browser action can have a popup,
+which is implemented by an HTML file.
+Extensions can also
+use chrome.tabs.create()
+or window.open()
+to display HTML files that are in the extension.
+The HTML pages inside an extension +have complete access to each other's DOMs, +and they can invoke functions on each other. +
-The background page is an invisible page -where you can put the main logic of the extension. -The extension's other pages should have -only the code that's necessary -to show the state of the extension -and to get input from the user.
+The following figure shows the architecture +of a browser action's popup. +The popup's contents are a web page +defined by an HTML file +(popup.html
).
+The popup doesn't need to duplicate code
+that's in the background page
+(background.html
)
+because the popup can invoke functions on the background page.
+
+
+-For more information, see -Background Pages. +See the Browser Actions page and +the Communication between pages section +for example code and more details.
+If your extension needs to interact with web pages, then it needs a content script. -Content scripts are JavaScript files that run in the context of web pages. -Using the standard -Document Object Model -(DOM), -content scripts can read details of the web pages the browser visits, -and they can make changes to the pages. +A content script is some JavaScript +that executes in the context of a page +that's been loaded into the browser. +Think of a content script as part of that loaded page, +not as part of the extension it was packaged with +(its parent extension).
+Content scripts can read details of the web pages the browser visits, +and they can make changes to the pages. In the following figure, the content script can read and modify -the DOM for the web page displayed in Window 1. -If the toolstrip's UI needs to change -to reflect the web page's contents, -the content script can request that change -by sending a message to the parent extension. +the DOM for the displayed web page. +It cannot, however, modify the DOM of its parent extension's background page. +
+ ++Content scripts aren't completely cut off from their parent extensions. +A content script can exchange messages with its parent extension, +as the arrows in the following figure show. +For example, a content script might send a message +whenever it finds an RSS feed in a browser page. +Or a background page might send a message +asking a content script to change the appearance of its browser page.
The HTML pages within an extension often need to communicate.
-An example is when the background page tells
-UI pages (such as toolstrips)
-to update their appearance.
+
+[PENDING: For example, ...]
+
Because all of an extension's pages
execute in same process on the same thread,
the pages can make direct function calls to each other.
@@ -256,39 +283,17 @@ the pages can make direct function calls to each other.
To find pages in the extension, use
chrome.extension
methods such as
-getViews()
,
-getBackgroundPage()
,
-and getToolstrips()
.
+getViews()
and
+getBackgroundPage()
.
Once a page has a reference to other pages within the extension,
-the first page can invoke functions on the other pages.
-It can even manipulate their DOMs.
+the first page can invoke functions on the other pages,
+and it can manipulate their DOMs.
-Here's an example of -communication between toolstrips and the background page. -
- --//In background.html: -function updateUI(checked) { - var toolstrips = chrome.extension.getToolstrips(); - for (var i in toolstrips) { - if (toolstrips[i].enableCheckbox) - toolstrips[i].enableCheckbox(checked); - } -} - -//In toolstrip.html: -function enableCheckbox(checked) { - var cb = document.getElementById('checkbox'); - cb.checked = checked; -} -- -
-A good summary of communication mechanisms is at -http://www.chromeplugins.org/google/plugins-development/communication-7883.html. +
+[PENDING: Here's an example of +communication between xyz and the background page. +(code example goes here)]
-- cgit v1.1