summaryrefslogtreecommitdiffstats
path: root/chrome/browser/automation/automation_extension_function.h
blob: ed57ca17f425f552882dca20b1fce449893c995a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright (c) 2009 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.

// Defines AutomationExtensionFunction.

#ifndef CHROME_BROWSER_AUTOMATION_AUTOMATION_EXTENSION_FUNCTION_H_
#define CHROME_BROWSER_AUTOMATION_AUTOMATION_EXTENSION_FUNCTION_H_

#include <string>

#include "chrome/browser/extensions/extension_function.h"

class RenderViewHost;

// An extension function that pipes the extension API call through the
// automation interface, so that extensions can be tested using UITests.
class AutomationExtensionFunction : public ExtensionFunction {
 public:
  AutomationExtensionFunction() { }

  // ExtensionFunction implementation.
  virtual void SetArgs(const Value* args);
  virtual const std::string GetResult();
  virtual const std::string GetError();
  virtual void Run();

  static ExtensionFunction* Factory();

  // If the list of enabled functions is non-empty, we enable according to the
  // list ("*" means enable all, otherwise we enable individual named
  // functions). If empty, we restore the initial functions.
  //
  // Note that all calls to this function, except a call with the empty list,
  // are additive.  Functions previously enabled will remain enabled until
  // you clear all function forwarding by specifying the empty list.
  static void SetEnabled(const std::vector<std::string>& functions_enabled);

  // Intercepts messages sent from the external host to check if they
  // are actually responses to extension API calls.  If they are, redirects
  // the message to view_host->SendExtensionResponse and returns true,
  // otherwise returns false to indicate the message was not intercepted.
  static bool InterceptMessageFromExternalHost(RenderViewHost* view_host,
                                               const std::string& message,
                                               const std::string& origin,
                                               const std::string& target);

 private:
  ~AutomationExtensionFunction() {}

  static bool enabled_;
  std::string args_;
  DISALLOW_COPY_AND_ASSIGN(AutomationExtensionFunction);
};

#endif  // CHROME_BROWSER_AUTOMATION_AUTOMATION_EXTENSION_FUNCTION_H_