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_ui/web_ui_url_fetcher.h"
12 #include "extensions/browser/guest_view/web_view/web_view_guest.h"
14 // WARNING: WebViewInternal could be loaded in an unblessed context, thus any
15 // new APIs must extend WebViewInternalExtensionFunction or
16 // WebViewInternalExecuteCodeFunction which do a process ID check to prevent
17 // abuse by normal renderer processes.
18 namespace extensions
{
20 // An abstract base class for async webview APIs. It does a process ID check
21 // in RunAsync, and then calls RunAsyncSafe which must be overriden by all
23 class WebViewInternalExtensionFunction
: public AsyncExtensionFunction
{
25 WebViewInternalExtensionFunction() {}
28 ~WebViewInternalExtensionFunction() override
{}
30 // ExtensionFunction implementation.
31 bool RunAsync() final
;
34 virtual bool RunAsyncSafe(WebViewGuest
* guest
) = 0;
37 class WebViewInternalNavigateFunction
38 : public WebViewInternalExtensionFunction
{
40 DECLARE_EXTENSION_FUNCTION("webViewInternal.navigate",
41 WEBVIEWINTERNAL_NAVIGATE
);
42 WebViewInternalNavigateFunction() {}
45 ~WebViewInternalNavigateFunction() override
{}
48 // WebViewInternalExtensionFunction implementation.
49 bool RunAsyncSafe(WebViewGuest
* guest
) override
;
51 DISALLOW_COPY_AND_ASSIGN(WebViewInternalNavigateFunction
);
54 class WebViewInternalExecuteCodeFunction
55 : public extensions::ExecuteCodeFunction
{
57 WebViewInternalExecuteCodeFunction();
60 ~WebViewInternalExecuteCodeFunction() override
;
62 // Initialize |details_| if it hasn't already been.
64 bool ShouldInsertCSS() const override
;
65 bool CanExecuteScriptOnPage() override
;
66 // Guarded by a process ID check.
67 extensions::ScriptExecutor
* GetScriptExecutor() final
;
68 bool IsWebView() const override
;
69 const GURL
& GetWebViewSrc() const override
;
70 bool LoadFile(const std::string
& file
) override
;
73 // Loads a file url on WebUI.
74 bool LoadFileForWebUI(const std::string
& file_src
,
75 const WebUIURLFetcher::WebUILoadFileCallback
& callback
);
77 // Contains extension resource built from path of file which is
78 // specified in JSON arguments.
79 extensions::ExtensionResource resource_
;
81 int guest_instance_id_
;
85 scoped_ptr
<WebUIURLFetcher
> url_fetcher_
;
87 DISALLOW_COPY_AND_ASSIGN(WebViewInternalExecuteCodeFunction
);
90 class WebViewInternalExecuteScriptFunction
91 : public WebViewInternalExecuteCodeFunction
{
93 WebViewInternalExecuteScriptFunction();
96 ~WebViewInternalExecuteScriptFunction() override
{}
98 void OnExecuteCodeFinished(const std::string
& error
,
100 const base::ListValue
& result
) override
;
102 DECLARE_EXTENSION_FUNCTION("webViewInternal.executeScript",
103 WEBVIEWINTERNAL_EXECUTESCRIPT
)
106 DISALLOW_COPY_AND_ASSIGN(WebViewInternalExecuteScriptFunction
);
109 class WebViewInternalInsertCSSFunction
110 : public WebViewInternalExecuteCodeFunction
{
112 WebViewInternalInsertCSSFunction();
115 ~WebViewInternalInsertCSSFunction() override
{}
117 bool ShouldInsertCSS() const override
;
119 DECLARE_EXTENSION_FUNCTION("webViewInternal.insertCSS",
120 WEBVIEWINTERNAL_INSERTCSS
)
123 DISALLOW_COPY_AND_ASSIGN(WebViewInternalInsertCSSFunction
);
126 class WebViewInternalAddContentScriptsFunction
127 : public UIThreadExtensionFunction
{
129 DECLARE_EXTENSION_FUNCTION("webViewInternal.addContentScripts",
130 WEBVIEWINTERNAL_ADDCONTENTSCRIPTS
);
132 WebViewInternalAddContentScriptsFunction();
135 ~WebViewInternalAddContentScriptsFunction() override
;
138 ExecuteCodeFunction::ResponseAction
Run() override
;
140 DISALLOW_COPY_AND_ASSIGN(WebViewInternalAddContentScriptsFunction
);
143 class WebViewInternalRemoveContentScriptsFunction
144 : public UIThreadExtensionFunction
{
146 DECLARE_EXTENSION_FUNCTION("webViewInternal.removeContentScripts",
147 WEBVIEWINTERNAL_REMOVECONTENTSCRIPTS
);
149 WebViewInternalRemoveContentScriptsFunction();
152 ~WebViewInternalRemoveContentScriptsFunction() override
;
155 ExecuteCodeFunction::ResponseAction
Run() override
;
157 DISALLOW_COPY_AND_ASSIGN(WebViewInternalRemoveContentScriptsFunction
);
160 class WebViewInternalSetNameFunction
: public WebViewInternalExtensionFunction
{
162 DECLARE_EXTENSION_FUNCTION("webViewInternal.setName",
163 WEBVIEWINTERNAL_SETNAME
);
165 WebViewInternalSetNameFunction();
168 ~WebViewInternalSetNameFunction() override
;
171 bool RunAsyncSafe(WebViewGuest
* guest
) override
;
173 DISALLOW_COPY_AND_ASSIGN(WebViewInternalSetNameFunction
);
176 class WebViewInternalSetAllowTransparencyFunction
:
177 public WebViewInternalExtensionFunction
{
179 DECLARE_EXTENSION_FUNCTION("webViewInternal.setAllowTransparency",
180 WEBVIEWINTERNAL_SETALLOWTRANSPARENCY
);
182 WebViewInternalSetAllowTransparencyFunction();
185 ~WebViewInternalSetAllowTransparencyFunction() override
;
188 bool RunAsyncSafe(WebViewGuest
* guest
) override
;
190 DISALLOW_COPY_AND_ASSIGN(WebViewInternalSetAllowTransparencyFunction
);
193 class WebViewInternalSetAllowScalingFunction
194 : public WebViewInternalExtensionFunction
{
196 DECLARE_EXTENSION_FUNCTION("webViewInternal.setAllowScaling",
197 WEBVIEWINTERNAL_SETALLOWSCALING
);
199 WebViewInternalSetAllowScalingFunction();
202 ~WebViewInternalSetAllowScalingFunction() override
;
205 bool RunAsyncSafe(WebViewGuest
* guest
) override
;
207 DISALLOW_COPY_AND_ASSIGN(WebViewInternalSetAllowScalingFunction
);
210 class WebViewInternalSetZoomFunction
: public WebViewInternalExtensionFunction
{
212 DECLARE_EXTENSION_FUNCTION("webViewInternal.setZoom",
213 WEBVIEWINTERNAL_SETZOOM
);
215 WebViewInternalSetZoomFunction();
218 ~WebViewInternalSetZoomFunction() override
;
221 bool RunAsyncSafe(WebViewGuest
* guest
) override
;
223 DISALLOW_COPY_AND_ASSIGN(WebViewInternalSetZoomFunction
);
226 class WebViewInternalGetZoomFunction
: public WebViewInternalExtensionFunction
{
228 DECLARE_EXTENSION_FUNCTION("webViewInternal.getZoom",
229 WEBVIEWINTERNAL_GETZOOM
);
231 WebViewInternalGetZoomFunction();
234 ~WebViewInternalGetZoomFunction() override
;
237 bool RunAsyncSafe(WebViewGuest
* guest
) override
;
239 DISALLOW_COPY_AND_ASSIGN(WebViewInternalGetZoomFunction
);
242 class WebViewInternalSetZoomModeFunction
243 : public WebViewInternalExtensionFunction
{
245 DECLARE_EXTENSION_FUNCTION("webViewInternal.setZoomMode",
246 WEBVIEWINTERNAL_SETZOOMMODE
);
248 WebViewInternalSetZoomModeFunction();
251 ~WebViewInternalSetZoomModeFunction() override
;
254 bool RunAsyncSafe(WebViewGuest
* guest
) override
;
256 DISALLOW_COPY_AND_ASSIGN(WebViewInternalSetZoomModeFunction
);
259 class WebViewInternalGetZoomModeFunction
260 : public WebViewInternalExtensionFunction
{
262 DECLARE_EXTENSION_FUNCTION("webViewInternal.getZoomMode",
263 WEBVIEWINTERNAL_GETZOOMMODE
);
265 WebViewInternalGetZoomModeFunction();
268 ~WebViewInternalGetZoomModeFunction() override
;
271 bool RunAsyncSafe(WebViewGuest
* guest
) override
;
273 DISALLOW_COPY_AND_ASSIGN(WebViewInternalGetZoomModeFunction
);
276 class WebViewInternalFindFunction
: public WebViewInternalExtensionFunction
{
278 DECLARE_EXTENSION_FUNCTION("webViewInternal.find", WEBVIEWINTERNAL_FIND
);
280 WebViewInternalFindFunction();
282 // Exposes SendResponse() for use by WebViewInternalFindHelper.
283 using WebViewInternalExtensionFunction::SendResponse
;
286 ~WebViewInternalFindFunction() override
;
289 // WebViewInternalExtensionFunction implementation.
290 bool RunAsyncSafe(WebViewGuest
* guest
) override
;
292 DISALLOW_COPY_AND_ASSIGN(WebViewInternalFindFunction
);
295 class WebViewInternalStopFindingFunction
296 : public WebViewInternalExtensionFunction
{
298 DECLARE_EXTENSION_FUNCTION("webViewInternal.stopFinding",
299 WEBVIEWINTERNAL_STOPFINDING
);
301 WebViewInternalStopFindingFunction();
304 ~WebViewInternalStopFindingFunction() override
;
307 // WebViewInternalExtensionFunction implementation.
308 bool RunAsyncSafe(WebViewGuest
* guest
) override
;
310 DISALLOW_COPY_AND_ASSIGN(WebViewInternalStopFindingFunction
);
313 class WebViewInternalLoadDataWithBaseUrlFunction
314 : public WebViewInternalExtensionFunction
{
316 DECLARE_EXTENSION_FUNCTION("webViewInternal.loadDataWithBaseUrl",
317 WEBVIEWINTERNAL_LOADDATAWITHBASEURL
);
319 WebViewInternalLoadDataWithBaseUrlFunction();
322 ~WebViewInternalLoadDataWithBaseUrlFunction() override
;
325 bool RunAsyncSafe(WebViewGuest
* guest
) override
;
327 DISALLOW_COPY_AND_ASSIGN(WebViewInternalLoadDataWithBaseUrlFunction
);
330 class WebViewInternalGoFunction
: public WebViewInternalExtensionFunction
{
332 DECLARE_EXTENSION_FUNCTION("webViewInternal.go", WEBVIEWINTERNAL_GO
);
334 WebViewInternalGoFunction();
337 ~WebViewInternalGoFunction() override
;
340 // WebViewInternalExtensionFunction implementation.
341 bool RunAsyncSafe(WebViewGuest
* guest
) override
;
343 DISALLOW_COPY_AND_ASSIGN(WebViewInternalGoFunction
);
346 class WebViewInternalReloadFunction
: public WebViewInternalExtensionFunction
{
348 DECLARE_EXTENSION_FUNCTION("webViewInternal.reload", WEBVIEWINTERNAL_RELOAD
);
350 WebViewInternalReloadFunction();
353 ~WebViewInternalReloadFunction() override
;
356 // WebViewInternalExtensionFunction implementation.
357 bool RunAsyncSafe(WebViewGuest
* guest
) override
;
359 DISALLOW_COPY_AND_ASSIGN(WebViewInternalReloadFunction
);
362 class WebViewInternalSetPermissionFunction
363 : public WebViewInternalExtensionFunction
{
365 DECLARE_EXTENSION_FUNCTION("webViewInternal.setPermission",
366 WEBVIEWINTERNAL_SETPERMISSION
);
368 WebViewInternalSetPermissionFunction();
371 ~WebViewInternalSetPermissionFunction() override
;
374 // WebViewInternalExtensionFunction implementation.
375 bool RunAsyncSafe(WebViewGuest
* guest
) override
;
377 DISALLOW_COPY_AND_ASSIGN(WebViewInternalSetPermissionFunction
);
380 class WebViewInternalOverrideUserAgentFunction
381 : public WebViewInternalExtensionFunction
{
383 DECLARE_EXTENSION_FUNCTION("webViewInternal.overrideUserAgent",
384 WEBVIEWINTERNAL_OVERRIDEUSERAGENT
);
386 WebViewInternalOverrideUserAgentFunction();
389 ~WebViewInternalOverrideUserAgentFunction() override
;
392 // WebViewInternalExtensionFunction implementation.
393 bool RunAsyncSafe(WebViewGuest
* guest
) override
;
395 DISALLOW_COPY_AND_ASSIGN(WebViewInternalOverrideUserAgentFunction
);
398 class WebViewInternalStopFunction
: public WebViewInternalExtensionFunction
{
400 DECLARE_EXTENSION_FUNCTION("webViewInternal.stop", WEBVIEWINTERNAL_STOP
);
402 WebViewInternalStopFunction();
405 ~WebViewInternalStopFunction() override
;
408 // WebViewInternalExtensionFunction implementation.
409 bool RunAsyncSafe(WebViewGuest
* guest
) override
;
411 DISALLOW_COPY_AND_ASSIGN(WebViewInternalStopFunction
);
414 class WebViewInternalTerminateFunction
415 : public WebViewInternalExtensionFunction
{
417 DECLARE_EXTENSION_FUNCTION("webViewInternal.terminate",
418 WEBVIEWINTERNAL_TERMINATE
);
420 WebViewInternalTerminateFunction();
423 ~WebViewInternalTerminateFunction() override
;
426 // WebViewInternalExtensionFunction implementation.
427 bool RunAsyncSafe(WebViewGuest
* guest
) override
;
429 DISALLOW_COPY_AND_ASSIGN(WebViewInternalTerminateFunction
);
432 class WebViewInternalClearDataFunction
433 : public WebViewInternalExtensionFunction
{
435 DECLARE_EXTENSION_FUNCTION("webViewInternal.clearData",
436 WEBVIEWINTERNAL_CLEARDATA
);
438 WebViewInternalClearDataFunction();
441 ~WebViewInternalClearDataFunction() override
;
444 // WebViewInternalExtensionFunction implementation.
445 bool RunAsyncSafe(WebViewGuest
* guest
) override
;
447 uint32
GetRemovalMask();
448 void ClearDataDone();
450 // Removal start time.
451 base::Time remove_since_
;
452 // Removal mask, corresponds to StoragePartition::RemoveDataMask enum.
454 // Tracks any data related or parse errors.
457 DISALLOW_COPY_AND_ASSIGN(WebViewInternalClearDataFunction
);
460 } // namespace extensions
462 #endif // CHROME_BROWSER_EXTENSIONS_API_WEB_VIEW_WEB_VIEW_INTERNAL_API_H_