context_menus_custom_bindings.cc 1016 B

12345678910111213141516171819202122232425262728293031323334353637
  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. #include "extensions/renderer/context_menus_custom_bindings.h"
  5. #include <stdint.h>
  6. #include <atomic>
  7. #include "base/bind.h"
  8. #include "base/callback.h"
  9. #include "v8/include/v8.h"
  10. namespace {
  11. std::atomic<int32_t> menu_counter{0};
  12. void GetNextContextMenuId(const v8::FunctionCallbackInfo<v8::Value>& args) {
  13. // TODO(crbug.com/942373): We should use base::UnguessableToken or base::GUID
  14. // here, and move to using a string for all context menu IDs.
  15. args.GetReturnValue().Set(++menu_counter);
  16. }
  17. } // namespace
  18. namespace extensions {
  19. ContextMenusCustomBindings::ContextMenusCustomBindings(ScriptContext* context)
  20. : ObjectBackedNativeHandler(context) {}
  21. void ContextMenusCustomBindings::AddRoutes() {
  22. RouteHandlerFunction("GetNextContextMenuId",
  23. base::BindRepeating(&GetNextContextMenuId));
  24. }
  25. } // extensions