[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" |
[email protected] | 117afcf | 2013-08-30 02:38:09 | [diff] [blame] | 9 | #include "third_party/WebKit/public/platform/WebString.h" |
[email protected] | 117afcf | 2013-08-30 02:38:09 | [diff] [blame] | 10 | #include "third_party/WebKit/public/web/WebSelector.h" |
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) |
[email protected] | 117afcf | 2013-08-30 02:38:09 | [diff] [blame] | 17 | : ObjectBackedNativeHandler(context) { |
rdevlin.cronin | 363323d | 2016-04-22 20:47:02 | [diff] [blame] | 18 | RouteFunction("CanonicalizeCompoundSelector", "declarativeContent", |
[email protected] | 117afcf | 2013-08-30 02:38:09 | [diff] [blame] | 19 | base::Bind(&CssNativeHandler::CanonicalizeCompoundSelector, |
20 | base::Unretained(this))); | ||||
21 | } | ||||
22 | |||||
23 | void CssNativeHandler::CanonicalizeCompoundSelector( | ||||
24 | const v8::FunctionCallbackInfo<v8::Value>& args) { | ||||
25 | CHECK_EQ(args.Length(), 1); | ||||
26 | CHECK(args[0]->IsString()); | ||||
esprehn | 7252f0b | 2016-03-02 04:57:24 | [diff] [blame] | 27 | std::string input_selector = *v8::String::Utf8Value(args[0]); |
28 | // TODO(esprehn): This API shouldn't exist, the extension code should be | ||||
29 | // moved into blink. | ||||
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame^] | 30 | WebString output_selector = blink::CanonicalizeSelector( |
31 | WebString::FromUTF8(input_selector), blink::kWebSelectorTypeCompound); | ||||
esprehn | 7252f0b | 2016-03-02 04:57:24 | [diff] [blame] | 32 | args.GetReturnValue().Set(v8_helpers::ToV8StringUnsafe( |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame^] | 33 | args.GetIsolate(), output_selector.Utf8().c_str())); |
[email protected] | 117afcf | 2013-08-30 02:38:09 | [diff] [blame] | 34 | } |
35 | |||||
36 | } // namespace extensions |