blob: ad6d18373845b0d3f0af41df6a112ab42856cf7b [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"
[email protected]117afcf2013-08-30 02:38:099#include "third_party/WebKit/public/platform/WebString.h"
[email protected]117afcf2013-08-30 02:38:0910#include "third_party/WebKit/public/web/WebSelector.h"
11
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)
[email protected]117afcf2013-08-30 02:38:0917 : ObjectBackedNativeHandler(context) {
rdevlin.cronin363323d2016-04-22 20:47:0218 RouteFunction("CanonicalizeCompoundSelector", "declarativeContent",
[email protected]117afcf2013-08-30 02:38:0919 base::Bind(&CssNativeHandler::CanonicalizeCompoundSelector,
20 base::Unretained(this)));
21}
22
23void CssNativeHandler::CanonicalizeCompoundSelector(
24 const v8::FunctionCallbackInfo<v8::Value>& args) {
25 CHECK_EQ(args.Length(), 1);
26 CHECK(args[0]->IsString());
Adam Klein686c0e52018-01-17 23:42:3327 v8::Isolate* isolate = args.GetIsolate();
28 std::string input_selector = *v8::String::Utf8Value(isolate, args[0]);
esprehn7252f0b2016-03-02 04:57:2429 // TODO(esprehn): This API shouldn't exist, the extension code should be
30 // moved into blink.
Blink Reformat1c4d759e2017-04-09 16:34:5431 WebString output_selector = blink::CanonicalizeSelector(
32 WebString::FromUTF8(input_selector), blink::kWebSelectorTypeCompound);
Adam Klein686c0e52018-01-17 23:42:3333 args.GetReturnValue().Set(
34 v8_helpers::ToV8StringUnsafe(isolate, output_selector.Utf8().c_str()));
[email protected]117afcf2013-08-30 02:38:0935}
36
37} // namespace extensions