Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Side by Side Diff: chrome/browser/extensions/api/tabs/tabs_api.h

Issue 11747025: Run the JSON Schema Compiler's bundle compilation on JSON files. Previously it (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix ms release build Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_TABS_TABS_H__ 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_TABS_TABS_API_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_TABS_TABS_H__ 6 #define CHROME_BROWSER_EXTENSIONS_API_TABS_TABS_API_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "chrome/browser/extensions/extension_function.h" 12 #include "chrome/browser/extensions/extension_function.h"
13 #include "chrome/common/extensions/extension_resource.h"
14 #include "chrome/common/extensions/user_script.h"
13 #include "content/public/browser/notification_observer.h" 15 #include "content/public/browser/notification_observer.h"
14 #include "content/public/browser/notification_registrar.h" 16 #include "content/public/browser/notification_registrar.h"
15 #include "googleurl/src/gurl.h" 17 #include "googleurl/src/gurl.h"
16 18
17 class BackingStore; 19 class BackingStore;
18 class GURL; 20 class GURL;
19 class PrefServiceSyncable; 21 class PrefServiceSyncable;
20 class SkBitmap; 22 class SkBitmap;
21 23
22 namespace base { 24 namespace base {
23 class DictionaryValue; 25 class DictionaryValue;
24 } 26 }
25 27
26 namespace content { 28 namespace content {
27 class WebContents; 29 class WebContents;
28 } 30 }
29 31
32 namespace extensions {
33 namespace api {
34 namespace tabs {
35 struct InjectDetails;
36 } // namespace tabs
37 } // namespace api
38 } // namespace extensions
39
30 namespace skia { 40 namespace skia {
31 class PlatformBitmap; 41 class PlatformBitmap;
32 } 42 }
33 43
34 // Windows 44 // Windows
35 class GetWindowFunction : public SyncExtensionFunction { 45 class WindowsGetFunction : public SyncExtensionFunction {
36 virtual ~GetWindowFunction() {} 46 virtual ~WindowsGetFunction() {}
37 virtual bool RunImpl() OVERRIDE; 47 virtual bool RunImpl() OVERRIDE;
38 DECLARE_EXTENSION_FUNCTION_NAME("windows.get") 48 DECLARE_EXTENSION_FUNCTION_NAME("windows.get")
39 }; 49 };
40 class GetCurrentWindowFunction : public SyncExtensionFunction { 50 class WindowsGetCurrentFunction : public SyncExtensionFunction {
41 virtual ~GetCurrentWindowFunction() {} 51 virtual ~WindowsGetCurrentFunction() {}
42 virtual bool RunImpl() OVERRIDE; 52 virtual bool RunImpl() OVERRIDE;
43 DECLARE_EXTENSION_FUNCTION_NAME("windows.getCurrent") 53 DECLARE_EXTENSION_FUNCTION_NAME("windows.getCurrent")
44 }; 54 };
45 class GetLastFocusedWindowFunction : public SyncExtensionFunction { 55 class WindowsGetLastFocusedFunction : public SyncExtensionFunction {
46 virtual ~GetLastFocusedWindowFunction() {} 56 virtual ~WindowsGetLastFocusedFunction() {}
47 virtual bool RunImpl() OVERRIDE; 57 virtual bool RunImpl() OVERRIDE;
48 DECLARE_EXTENSION_FUNCTION_NAME("windows.getLastFocused") 58 DECLARE_EXTENSION_FUNCTION_NAME("windows.getLastFocused")
49 }; 59 };
50 class GetAllWindowsFunction : public SyncExtensionFunction { 60 class WindowsGetAllFunction : public SyncExtensionFunction {
51 virtual ~GetAllWindowsFunction() {} 61 virtual ~WindowsGetAllFunction() {}
52 virtual bool RunImpl() OVERRIDE; 62 virtual bool RunImpl() OVERRIDE;
53 DECLARE_EXTENSION_FUNCTION_NAME("windows.getAll") 63 DECLARE_EXTENSION_FUNCTION_NAME("windows.getAll")
54 }; 64 };
55 class CreateWindowFunction : public SyncExtensionFunction { 65 class WindowsCreateFunction : public SyncExtensionFunction {
56 virtual ~CreateWindowFunction() {} 66 virtual ~WindowsCreateFunction() {}
57 virtual bool RunImpl() OVERRIDE; 67 virtual bool RunImpl() OVERRIDE;
58 // Returns whether the window should be created in incognito mode. 68 // Returns whether the window should be created in incognito mode.
59 // |urls| is the list of urls to open. If we are creating an incognito window, 69 // |urls| is the list of urls to open. If we are creating an incognito window,
60 // the function will remove these urls which may not be opened in incognito 70 // the function will remove these urls which may not be opened in incognito
61 // mode. If window creation leads the browser into an erroneous state, 71 // mode. If window creation leads the browser into an erroneous state,
62 // |is_error| is set to true (also, error_ member variable is assigned 72 // |is_error| is set to true (also, error_ member variable is assigned
63 // the proper error message). 73 // the proper error message).
64 bool ShouldOpenIncognitoWindow(const base::DictionaryValue* args, 74 bool ShouldOpenIncognitoWindow(const base::DictionaryValue* args,
65 std::vector<GURL>* urls, 75 std::vector<GURL>* urls,
66 bool* is_error); 76 bool* is_error);
67 DECLARE_EXTENSION_FUNCTION_NAME("windows.create") 77 DECLARE_EXTENSION_FUNCTION_NAME("windows.create")
68 }; 78 };
69 class UpdateWindowFunction : public SyncExtensionFunction { 79 class WindowsUpdateFunction : public SyncExtensionFunction {
70 virtual ~UpdateWindowFunction() {} 80 virtual ~WindowsUpdateFunction() {}
71 virtual bool RunImpl() OVERRIDE; 81 virtual bool RunImpl() OVERRIDE;
72 DECLARE_EXTENSION_FUNCTION_NAME("windows.update") 82 DECLARE_EXTENSION_FUNCTION_NAME("windows.update")
73 }; 83 };
74 class RemoveWindowFunction : public SyncExtensionFunction { 84 class WindowsRemoveFunction : public SyncExtensionFunction {
75 virtual ~RemoveWindowFunction() {} 85 virtual ~WindowsRemoveFunction() {}
76 virtual bool RunImpl() OVERRIDE; 86 virtual bool RunImpl() OVERRIDE;
77 DECLARE_EXTENSION_FUNCTION_NAME("windows.remove") 87 DECLARE_EXTENSION_FUNCTION_NAME("windows.remove")
78 }; 88 };
79 89
80 // Tabs 90 // Tabs
81 class GetTabFunction : public SyncExtensionFunction { 91 class TabsGetFunction : public SyncExtensionFunction {
82 virtual ~GetTabFunction() {} 92 virtual ~TabsGetFunction() {}
83 virtual bool RunImpl() OVERRIDE; 93 virtual bool RunImpl() OVERRIDE;
84 DECLARE_EXTENSION_FUNCTION_NAME("tabs.get") 94 DECLARE_EXTENSION_FUNCTION_NAME("tabs.get")
85 }; 95 };
86 class GetCurrentTabFunction : public SyncExtensionFunction { 96 class TabsGetCurrentFunction : public SyncExtensionFunction {
87 virtual ~GetCurrentTabFunction() {} 97 virtual ~TabsGetCurrentFunction() {}
88 virtual bool RunImpl() OVERRIDE; 98 virtual bool RunImpl() OVERRIDE;
89 DECLARE_EXTENSION_FUNCTION_NAME("tabs.getCurrent") 99 DECLARE_EXTENSION_FUNCTION_NAME("tabs.getCurrent")
90 }; 100 };
91 class GetSelectedTabFunction : public SyncExtensionFunction { 101 class TabsGetSelectedFunction : public SyncExtensionFunction {
92 virtual ~GetSelectedTabFunction() {} 102 virtual ~TabsGetSelectedFunction() {}
93 virtual bool RunImpl() OVERRIDE; 103 virtual bool RunImpl() OVERRIDE;
94 DECLARE_EXTENSION_FUNCTION_NAME("tabs.getSelected") 104 DECLARE_EXTENSION_FUNCTION_NAME("tabs.getSelected")
95 }; 105 };
96 class GetAllTabsInWindowFunction : public SyncExtensionFunction { 106 class TabsGetAllInWindowFunction : public SyncExtensionFunction {
97 virtual ~GetAllTabsInWindowFunction() {} 107 virtual ~TabsGetAllInWindowFunction() {}
98 virtual bool RunImpl() OVERRIDE; 108 virtual bool RunImpl() OVERRIDE;
99 DECLARE_EXTENSION_FUNCTION_NAME("tabs.getAllInWindow") 109 DECLARE_EXTENSION_FUNCTION_NAME("tabs.getAllInWindow")
100 }; 110 };
101 class QueryTabsFunction : public SyncExtensionFunction { 111 class TabsQueryFunction : public SyncExtensionFunction {
102 virtual ~QueryTabsFunction() {} 112 virtual ~TabsQueryFunction() {}
103 virtual bool RunImpl() OVERRIDE; 113 virtual bool RunImpl() OVERRIDE;
104 DECLARE_EXTENSION_FUNCTION_NAME("tabs.query") 114 DECLARE_EXTENSION_FUNCTION_NAME("tabs.query")
105 }; 115 };
106 class CreateTabFunction : public SyncExtensionFunction { 116 class TabsCreateFunction : public SyncExtensionFunction {
107 virtual ~CreateTabFunction() {} 117 virtual ~TabsCreateFunction() {}
108 virtual bool RunImpl() OVERRIDE; 118 virtual bool RunImpl() OVERRIDE;
109 DECLARE_EXTENSION_FUNCTION_NAME("tabs.create") 119 DECLARE_EXTENSION_FUNCTION_NAME("tabs.create")
110 }; 120 };
111 class DuplicateTabFunction : public SyncExtensionFunction { 121 class TabsDuplicateFunction : public SyncExtensionFunction {
112 virtual ~DuplicateTabFunction() {} 122 virtual ~TabsDuplicateFunction() {}
113 virtual bool RunImpl() OVERRIDE; 123 virtual bool RunImpl() OVERRIDE;
114 DECLARE_EXTENSION_FUNCTION_NAME("tabs.duplicate") 124 DECLARE_EXTENSION_FUNCTION_NAME("tabs.duplicate")
115 }; 125 };
116 class HighlightTabsFunction : public SyncExtensionFunction { 126 class TabsHighlightFunction : public SyncExtensionFunction {
117 virtual ~HighlightTabsFunction() {} 127 virtual ~TabsHighlightFunction() {}
118 virtual bool RunImpl() OVERRIDE; 128 virtual bool RunImpl() OVERRIDE;
119 DECLARE_EXTENSION_FUNCTION_NAME("tabs.highlight") 129 DECLARE_EXTENSION_FUNCTION_NAME("tabs.highlight")
120 }; 130 };
121 class UpdateTabFunction : public AsyncExtensionFunction { 131 class TabsUpdateFunction : public AsyncExtensionFunction {
122 public: 132 public:
123 UpdateTabFunction(); 133 TabsUpdateFunction();
124 134
125 protected: 135 protected:
126 virtual ~UpdateTabFunction() {} 136 virtual ~TabsUpdateFunction() {}
127 virtual bool UpdateURLIfPresent(base::DictionaryValue* update_props, 137 virtual bool UpdateURLIfPresent(base::DictionaryValue* update_props,
128 int tab_id, 138 int tab_id,
129 bool* is_async); 139 bool* is_async);
130 virtual void PopulateResult(); 140 virtual void PopulateResult();
131 141
132 content::WebContents* web_contents_; 142 content::WebContents* web_contents_;
133 143
134 private: 144 private:
135 virtual bool RunImpl() OVERRIDE; 145 virtual bool RunImpl() OVERRIDE;
136 void OnExecuteCodeFinished(const std::string& error, 146 void OnExecuteCodeFinished(const std::string& error,
137 int32 on_page_id, 147 int32 on_page_id,
138 const GURL& on_url, 148 const GURL& on_url,
139 const ListValue& script_result); 149 const ListValue& script_result);
140 150
141 DECLARE_EXTENSION_FUNCTION_NAME("tabs.update") 151 DECLARE_EXTENSION_FUNCTION_NAME("tabs.update")
142 }; 152 };
143 class MoveTabsFunction : public SyncExtensionFunction { 153 class TabsMoveFunction : public SyncExtensionFunction {
144 virtual ~MoveTabsFunction() {} 154 virtual ~TabsMoveFunction() {}
145 virtual bool RunImpl() OVERRIDE; 155 virtual bool RunImpl() OVERRIDE;
146 DECLARE_EXTENSION_FUNCTION_NAME("tabs.move") 156 DECLARE_EXTENSION_FUNCTION_NAME("tabs.move")
147 }; 157 };
148 class ReloadTabFunction : public SyncExtensionFunction { 158 class TabsReloadFunction : public SyncExtensionFunction {
149 virtual ~ReloadTabFunction() {} 159 virtual ~TabsReloadFunction() {}
150 virtual bool RunImpl() OVERRIDE; 160 virtual bool RunImpl() OVERRIDE;
151 DECLARE_EXTENSION_FUNCTION_NAME("tabs.reload") 161 DECLARE_EXTENSION_FUNCTION_NAME("tabs.reload")
152 }; 162 };
153 class RemoveTabsFunction : public SyncExtensionFunction { 163 class TabsRemoveFunction : public SyncExtensionFunction {
154 virtual ~RemoveTabsFunction() {} 164 virtual ~TabsRemoveFunction() {}
155 virtual bool RunImpl() OVERRIDE; 165 virtual bool RunImpl() OVERRIDE;
156 DECLARE_EXTENSION_FUNCTION_NAME("tabs.remove") 166 DECLARE_EXTENSION_FUNCTION_NAME("tabs.remove")
157 }; 167 };
158 class DetectTabLanguageFunction : public AsyncExtensionFunction, 168 class TabsDetectLanguageFunction : public AsyncExtensionFunction,
159 public content::NotificationObserver { 169 public content::NotificationObserver {
160 private: 170 private:
161 virtual ~DetectTabLanguageFunction() {} 171 virtual ~TabsDetectLanguageFunction() {}
162 virtual bool RunImpl() OVERRIDE; 172 virtual bool RunImpl() OVERRIDE;
163 173
164 virtual void Observe(int type, 174 virtual void Observe(int type,
165 const content::NotificationSource& source, 175 const content::NotificationSource& source,
166 const content::NotificationDetails& details) OVERRIDE; 176 const content::NotificationDetails& details) OVERRIDE;
167 void GotLanguage(const std::string& language); 177 void GotLanguage(const std::string& language);
168 content::NotificationRegistrar registrar_; 178 content::NotificationRegistrar registrar_;
169 DECLARE_EXTENSION_FUNCTION_NAME("tabs.detectLanguage") 179 DECLARE_EXTENSION_FUNCTION_NAME("tabs.detectLanguage")
170 }; 180 };
171 class CaptureVisibleTabFunction : public AsyncExtensionFunction, 181 class TabsCaptureVisibleTabFunction : public AsyncExtensionFunction,
172 public content::NotificationObserver { 182 public content::NotificationObserver {
173 public: 183 public:
174 static void RegisterUserPrefs(PrefServiceSyncable* service); 184 static void RegisterUserPrefs(PrefServiceSyncable* service);
175 185
176 protected: 186 protected:
177 enum ImageFormat { 187 enum ImageFormat {
178 FORMAT_JPEG, 188 FORMAT_JPEG,
179 FORMAT_PNG 189 FORMAT_PNG
180 }; 190 };
181 191
182 // The default quality setting used when encoding jpegs. 192 // The default quality setting used when encoding jpegs.
183 static const int kDefaultQuality; 193 static const int kDefaultQuality;
184 194
185 virtual ~CaptureVisibleTabFunction() {} 195 virtual ~TabsCaptureVisibleTabFunction() {}
186 virtual bool RunImpl() OVERRIDE; 196 virtual bool RunImpl() OVERRIDE;
187 virtual bool GetTabToCapture(content::WebContents** web_contents); 197 virtual bool GetTabToCapture(content::WebContents** web_contents);
188 virtual void Observe(int type, 198 virtual void Observe(int type,
189 const content::NotificationSource& source, 199 const content::NotificationSource& source,
190 const content::NotificationDetails& details) OVERRIDE; 200 const content::NotificationDetails& details) OVERRIDE;
191 void SendResultFromBitmap(const SkBitmap& screen_capture); 201 void SendResultFromBitmap(const SkBitmap& screen_capture);
192 202
193 private: 203 private:
194 void CopyFromBackingStoreComplete(skia::PlatformBitmap* bitmap, 204 void CopyFromBackingStoreComplete(skia::PlatformBitmap* bitmap,
195 bool succeeded); 205 bool succeeded);
196 206
197 content::NotificationRegistrar registrar_; 207 content::NotificationRegistrar registrar_;
198 208
199 // The format (JPEG vs PNG) of the resulting image. Set in RunImpl(). 209 // The format (JPEG vs PNG) of the resulting image. Set in RunImpl().
200 ImageFormat image_format_; 210 ImageFormat image_format_;
201 211
202 // Quality setting to use when encoding jpegs. Set in RunImpl(). 212 // Quality setting to use when encoding jpegs. Set in RunImpl().
203 int image_quality_; 213 int image_quality_;
204 214
205 DECLARE_EXTENSION_FUNCTION_NAME("tabs.captureVisibleTab") 215 DECLARE_EXTENSION_FUNCTION_NAME("tabs.captureVisibleTab")
206 }; 216 };
207 217
208 #endif // CHROME_BROWSER_EXTENSIONS_API_TABS_TABS_H__ 218 // Implement API call tabs.executeScript and tabs.insertCSS.
219 class ExecuteCodeInTabFunction : public AsyncExtensionFunction {
220 public:
221 ExecuteCodeInTabFunction();
222
223 protected:
224 virtual ~ExecuteCodeInTabFunction();
225
226 // ExtensionFunction:
227 virtual bool HasPermission() OVERRIDE;
228 virtual bool RunImpl() OVERRIDE;
229
230 // Message handler.
231 virtual void OnExecuteCodeFinished(const std::string& error,
232 int32 on_page_id,
233 const GURL& on_url,
234 const ListValue& script_result);
235
236 private:
237 // Initialize the |execute_tab_id_| and |details_| if they haven't already
238 // been. Returns whether initialization was successful.
239 bool Init();
240
241 // Called when contents from the file whose path is specified in JSON
242 // arguments has been loaded.
243 void DidLoadFile(bool success, const std::string& data);
244
245 // Runs on FILE thread. Loads message bundles for the extension and
246 // localizes the CSS data. Calls back DidLoadAndLocalizeFile on the UI thread.
247 void LocalizeCSS(
248 const std::string& data,
249 const std::string& extension_id,
250 const FilePath& extension_path,
251 const std::string& extension_default_locale);
252
253 // Called when contents from the loaded file have been localized.
254 void DidLoadAndLocalizeFile(bool success, const std::string& data);
255
256 // Run in UI thread. Code string contains the code to be executed. Returns
257 // true on success. If true is returned, this does an AddRef.
258 bool Execute(const std::string& code_string);
259
260 // Id of tab which executes code.
261 int execute_tab_id_;
262
263 // The injection details.
264 scoped_ptr<extensions::api::tabs::InjectDetails> details_;
265
266 // Contains extension resource built from path of file which is
267 // specified in JSON arguments.
268 ExtensionResource resource_;
269 };
270
271 class TabsExecuteScriptFunction : public ExecuteCodeInTabFunction {
272 private:
273 virtual ~TabsExecuteScriptFunction() {}
274
275 virtual void OnExecuteCodeFinished(const std::string& error,
276 int32 on_page_id,
277 const GURL& on_url,
278 const ListValue& script_result) OVERRIDE;
279
280 DECLARE_EXTENSION_FUNCTION_NAME("tabs.executeScript")
281 };
282
283 class TabsInsertCSSFunction : public ExecuteCodeInTabFunction {
284 private:
285 virtual ~TabsInsertCSSFunction() {}
286
287 DECLARE_EXTENSION_FUNCTION_NAME("tabs.insertCSS")
288 };
289
290 #endif // CHROME_BROWSER_EXTENSIONS_API_TABS_TABS_API_H_
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/tabs/tabs.cc ('k') | chrome/browser/extensions/api/tabs/tabs_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698