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
22 class WebViewInternalExtensionFunction
: public AsyncExtensionFunction
{
24 WebViewInternalExtensionFunction() {}
27 ~WebViewInternalExtensionFunction() override
{}
29 // ExtensionFunction implementation.
30 bool RunAsync() final
;
33 virtual bool RunAsyncSafe(WebViewGuest
* guest
) = 0;
36 class WebViewInternalNavigateFunction
37 : public WebViewInternalExtensionFunction
{
39 DECLARE_EXTENSION_FUNCTION("webViewInternal.navigate",
40 WEBVIEWINTERNAL_NAVIGATE
);
41 WebViewInternalNavigateFunction() {}
44 ~WebViewInternalNavigateFunction() override
{}
47 // WebViewInternalExtensionFunction implementation.
48 bool RunAsyncSafe(WebViewGuest
* guest
) override
;
50 DISALLOW_COPY_AND_ASSIGN(WebViewInternalNavigateFunction
);
53 class WebViewInternalExecuteCodeFunction
54 : public extensions::ExecuteCodeFunction
{
56 WebViewInternalExecuteCodeFunction();
59 ~WebViewInternalExecuteCodeFunction() override
;
61 // Initialize |details_| if it hasn't already been.
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
;
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_
;
79 DISALLOW_COPY_AND_ASSIGN(WebViewInternalExecuteCodeFunction
);
82 class WebViewInternalExecuteScriptFunction
83 : public WebViewInternalExecuteCodeFunction
{
85 WebViewInternalExecuteScriptFunction();
88 ~WebViewInternalExecuteScriptFunction() override
{}
90 void OnExecuteCodeFinished(const std::string
& error
,
92 const base::ListValue
& result
) override
;
94 DECLARE_EXTENSION_FUNCTION("webViewInternal.executeScript",
95 WEBVIEWINTERNAL_EXECUTESCRIPT
)
98 DISALLOW_COPY_AND_ASSIGN(WebViewInternalExecuteScriptFunction
);
101 class WebViewInternalInsertCSSFunction
102 : public WebViewInternalExecuteCodeFunction
{
104 WebViewInternalInsertCSSFunction();
107 ~WebViewInternalInsertCSSFunction() override
{}
109 bool ShouldInsertCSS() const override
;
111 DECLARE_EXTENSION_FUNCTION("webViewInternal.insertCSS",
112 WEBVIEWINTERNAL_INSERTCSS
)
115 DISALLOW_COPY_AND_ASSIGN(WebViewInternalInsertCSSFunction
);
118 class WebViewInternalCaptureVisibleRegionFunction
119 : public extensions::CaptureWebContentsFunction
{
120 DECLARE_EXTENSION_FUNCTION("webViewInternal.captureVisibleRegion",
121 WEBVIEWINTERNAL_CAPTUREVISIBLEREGION
);
123 WebViewInternalCaptureVisibleRegionFunction();
126 ~WebViewInternalCaptureVisibleRegionFunction() override
;
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
{
139 DECLARE_EXTENSION_FUNCTION("webViewInternal.setName",
140 WEBVIEWINTERNAL_SETNAME
);
142 WebViewInternalSetNameFunction();
145 ~WebViewInternalSetNameFunction() override
;
148 bool RunAsyncSafe(WebViewGuest
* guest
) override
;
150 DISALLOW_COPY_AND_ASSIGN(WebViewInternalSetNameFunction
);
153 class WebViewInternalSetAllowTransparencyFunction
:
154 public WebViewInternalExtensionFunction
{
156 DECLARE_EXTENSION_FUNCTION("webViewInternal.setAllowTransparency",
157 WEBVIEWINTERNAL_SETALLOWTRANSPARENCY
);
159 WebViewInternalSetAllowTransparencyFunction();
162 ~WebViewInternalSetAllowTransparencyFunction() override
;
165 bool RunAsyncSafe(WebViewGuest
* guest
) override
;
167 DISALLOW_COPY_AND_ASSIGN(WebViewInternalSetAllowTransparencyFunction
);
170 class WebViewInternalSetZoomFunction
: public WebViewInternalExtensionFunction
{
172 DECLARE_EXTENSION_FUNCTION("webViewInternal.setZoom",
173 WEBVIEWINTERNAL_SETZOOM
);
175 WebViewInternalSetZoomFunction();
178 ~WebViewInternalSetZoomFunction() override
;
181 bool RunAsyncSafe(WebViewGuest
* guest
) override
;
183 DISALLOW_COPY_AND_ASSIGN(WebViewInternalSetZoomFunction
);
186 class WebViewInternalGetZoomFunction
: public WebViewInternalExtensionFunction
{
188 DECLARE_EXTENSION_FUNCTION("webViewInternal.getZoom",
189 WEBVIEWINTERNAL_GETZOOM
);
191 WebViewInternalGetZoomFunction();
194 ~WebViewInternalGetZoomFunction() override
;
197 bool RunAsyncSafe(WebViewGuest
* guest
) override
;
199 DISALLOW_COPY_AND_ASSIGN(WebViewInternalGetZoomFunction
);
202 class WebViewInternalFindFunction
: public WebViewInternalExtensionFunction
{
204 DECLARE_EXTENSION_FUNCTION("webViewInternal.find", WEBVIEWINTERNAL_FIND
);
206 WebViewInternalFindFunction();
208 // Exposes SendResponse() for use by WebViewInternalFindHelper.
209 using WebViewInternalExtensionFunction::SendResponse
;
212 ~WebViewInternalFindFunction() override
;
215 // WebViewInternalExtensionFunction implementation.
216 bool RunAsyncSafe(WebViewGuest
* guest
) override
;
218 DISALLOW_COPY_AND_ASSIGN(WebViewInternalFindFunction
);
221 class WebViewInternalStopFindingFunction
222 : public WebViewInternalExtensionFunction
{
224 DECLARE_EXTENSION_FUNCTION("webViewInternal.stopFinding",
225 WEBVIEWINTERNAL_STOPFINDING
);
227 WebViewInternalStopFindingFunction();
230 ~WebViewInternalStopFindingFunction() override
;
233 // WebViewInternalExtensionFunction implementation.
234 bool RunAsyncSafe(WebViewGuest
* guest
) override
;
236 DISALLOW_COPY_AND_ASSIGN(WebViewInternalStopFindingFunction
);
239 class WebViewInternalLoadDataWithBaseUrlFunction
240 : public WebViewInternalExtensionFunction
{
242 DECLARE_EXTENSION_FUNCTION("webViewInternal.loadDataWithBaseUrl",
243 WEBVIEWINTERNAL_LOADDATAWITHBASEURL
);
245 WebViewInternalLoadDataWithBaseUrlFunction();
248 ~WebViewInternalLoadDataWithBaseUrlFunction() override
;
251 bool RunAsyncSafe(WebViewGuest
* guest
) override
;
253 DISALLOW_COPY_AND_ASSIGN(WebViewInternalLoadDataWithBaseUrlFunction
);
256 class WebViewInternalGoFunction
: public WebViewInternalExtensionFunction
{
258 DECLARE_EXTENSION_FUNCTION("webViewInternal.go", WEBVIEWINTERNAL_GO
);
260 WebViewInternalGoFunction();
263 ~WebViewInternalGoFunction() override
;
266 // WebViewInternalExtensionFunction implementation.
267 bool RunAsyncSafe(WebViewGuest
* guest
) override
;
269 DISALLOW_COPY_AND_ASSIGN(WebViewInternalGoFunction
);
272 class WebViewInternalReloadFunction
: public WebViewInternalExtensionFunction
{
274 DECLARE_EXTENSION_FUNCTION("webViewInternal.reload", WEBVIEWINTERNAL_RELOAD
);
276 WebViewInternalReloadFunction();
279 ~WebViewInternalReloadFunction() override
;
282 // WebViewInternalExtensionFunction implementation.
283 bool RunAsyncSafe(WebViewGuest
* guest
) override
;
285 DISALLOW_COPY_AND_ASSIGN(WebViewInternalReloadFunction
);
288 class WebViewInternalSetPermissionFunction
289 : public WebViewInternalExtensionFunction
{
291 DECLARE_EXTENSION_FUNCTION("webViewInternal.setPermission",
292 WEBVIEWINTERNAL_SETPERMISSION
);
294 WebViewInternalSetPermissionFunction();
297 ~WebViewInternalSetPermissionFunction() override
;
300 // WebViewInternalExtensionFunction implementation.
301 bool RunAsyncSafe(WebViewGuest
* guest
) override
;
303 DISALLOW_COPY_AND_ASSIGN(WebViewInternalSetPermissionFunction
);
306 class WebViewInternalOverrideUserAgentFunction
307 : public WebViewInternalExtensionFunction
{
309 DECLARE_EXTENSION_FUNCTION("webViewInternal.overrideUserAgent",
310 WEBVIEWINTERNAL_OVERRIDEUSERAGENT
);
312 WebViewInternalOverrideUserAgentFunction();
315 ~WebViewInternalOverrideUserAgentFunction() override
;
318 // WebViewInternalExtensionFunction implementation.
319 bool RunAsyncSafe(WebViewGuest
* guest
) override
;
321 DISALLOW_COPY_AND_ASSIGN(WebViewInternalOverrideUserAgentFunction
);
324 class WebViewInternalStopFunction
: public WebViewInternalExtensionFunction
{
326 DECLARE_EXTENSION_FUNCTION("webViewInternal.stop", WEBVIEWINTERNAL_STOP
);
328 WebViewInternalStopFunction();
331 ~WebViewInternalStopFunction() override
;
334 // WebViewInternalExtensionFunction implementation.
335 bool RunAsyncSafe(WebViewGuest
* guest
) override
;
337 DISALLOW_COPY_AND_ASSIGN(WebViewInternalStopFunction
);
340 class WebViewInternalTerminateFunction
341 : public WebViewInternalExtensionFunction
{
343 DECLARE_EXTENSION_FUNCTION("webViewInternal.terminate",
344 WEBVIEWINTERNAL_TERMINATE
);
346 WebViewInternalTerminateFunction();
349 ~WebViewInternalTerminateFunction() override
;
352 // WebViewInternalExtensionFunction implementation.
353 bool RunAsyncSafe(WebViewGuest
* guest
) override
;
355 DISALLOW_COPY_AND_ASSIGN(WebViewInternalTerminateFunction
);
358 class WebViewInternalClearDataFunction
359 : public WebViewInternalExtensionFunction
{
361 DECLARE_EXTENSION_FUNCTION("webViewInternal.clearData",
362 WEBVIEWINTERNAL_CLEARDATA
);
364 WebViewInternalClearDataFunction();
367 ~WebViewInternalClearDataFunction() override
;
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.
380 // Tracks any data related or parse errors.
383 DISALLOW_COPY_AND_ASSIGN(WebViewInternalClearDataFunction
);
386 } // namespace extensions
388 #endif // CHROME_BROWSER_EXTENSIONS_API_WEB_VIEW_WEB_VIEW_INTERNAL_API_H_