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

Unified Diff: chrome/browser/extensions/api/declarative_webrequest/webrequest_rule.cc

Issue 9820003: Implementation of beginning of Declarative Web Request API backend (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 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/browser/extensions/api/declarative_webrequest/webrequest_rule.cc
diff --git a/chrome/browser/extensions/api/declarative_webrequest/webrequest_rule.cc b/chrome/browser/extensions/api/declarative_webrequest/webrequest_rule.cc
new file mode 100644
index 0000000000000000000000000000000000000000..1b867119c862a80d67ab7dc8dbb53f71a0ec9c4f
--- /dev/null
+++ b/chrome/browser/extensions/api/declarative_webrequest/webrequest_rule.cc
@@ -0,0 +1,65 @@
+// Copyright (c) 2012 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/browser/extensions/api/declarative_webrequest/webrequest_rule.h"
+
+#include "base/logging.h"
+#include "chrome/browser/extensions/api/declarative_webrequest/webrequest_action.h"
+#include "chrome/browser/extensions/api/declarative_webrequest/webrequest_condition.h"
+
+namespace extensions {
+namespace declarative_webrequest {
+
+WebRequestRule::WebRequestRule(
+ scoped_ptr<WebRequestConditionCollection> conditions,
+ scoped_ptr<WebRequestActionCollection> actions)
+ : conditions_(conditions.release()),
+ actions_(actions.release()) {
+ CHECK(conditions_.get());
+ CHECK(actions_.get());
+}
+
+WebRequestRule::~WebRequestRule() {}
+
+// static
+bool WebRequestRuleFactory::CheckConsistency(
+ WebRequestConditionCollection* conditions,
+ WebRequestActionCollection* actions,
+ std::string* error) {
+ // TODO(battre): Implement this.
+ return true;
+}
+
+// static
+scoped_ptr<WebRequestRule> WebRequestRuleFactory::CreateRule(
+ URLMatcherConditionFactory* url_matcher_condition_factory,
+ linked_ptr<RulesRegistry::Rule> rule,
+ std::string* error) {
+ scoped_ptr<WebRequestRule> error_result;
+
+ scoped_ptr<WebRequestConditionCollection> conditions =
+ WebRequestConditionFactory::CreateConditionCollection(
Matt Perry 2012/03/22 23:07:25 +2 indent
battre 2012/03/26 18:35:51 Done.
+ url_matcher_condition_factory, rule->conditions, error);
+ if (!error->empty())
+ return error_result.Pass();
+ CHECK(conditions.get());
+
+ // Parse Actions
Matt Perry 2012/03/22 23:07:25 nit: superfluous comment
battre 2012/03/26 18:35:51 Done.
+ scoped_ptr<WebRequestActionCollection> actions =
+ WebRequestActionFactory::CreateActionCollection(rule->actions, error);
+ if (!error->empty())
+ return error_result.Pass();
+ CHECK(actions.get());
+
+ if (!CheckConsistency(conditions.get(), actions.get(), error)) {
+ DCHECK(!error->empty());
+ return error_result.Pass();
+ }
+
+ return scoped_ptr<WebRequestRule>(
+ new WebRequestRule(conditions.Pass(), actions.Pass()));
+}
+
+} // namespace declarative_webrequest
+} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698