extension_processes_api.cc revision c407dc5cd9bdc5668497f21b26b09d988ab439de
1// Copyright (c) 2010 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/browser/extensions/extension_processes_api.h"
6
7#include "chrome/browser/extensions/extension_tabs_module.h"
8#include "chrome/browser/extensions/extension_processes_api_constants.h"
9#include "chrome/browser/renderer_host/render_process_host.h"
10#include "chrome/browser/tab_contents/tab_contents.h"
11
12namespace keys = extension_processes_api_constants;
13
14DictionaryValue* CreateProcessValue(int process_id) {
15  DictionaryValue* result = new DictionaryValue();
16  result->SetInteger(keys::kIdKey, process_id);
17
18  return result;
19}
20
21bool GetProcessForTabFunction::RunImpl() {
22  int tab_id;
23  EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id));
24
25  TabContents* contents = NULL;
26  int tab_index = -1;
27  if (!ExtensionTabUtil::GetTabById(tab_id, profile(), include_incognito(),
28                                    NULL, NULL, &contents, &tab_index))
29    return false;
30
31  int process_id = contents->GetRenderProcessHost()->id();
32  result_.reset(CreateProcessValue(process_id));
33  return true;
34}
35