summaryrefslogtreecommitdiffstats
path: root/chrome/browser/automation/automation_extension_function.h
blob: 1d1da41ec4141ea5eb7b4216216e2840e0dd20d5 (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
// 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 std::string& args);
  virtual const std::string GetResult();
  virtual const std::string GetError();
  virtual void Run();

  static ExtensionFunction* Factory();

  // If enabled, we set an instance of this function as the functor
  // for all function names in ExtensionFunctionFactoryRegistry.
  // If disabled, we restore the initial functions.
  static void SetEnabled(bool 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:
  static bool enabled_;
  std::string args_;
  DISALLOW_COPY_AND_ASSIGN(AutomationExtensionFunction);
};

#endif  // CHROME_BROWSER_AUTOMATION_AUTOMATION_EXTENSION_FUNCTION_H_