1 // Copyright 2014 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_DETAILS_H_
6 #define CHROME_BROWSER_EXTENSIONS_CHROME_EXTENSION_FUNCTION_DETAILS_H_
8 #include "base/macros.h"
12 class UIThreadExtensionFunction
;
18 namespace extensions
{
19 class WindowController
;
20 } // namespace extensions
22 // Provides Chrome-specific details to UIThreadExtensionFunction
24 class ChromeExtensionFunctionDetails
{
26 // Constructs a new ChromeExtensionFunctionDetails instance for |function|.
27 // This instance does not own |function| and must outlive it.
28 explicit ChromeExtensionFunctionDetails(UIThreadExtensionFunction
* function
);
29 ~ChromeExtensionFunctionDetails();
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(
36 const extensions::WindowController
* window_controller
) 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 and tabs
42 // all have a containing browser, but background pages and notification
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() const;
58 // Same as above but uses WindowControllerList instead of BrowserList.
59 extensions::WindowController
* GetExtensionWindowController() const;
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();
65 // Returns a pointer to the associated UIThreadExtensionFunction
66 UIThreadExtensionFunction
* function() { return function_
; }
67 const UIThreadExtensionFunction
* function() const { return function_
; }
70 // The function for which these details have been created. Must outlive the
71 // ChromeExtensionFunctionDetails instance.
72 UIThreadExtensionFunction
* function_
;
74 DISALLOW_COPY_AND_ASSIGN(ChromeExtensionFunctionDetails
);
77 #endif // CHROME_BROWSER_EXTENSIONS_CHROME_EXTENSION_FUNCTION_DETAILS_H_