Home | History | Annotate | Download | only in extensions
      1 // Copyright (c) 2012 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/web_request_custom_bindings.h"
      6 
      7 #include <string>
      8 
      9 #include "base/bind.h"
     10 #include "base/strings/string_number_conversions.h"
     11 #include "grit/renderer_resources.h"
     12 #include "v8/include/v8.h"
     13 
     14 namespace extensions {
     15 
     16 WebRequestCustomBindings::WebRequestCustomBindings(
     17     Dispatcher* dispatcher, ChromeV8Context* context)
     18     : ChromeV8Extension(dispatcher, context) {
     19   RouteFunction("GetUniqueSubEventName",
     20       base::Bind(&WebRequestCustomBindings::GetUniqueSubEventName,
     21                  base::Unretained(this)));
     22 }
     23 
     24 // Attach an event name to an object.
     25 void WebRequestCustomBindings::GetUniqueSubEventName(
     26     const v8::FunctionCallbackInfo<v8::Value>& args) {
     27   static int next_event_id = 0;
     28   DCHECK(args.Length() == 1);
     29   DCHECK(args[0]->IsString());
     30   std::string event_name(*v8::String::AsciiValue(args[0]));
     31   std::string unique_event_name =
     32       event_name + "/" + base::IntToString(++next_event_id);
     33   args.GetReturnValue().Set(v8::String::New(unique_event_name.c_str()));
     34 }
     35 
     36 }  // namespace extensions
     37