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 // Gets the "current" browser, if any.
35 // Many extension APIs operate relative to the current browser, which is the
36 // browser the calling code is running inside of. For example, popups, tabs,
37 // and infobars all have a containing browser, but background pages and
38 // notification bubbles do not.
40 // If there is no containing window, the current browser defaults to the
43 // Incognito browsers are not considered unless the calling extension has
44 // incognito access enabled.
46 // This method can return NULL if there is no matching browser, which can
47 // happen if only incognito windows are open, or early in startup or shutdown
48 // shutdown when there are no active windows.
50 // TODO(stevenjb): Replace this with GetExtensionWindowController().
51 Browser
* GetCurrentBrowser();
53 // Same as above but uses WindowControllerList instead of BrowserList.
54 extensions::WindowController
* GetExtensionWindowController();
56 // Gets the "current" web contents if any. If there is no associated web
57 // contents then defaults to the foremost one.
58 content::WebContents
* GetAssociatedWebContents() override
;
61 ~ChromeUIThreadExtensionFunction() override
;
64 // A chrome specific analog to AsyncExtensionFunction. This has access to a
67 // DEPRECATED: Please consider inherting UIThreadExtensionFunction or
68 // AsyncExtensionFunction directly. Then if you need access to Chrome details,
69 // you can construct a ChromeExtensionFunctionDetails object within your
70 // function implementation.
71 class ChromeAsyncExtensionFunction
: public ChromeUIThreadExtensionFunction
{
73 ChromeAsyncExtensionFunction();
76 ~ChromeAsyncExtensionFunction() override
;
78 // Deprecated, see AsyncExtensionFunction::RunAsync.
79 virtual bool RunAsync() = 0;
81 // ValidationFailure override to match RunAsync().
82 static bool ValidationFailure(ChromeAsyncExtensionFunction
* function
);
85 // If you're hitting a compile error here due to "final" - great! You're doing
86 // the right thing, you just need to extend ChromeUIThreadExtensionFunction
87 // instead of ChromeAsyncExtensionFunction.
88 ResponseAction
Run() final
;
91 // A chrome specific analog to SyncExtensionFunction. This has access to a
94 // DEPRECATED: Please consider inherting UIThreadExtensionFunction or
95 // SyncExtensionFunction directly. Then if you need access to Chrome details,
96 // you can construct a ChromeExtensionFunctionDetails object within your
97 // function implementation.
98 class ChromeSyncExtensionFunction
: public ChromeUIThreadExtensionFunction
{
100 ChromeSyncExtensionFunction();
103 ~ChromeSyncExtensionFunction() override
;
105 // Deprecated, see SyncExtensionFunction::RunSync.
106 virtual bool RunSync() = 0;
108 // ValidationFailure override to match RunSync().
109 static bool ValidationFailure(ChromeSyncExtensionFunction
* function
);
112 // If you're hitting a compile error here due to "final" - great! You're doing
113 // the right thing, you just need to extend ChromeUIThreadExtensionFunction
114 // instead of ChromeSyncExtensionFunction.
115 ResponseAction
Run() final
;
118 #endif // CHROME_BROWSER_EXTENSIONS_CHROME_EXTENSION_FUNCTION_H_