Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / extensions / browser / api / guest_view / web_view / web_view_internal_api.h
blobf9b5143d92ff0138302aff619f2d69ac60bfd921
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
22 // subclasses.
23 class WebViewInternalExtensionFunction : public AsyncExtensionFunction {
24 public:
25 WebViewInternalExtensionFunction() {}
27 protected:
28 ~WebViewInternalExtensionFunction() override {}
30 // ExtensionFunction implementation.
31 bool RunAsync() final;
33 private:
34 virtual bool RunAsyncSafe(WebViewGuest* guest) = 0;
37 class WebViewInternalNavigateFunction
38 : public WebViewInternalExtensionFunction {
39 public:
40 DECLARE_EXTENSION_FUNCTION("webViewInternal.navigate",
41 WEBVIEWINTERNAL_NAVIGATE);
42 WebViewInternalNavigateFunction() {}
44 protected:
45 ~WebViewInternalNavigateFunction() override {}
47 private:
48 // WebViewInternalExtensionFunction implementation.
49 bool RunAsyncSafe(WebViewGuest* guest) override;
51 DISALLOW_COPY_AND_ASSIGN(WebViewInternalNavigateFunction);
54 class WebViewInternalExecuteCodeFunction
55 : public extensions::ExecuteCodeFunction {
56 public:
57 WebViewInternalExecuteCodeFunction();
59 protected:
60 ~WebViewInternalExecuteCodeFunction() override;
62 // Initialize |details_| if it hasn't already been.
63 bool Init() override;
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;
72 private:
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_;
83 GURL guest_src_;
85 scoped_ptr<WebUIURLFetcher> url_fetcher_;
87 DISALLOW_COPY_AND_ASSIGN(WebViewInternalExecuteCodeFunction);
90 class WebViewInternalExecuteScriptFunction
91 : public WebViewInternalExecuteCodeFunction {
92 public:
93 WebViewInternalExecuteScriptFunction();
95 protected:
96 ~WebViewInternalExecuteScriptFunction() override {}
98 void OnExecuteCodeFinished(const std::string& error,
99 const GURL& on_url,
100 const base::ListValue& result) override;
102 DECLARE_EXTENSION_FUNCTION("webViewInternal.executeScript",
103 WEBVIEWINTERNAL_EXECUTESCRIPT)
105 private:
106 DISALLOW_COPY_AND_ASSIGN(WebViewInternalExecuteScriptFunction);
109 class WebViewInternalInsertCSSFunction
110 : public WebViewInternalExecuteCodeFunction {
111 public:
112 WebViewInternalInsertCSSFunction();
114 protected:
115 ~WebViewInternalInsertCSSFunction() override {}
117 bool ShouldInsertCSS() const override;
119 DECLARE_EXTENSION_FUNCTION("webViewInternal.insertCSS",
120 WEBVIEWINTERNAL_INSERTCSS)
122 private:
123 DISALLOW_COPY_AND_ASSIGN(WebViewInternalInsertCSSFunction);
126 class WebViewInternalAddContentScriptsFunction
127 : public UIThreadExtensionFunction {
128 public:
129 DECLARE_EXTENSION_FUNCTION("webViewInternal.addContentScripts",
130 WEBVIEWINTERNAL_ADDCONTENTSCRIPTS);
132 WebViewInternalAddContentScriptsFunction();
134 protected:
135 ~WebViewInternalAddContentScriptsFunction() override;
137 private:
138 ExecuteCodeFunction::ResponseAction Run() override;
140 DISALLOW_COPY_AND_ASSIGN(WebViewInternalAddContentScriptsFunction);
143 class WebViewInternalRemoveContentScriptsFunction
144 : public UIThreadExtensionFunction {
145 public:
146 DECLARE_EXTENSION_FUNCTION("webViewInternal.removeContentScripts",
147 WEBVIEWINTERNAL_REMOVECONTENTSCRIPTS);
149 WebViewInternalRemoveContentScriptsFunction();
151 protected:
152 ~WebViewInternalRemoveContentScriptsFunction() override;
154 private:
155 ExecuteCodeFunction::ResponseAction Run() override;
157 DISALLOW_COPY_AND_ASSIGN(WebViewInternalRemoveContentScriptsFunction);
160 class WebViewInternalSetNameFunction : public WebViewInternalExtensionFunction {
161 public:
162 DECLARE_EXTENSION_FUNCTION("webViewInternal.setName",
163 WEBVIEWINTERNAL_SETNAME);
165 WebViewInternalSetNameFunction();
167 protected:
168 ~WebViewInternalSetNameFunction() override;
170 private:
171 bool RunAsyncSafe(WebViewGuest* guest) override;
173 DISALLOW_COPY_AND_ASSIGN(WebViewInternalSetNameFunction);
176 class WebViewInternalSetAllowTransparencyFunction :
177 public WebViewInternalExtensionFunction {
178 public:
179 DECLARE_EXTENSION_FUNCTION("webViewInternal.setAllowTransparency",
180 WEBVIEWINTERNAL_SETALLOWTRANSPARENCY);
182 WebViewInternalSetAllowTransparencyFunction();
184 protected:
185 ~WebViewInternalSetAllowTransparencyFunction() override;
187 private:
188 bool RunAsyncSafe(WebViewGuest* guest) override;
190 DISALLOW_COPY_AND_ASSIGN(WebViewInternalSetAllowTransparencyFunction);
193 class WebViewInternalSetAllowScalingFunction
194 : public WebViewInternalExtensionFunction {
195 public:
196 DECLARE_EXTENSION_FUNCTION("webViewInternal.setAllowScaling",
197 WEBVIEWINTERNAL_SETALLOWSCALING);
199 WebViewInternalSetAllowScalingFunction();
201 protected:
202 ~WebViewInternalSetAllowScalingFunction() override;
204 private:
205 bool RunAsyncSafe(WebViewGuest* guest) override;
207 DISALLOW_COPY_AND_ASSIGN(WebViewInternalSetAllowScalingFunction);
210 class WebViewInternalSetZoomFunction : public WebViewInternalExtensionFunction {
211 public:
212 DECLARE_EXTENSION_FUNCTION("webViewInternal.setZoom",
213 WEBVIEWINTERNAL_SETZOOM);
215 WebViewInternalSetZoomFunction();
217 protected:
218 ~WebViewInternalSetZoomFunction() override;
220 private:
221 bool RunAsyncSafe(WebViewGuest* guest) override;
223 DISALLOW_COPY_AND_ASSIGN(WebViewInternalSetZoomFunction);
226 class WebViewInternalGetZoomFunction : public WebViewInternalExtensionFunction {
227 public:
228 DECLARE_EXTENSION_FUNCTION("webViewInternal.getZoom",
229 WEBVIEWINTERNAL_GETZOOM);
231 WebViewInternalGetZoomFunction();
233 protected:
234 ~WebViewInternalGetZoomFunction() override;
236 private:
237 bool RunAsyncSafe(WebViewGuest* guest) override;
239 DISALLOW_COPY_AND_ASSIGN(WebViewInternalGetZoomFunction);
242 class WebViewInternalSetZoomModeFunction
243 : public WebViewInternalExtensionFunction {
244 public:
245 DECLARE_EXTENSION_FUNCTION("webViewInternal.setZoomMode",
246 WEBVIEWINTERNAL_SETZOOMMODE);
248 WebViewInternalSetZoomModeFunction();
250 protected:
251 ~WebViewInternalSetZoomModeFunction() override;
253 private:
254 bool RunAsyncSafe(WebViewGuest* guest) override;
256 DISALLOW_COPY_AND_ASSIGN(WebViewInternalSetZoomModeFunction);
259 class WebViewInternalGetZoomModeFunction
260 : public WebViewInternalExtensionFunction {
261 public:
262 DECLARE_EXTENSION_FUNCTION("webViewInternal.getZoomMode",
263 WEBVIEWINTERNAL_GETZOOMMODE);
265 WebViewInternalGetZoomModeFunction();
267 protected:
268 ~WebViewInternalGetZoomModeFunction() override;
270 private:
271 bool RunAsyncSafe(WebViewGuest* guest) override;
273 DISALLOW_COPY_AND_ASSIGN(WebViewInternalGetZoomModeFunction);
276 class WebViewInternalFindFunction : public WebViewInternalExtensionFunction {
277 public:
278 DECLARE_EXTENSION_FUNCTION("webViewInternal.find", WEBVIEWINTERNAL_FIND);
280 WebViewInternalFindFunction();
282 // Exposes SendResponse() for use by WebViewInternalFindHelper.
283 using WebViewInternalExtensionFunction::SendResponse;
285 protected:
286 ~WebViewInternalFindFunction() override;
288 private:
289 // WebViewInternalExtensionFunction implementation.
290 bool RunAsyncSafe(WebViewGuest* guest) override;
292 DISALLOW_COPY_AND_ASSIGN(WebViewInternalFindFunction);
295 class WebViewInternalStopFindingFunction
296 : public WebViewInternalExtensionFunction {
297 public:
298 DECLARE_EXTENSION_FUNCTION("webViewInternal.stopFinding",
299 WEBVIEWINTERNAL_STOPFINDING);
301 WebViewInternalStopFindingFunction();
303 protected:
304 ~WebViewInternalStopFindingFunction() override;
306 private:
307 // WebViewInternalExtensionFunction implementation.
308 bool RunAsyncSafe(WebViewGuest* guest) override;
310 DISALLOW_COPY_AND_ASSIGN(WebViewInternalStopFindingFunction);
313 class WebViewInternalLoadDataWithBaseUrlFunction
314 : public WebViewInternalExtensionFunction {
315 public:
316 DECLARE_EXTENSION_FUNCTION("webViewInternal.loadDataWithBaseUrl",
317 WEBVIEWINTERNAL_LOADDATAWITHBASEURL);
319 WebViewInternalLoadDataWithBaseUrlFunction();
321 protected:
322 ~WebViewInternalLoadDataWithBaseUrlFunction() override;
324 private:
325 bool RunAsyncSafe(WebViewGuest* guest) override;
327 DISALLOW_COPY_AND_ASSIGN(WebViewInternalLoadDataWithBaseUrlFunction);
330 class WebViewInternalGoFunction : public WebViewInternalExtensionFunction {
331 public:
332 DECLARE_EXTENSION_FUNCTION("webViewInternal.go", WEBVIEWINTERNAL_GO);
334 WebViewInternalGoFunction();
336 protected:
337 ~WebViewInternalGoFunction() override;
339 private:
340 // WebViewInternalExtensionFunction implementation.
341 bool RunAsyncSafe(WebViewGuest* guest) override;
343 DISALLOW_COPY_AND_ASSIGN(WebViewInternalGoFunction);
346 class WebViewInternalReloadFunction : public WebViewInternalExtensionFunction {
347 public:
348 DECLARE_EXTENSION_FUNCTION("webViewInternal.reload", WEBVIEWINTERNAL_RELOAD);
350 WebViewInternalReloadFunction();
352 protected:
353 ~WebViewInternalReloadFunction() override;
355 private:
356 // WebViewInternalExtensionFunction implementation.
357 bool RunAsyncSafe(WebViewGuest* guest) override;
359 DISALLOW_COPY_AND_ASSIGN(WebViewInternalReloadFunction);
362 class WebViewInternalSetPermissionFunction
363 : public WebViewInternalExtensionFunction {
364 public:
365 DECLARE_EXTENSION_FUNCTION("webViewInternal.setPermission",
366 WEBVIEWINTERNAL_SETPERMISSION);
368 WebViewInternalSetPermissionFunction();
370 protected:
371 ~WebViewInternalSetPermissionFunction() override;
373 private:
374 // WebViewInternalExtensionFunction implementation.
375 bool RunAsyncSafe(WebViewGuest* guest) override;
377 DISALLOW_COPY_AND_ASSIGN(WebViewInternalSetPermissionFunction);
380 class WebViewInternalOverrideUserAgentFunction
381 : public WebViewInternalExtensionFunction {
382 public:
383 DECLARE_EXTENSION_FUNCTION("webViewInternal.overrideUserAgent",
384 WEBVIEWINTERNAL_OVERRIDEUSERAGENT);
386 WebViewInternalOverrideUserAgentFunction();
388 protected:
389 ~WebViewInternalOverrideUserAgentFunction() override;
391 private:
392 // WebViewInternalExtensionFunction implementation.
393 bool RunAsyncSafe(WebViewGuest* guest) override;
395 DISALLOW_COPY_AND_ASSIGN(WebViewInternalOverrideUserAgentFunction);
398 class WebViewInternalStopFunction : public WebViewInternalExtensionFunction {
399 public:
400 DECLARE_EXTENSION_FUNCTION("webViewInternal.stop", WEBVIEWINTERNAL_STOP);
402 WebViewInternalStopFunction();
404 protected:
405 ~WebViewInternalStopFunction() override;
407 private:
408 // WebViewInternalExtensionFunction implementation.
409 bool RunAsyncSafe(WebViewGuest* guest) override;
411 DISALLOW_COPY_AND_ASSIGN(WebViewInternalStopFunction);
414 class WebViewInternalTerminateFunction
415 : public WebViewInternalExtensionFunction {
416 public:
417 DECLARE_EXTENSION_FUNCTION("webViewInternal.terminate",
418 WEBVIEWINTERNAL_TERMINATE);
420 WebViewInternalTerminateFunction();
422 protected:
423 ~WebViewInternalTerminateFunction() override;
425 private:
426 // WebViewInternalExtensionFunction implementation.
427 bool RunAsyncSafe(WebViewGuest* guest) override;
429 DISALLOW_COPY_AND_ASSIGN(WebViewInternalTerminateFunction);
432 class WebViewInternalClearDataFunction
433 : public WebViewInternalExtensionFunction {
434 public:
435 DECLARE_EXTENSION_FUNCTION("webViewInternal.clearData",
436 WEBVIEWINTERNAL_CLEARDATA);
438 WebViewInternalClearDataFunction();
440 protected:
441 ~WebViewInternalClearDataFunction() override;
443 private:
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.
453 uint32 remove_mask_;
454 // Tracks any data related or parse errors.
455 bool bad_message_;
457 DISALLOW_COPY_AND_ASSIGN(WebViewInternalClearDataFunction);
460 } // namespace extensions
462 #endif // CHROME_BROWSER_EXTENSIONS_API_WEB_VIEW_WEB_VIEW_INTERNAL_API_H_