summaryrefslogtreecommitdiffstats
path: root/chrome/browser/tab_util.cc
blob: 815abfeeb83b098b9525ae4cf4c5475c979d4cc8 (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
35
36
37
38
39
// Copyright (c) 2006-2008 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.

#include "chrome/browser/tab_util.h"

#include "chrome/browser/render_view_host.h"
#include "chrome/browser/render_process_host.h"
#include "chrome/browser/resource_dispatcher_host.h"
#include "chrome/browser/web_contents.h"
#include "net/url_request/url_request.h"

bool tab_util::GetTabContentsID(URLRequest* request,
                                int* render_process_id,
                                int* render_view_id) {

  if (!request || !render_process_id || !render_view_id)
    return false;

  ResourceDispatcherHost::ExtraRequestInfo* info =
      ResourceDispatcherHost::ExtraInfoForRequest(request);
  if (!info)
    return false;

  *render_process_id = info->render_process_host_id;
  *render_view_id = info->render_view_id;
  return true;
}

TabContents* tab_util::GetTabContentsByID(int render_process_id,
                                          int render_view_id) {
  RenderViewHost* render_view_host =
      RenderViewHost::FromID(render_process_id, render_view_id);
  if (!render_view_host)
    return NULL;

  return static_cast<WebContents*>(render_view_host->delegate());
}