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"
17 namespace extensions
{
18 class WindowController
;
21 // A chrome specific analog to AsyncExtensionFunction. This has access to a
24 // DEPRECATED: Please consider inherting UIThreadExtensionFunction directly.
25 // Then if you need access to Chrome details, you can construct a
26 // ChromeExtensionFunctionDetails object within your function implementation.
27 class ChromeUIThreadExtensionFunction
: public UIThreadExtensionFunction
{
29 ChromeUIThreadExtensionFunction();
31 Profile
* GetProfile() const;
33 // Returns true if this function (and the profile and extension that it was
34 // invoked from) can operate on the window wrapped by |window_controller|.
35 bool CanOperateOnWindow(const extensions::WindowController
* window_controller
)
38 // Gets the "current" browser, if any.
40 // Many extension APIs operate relative to the current browser, which is the
41 // browser the calling code is running inside of. For example, popups, tabs,
42 // and infobars all have a containing browser, but background pages and
43 // notification bubbles do not.
45 // If there is no containing window, the current browser defaults to the
48 // Incognito browsers are not considered unless the calling extension has
49 // incognito access enabled.
51 // This method can return NULL if there is no matching browser, which can
52 // happen if only incognito windows are open, or early in startup or shutdown
53 // shutdown when there are no active windows.
55 // TODO(stevenjb): Replace this with GetExtensionWindowController().
56 Browser
* GetCurrentBrowser();
58 // Same as above but uses WindowControllerList instead of BrowserList.
59 extensions::WindowController
* GetExtensionWindowController();
61 // Gets the "current" web contents if any. If there is no associated web
62 // contents then defaults to the foremost one.
63 content::WebContents
* GetAssociatedWebContents() override
;
66 ~ChromeUIThreadExtensionFunction() override
;
69 // A chrome specific analog to AsyncExtensionFunction. This has access to a
72 // DEPRECATED: Please consider inherting UIThreadExtensionFunction or
73 // AsyncExtensionFunction directly. Then if you need access to Chrome details,
74 // you can construct a ChromeExtensionFunctionDetails object within your
75 // function implementation.
76 class ChromeAsyncExtensionFunction
: public ChromeUIThreadExtensionFunction
{
78 ChromeAsyncExtensionFunction();
81 ~ChromeAsyncExtensionFunction() override
;
83 // Deprecated, see AsyncExtensionFunction::RunAsync.
84 virtual bool RunAsync() = 0;
86 // ValidationFailure override to match RunAsync().
87 static bool ValidationFailure(ChromeAsyncExtensionFunction
* function
);
90 // If you're hitting a compile error here due to "final" - great! You're doing
91 // the right thing, you just need to extend ChromeUIThreadExtensionFunction
92 // instead of ChromeAsyncExtensionFunction.
93 ResponseAction
Run() final
;
96 // A chrome specific analog to SyncExtensionFunction. This has access to a
99 // DEPRECATED: Please consider inherting UIThreadExtensionFunction or
100 // SyncExtensionFunction directly. Then if you need access to Chrome details,
101 // you can construct a ChromeExtensionFunctionDetails object within your
102 // function implementation.
103 class ChromeSyncExtensionFunction
: public ChromeUIThreadExtensionFunction
{
105 ChromeSyncExtensionFunction();
108 ~ChromeSyncExtensionFunction() override
;
110 // Deprecated, see SyncExtensionFunction::RunSync.
111 virtual bool RunSync() = 0;
113 // ValidationFailure override to match RunSync().
114 static bool ValidationFailure(ChromeSyncExtensionFunction
* function
);
117 // If you're hitting a compile error here due to "final" - great! You're doing
118 // the right thing, you just need to extend ChromeUIThreadExtensionFunction
119 // instead of ChromeSyncExtensionFunction.
120 ResponseAction
Run() final
;
123 #endif // CHROME_BROWSER_EXTENSIONS_CHROME_EXTENSION_FUNCTION_H_