blob: c6a1049555fafb334bef9719155f37ff2c72a333 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Checks that there is only one window and one tab, and calls back |callback|
// with its id (or -1 if there is more than 1 window or more than 1 tab).
function getCurrentSingleTabId(callback) {
chrome.windows.getAll({"populate":true}, function(windows) {
if (windows.length != 1 || windows[0].tabs.length != 1) {
callback(-1);
} else {
callback(windows[0].tabs[0].id);
}
});
}
function navigateCurrentTab(url) {
getCurrentSingleTabId(function(tabid) {
chrome.tabs.update(tabid, {"url": url});
});
}
function onclick(info) {
navigateCurrentTab(chrome.extension.getURL("test2.html"));
}
window.onload = function() {
chrome.experimental.contextMenu.create({"title":"Extension Item 1",
"onclick": onclick}, function(id) {
if (!chrome.extension.lastError) {
navigateCurrentTab(chrome.extension.getURL("test.html"));
}
});
};
|