| Index: chrome/browser/extensions/api/declarative_webrequest/webrequest_action.h
|
| diff --git a/chrome/browser/extensions/api/declarative_webrequest/webrequest_action.h b/chrome/browser/extensions/api/declarative_webrequest/webrequest_action.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..50f6d0d5ab69b8345692e733b19154d21a8cc0fa
|
| --- /dev/null
|
| +++ b/chrome/browser/extensions/api/declarative_webrequest/webrequest_action.h
|
| @@ -0,0 +1,104 @@
|
| +// 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.
|
| +
|
| +#ifndef CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_ACTION_H_
|
| +#define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_ACTION_H_
|
| +#pragma once
|
| +
|
| +#include <string>
|
| +#include <vector>
|
| +
|
| +#include "base/compiler_specific.h"
|
| +#include "base/memory/linked_ptr.h"
|
| +#include "tools/json_schema_compiler/any.h"
|
| +
|
| +namespace base {
|
| +class Value;
|
| +}
|
| +
|
| +namespace extensions {
|
| +namespace declarative_webrequest {
|
| +
|
| +// Base class for all WebRequestActions of the declarative Web Request API.
|
| +class WebRequestAction {
|
| + public:
|
| + enum Types {
|
| + ACTION_CANCEL_REQUEST
|
| + };
|
| +
|
| + WebRequestAction();
|
| + virtual ~WebRequestAction();
|
| +
|
| + // Returns a bit vector representing extensions::RequestStages. The bit vector
|
| + // contains a 1 for each request stage during which the condition can be
|
| + // tested.
|
| + virtual int GetStages() const = 0;
|
| +
|
| + virtual Types type() const = 0;
|
| +
|
| + // TODO(battre): Add method that corresponds to executing the action.
|
| +};
|
| +
|
| +// Immutable container for multiple actions.
|
| +class WebRequestActionCollection {
|
| + public:
|
| + // TODO(battre): As WebRequestActionCollection can become the single
|
| + // owner of all actions, we can optimize here by making some of them
|
| + // singletons (e.g. Cancel actions).
|
| + typedef std::vector<linked_ptr<WebRequestAction> > Actions;
|
| +
|
| + explicit WebRequestActionCollection(const Actions& actions);
|
| + virtual ~WebRequestActionCollection();
|
| +
|
| + const Actions& actions() const { return actions_; }
|
| +
|
| + // TODO(battre): Add method that corresponds to executing the action.
|
| +
|
| + private:
|
| + Actions actions_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(WebRequestActionCollection);
|
| +};
|
| +
|
| +// Factory for easy instantiation of various WebRequestAction types.
|
| +class WebRequestActionFactory {
|
| + public:
|
| + typedef std::vector<linked_ptr<json_schema_compiler::any::Any> > AnyVector;
|
| +
|
| + static bool IsHandledByThisFactory(const std::string& action_name);
|
| +
|
| + static scoped_ptr<WebRequestAction> CreateAction(
|
| + const base::Value& json_action,
|
| + std::string* error);
|
| + static scoped_ptr<WebRequestActionCollection> CreateActionCollection(
|
| + const AnyVector& actions,
|
| + std::string* error);
|
| +
|
| + private:
|
| + DISALLOW_IMPLICIT_CONSTRUCTORS(WebRequestActionFactory);
|
| +};
|
| +
|
| +// Action that instructs to cancel a network request.
|
| +class WebRequestCancelAction : public WebRequestAction {
|
| + public:
|
| + WebRequestCancelAction();
|
| + virtual ~WebRequestCancelAction();
|
| +
|
| + // Implementation of WebRequestAction:
|
| + virtual int GetStages() const OVERRIDE;
|
| + virtual Types type() const OVERRIDE {
|
| + return WebRequestAction::ACTION_CANCEL_REQUEST;
|
| + }
|
| +
|
| + private:
|
| + DISALLOW_COPY_AND_ASSIGN(WebRequestCancelAction);
|
| +};
|
| +
|
| +// TODO(battre) Implement further actions:
|
| +// Redirect to constant url, Redirect by RegEx, Set header, Remove header, ...
|
| +
|
| +} // namespace declarative_webrequest
|
| +} // namespace extensions
|
| +
|
| +#endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_ACTION_H_
|
|
|