summaryrefslogtreecommitdiff
path: root/chromium/extensions/renderer/css_native_handler.cc
blob: 41768f6af4b271a76ac89e9ba20d8bdf06f25277 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "extensions/renderer/css_native_handler.h"

#include "extensions/renderer/script_context.h"
#include "extensions/renderer/v8_helpers.h"
#include "third_party/blink/public/platform/web_string.h"
#include "third_party/blink/public/web/web_selector.h"

namespace extensions {

using blink::WebString;

CssNativeHandler::CssNativeHandler(ScriptContext* context)
    : ObjectBackedNativeHandler(context) {}

void CssNativeHandler::AddRoutes() {
  RouteHandlerFunction(
      "CanonicalizeCompoundSelector", "declarativeContent",
      base::Bind(&CssNativeHandler::CanonicalizeCompoundSelector,
                 base::Unretained(this)));
}

void CssNativeHandler::CanonicalizeCompoundSelector(
    const v8::FunctionCallbackInfo<v8::Value>& args) {
  CHECK_EQ(args.Length(), 1);
  CHECK(args[0]->IsString());
  v8::Isolate* isolate = args.GetIsolate();
  std::string input_selector = *v8::String::Utf8Value(isolate, args[0]);
  // TODO(esprehn): This API shouldn't exist, the extension code should be
  // moved into blink.
  WebString output_selector = blink::CanonicalizeSelector(
      WebString::FromUTF8(input_selector), blink::kWebSelectorTypeCompound);
  args.GetReturnValue().Set(
      v8_helpers::ToV8StringUnsafe(isolate, output_selector.Utf8().c_str()));
}

}  // namespace extensions