1 // Copyright 2014 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 "extensions/renderer/id_generator_custom_bindings.h" 6 7 #include "base/bind.h" 8 9 namespace extensions { 10 11 IdGeneratorCustomBindings::IdGeneratorCustomBindings(ScriptContext* context) 12 : ObjectBackedNativeHandler(context) { 13 RouteFunction("GetNextId", 14 base::Bind(&IdGeneratorCustomBindings::GetNextId, 15 base::Unretained(this))); 16 } 17 18 void IdGeneratorCustomBindings::GetNextId( 19 const v8::FunctionCallbackInfo<v8::Value>& args) { 20 static int32_t next_id = 0; 21 ++next_id; 22 // Make sure 0 is never returned because some APIs (particularly WebRequest) 23 // have special meaning for 0 IDs. 24 if (next_id == 0) 25 next_id = 1; 26 args.GetReturnValue().Set(next_id); 27 } 28 29 } // namespace extensions 30