| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "chrome/renderer/extensions/id_generator_custom_bindings.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "grit/renderer_resources.h" | |
| 9 #include "v8/include/v8.h" | |
| 10 | |
| 11 namespace extensions { | |
| 12 | |
| 13 IdGeneratorCustomBindings::IdGeneratorCustomBindings(Dispatcher* dispatcher, | |
| 14 ChromeV8Context* context) | |
| 15 : ChromeV8Extension(dispatcher, context) { | |
| 16 RouteFunction("GetNextId", base::Bind(&IdGeneratorCustomBindings::GetNextId, | |
| 17 base::Unretained(this))); | |
| 18 } | |
| 19 | |
| 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); | |
| 29 } | |
| 30 | |
| 31 } // namespace extensions | |
| OLD | NEW |