- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / common / extensions / docs / templates / intros / commands.html
1 <h2 id="manifest">Manifest</h2>
2 <p>
3 You must set manifest_version to (at least) 2 to use this API.
4 </p>
5
6 <h2 id="usage">Usage</h2>
7 <p>The commands API allows you to define specific commands, and bind them to a
8 default key combination. Each command your extension accepts must be listed in
9 the manifest as an attribute of the 'commands' manifest key. An extension can
10 have many commands but only 4 suggested keys can be specified. The user can
11 manually add more shortcuts from the chrome://extensions page.</p>
12
13 <p>Supported keys: A-Z, 0-9, Comma, Period, Home, End, PageUp, PageDown, Insert,
14 Delete, Tab, Arrow keys (Up, Down, Left, Right) and the Media Keys
15 (MediaNextTrack, MediaPlayPause, MediaPrevTrack, MediaStop).</p>
16
17 <p>Note: All key combinations must include either Ctrl* or Alt. Combinations
18 that involve Ctrl+Alt are not permitted in order to avoid conflicts with the
19 AltGr key. Shift can be used in addition to Alt or Ctrl, but is not required.
20 Modifiers (such as Ctrl) can not be used in combination with the Media Keys.<p>
21
22 <p>* Also note that on Mac 'Ctrl' is automatically converted to 'Command'. If
23 you want 'Ctrl' instead, please specify 'MacCtrl'.</p>
24
25 <p>Certain Chrome shortcuts (e.g. window management) always take priority over
26 Extension Command shortcuts and can not be overwritten.</p>
27
28 <pre data-filename="manifest.json">
29 {
30   "name": "My extension",
31   ...
32 <b>  "commands": {
33     "toggle-feature-foo": {
34       "suggested_key": {
35         "default": "Ctrl+Shift+Y",
36         "mac": "Command+Shift+Y"
37       },
38       "description": "Toggle feature foo"
39     },
40     "_execute_browser_action": {
41       "suggested_key": {
42         "windows": "Ctrl+Shift+Y",
43         "mac": "Command+Shift+Y",
44         "chromeos": "Ctrl+Shift+U",
45         "linux": "Ctrl+Shift+J"
46       }
47     },
48     "_execute_page_action": {
49       "suggested_key": {
50         "default": "Ctrl+E",
51         "windows": "Alt+P",
52         "mac": "Option+P"
53       }
54     }
55   }</b>,
56   ...
57 }</pre>
58
59 <p>In your background page, you can bind a handler to each of the commands
60 defined in the manifest (except for '_execute_browser_action' and
61 '_execute_page_action') via onCommand.addListener. For example:</p>
62
63 <pre>
64 chrome.commands.onCommand.addListener(function(command) {
65   console.log('Command:', command);
66 });
67 </pre>
68
69 <p>The '_execute_browser_action' and '_execute_page_action' commands are
70 reserved for the action of opening your extension's popups. They won't normally
71 generate events that you can handle. If you need to take action based on your
72 popup opening, consider listening for an 'onDomReady' event inside your popup's
73 code.
74 </p>