Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / extensions / chrome_extension_function.h
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.
4
5 #ifndef CHROME_BROWSER_EXTENSIONS_CHROME_EXTENSION_FUNCTION_H_
6 #define CHROME_BROWSER_EXTENSIONS_CHROME_EXTENSION_FUNCTION_H_
7
8 #include "extensions/browser/extension_function.h"
9
10 class Browser;
11 class Profile;
12
13 namespace content {
14 class WebContents;
15 }
16
17 namespace extensions {
18 class WindowController;
19 }
20
21 // A chrome specific analog to AsyncExtensionFunction. This has access to a
22 // chrome Profile.
23 //
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();
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(const extensions::WindowController* window_controller)
36       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();
57
58   // Same as above but uses WindowControllerList instead of BrowserList.
59   extensions::WindowController* GetExtensionWindowController();
60
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;
64
65  protected:
66   virtual ~ChromeUIThreadExtensionFunction();
67 };
68
69 // A chrome specific analog to AsyncExtensionFunction. This has access to a
70 // chrome Profile.
71 //
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();
79
80  protected:
81   virtual ~ChromeAsyncExtensionFunction();
82
83   // Deprecated, see AsyncExtensionFunction::RunAsync.
84   virtual bool RunAsync() = 0;
85
86   // ValidationFailure override to match RunAsync().
87   static bool ValidationFailure(ChromeAsyncExtensionFunction* function);
88
89  private:
90   virtual ResponseAction Run() OVERRIDE;
91 };
92
93 // A chrome specific analog to SyncExtensionFunction. This has access to a
94 // chrome Profile.
95 //
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();
103
104  protected:
105   virtual ~ChromeSyncExtensionFunction();
106
107   // Deprecated, see SyncExtensionFunction::RunSync.
108   virtual bool RunSync() = 0;
109
110   // ValidationFailure override to match RunSync().
111   static bool ValidationFailure(ChromeSyncExtensionFunction* function);
112
113  private:
114   virtual ResponseAction Run() OVERRIDE;
115 };
116
117 #endif  // CHROME_BROWSER_EXTENSIONS_CHROME_EXTENSION_FUNCTION_H_