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.
4
5#ifndef CHROME_BROWSER_EXTENSIONS_CHROME_EXTENSION_FUNCTION_DETAILS_H_
6#define CHROME_BROWSER_EXTENSIONS_CHROME_EXTENSION_FUNCTION_DETAILS_H_
7
8#include "base/macros.h"
9
10class Browser;
11class Profile;
12class UIThreadExtensionFunction;
13
14namespace content {
15class WebContents;
16}
17
18namespace extensions {
19class WindowController;
20}  // namespace extensions
21
22// Provides Chrome-specific details to UIThreadExtensionFunction
23// implementations.
24class ChromeExtensionFunctionDetails {
25 public:
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();
30
31  Profile* GetProfile() const;
32
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;
37
38  // Gets the "current" browser, if any.
39  //
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.
44  //
45  // If there is no containing window, the current browser defaults to the
46  // foremost one.
47  //
48  // Incognito browsers are not considered unless the calling extension has
49  // incognito access enabled.
50  //
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.
54  //
55  // TODO(stevenjb): Replace this with GetExtensionWindowController().
56  Browser* GetCurrentBrowser() const;
57
58  // Same as above but uses WindowControllerList instead of BrowserList.
59  extensions::WindowController* GetExtensionWindowController() const;
60
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();
64
65  // Returns a pointer to the associated UIThreadExtensionFunction
66  UIThreadExtensionFunction* function() { return function_; }
67  const UIThreadExtensionFunction* function() const { return function_; }
68
69 private:
70  // The function for which these details have been created. Must outlive the
71  // ChromeExtensionFunctionDetails instance.
72  UIThreadExtensionFunction* function_;
73
74  DISALLOW_COPY_AND_ASSIGN(ChromeExtensionFunctionDetails);
75};
76
77#endif  // CHROME_BROWSER_EXTENSIONS_CHROME_EXTENSION_FUNCTION_DETAILS_H_
78