Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(32)

Unified Diff: chrome/renderer/extensions/schema_utils_native_handler.cc

Issue 23478003: Check and canonicalize CSS selectors before registering PageStateMatchers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use WebKit::canonicalizeSelector() instead of CSSStyleRule.selectorText Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698