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 CHROME_BROWSER_EXTENSIONS_API_WEB_VIEW_WEB_VIEW_INTERNAL_API_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_WEB_VIEW_WEB_VIEW_INTERNAL_API_H_
8 #include "chrome/browser/extensions/api/capture_web_contents_function.h"
9 #include "chrome/browser/extensions/api/execute_code_function.h"
10 #include "chrome/browser/guest_view/web_view/web_view_find_helper.h"
11 #include "chrome/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 // TODO(guohui): refactor WebViewInternalExecuteCodeFunction to also extend
18 // WebViewInternalExtensionFunction.
19 namespace extensions {
21 // An abstract base class for async webview APIs. It does a process ID check
22 // in RunAsync, and then calls RunAsyncSafe which must be overriden by all
24 class WebViewInternalExtensionFunction : public AsyncExtensionFunction {
26 WebViewInternalExtensionFunction() {}
29 virtual ~WebViewInternalExtensionFunction() {}
31 // ExtensionFunction implementation.
32 virtual bool RunAsync() OVERRIDE FINAL;
35 virtual bool RunAsyncSafe(WebViewGuest* guest) = 0;
38 class WebViewInternalContextMenusCreateFunction
39 : public AsyncExtensionFunction {
41 DECLARE_EXTENSION_FUNCTION("webViewInternal.contextMenusCreate",
42 WEBVIEWINTERNAL_CONTEXTMENUSCREATE);
43 WebViewInternalContextMenusCreateFunction() {}
46 virtual ~WebViewInternalContextMenusCreateFunction() {}
48 // ExtensionFunction implementation.
49 virtual bool RunAsync() OVERRIDE;
52 DISALLOW_COPY_AND_ASSIGN(WebViewInternalContextMenusCreateFunction);
55 class WebViewInternalContextMenusUpdateFunction
56 : public AsyncExtensionFunction {
58 DECLARE_EXTENSION_FUNCTION("webViewInternal.contextMenusUpdate",
59 WEBVIEWINTERNAL_CONTEXTMENUSUPDATE);
60 WebViewInternalContextMenusUpdateFunction() {}
63 virtual ~WebViewInternalContextMenusUpdateFunction() {}
65 // ExtensionFunction implementation.
66 virtual bool RunAsync() OVERRIDE;
69 DISALLOW_COPY_AND_ASSIGN(WebViewInternalContextMenusUpdateFunction);
72 class WebViewInternalContextMenusRemoveFunction
73 : public AsyncExtensionFunction {
75 DECLARE_EXTENSION_FUNCTION("webViewInternal.contextMenusRemove",
76 WEBVIEWINTERNAL_CONTEXTMENUSREMOVE);
77 WebViewInternalContextMenusRemoveFunction() {}
80 virtual ~WebViewInternalContextMenusRemoveFunction() {}
82 // ExtensionFunction implementation.
83 virtual bool RunAsync() OVERRIDE;
86 DISALLOW_COPY_AND_ASSIGN(WebViewInternalContextMenusRemoveFunction);
89 class WebViewInternalContextMenusRemoveAllFunction
90 : public AsyncExtensionFunction {
92 DECLARE_EXTENSION_FUNCTION("webViewInternal.contextMenusRemoveAll",
93 WEBVIEWINTERNAL_CONTEXTMENUSREMOVEALL);
94 WebViewInternalContextMenusRemoveAllFunction() {}
97 virtual ~WebViewInternalContextMenusRemoveAllFunction() {}
99 // ExtensionFunction implementation.
100 virtual bool RunAsync() OVERRIDE;
103 DISALLOW_COPY_AND_ASSIGN(WebViewInternalContextMenusRemoveAllFunction);
106 class WebViewInternalNavigateFunction
107 : public WebViewInternalExtensionFunction {
109 DECLARE_EXTENSION_FUNCTION("webViewInternal.navigate",
110 WEBVIEWINTERNAL_NAVIGATE);
111 WebViewInternalNavigateFunction() {}
114 virtual ~WebViewInternalNavigateFunction() {}
117 // WebViewInternalExtensionFunction implementation.
118 virtual bool RunAsyncSafe(WebViewGuest* guest) OVERRIDE;
120 DISALLOW_COPY_AND_ASSIGN(WebViewInternalNavigateFunction);
123 class WebViewInternalClearDataFunction
124 : public WebViewInternalExtensionFunction {
126 DECLARE_EXTENSION_FUNCTION("webViewInternal.clearData",
127 WEBVIEWINTERNAL_CLEARDATA);
129 WebViewInternalClearDataFunction();
132 virtual ~WebViewInternalClearDataFunction();
135 // WebViewInternalExtensionFunction implementation.
136 virtual bool RunAsyncSafe(WebViewGuest* guest) OVERRIDE;
138 uint32 GetRemovalMask();
139 void ClearDataDone();
141 // Removal start time.
142 base::Time remove_since_;
143 // Removal mask, corresponds to StoragePartition::RemoveDataMask enum.
145 // Tracks any data related or parse errors.
148 DISALLOW_COPY_AND_ASSIGN(WebViewInternalClearDataFunction);
151 class WebViewInternalExecuteCodeFunction
152 : public extensions::ExecuteCodeFunction {
154 WebViewInternalExecuteCodeFunction();
157 virtual ~WebViewInternalExecuteCodeFunction();
159 // Initialize |details_| if it hasn't already been.
160 virtual bool Init() OVERRIDE;
161 virtual bool ShouldInsertCSS() const OVERRIDE;
162 virtual bool CanExecuteScriptOnPage() OVERRIDE;
163 // Guarded by a process ID check.
164 virtual extensions::ScriptExecutor* GetScriptExecutor() OVERRIDE FINAL;
165 virtual bool IsWebView() const OVERRIDE;
166 virtual const GURL& GetWebViewSrc() const OVERRIDE;
169 // Contains extension resource built from path of file which is
170 // specified in JSON arguments.
171 extensions::ExtensionResource resource_;
173 int guest_instance_id_;
177 DISALLOW_COPY_AND_ASSIGN(WebViewInternalExecuteCodeFunction);
180 class WebViewInternalExecuteScriptFunction
181 : public WebViewInternalExecuteCodeFunction {
183 WebViewInternalExecuteScriptFunction();
186 virtual ~WebViewInternalExecuteScriptFunction() {}
188 virtual void OnExecuteCodeFinished(const std::string& error,
190 const base::ListValue& result) OVERRIDE;
192 DECLARE_EXTENSION_FUNCTION("webViewInternal.executeScript",
193 WEBVIEWINTERNAL_EXECUTESCRIPT)
196 DISALLOW_COPY_AND_ASSIGN(WebViewInternalExecuteScriptFunction);
199 class WebViewInternalInsertCSSFunction
200 : public WebViewInternalExecuteCodeFunction {
202 WebViewInternalInsertCSSFunction();
205 virtual ~WebViewInternalInsertCSSFunction() {}
207 virtual bool ShouldInsertCSS() const OVERRIDE;
209 DECLARE_EXTENSION_FUNCTION("webViewInternal.insertCSS",
210 WEBVIEWINTERNAL_INSERTCSS)
213 DISALLOW_COPY_AND_ASSIGN(WebViewInternalInsertCSSFunction);
216 class WebViewInternalCaptureVisibleRegionFunction
217 : public extensions::CaptureWebContentsFunction {
218 DECLARE_EXTENSION_FUNCTION("webViewInternal.captureVisibleRegion",
219 WEBVIEWINTERNAL_CAPTUREVISIBLEREGION);
221 WebViewInternalCaptureVisibleRegionFunction();
224 virtual ~WebViewInternalCaptureVisibleRegionFunction();
227 // extensions::CaptureWebContentsFunction implementation.
228 virtual bool IsScreenshotEnabled() OVERRIDE;
229 virtual content::WebContents* GetWebContentsForID(int id) OVERRIDE;
230 virtual void OnCaptureFailure(FailureReason reason) OVERRIDE;
232 DISALLOW_COPY_AND_ASSIGN(WebViewInternalCaptureVisibleRegionFunction);
235 class WebViewInternalSetNameFunction : public WebViewInternalExtensionFunction {
237 DECLARE_EXTENSION_FUNCTION("webViewInternal.setName",
238 WEBVIEWINTERNAL_SETNAME);
240 WebViewInternalSetNameFunction();
243 virtual ~WebViewInternalSetNameFunction();
246 virtual bool RunAsyncSafe(WebViewGuest* guest) OVERRIDE;
248 DISALLOW_COPY_AND_ASSIGN(WebViewInternalSetNameFunction);
251 class WebViewInternalSetZoomFunction : public WebViewInternalExtensionFunction {
253 DECLARE_EXTENSION_FUNCTION("webViewInternal.setZoom",
254 WEBVIEWINTERNAL_SETZOOM);
256 WebViewInternalSetZoomFunction();
259 virtual ~WebViewInternalSetZoomFunction();
262 virtual bool RunAsyncSafe(WebViewGuest* guest) OVERRIDE;
264 DISALLOW_COPY_AND_ASSIGN(WebViewInternalSetZoomFunction);
267 class WebViewInternalGetZoomFunction : public WebViewInternalExtensionFunction {
269 DECLARE_EXTENSION_FUNCTION("webViewInternal.getZoom",
270 WEBVIEWINTERNAL_GETZOOM);
272 WebViewInternalGetZoomFunction();
275 virtual ~WebViewInternalGetZoomFunction();
278 virtual bool RunAsyncSafe(WebViewGuest* guest) OVERRIDE;
280 DISALLOW_COPY_AND_ASSIGN(WebViewInternalGetZoomFunction);
283 class WebViewInternalFindFunction : public WebViewInternalExtensionFunction {
285 DECLARE_EXTENSION_FUNCTION("webViewInternal.find", WEBVIEWINTERNAL_FIND);
287 WebViewInternalFindFunction();
289 // Exposes SendResponse() for use by WebViewInternalFindHelper.
290 using WebViewInternalExtensionFunction::SendResponse;
293 virtual ~WebViewInternalFindFunction();
296 // WebViewInternalExtensionFunction implementation.
297 virtual bool RunAsyncSafe(WebViewGuest* guest) OVERRIDE;
299 DISALLOW_COPY_AND_ASSIGN(WebViewInternalFindFunction);
302 class WebViewInternalStopFindingFunction
303 : public WebViewInternalExtensionFunction {
305 DECLARE_EXTENSION_FUNCTION("webViewInternal.stopFinding",
306 WEBVIEWINTERNAL_STOPFINDING);
308 WebViewInternalStopFindingFunction();
311 virtual ~WebViewInternalStopFindingFunction();
314 // WebViewInternalExtensionFunction implementation.
315 virtual bool RunAsyncSafe(WebViewGuest* guest) OVERRIDE;
317 DISALLOW_COPY_AND_ASSIGN(WebViewInternalStopFindingFunction);
320 class WebViewInternalGoFunction : public WebViewInternalExtensionFunction {
322 DECLARE_EXTENSION_FUNCTION("webViewInternal.go", WEBVIEWINTERNAL_GO);
324 WebViewInternalGoFunction();
327 virtual ~WebViewInternalGoFunction();
330 // WebViewInternalExtensionFunction implementation.
331 virtual bool RunAsyncSafe(WebViewGuest* guest) OVERRIDE;
333 DISALLOW_COPY_AND_ASSIGN(WebViewInternalGoFunction);
336 class WebViewInternalReloadFunction : public WebViewInternalExtensionFunction {
338 DECLARE_EXTENSION_FUNCTION("webViewInternal.reload", WEBVIEWINTERNAL_RELOAD);
340 WebViewInternalReloadFunction();
343 virtual ~WebViewInternalReloadFunction();
346 // WebViewInternalExtensionFunction implementation.
347 virtual bool RunAsyncSafe(WebViewGuest* guest) OVERRIDE;
349 DISALLOW_COPY_AND_ASSIGN(WebViewInternalReloadFunction);
352 class WebViewInternalSetPermissionFunction
353 : public WebViewInternalExtensionFunction {
355 DECLARE_EXTENSION_FUNCTION("webViewInternal.setPermission",
356 WEBVIEWINTERNAL_SETPERMISSION);
358 WebViewInternalSetPermissionFunction();
361 virtual ~WebViewInternalSetPermissionFunction();
364 // WebViewInternalExtensionFunction implementation.
365 virtual bool RunAsyncSafe(WebViewGuest* guest) OVERRIDE;
367 DISALLOW_COPY_AND_ASSIGN(WebViewInternalSetPermissionFunction);
370 class WebViewInternalShowContextMenuFunction
371 : public WebViewInternalExtensionFunction {
373 DECLARE_EXTENSION_FUNCTION("webViewInternal.showContextMenu",
374 WEBVIEWINTERNAL_SHOWCONTEXTMENU);
376 WebViewInternalShowContextMenuFunction();
379 virtual ~WebViewInternalShowContextMenuFunction();
382 // WebViewInternalExtensionFunction implementation.
383 virtual bool RunAsyncSafe(WebViewGuest* guest) OVERRIDE;
385 DISALLOW_COPY_AND_ASSIGN(WebViewInternalShowContextMenuFunction);
388 class WebViewInternalOverrideUserAgentFunction
389 : public WebViewInternalExtensionFunction {
391 DECLARE_EXTENSION_FUNCTION("webViewInternal.overrideUserAgent",
392 WEBVIEWINTERNAL_OVERRIDEUSERAGENT);
394 WebViewInternalOverrideUserAgentFunction();
397 virtual ~WebViewInternalOverrideUserAgentFunction();
400 // WebViewInternalExtensionFunction implementation.
401 virtual bool RunAsyncSafe(WebViewGuest* guest) OVERRIDE;
403 DISALLOW_COPY_AND_ASSIGN(WebViewInternalOverrideUserAgentFunction);
406 class WebViewInternalStopFunction : public WebViewInternalExtensionFunction {
408 DECLARE_EXTENSION_FUNCTION("webViewInternal.stop", WEBVIEWINTERNAL_STOP);
410 WebViewInternalStopFunction();
413 virtual ~WebViewInternalStopFunction();
416 // WebViewInternalExtensionFunction implementation.
417 virtual bool RunAsyncSafe(WebViewGuest* guest) OVERRIDE;
419 DISALLOW_COPY_AND_ASSIGN(WebViewInternalStopFunction);
422 class WebViewInternalTerminateFunction
423 : public WebViewInternalExtensionFunction {
425 DECLARE_EXTENSION_FUNCTION("webViewInternal.terminate",
426 WEBVIEWINTERNAL_TERMINATE);
428 WebViewInternalTerminateFunction();
431 virtual ~WebViewInternalTerminateFunction();
434 // WebViewInternalExtensionFunction implementation.
435 virtual bool RunAsyncSafe(WebViewGuest* guest) OVERRIDE;
437 DISALLOW_COPY_AND_ASSIGN(WebViewInternalTerminateFunction);
440 } // namespace extensions
442 #endif // CHROME_BROWSER_EXTENSIONS_API_WEB_VIEW_WEB_VIEW_INTERNAL_API_H_