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/templates/articles/activeTab.html

Issue 10874057: Document the activeTab extension permission. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: tweaks Created 8 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 <style>
2 #active-tab-images {
3 margin-top: 1em;
4 }
5 #active-tab-images tr {
6 vertical-align: top;
7 }
8 #active-tab-images .spacing {
9 width: 1em;
10 }
11 #active-tab-before {
12 width: 334px;
13 }
14 #active-tab-after {
15 width: 265px;
16 }
17 </style>
18
19 <h1>The activeTab permission</h1>
20
21 <p>
22 The <code>activeTab</code> permission gives an extension temporary access to the currently active tab when the user <em>invokes</em> the extension - for example by clicking its <a href="browserAction.html">browser action</a>. Access to the tab lasts until the tab is navigated or closed.
23 </p>
24
25 <p>
26 The main benefit of the <code>activeTab</code> permission is that it displays <e m>no warning message</em> during installation:
27 </p>
28
29 <table id="active-tab-images">
30 <tr>
31 <th>Without activeTab</th>
32 <th class="spacing"></th>
33 <th>With activeTab</th>
34 </tr>
35 <tr>
36 <td><img id="active-tab-before" src="{{static}}/images/active-tab-before.png "></td>
37 <td class="spacing"></td>
38 <td><img id="active-tab-after" src="{{static}}/images/active-tab-after.png"> </td>
39 </tr>
40 </table>
41
42 <h2 id="example">Example</h2>
43
44 <h3 id="manifest.json">manifest.json</h3>
45
46 <p>
47 <pre>
48 {
49 "manifest_version": 2,
50 "name": "Page Redder",
51 "version": 1,
52 <b>"permissions": ["activeTab"]</b>,
53 "browser_action": {},
54 "background": {
55 "scripts": ["background.js"],
56 "persistent": false
57 }
58 }
59 </pre>
60 </p>
61
62 <h3 id="background.js">background.js</h3>
63
64 <p>
65 <pre>
66 chrome.browserAction.onClicked.addListener(function(tab) {
67 // No tabs or host permissions needed!
68 chrome.tabs.executeScript(tab.id, {code:"document.body.bgColor='red'"});
69 });
70 </pre>
71 </p>
72
73 <h2 id="motivation">Motivation</h2>
74
75 <p>
76 Consider a web clipping extension that has a <a href="browserAction.html">browse r action</a> and <a href="contextMenus.html">context menu item</a>. This extensi on may only really need to access tabs when its browser action is clicked, or wh en its context menu item is executed.
77 </p>
78
79 <p>
80 Without <code>activeTab</code>, this extension would need to request full, persi stent access to every web site, just so that it could do its work if it happened to be called upon by the user. This is a lot of power to entrust to such a simp le extension. And if the extension is ever compromised, the attacker gets access to everything the extension had.
81 </p>
82
83 <p>
84 In contrast, an extension with the <code>activeTab</code> permission only obtain s access to a tab in response to an explicit user gesture. If the extension is c ompromised the attacker would need to wait for the user to invoke the extension before obtaining access. And that access only lasts until the tab is navigated o r closed.
85 </p>
86
87 <h2 id="what-activeTab-allows">What activeTab allows</h2>
88
89 <p>
90 While the <code>activeTab</code> permission is enabled for a tab, an extension c an:
91 <ul>
92 <li>Call <code><a href="tabs.html#method-executeScript">executeScript()</a></c ode> or <code><a href="tabs.html#method-insertCSS">insertCSS()</a></code> on tha t tab.
93 <li>Get the URL, title, and favicon for that tab via an API that returns a <co de><a href="tabs.html#type-Tab">Tab</a></code> object (essentially, <code>active Tab</code> grants the <code><a href="tabs.html#manifest">tabs</a></code> permiss ion temporarily).
94 </ul>
95 </p>
96
97 <h2 id="invoking-activeTab">Invoking activeTab</h2>
98
99 <p>
100 The following user gestures enable <code>activeTab</code>:
101 <ul>
102 <li>Executing a <a href="browserAction.html">browser action</a>
103 <li>Executing a <a href="pageAction.html">page action</a>
104 <li>Executing a <a href="contextMenus.html">context menu item</a>
105 <li>Executing a keyboard shortcut from the <a href="commands.html">commands AP I</a>
106 <li>Accepting a suggestion from the <a href="omnibox.html">omnibox API</a>
107 </ul>
108 </p>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698