[email protected] | 701a94e | 2014-04-17 04:37:37 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
[email protected] | 117afcf | 2013-08-30 02:38:09 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
[email protected] | 701a94e | 2014-04-17 04:37:37 | [diff] [blame] | 5 | #include "extensions/renderer/css_native_handler.h" |
[email protected] | 117afcf | 2013-08-30 02:38:09 | [diff] [blame] | 6 | |
[email protected] | 701a94e | 2014-04-17 04:37:37 | [diff] [blame] | 7 | #include "extensions/renderer/script_context.h" |
esprehn | 7252f0b | 2016-03-02 04:57:24 | [diff] [blame] | 8 | #include "extensions/renderer/v8_helpers.h" |
Blink Reformat | a30d423 | 2018-04-07 15:31:06 | [diff] [blame] | 9 | #include "third_party/blink/public/platform/web_string.h" |
10 | #include "third_party/blink/public/web/web_selector.h" | ||||
[email protected] | 117afcf | 2013-08-30 02:38:09 | [diff] [blame] | 11 | |
12 | namespace extensions { | ||||
13 | |||||
[email protected] | a1221aea | 2013-11-07 01:31:30 | [diff] [blame] | 14 | using blink::WebString; |
[email protected] | 117afcf | 2013-08-30 02:38:09 | [diff] [blame] | 15 | |
[email protected] | 701a94e | 2014-04-17 04:37:37 | [diff] [blame] | 16 | CssNativeHandler::CssNativeHandler(ScriptContext* context) |
Devlin Cronin | d9ea834 | 2018-01-27 06:00:04 | [diff] [blame] | 17 | : ObjectBackedNativeHandler(context) {} |
18 | |||||
19 | void CssNativeHandler::AddRoutes() { | ||||
20 | RouteHandlerFunction( | ||||
21 | "CanonicalizeCompoundSelector", "declarativeContent", | ||||
Devlin Cronin | cc02a0c | 2019-01-03 22:15:07 | [diff] [blame] | 22 | base::BindRepeating(&CssNativeHandler::CanonicalizeCompoundSelector, |
23 | base::Unretained(this))); | ||||
[email protected] | 117afcf | 2013-08-30 02:38:09 | [diff] [blame] | 24 | } |
25 | |||||
26 | void CssNativeHandler::CanonicalizeCompoundSelector( | ||||
27 | const v8::FunctionCallbackInfo<v8::Value>& args) { | ||||
28 | CHECK_EQ(args.Length(), 1); | ||||
29 | CHECK(args[0]->IsString()); | ||||
Adam Klein | 686c0e5 | 2018-01-17 23:42:33 | [diff] [blame] | 30 | v8::Isolate* isolate = args.GetIsolate(); |
31 | std::string input_selector = *v8::String::Utf8Value(isolate, args[0]); | ||||
esprehn | 7252f0b | 2016-03-02 04:57:24 | [diff] [blame] | 32 | // TODO(esprehn): This API shouldn't exist, the extension code should be |
33 | // moved into blink. | ||||
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 34 | WebString output_selector = blink::CanonicalizeSelector( |
35 | WebString::FromUTF8(input_selector), blink::kWebSelectorTypeCompound); | ||||
Adam Klein | 686c0e5 | 2018-01-17 23:42:33 | [diff] [blame] | 36 | args.GetReturnValue().Set( |
37 | v8_helpers::ToV8StringUnsafe(isolate, output_selector.Utf8().c_str())); | ||||
[email protected] | 117afcf | 2013-08-30 02:38:09 | [diff] [blame] | 38 | } |
39 | |||||
40 | } // namespace extensions |