Add testing/scripts/OWNERS
[chromium-blink-merge.git] / extensions / browser / api / web_view / web_view_internal_api.h
blob7aebf6303dd0943e4aee9f279e6f38865f98e31f
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 WebViewInternalCaptureVisibleRegionFunction
119 : public extensions::CaptureWebContentsFunction {
120 DECLARE_EXTENSION_FUNCTION("webViewInternal.captureVisibleRegion",
121 WEBVIEWINTERNAL_CAPTUREVISIBLEREGION);
123 WebViewInternalCaptureVisibleRegionFunction();
125 protected:
126 ~WebViewInternalCaptureVisibleRegionFunction() override;
128 private:
129 // extensions::CaptureWebContentsFunction implementation.
130 bool IsScreenshotEnabled() override;
131 content::WebContents* GetWebContentsForID(int id) override;
132 void OnCaptureFailure(FailureReason reason) override;
134 DISALLOW_COPY_AND_ASSIGN(WebViewInternalCaptureVisibleRegionFunction);
137 class WebViewInternalSetNameFunction : public WebViewInternalExtensionFunction {
138 public:
139 DECLARE_EXTENSION_FUNCTION("webViewInternal.setName",
140 WEBVIEWINTERNAL_SETNAME);
142 WebViewInternalSetNameFunction();
144 protected:
145 ~WebViewInternalSetNameFunction() override;
147 private:
148 bool RunAsyncSafe(WebViewGuest* guest) override;
150 DISALLOW_COPY_AND_ASSIGN(WebViewInternalSetNameFunction);
153 class WebViewInternalSetAllowTransparencyFunction :
154 public WebViewInternalExtensionFunction {
155 public:
156 DECLARE_EXTENSION_FUNCTION("webViewInternal.setAllowTransparency",
157 WEBVIEWINTERNAL_SETALLOWTRANSPARENCY);
159 WebViewInternalSetAllowTransparencyFunction();
161 protected:
162 ~WebViewInternalSetAllowTransparencyFunction() override;
164 private:
165 bool RunAsyncSafe(WebViewGuest* guest) override;
167 DISALLOW_COPY_AND_ASSIGN(WebViewInternalSetAllowTransparencyFunction);
170 class WebViewInternalSetZoomFunction : public WebViewInternalExtensionFunction {
171 public:
172 DECLARE_EXTENSION_FUNCTION("webViewInternal.setZoom",
173 WEBVIEWINTERNAL_SETZOOM);
175 WebViewInternalSetZoomFunction();
177 protected:
178 ~WebViewInternalSetZoomFunction() override;
180 private:
181 bool RunAsyncSafe(WebViewGuest* guest) override;
183 DISALLOW_COPY_AND_ASSIGN(WebViewInternalSetZoomFunction);
186 class WebViewInternalGetZoomFunction : public WebViewInternalExtensionFunction {
187 public:
188 DECLARE_EXTENSION_FUNCTION("webViewInternal.getZoom",
189 WEBVIEWINTERNAL_GETZOOM);
191 WebViewInternalGetZoomFunction();
193 protected:
194 ~WebViewInternalGetZoomFunction() override;
196 private:
197 bool RunAsyncSafe(WebViewGuest* guest) override;
199 DISALLOW_COPY_AND_ASSIGN(WebViewInternalGetZoomFunction);
202 class WebViewInternalFindFunction : public WebViewInternalExtensionFunction {
203 public:
204 DECLARE_EXTENSION_FUNCTION("webViewInternal.find", WEBVIEWINTERNAL_FIND);
206 WebViewInternalFindFunction();
208 // Exposes SendResponse() for use by WebViewInternalFindHelper.
209 using WebViewInternalExtensionFunction::SendResponse;
211 protected:
212 ~WebViewInternalFindFunction() override;
214 private:
215 // WebViewInternalExtensionFunction implementation.
216 bool RunAsyncSafe(WebViewGuest* guest) override;
218 DISALLOW_COPY_AND_ASSIGN(WebViewInternalFindFunction);
221 class WebViewInternalStopFindingFunction
222 : public WebViewInternalExtensionFunction {
223 public:
224 DECLARE_EXTENSION_FUNCTION("webViewInternal.stopFinding",
225 WEBVIEWINTERNAL_STOPFINDING);
227 WebViewInternalStopFindingFunction();
229 protected:
230 ~WebViewInternalStopFindingFunction() override;
232 private:
233 // WebViewInternalExtensionFunction implementation.
234 bool RunAsyncSafe(WebViewGuest* guest) override;
236 DISALLOW_COPY_AND_ASSIGN(WebViewInternalStopFindingFunction);
239 class WebViewInternalLoadDataWithBaseUrlFunction
240 : public WebViewInternalExtensionFunction {
241 public:
242 DECLARE_EXTENSION_FUNCTION("webViewInternal.loadDataWithBaseUrl",
243 WEBVIEWINTERNAL_LOADDATAWITHBASEURL);
245 WebViewInternalLoadDataWithBaseUrlFunction();
247 protected:
248 ~WebViewInternalLoadDataWithBaseUrlFunction() override;
250 private:
251 bool RunAsyncSafe(WebViewGuest* guest) override;
253 DISALLOW_COPY_AND_ASSIGN(WebViewInternalLoadDataWithBaseUrlFunction);
256 class WebViewInternalGoFunction : public WebViewInternalExtensionFunction {
257 public:
258 DECLARE_EXTENSION_FUNCTION("webViewInternal.go", WEBVIEWINTERNAL_GO);
260 WebViewInternalGoFunction();
262 protected:
263 ~WebViewInternalGoFunction() override;
265 private:
266 // WebViewInternalExtensionFunction implementation.
267 bool RunAsyncSafe(WebViewGuest* guest) override;
269 DISALLOW_COPY_AND_ASSIGN(WebViewInternalGoFunction);
272 class WebViewInternalReloadFunction : public WebViewInternalExtensionFunction {
273 public:
274 DECLARE_EXTENSION_FUNCTION("webViewInternal.reload", WEBVIEWINTERNAL_RELOAD);
276 WebViewInternalReloadFunction();
278 protected:
279 ~WebViewInternalReloadFunction() override;
281 private:
282 // WebViewInternalExtensionFunction implementation.
283 bool RunAsyncSafe(WebViewGuest* guest) override;
285 DISALLOW_COPY_AND_ASSIGN(WebViewInternalReloadFunction);
288 class WebViewInternalSetPermissionFunction
289 : public WebViewInternalExtensionFunction {
290 public:
291 DECLARE_EXTENSION_FUNCTION("webViewInternal.setPermission",
292 WEBVIEWINTERNAL_SETPERMISSION);
294 WebViewInternalSetPermissionFunction();
296 protected:
297 ~WebViewInternalSetPermissionFunction() override;
299 private:
300 // WebViewInternalExtensionFunction implementation.
301 bool RunAsyncSafe(WebViewGuest* guest) override;
303 DISALLOW_COPY_AND_ASSIGN(WebViewInternalSetPermissionFunction);
306 class WebViewInternalOverrideUserAgentFunction
307 : public WebViewInternalExtensionFunction {
308 public:
309 DECLARE_EXTENSION_FUNCTION("webViewInternal.overrideUserAgent",
310 WEBVIEWINTERNAL_OVERRIDEUSERAGENT);
312 WebViewInternalOverrideUserAgentFunction();
314 protected:
315 ~WebViewInternalOverrideUserAgentFunction() override;
317 private:
318 // WebViewInternalExtensionFunction implementation.
319 bool RunAsyncSafe(WebViewGuest* guest) override;
321 DISALLOW_COPY_AND_ASSIGN(WebViewInternalOverrideUserAgentFunction);
324 class WebViewInternalStopFunction : public WebViewInternalExtensionFunction {
325 public:
326 DECLARE_EXTENSION_FUNCTION("webViewInternal.stop", WEBVIEWINTERNAL_STOP);
328 WebViewInternalStopFunction();
330 protected:
331 ~WebViewInternalStopFunction() override;
333 private:
334 // WebViewInternalExtensionFunction implementation.
335 bool RunAsyncSafe(WebViewGuest* guest) override;
337 DISALLOW_COPY_AND_ASSIGN(WebViewInternalStopFunction);
340 class WebViewInternalTerminateFunction
341 : public WebViewInternalExtensionFunction {
342 public:
343 DECLARE_EXTENSION_FUNCTION("webViewInternal.terminate",
344 WEBVIEWINTERNAL_TERMINATE);
346 WebViewInternalTerminateFunction();
348 protected:
349 ~WebViewInternalTerminateFunction() override;
351 private:
352 // WebViewInternalExtensionFunction implementation.
353 bool RunAsyncSafe(WebViewGuest* guest) override;
355 DISALLOW_COPY_AND_ASSIGN(WebViewInternalTerminateFunction);
358 class WebViewInternalClearDataFunction
359 : public WebViewInternalExtensionFunction {
360 public:
361 DECLARE_EXTENSION_FUNCTION("webViewInternal.clearData",
362 WEBVIEWINTERNAL_CLEARDATA);
364 WebViewInternalClearDataFunction();
366 protected:
367 ~WebViewInternalClearDataFunction() override;
369 private:
370 // WebViewInternalExtensionFunction implementation.
371 bool RunAsyncSafe(WebViewGuest* guest) override;
373 uint32 GetRemovalMask();
374 void ClearDataDone();
376 // Removal start time.
377 base::Time remove_since_;
378 // Removal mask, corresponds to StoragePartition::RemoveDataMask enum.
379 uint32 remove_mask_;
380 // Tracks any data related or parse errors.
381 bool bad_message_;
383 DISALLOW_COPY_AND_ASSIGN(WebViewInternalClearDataFunction);
386 } // namespace extensions
388 #endif // CHROME_BROWSER_EXTENSIONS_API_WEB_VIEW_WEB_VIEW_INTERNAL_API_H_