onActivated
タブの変更をリッスンするには、(Chrome 18 以降のみ) を使用する必要があります。非推奨のイベントですonActiveChanged
。onSelectionChanged
ソース コード (添付ファイルを参照)、これらのイベントの目的、およびその使用法。明確にするために、以前の回答を小さなデモで更新しました。
これは、ソース コードの関連部分です。
void ExtensionBrowserEventRouter::ActiveTabChanged(
TabContentsWrapper* old_contents,
TabContentsWrapper* new_contents,
int index,
bool user_gesture) {
ListValue args;
int tab_id = ExtensionTabUtil::GetTabId(new_contents->web_contents());
args.Append(Value::CreateIntegerValue(tab_id));
DictionaryValue* object_args = new DictionaryValue();
object_args->Set(tab_keys::kWindowIdKey, Value::CreateIntegerValue(
ExtensionTabUtil::GetWindowIdOfTab(new_contents->web_contents())));
args.Append(object_args);
// The onActivated event replaced onActiveChanged and onSelectionChanged. The
// deprecated events take two arguments: tabId, {windowId}.
std::string old_json_args;
base::JSONWriter::Write(&args, &old_json_args);
// The onActivated event takes one argument: {windowId, tabId}.
std::string new_json_args;
args.Remove(0, NULL);
object_args->Set(tab_keys::kTabIdKey, Value::CreateIntegerValue(tab_id));
base::JSONWriter::Write(&args, &new_json_args);
Profile* profile = new_contents->profile();
DispatchEvent(profile, events::kOnTabSelectionChanged, old_json_args);
DispatchEvent(profile, events::kOnTabActiveChanged, old_json_args);
DispatchEvent(profile, events::kOnTabActivated, new_json_args);
}