Index: chrome/renderer/extensions/schema_utils_native_handler.cc |
diff --git a/chrome/renderer/extensions/schema_utils_native_handler.cc b/chrome/renderer/extensions/schema_utils_native_handler.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..50eac8772b225910fc70e39c43e613cd1c66ff6f |
--- /dev/null |
+++ b/chrome/renderer/extensions/schema_utils_native_handler.cc |
@@ -0,0 +1,44 @@ |
+// Copyright 2013 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 "chrome/renderer/extensions/schema_utils_native_handler.h" |
+ |
+#include "chrome/renderer/extensions/chrome_v8_context.h" |
+#include "third_party/WebKit/public/platform/WebString.h" |
+#include "third_party/WebKit/public/web/WebScriptBindings.h" |
+#include "third_party/WebKit/public/web/WebSelector.h" |
+ |
+namespace extensions { |
+ |
+using WebKit::WebString; |
+ |
+SchemaUtilsNativeHandler::SchemaUtilsNativeHandler(ChromeV8Context* context) |
+ : ObjectBackedNativeHandler(context) { |
+ RouteFunction( |
+ "CanonicalizeCompoundSelector", |
+ base::Bind(&SchemaUtilsNativeHandler::CanonicalizeCompoundSelector, |
+ base::Unretained(this))); |
+} |
+ |
+void SchemaUtilsNativeHandler::CanonicalizeCompoundSelector( |
+ const v8::FunctionCallbackInfo<v8::Value>& args) { |
+ CHECK_EQ(args.Length(), 1); |
+ v8::Local<v8::Value> arg_string; |
Jeffrey Yasskin
2013/08/29 03:39:39
There's an implicit HandleScope around native func
not at google - send to devlin
2013/08/29 15:20:25
Yep.
|
+ { |
+ v8::TryCatch block; |
+ arg_string = args[0]->ToString(); |
+ if (block.HasCaught()){ |
+ block.ReThrow(); |
+ args.GetReturnValue().Set(v8::Undefined()); |
not at google - send to devlin
2013/08/29 15:20:25
I imagine that setting a return value after throwi
Jeffrey Yasskin
2013/08/29 21:46:43
Yeah, must be, since forgetting to return didn't b
|
+ } |
not at google - send to devlin
2013/08/29 15:20:25
I would think that you'd rather throw a schema val
Jeffrey Yasskin
2013/08/29 21:46:43
Sure, done. The schema validator seems to check al
|
+ } |
+ WebString input_selector = |
+ WebKit::WebScriptBindings::toWebString(arg_string.As<v8::String>()); |
+ WebString output_selector = WebKit::canonicalizeSelector( |
+ input_selector, WebKit::WebSelectorTypeCompound); |
+ args.GetReturnValue().Set(WebKit::WebScriptBindings::toV8String( |
+ output_selector, context()->v8_context()->GetIsolate())); |
+} |
+ |
+} // namespace extensions |