ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / extensions / browser / api / web_view / web_view_internal_api.h
blob37483df9e0a1c09c9b74057999f9cb005b590faa
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 EXTENSIONS_BROWSER_API_WEB_VIEW_WEB_VIEW_INTERNAL_API_H_
6 #define EXTENSIONS_BROWSER_API_WEB_VIEW_WEB_VIEW_INTERNAL_API_H_
8 #include "extensions/browser/api/capture_web_contents_function.h"
9 #include "extensions/browser/api/execute_code_function.h"
10 #include "extensions/browser/extension_function.h"
11 #include "extensions/browser/guest_view/web_view/web_view_guest.h"
13 // WARNING: WebViewInternal could be loaded in an unblessed context, thus any
14 // new APIs must extend WebViewInternalExtensionFunction or
15 // WebViewInternalExecuteCodeFunction which do a process ID check to prevent
16 // abuse by normal renderer processes.
17 namespace extensions {
19 // An abstract base class for async webview APIs. It does a process ID check
20 // in RunAsync, and then calls RunAsyncSafe which must be overriden by all
21 // subclasses.
22 class WebViewInternalExtensionFunction : public AsyncExtensionFunction {
23 public:
24 WebViewInternalExtensionFunction() {}
26 protected:
27 ~WebViewInternalExtensionFunction() override {}
29 // ExtensionFunction implementation.
30 bool RunAsync() final;
32 private:
33 virtual bool RunAsyncSafe(WebViewGuest* guest) = 0;
36 class WebViewInternalNavigateFunction
37 : public WebViewInternalExtensionFunction {
38 public:
39 DECLARE_EXTENSION_FUNCTION("webViewInternal.navigate",
40 WEBVIEWINTERNAL_NAVIGATE);
41 WebViewInternalNavigateFunction() {}
43 protected:
44 ~WebViewInternalNavigateFunction() override {}
46 private:
47 // WebViewInternalExtensionFunction implementation.
48 bool RunAsyncSafe(WebViewGuest* guest) override;
50 DISALLOW_COPY_AND_ASSIGN(WebViewInternalNavigateFunction);
53 class WebViewInternalExecuteCodeFunction
54 : public extensions::ExecuteCodeFunction {
55 public:
56 WebViewInternalExecuteCodeFunction();
58 protected:
59 ~WebViewInternalExecuteCodeFunction() override;
61 // Initialize |details_| if it hasn't already been.
62 bool Init() override;
63 bool ShouldInsertCSS() const override;
64 bool CanExecuteScriptOnPage() override;
65 // Guarded by a process ID check.
66 extensions::ScriptExecutor* GetScriptExecutor() final;
67 bool IsWebView() const override;
68 const GURL& GetWebViewSrc() const override;
70 private:
71 // Contains extension resource built from path of file which is
72 // specified in JSON arguments.
73 extensions::ExtensionResource resource_;
75 int guest_instance_id_;
77 GURL guest_src_;
79 DISALLOW_COPY_AND_ASSIGN(WebViewInternalExecuteCodeFunction);
82 class WebViewInternalExecuteScriptFunction
83 : public WebViewInternalExecuteCodeFunction {
84 public:
85 WebViewInternalExecuteScriptFunction();
87 protected:
88 ~WebViewInternalExecuteScriptFunction() override {}
90 void OnExecuteCodeFinished(const std::string& error,
91 const GURL& on_url,
92 const base::ListValue& result) override;
94 DECLARE_EXTENSION_FUNCTION("webViewInternal.executeScript",
95 WEBVIEWINTERNAL_EXECUTESCRIPT)
97 private:
98 DISALLOW_COPY_AND_ASSIGN(WebViewInternalExecuteScriptFunction);
101 class WebViewInternalInsertCSSFunction
102 : public WebViewInternalExecuteCodeFunction {
103 public:
104 WebViewInternalInsertCSSFunction();
106 protected:
107 ~WebViewInternalInsertCSSFunction() override {}
109 bool ShouldInsertCSS() const override;
111 DECLARE_EXTENSION_FUNCTION("webViewInternal.insertCSS",
112 WEBVIEWINTERNAL_INSERTCSS)
114 private:
115 DISALLOW_COPY_AND_ASSIGN(WebViewInternalInsertCSSFunction);
118 class WebViewInternalSetNameFunction : public WebViewInternalExtensionFunction {
119 public:
120 DECLARE_EXTENSION_FUNCTION("webViewInternal.setName",
121 WEBVIEWINTERNAL_SETNAME);
123 WebViewInternalSetNameFunction();
125 protected:
126 ~WebViewInternalSetNameFunction() override;
128 private:
129 bool RunAsyncSafe(WebViewGuest* guest) override;
131 DISALLOW_COPY_AND_ASSIGN(WebViewInternalSetNameFunction);
134 class WebViewInternalSetAllowTransparencyFunction :
135 public WebViewInternalExtensionFunction {
136 public:
137 DECLARE_EXTENSION_FUNCTION("webViewInternal.setAllowTransparency",
138 WEBVIEWINTERNAL_SETALLOWTRANSPARENCY);
140 WebViewInternalSetAllowTransparencyFunction();
142 protected:
143 ~WebViewInternalSetAllowTransparencyFunction() override;
145 private:
146 bool RunAsyncSafe(WebViewGuest* guest) override;
148 DISALLOW_COPY_AND_ASSIGN(WebViewInternalSetAllowTransparencyFunction);
151 class WebViewInternalSetAllowScalingFunction
152 : public WebViewInternalExtensionFunction {
153 public:
154 DECLARE_EXTENSION_FUNCTION("webViewInternal.setAllowScaling",
155 WEBVIEWINTERNAL_SETALLOWSCALING);
157 WebViewInternalSetAllowScalingFunction();
159 protected:
160 ~WebViewInternalSetAllowScalingFunction() override;
162 private:
163 bool RunAsyncSafe(WebViewGuest* guest) override;
165 DISALLOW_COPY_AND_ASSIGN(WebViewInternalSetAllowScalingFunction);
168 class WebViewInternalSetZoomFunction : public WebViewInternalExtensionFunction {
169 public:
170 DECLARE_EXTENSION_FUNCTION("webViewInternal.setZoom",
171 WEBVIEWINTERNAL_SETZOOM);
173 WebViewInternalSetZoomFunction();
175 protected:
176 ~WebViewInternalSetZoomFunction() override;
178 private:
179 bool RunAsyncSafe(WebViewGuest* guest) override;
181 DISALLOW_COPY_AND_ASSIGN(WebViewInternalSetZoomFunction);
184 class WebViewInternalGetZoomFunction : public WebViewInternalExtensionFunction {
185 public:
186 DECLARE_EXTENSION_FUNCTION("webViewInternal.getZoom",
187 WEBVIEWINTERNAL_GETZOOM);
189 WebViewInternalGetZoomFunction();
191 protected:
192 ~WebViewInternalGetZoomFunction() override;
194 private:
195 bool RunAsyncSafe(WebViewGuest* guest) override;
197 DISALLOW_COPY_AND_ASSIGN(WebViewInternalGetZoomFunction);
200 class WebViewInternalFindFunction : public WebViewInternalExtensionFunction {
201 public:
202 DECLARE_EXTENSION_FUNCTION("webViewInternal.find", WEBVIEWINTERNAL_FIND);
204 WebViewInternalFindFunction();
206 // Exposes SendResponse() for use by WebViewInternalFindHelper.
207 using WebViewInternalExtensionFunction::SendResponse;
209 protected:
210 ~WebViewInternalFindFunction() override;
212 private:
213 // WebViewInternalExtensionFunction implementation.
214 bool RunAsyncSafe(WebViewGuest* guest) override;
216 DISALLOW_COPY_AND_ASSIGN(WebViewInternalFindFunction);
219 class WebViewInternalStopFindingFunction
220 : public WebViewInternalExtensionFunction {
221 public:
222 DECLARE_EXTENSION_FUNCTION("webViewInternal.stopFinding",
223 WEBVIEWINTERNAL_STOPFINDING);
225 WebViewInternalStopFindingFunction();
227 protected:
228 ~WebViewInternalStopFindingFunction() override;
230 private:
231 // WebViewInternalExtensionFunction implementation.
232 bool RunAsyncSafe(WebViewGuest* guest) override;
234 DISALLOW_COPY_AND_ASSIGN(WebViewInternalStopFindingFunction);
237 class WebViewInternalLoadDataWithBaseUrlFunction
238 : public WebViewInternalExtensionFunction {
239 public:
240 DECLARE_EXTENSION_FUNCTION("webViewInternal.loadDataWithBaseUrl",
241 WEBVIEWINTERNAL_LOADDATAWITHBASEURL);
243 WebViewInternalLoadDataWithBaseUrlFunction();
245 protected:
246 ~WebViewInternalLoadDataWithBaseUrlFunction() override;
248 private:
249 bool RunAsyncSafe(WebViewGuest* guest) override;
251 DISALLOW_COPY_AND_ASSIGN(WebViewInternalLoadDataWithBaseUrlFunction);
254 class WebViewInternalGoFunction : public WebViewInternalExtensionFunction {
255 public:
256 DECLARE_EXTENSION_FUNCTION("webViewInternal.go", WEBVIEWINTERNAL_GO);
258 WebViewInternalGoFunction();
260 protected:
261 ~WebViewInternalGoFunction() override;
263 private:
264 // WebViewInternalExtensionFunction implementation.
265 bool RunAsyncSafe(WebViewGuest* guest) override;
267 DISALLOW_COPY_AND_ASSIGN(WebViewInternalGoFunction);
270 class WebViewInternalReloadFunction : public WebViewInternalExtensionFunction {
271 public:
272 DECLARE_EXTENSION_FUNCTION("webViewInternal.reload", WEBVIEWINTERNAL_RELOAD);
274 WebViewInternalReloadFunction();
276 protected:
277 ~WebViewInternalReloadFunction() override;
279 private:
280 // WebViewInternalExtensionFunction implementation.
281 bool RunAsyncSafe(WebViewGuest* guest) override;
283 DISALLOW_COPY_AND_ASSIGN(WebViewInternalReloadFunction);
286 class WebViewInternalSetPermissionFunction
287 : public WebViewInternalExtensionFunction {
288 public:
289 DECLARE_EXTENSION_FUNCTION("webViewInternal.setPermission",
290 WEBVIEWINTERNAL_SETPERMISSION);
292 WebViewInternalSetPermissionFunction();
294 protected:
295 ~WebViewInternalSetPermissionFunction() override;
297 private:
298 // WebViewInternalExtensionFunction implementation.
299 bool RunAsyncSafe(WebViewGuest* guest) override;
301 DISALLOW_COPY_AND_ASSIGN(WebViewInternalSetPermissionFunction);
304 class WebViewInternalOverrideUserAgentFunction
305 : public WebViewInternalExtensionFunction {
306 public:
307 DECLARE_EXTENSION_FUNCTION("webViewInternal.overrideUserAgent",
308 WEBVIEWINTERNAL_OVERRIDEUSERAGENT);
310 WebViewInternalOverrideUserAgentFunction();
312 protected:
313 ~WebViewInternalOverrideUserAgentFunction() override;
315 private:
316 // WebViewInternalExtensionFunction implementation.
317 bool RunAsyncSafe(WebViewGuest* guest) override;
319 DISALLOW_COPY_AND_ASSIGN(WebViewInternalOverrideUserAgentFunction);
322 class WebViewInternalStopFunction : public WebViewInternalExtensionFunction {
323 public:
324 DECLARE_EXTENSION_FUNCTION("webViewInternal.stop", WEBVIEWINTERNAL_STOP);
326 WebViewInternalStopFunction();
328 protected:
329 ~WebViewInternalStopFunction() override;
331 private:
332 // WebViewInternalExtensionFunction implementation.
333 bool RunAsyncSafe(WebViewGuest* guest) override;
335 DISALLOW_COPY_AND_ASSIGN(WebViewInternalStopFunction);
338 class WebViewInternalTerminateFunction
339 : public WebViewInternalExtensionFunction {
340 public:
341 DECLARE_EXTENSION_FUNCTION("webViewInternal.terminate",
342 WEBVIEWINTERNAL_TERMINATE);
344 WebViewInternalTerminateFunction();
346 protected:
347 ~WebViewInternalTerminateFunction() override;
349 private:
350 // WebViewInternalExtensionFunction implementation.
351 bool RunAsyncSafe(WebViewGuest* guest) override;
353 DISALLOW_COPY_AND_ASSIGN(WebViewInternalTerminateFunction);
356 class WebViewInternalClearDataFunction
357 : public WebViewInternalExtensionFunction {
358 public:
359 DECLARE_EXTENSION_FUNCTION("webViewInternal.clearData",
360 WEBVIEWINTERNAL_CLEARDATA);
362 WebViewInternalClearDataFunction();
364 protected:
365 ~WebViewInternalClearDataFunction() override;
367 private:
368 // WebViewInternalExtensionFunction implementation.
369 bool RunAsyncSafe(WebViewGuest* guest) override;
371 uint32 GetRemovalMask();
372 void ClearDataDone();
374 // Removal start time.
375 base::Time remove_since_;
376 // Removal mask, corresponds to StoragePartition::RemoveDataMask enum.
377 uint32 remove_mask_;
378 // Tracks any data related or parse errors.
379 bool bad_message_;
381 DISALLOW_COPY_AND_ASSIGN(WebViewInternalClearDataFunction);
384 } // namespace extensions
386 #endif // CHROME_BROWSER_EXTENSIONS_API_WEB_VIEW_WEB_VIEW_INTERNAL_API_H_