blob: ee79b5ae46bb0e023461fe6b8ce8ebe5a224360c [file] [log] [blame]
[email protected]701a94e2014-04-17 04:37:371// Copyright 2014 The Chromium Authors. All rights reserved.
[email protected]117afcf2013-08-30 02:38:092// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]701a94e2014-04-17 04:37:375#include "extensions/renderer/css_native_handler.h"
[email protected]117afcf2013-08-30 02:38:096
[email protected]701a94e2014-04-17 04:37:377#include "extensions/renderer/script_context.h"
esprehn7252f0b2016-03-02 04:57:248#include "extensions/renderer/v8_helpers.h"
Blink Reformata30d4232018-04-07 15:31:069#include "third_party/blink/public/platform/web_string.h"
10#include "third_party/blink/public/web/web_selector.h"
[email protected]117afcf2013-08-30 02:38:0911
12namespace extensions {
13
[email protected]a1221aea2013-11-07 01:31:3014using blink::WebString;
[email protected]117afcf2013-08-30 02:38:0915
[email protected]701a94e2014-04-17 04:37:3716CssNativeHandler::CssNativeHandler(ScriptContext* context)
Devlin Cronind9ea8342018-01-27 06:00:0417 : ObjectBackedNativeHandler(context) {}
18
19void CssNativeHandler::AddRoutes() {
20 RouteHandlerFunction(
21 "CanonicalizeCompoundSelector", "declarativeContent",
Devlin Cronincc02a0c2019-01-03 22:15:0722 base::BindRepeating(&CssNativeHandler::CanonicalizeCompoundSelector,
23 base::Unretained(this)));
[email protected]117afcf2013-08-30 02:38:0924}
25
26void CssNativeHandler::CanonicalizeCompoundSelector(
27 const v8::FunctionCallbackInfo<v8::Value>& args) {
28 CHECK_EQ(args.Length(), 1);
29 CHECK(args[0]->IsString());
Adam Klein686c0e52018-01-17 23:42:3330 v8::Isolate* isolate = args.GetIsolate();
31 std::string input_selector = *v8::String::Utf8Value(isolate, args[0]);
esprehn7252f0b2016-03-02 04:57:2432 // TODO(esprehn): This API shouldn't exist, the extension code should be
33 // moved into blink.
Blink Reformat1c4d759e2017-04-09 16:34:5434 WebString output_selector = blink::CanonicalizeSelector(
35 WebString::FromUTF8(input_selector), blink::kWebSelectorTypeCompound);
Adam Klein686c0e52018-01-17 23:42:3336 args.GetReturnValue().Set(
37 v8_helpers::ToV8StringUnsafe(isolate, output_selector.Utf8().c_str()));
[email protected]117afcf2013-08-30 02:38:0938}
39
40} // namespace extensions