Revert 285173 "Removed InProcessBrowserTest::CleanUpOnMainThread()"
[chromium-blink-merge.git] / chrome / browser / extensions / chrome_extension_function.h
blobdc35815cd818c11e721a38e904da40b1cf733521
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_EXTENSIONS_CHROME_EXTENSION_FUNCTION_H_
6 #define CHROME_BROWSER_EXTENSIONS_CHROME_EXTENSION_FUNCTION_H_
8 #include "extensions/browser/extension_function.h"
10 class Browser;
11 class Profile;
13 namespace content {
14 class WebContents;
17 namespace extensions {
18 class WindowController;
21 // A chrome specific analog to AsyncExtensionFunction. This has access to a
22 // chrome Profile.
23 class ChromeUIThreadExtensionFunction : public UIThreadExtensionFunction {
24 public:
25 ChromeUIThreadExtensionFunction();
27 Profile* GetProfile() const;
29 // Returns true if this function (and the profile and extension that it was
30 // invoked from) can operate on the window wrapped by |window_controller|.
31 bool CanOperateOnWindow(const extensions::WindowController* window_controller)
32 const;
34 // Gets the "current" browser, if any.
36 // Many extension APIs operate relative to the current browser, which is the
37 // browser the calling code is running inside of. For example, popups, tabs,
38 // and infobars all have a containing browser, but background pages and
39 // notification bubbles do not.
41 // If there is no containing window, the current browser defaults to the
42 // foremost one.
44 // Incognito browsers are not considered unless the calling extension has
45 // incognito access enabled.
47 // This method can return NULL if there is no matching browser, which can
48 // happen if only incognito windows are open, or early in startup or shutdown
49 // shutdown when there are no active windows.
51 // TODO(stevenjb): Replace this with GetExtensionWindowController().
52 Browser* GetCurrentBrowser();
54 // Same as above but uses WindowControllerList instead of BrowserList.
55 extensions::WindowController* GetExtensionWindowController();
57 // Gets the "current" web contents if any. If there is no associated web
58 // contents then defaults to the foremost one.
59 virtual content::WebContents* GetAssociatedWebContents() OVERRIDE;
61 protected:
62 virtual ~ChromeUIThreadExtensionFunction();
65 // A chrome specific analog to AsyncExtensionFunction. This has access to a
66 // chrome Profile.
67 class ChromeAsyncExtensionFunction : public ChromeUIThreadExtensionFunction {
68 public:
69 ChromeAsyncExtensionFunction();
71 protected:
72 virtual ~ChromeAsyncExtensionFunction();
74 // Deprecated, see AsyncExtensionFunction::RunAsync.
75 virtual bool RunAsync() = 0;
77 // ValidationFailure override to match RunAsync().
78 static bool ValidationFailure(ChromeAsyncExtensionFunction* function);
80 private:
81 virtual ResponseAction Run() OVERRIDE;
84 // A chrome specific analog to SyncExtensionFunction. This has access to a
85 // chrome Profile.
86 class ChromeSyncExtensionFunction : public ChromeUIThreadExtensionFunction {
87 public:
88 ChromeSyncExtensionFunction();
90 protected:
91 virtual ~ChromeSyncExtensionFunction();
93 // Deprecated, see SyncExtensionFunction::RunSync.
94 virtual bool RunSync() = 0;
96 // ValidationFailure override to match RunSync().
97 static bool ValidationFailure(ChromeSyncExtensionFunction* function);
99 private:
100 virtual ResponseAction Run() OVERRIDE;
103 #endif // CHROME_BROWSER_EXTENSIONS_CHROME_EXTENSION_FUNCTION_H_