Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / renderer / extensions / id_generator_custom_bindings.cc
blob42c7d83e715636a7c64bd13b5c41eddf21bcb95d
1 // Copyright 2013 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.
5 #include "chrome/renderer/extensions/id_generator_custom_bindings.h"
7 #include "base/bind.h"
8 #include "grit/renderer_resources.h"
9 #include "v8/include/v8.h"
11 namespace extensions {
13 IdGeneratorCustomBindings::IdGeneratorCustomBindings(Dispatcher* dispatcher,
14 ChromeV8Context* context)
15 : ChromeV8Extension(dispatcher, context) {
16 RouteFunction("GetNextId", base::Bind(&IdGeneratorCustomBindings::GetNextId,
17 base::Unretained(this)));
20 void IdGeneratorCustomBindings::GetNextId(
21 const v8::FunctionCallbackInfo<v8::Value>& args) {
22 static int32_t next_id = 0;
23 ++next_id;
24 // Make sure 0 is never returned because some APIs (particularly WebRequest)
25 // have special meaning for 0 IDs.
26 if (next_id == 0)
27 next_id = 1;
28 args.GetReturnValue().Set(next_id);
31 } // namespace extensions