Adding instrumentation to locate the source of jankiness
[chromium-blink-merge.git] / chrome / browser / extensions / chrome_extension_function.h
blob013ff128f71c77a3d4a5a30600dfc88e030e1927
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.
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 {
28 public:
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)
36 const;
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
46 // foremost one.
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 virtual content::WebContents* GetAssociatedWebContents() override;
65 protected:
66 virtual ~ChromeUIThreadExtensionFunction();
69 // A chrome specific analog to AsyncExtensionFunction. This has access to a
70 // chrome Profile.
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 {
77 public:
78 ChromeAsyncExtensionFunction();
80 protected:
81 virtual ~ChromeAsyncExtensionFunction();
83 // Deprecated, see AsyncExtensionFunction::RunAsync.
84 virtual bool RunAsync() = 0;
86 // ValidationFailure override to match RunAsync().
87 static bool ValidationFailure(ChromeAsyncExtensionFunction* function);
89 private:
90 virtual ResponseAction Run() override;
93 // A chrome specific analog to SyncExtensionFunction. This has access to a
94 // chrome Profile.
96 // DEPRECATED: Please consider inherting UIThreadExtensionFunction or
97 // SyncExtensionFunction directly. Then if you need access to Chrome details,
98 // you can construct a ChromeExtensionFunctionDetails object within your
99 // function implementation.
100 class ChromeSyncExtensionFunction : public ChromeUIThreadExtensionFunction {
101 public:
102 ChromeSyncExtensionFunction();
104 protected:
105 virtual ~ChromeSyncExtensionFunction();
107 // Deprecated, see SyncExtensionFunction::RunSync.
108 virtual bool RunSync() = 0;
110 // ValidationFailure override to match RunSync().
111 static bool ValidationFailure(ChromeSyncExtensionFunction* function);
113 private:
114 virtual ResponseAction Run() override;
117 #endif // CHROME_BROWSER_EXTENSIONS_CHROME_EXTENSION_FUNCTION_H_