summaryrefslogtreecommitdiffstats
path: root/chrome/renderer/extensions/chrome_v8_extension_handler.cc
blob: 0698dd498dfdf0e4f324650b47a708113dbe28a6 (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
// Copyright (c) 2012 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/renderer/extensions/chrome_v8_extension_handler.h"

#include "base/logging.h"
#include "content/public/renderer/render_thread.h"
#include "extensions/renderer/script_context.h"

using content::RenderThread;

namespace extensions {

ChromeV8ExtensionHandler::ChromeV8ExtensionHandler(ScriptContext* context)
    : context_(context), routing_id_(MSG_ROUTING_NONE) {
}

ChromeV8ExtensionHandler::~ChromeV8ExtensionHandler() {
  if (routing_id_ != MSG_ROUTING_NONE)
    RenderThread::Get()->RemoveRoute(routing_id_);
}

int ChromeV8ExtensionHandler::GetRoutingID() {
  if (routing_id_ == MSG_ROUTING_NONE) {
    routing_id_ = RenderThread::Get()->GenerateRoutingID();
    RenderThread::Get()->AddRoute(routing_id_, this);
  }

  return routing_id_;
}

void ChromeV8ExtensionHandler::Send(IPC::Message* message) {
  RenderThread::Get()->Send(message);
}

}  // namespace extensions