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 WebViewInternalSetNameFunction
: public WebViewInternalExtensionFunction
{
120 DECLARE_EXTENSION_FUNCTION("webViewInternal.setName",
121 WEBVIEWINTERNAL_SETNAME
);
123 WebViewInternalSetNameFunction();
126 ~WebViewInternalSetNameFunction() override
;
129 bool RunAsyncSafe(WebViewGuest
* guest
) override
;
131 DISALLOW_COPY_AND_ASSIGN(WebViewInternalSetNameFunction
);
134 class WebViewInternalSetAllowTransparencyFunction
:
135 public WebViewInternalExtensionFunction
{
137 DECLARE_EXTENSION_FUNCTION("webViewInternal.setAllowTransparency",
138 WEBVIEWINTERNAL_SETALLOWTRANSPARENCY
);
140 WebViewInternalSetAllowTransparencyFunction();
143 ~WebViewInternalSetAllowTransparencyFunction() override
;
146 bool RunAsyncSafe(WebViewGuest
* guest
) override
;
148 DISALLOW_COPY_AND_ASSIGN(WebViewInternalSetAllowTransparencyFunction
);
151 class WebViewInternalSetAllowScalingFunction
152 : public WebViewInternalExtensionFunction
{
154 DECLARE_EXTENSION_FUNCTION("webViewInternal.setAllowScaling",
155 WEBVIEWINTERNAL_SETALLOWSCALING
);
157 WebViewInternalSetAllowScalingFunction();
160 ~WebViewInternalSetAllowScalingFunction() override
;
163 bool RunAsyncSafe(WebViewGuest
* guest
) override
;
165 DISALLOW_COPY_AND_ASSIGN(WebViewInternalSetAllowScalingFunction
);
168 class WebViewInternalSetZoomFunction
: public WebViewInternalExtensionFunction
{
170 DECLARE_EXTENSION_FUNCTION("webViewInternal.setZoom",
171 WEBVIEWINTERNAL_SETZOOM
);
173 WebViewInternalSetZoomFunction();
176 ~WebViewInternalSetZoomFunction() override
;
179 bool RunAsyncSafe(WebViewGuest
* guest
) override
;
181 DISALLOW_COPY_AND_ASSIGN(WebViewInternalSetZoomFunction
);
184 class WebViewInternalGetZoomFunction
: public WebViewInternalExtensionFunction
{
186 DECLARE_EXTENSION_FUNCTION("webViewInternal.getZoom",
187 WEBVIEWINTERNAL_GETZOOM
);
189 WebViewInternalGetZoomFunction();
192 ~WebViewInternalGetZoomFunction() override
;
195 bool RunAsyncSafe(WebViewGuest
* guest
) override
;
197 DISALLOW_COPY_AND_ASSIGN(WebViewInternalGetZoomFunction
);
200 class WebViewInternalFindFunction
: public WebViewInternalExtensionFunction
{
202 DECLARE_EXTENSION_FUNCTION("webViewInternal.find", WEBVIEWINTERNAL_FIND
);
204 WebViewInternalFindFunction();
206 // Exposes SendResponse() for use by WebViewInternalFindHelper.
207 using WebViewInternalExtensionFunction::SendResponse
;
210 ~WebViewInternalFindFunction() override
;
213 // WebViewInternalExtensionFunction implementation.
214 bool RunAsyncSafe(WebViewGuest
* guest
) override
;
216 DISALLOW_COPY_AND_ASSIGN(WebViewInternalFindFunction
);
219 class WebViewInternalStopFindingFunction
220 : public WebViewInternalExtensionFunction
{
222 DECLARE_EXTENSION_FUNCTION("webViewInternal.stopFinding",
223 WEBVIEWINTERNAL_STOPFINDING
);
225 WebViewInternalStopFindingFunction();
228 ~WebViewInternalStopFindingFunction() override
;
231 // WebViewInternalExtensionFunction implementation.
232 bool RunAsyncSafe(WebViewGuest
* guest
) override
;
234 DISALLOW_COPY_AND_ASSIGN(WebViewInternalStopFindingFunction
);
237 class WebViewInternalLoadDataWithBaseUrlFunction
238 : public WebViewInternalExtensionFunction
{
240 DECLARE_EXTENSION_FUNCTION("webViewInternal.loadDataWithBaseUrl",
241 WEBVIEWINTERNAL_LOADDATAWITHBASEURL
);
243 WebViewInternalLoadDataWithBaseUrlFunction();
246 ~WebViewInternalLoadDataWithBaseUrlFunction() override
;
249 bool RunAsyncSafe(WebViewGuest
* guest
) override
;
251 DISALLOW_COPY_AND_ASSIGN(WebViewInternalLoadDataWithBaseUrlFunction
);
254 class WebViewInternalGoFunction
: public WebViewInternalExtensionFunction
{
256 DECLARE_EXTENSION_FUNCTION("webViewInternal.go", WEBVIEWINTERNAL_GO
);
258 WebViewInternalGoFunction();
261 ~WebViewInternalGoFunction() override
;
264 // WebViewInternalExtensionFunction implementation.
265 bool RunAsyncSafe(WebViewGuest
* guest
) override
;
267 DISALLOW_COPY_AND_ASSIGN(WebViewInternalGoFunction
);
270 class WebViewInternalReloadFunction
: public WebViewInternalExtensionFunction
{
272 DECLARE_EXTENSION_FUNCTION("webViewInternal.reload", WEBVIEWINTERNAL_RELOAD
);
274 WebViewInternalReloadFunction();
277 ~WebViewInternalReloadFunction() override
;
280 // WebViewInternalExtensionFunction implementation.
281 bool RunAsyncSafe(WebViewGuest
* guest
) override
;
283 DISALLOW_COPY_AND_ASSIGN(WebViewInternalReloadFunction
);
286 class WebViewInternalSetPermissionFunction
287 : public WebViewInternalExtensionFunction
{
289 DECLARE_EXTENSION_FUNCTION("webViewInternal.setPermission",
290 WEBVIEWINTERNAL_SETPERMISSION
);
292 WebViewInternalSetPermissionFunction();
295 ~WebViewInternalSetPermissionFunction() override
;
298 // WebViewInternalExtensionFunction implementation.
299 bool RunAsyncSafe(WebViewGuest
* guest
) override
;
301 DISALLOW_COPY_AND_ASSIGN(WebViewInternalSetPermissionFunction
);
304 class WebViewInternalOverrideUserAgentFunction
305 : public WebViewInternalExtensionFunction
{
307 DECLARE_EXTENSION_FUNCTION("webViewInternal.overrideUserAgent",
308 WEBVIEWINTERNAL_OVERRIDEUSERAGENT
);
310 WebViewInternalOverrideUserAgentFunction();
313 ~WebViewInternalOverrideUserAgentFunction() override
;
316 // WebViewInternalExtensionFunction implementation.
317 bool RunAsyncSafe(WebViewGuest
* guest
) override
;
319 DISALLOW_COPY_AND_ASSIGN(WebViewInternalOverrideUserAgentFunction
);
322 class WebViewInternalStopFunction
: public WebViewInternalExtensionFunction
{
324 DECLARE_EXTENSION_FUNCTION("webViewInternal.stop", WEBVIEWINTERNAL_STOP
);
326 WebViewInternalStopFunction();
329 ~WebViewInternalStopFunction() override
;
332 // WebViewInternalExtensionFunction implementation.
333 bool RunAsyncSafe(WebViewGuest
* guest
) override
;
335 DISALLOW_COPY_AND_ASSIGN(WebViewInternalStopFunction
);
338 class WebViewInternalTerminateFunction
339 : public WebViewInternalExtensionFunction
{
341 DECLARE_EXTENSION_FUNCTION("webViewInternal.terminate",
342 WEBVIEWINTERNAL_TERMINATE
);
344 WebViewInternalTerminateFunction();
347 ~WebViewInternalTerminateFunction() override
;
350 // WebViewInternalExtensionFunction implementation.
351 bool RunAsyncSafe(WebViewGuest
* guest
) override
;
353 DISALLOW_COPY_AND_ASSIGN(WebViewInternalTerminateFunction
);
356 class WebViewInternalClearDataFunction
357 : public WebViewInternalExtensionFunction
{
359 DECLARE_EXTENSION_FUNCTION("webViewInternal.clearData",
360 WEBVIEWINTERNAL_CLEARDATA
);
362 WebViewInternalClearDataFunction();
365 ~WebViewInternalClearDataFunction() override
;
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.
378 // Tracks any data related or parse errors.
381 DISALLOW_COPY_AND_ASSIGN(WebViewInternalClearDataFunction
);
384 } // namespace extensions
386 #endif // CHROME_BROWSER_EXTENSIONS_API_WEB_VIEW_WEB_VIEW_INTERNAL_API_H_