Update {virtual,override,final} to follow C++11 style.
[chromium-blink-merge.git] / extensions / browser / api / web_view / web_view_internal_api.h
blobad66ed28ba97af15cdfa76cdc844bc8f44d8b102
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
21 // subclasses.
22 class WebViewInternalExtensionFunction : public AsyncExtensionFunction {
23 public:
24 WebViewInternalExtensionFunction() {}
26 protected:
27 ~WebViewInternalExtensionFunction() override {}
29 // ExtensionFunction implementation.
30 bool RunAsync() final;
32 private:
33 virtual bool RunAsyncSafe(WebViewGuest* guest) = 0;
36 class WebViewInternalNavigateFunction
37 : public WebViewInternalExtensionFunction {
38 public:
39 DECLARE_EXTENSION_FUNCTION("webViewInternal.navigate",
40 WEBVIEWINTERNAL_NAVIGATE);
41 WebViewInternalNavigateFunction() {}
43 protected:
44 ~WebViewInternalNavigateFunction() override {}
46 private:
47 // WebViewInternalExtensionFunction implementation.
48 bool RunAsyncSafe(WebViewGuest* guest) override;
50 DISALLOW_COPY_AND_ASSIGN(WebViewInternalNavigateFunction);
53 class WebViewInternalExecuteCodeFunction
54 : public extensions::ExecuteCodeFunction {
55 public:
56 WebViewInternalExecuteCodeFunction();
58 protected:
59 ~WebViewInternalExecuteCodeFunction() override;
61 // Initialize |details_| if it hasn't already been.
62 bool Init() override;
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;
70 private:
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_;
77 GURL guest_src_;
79 DISALLOW_COPY_AND_ASSIGN(WebViewInternalExecuteCodeFunction);
82 class WebViewInternalExecuteScriptFunction
83 : public WebViewInternalExecuteCodeFunction {
84 public:
85 WebViewInternalExecuteScriptFunction();
87 protected:
88 ~WebViewInternalExecuteScriptFunction() override {}
90 void OnExecuteCodeFinished(const std::string& error,
91 const GURL& on_url,
92 const base::ListValue& result) override;
94 DECLARE_EXTENSION_FUNCTION("webViewInternal.executeScript",
95 WEBVIEWINTERNAL_EXECUTESCRIPT)
97 private:
98 DISALLOW_COPY_AND_ASSIGN(WebViewInternalExecuteScriptFunction);
101 class WebViewInternalInsertCSSFunction
102 : public WebViewInternalExecuteCodeFunction {
103 public:
104 WebViewInternalInsertCSSFunction();
106 protected:
107 ~WebViewInternalInsertCSSFunction() override {}
109 bool ShouldInsertCSS() const override;
111 DECLARE_EXTENSION_FUNCTION("webViewInternal.insertCSS",
112 WEBVIEWINTERNAL_INSERTCSS)
114 private:
115 DISALLOW_COPY_AND_ASSIGN(WebViewInternalInsertCSSFunction);
118 class WebViewInternalSetNameFunction : public WebViewInternalExtensionFunction {
119 public:
120 DECLARE_EXTENSION_FUNCTION("webViewInternal.setName",
121 WEBVIEWINTERNAL_SETNAME);
123 WebViewInternalSetNameFunction();
125 protected:
126 ~WebViewInternalSetNameFunction() override;
128 private:
129 bool RunAsyncSafe(WebViewGuest* guest) override;
131 DISALLOW_COPY_AND_ASSIGN(WebViewInternalSetNameFunction);
134 class WebViewInternalSetAllowTransparencyFunction :
135 public WebViewInternalExtensionFunction {
136 public:
137 DECLARE_EXTENSION_FUNCTION("webViewInternal.setAllowTransparency",
138 WEBVIEWINTERNAL_SETALLOWTRANSPARENCY);
140 WebViewInternalSetAllowTransparencyFunction();
142 protected:
143 ~WebViewInternalSetAllowTransparencyFunction() override;
145 private:
146 bool RunAsyncSafe(WebViewGuest* guest) override;
148 DISALLOW_COPY_AND_ASSIGN(WebViewInternalSetAllowTransparencyFunction);
151 class WebViewInternalSetZoomFunction : public WebViewInternalExtensionFunction {
152 public:
153 DECLARE_EXTENSION_FUNCTION("webViewInternal.setZoom",
154 WEBVIEWINTERNAL_SETZOOM);
156 WebViewInternalSetZoomFunction();
158 protected:
159 ~WebViewInternalSetZoomFunction() override;
161 private:
162 bool RunAsyncSafe(WebViewGuest* guest) override;
164 DISALLOW_COPY_AND_ASSIGN(WebViewInternalSetZoomFunction);
167 class WebViewInternalGetZoomFunction : public WebViewInternalExtensionFunction {
168 public:
169 DECLARE_EXTENSION_FUNCTION("webViewInternal.getZoom",
170 WEBVIEWINTERNAL_GETZOOM);
172 WebViewInternalGetZoomFunction();
174 protected:
175 ~WebViewInternalGetZoomFunction() override;
177 private:
178 bool RunAsyncSafe(WebViewGuest* guest) override;
180 DISALLOW_COPY_AND_ASSIGN(WebViewInternalGetZoomFunction);
183 class WebViewInternalFindFunction : public WebViewInternalExtensionFunction {
184 public:
185 DECLARE_EXTENSION_FUNCTION("webViewInternal.find", WEBVIEWINTERNAL_FIND);
187 WebViewInternalFindFunction();
189 // Exposes SendResponse() for use by WebViewInternalFindHelper.
190 using WebViewInternalExtensionFunction::SendResponse;
192 protected:
193 ~WebViewInternalFindFunction() override;
195 private:
196 // WebViewInternalExtensionFunction implementation.
197 bool RunAsyncSafe(WebViewGuest* guest) override;
199 DISALLOW_COPY_AND_ASSIGN(WebViewInternalFindFunction);
202 class WebViewInternalStopFindingFunction
203 : public WebViewInternalExtensionFunction {
204 public:
205 DECLARE_EXTENSION_FUNCTION("webViewInternal.stopFinding",
206 WEBVIEWINTERNAL_STOPFINDING);
208 WebViewInternalStopFindingFunction();
210 protected:
211 ~WebViewInternalStopFindingFunction() override;
213 private:
214 // WebViewInternalExtensionFunction implementation.
215 bool RunAsyncSafe(WebViewGuest* guest) override;
217 DISALLOW_COPY_AND_ASSIGN(WebViewInternalStopFindingFunction);
220 class WebViewInternalLoadDataWithBaseUrlFunction
221 : public WebViewInternalExtensionFunction {
222 public:
223 DECLARE_EXTENSION_FUNCTION("webViewInternal.loadDataWithBaseUrl",
224 WEBVIEWINTERNAL_LOADDATAWITHBASEURL);
226 WebViewInternalLoadDataWithBaseUrlFunction();
228 protected:
229 ~WebViewInternalLoadDataWithBaseUrlFunction() override;
231 private:
232 bool RunAsyncSafe(WebViewGuest* guest) override;
234 DISALLOW_COPY_AND_ASSIGN(WebViewInternalLoadDataWithBaseUrlFunction);
237 class WebViewInternalGoFunction : public WebViewInternalExtensionFunction {
238 public:
239 DECLARE_EXTENSION_FUNCTION("webViewInternal.go", WEBVIEWINTERNAL_GO);
241 WebViewInternalGoFunction();
243 protected:
244 ~WebViewInternalGoFunction() override;
246 private:
247 // WebViewInternalExtensionFunction implementation.
248 bool RunAsyncSafe(WebViewGuest* guest) override;
250 DISALLOW_COPY_AND_ASSIGN(WebViewInternalGoFunction);
253 class WebViewInternalReloadFunction : public WebViewInternalExtensionFunction {
254 public:
255 DECLARE_EXTENSION_FUNCTION("webViewInternal.reload", WEBVIEWINTERNAL_RELOAD);
257 WebViewInternalReloadFunction();
259 protected:
260 ~WebViewInternalReloadFunction() override;
262 private:
263 // WebViewInternalExtensionFunction implementation.
264 bool RunAsyncSafe(WebViewGuest* guest) override;
266 DISALLOW_COPY_AND_ASSIGN(WebViewInternalReloadFunction);
269 class WebViewInternalSetPermissionFunction
270 : public WebViewInternalExtensionFunction {
271 public:
272 DECLARE_EXTENSION_FUNCTION("webViewInternal.setPermission",
273 WEBVIEWINTERNAL_SETPERMISSION);
275 WebViewInternalSetPermissionFunction();
277 protected:
278 ~WebViewInternalSetPermissionFunction() override;
280 private:
281 // WebViewInternalExtensionFunction implementation.
282 bool RunAsyncSafe(WebViewGuest* guest) override;
284 DISALLOW_COPY_AND_ASSIGN(WebViewInternalSetPermissionFunction);
287 class WebViewInternalOverrideUserAgentFunction
288 : public WebViewInternalExtensionFunction {
289 public:
290 DECLARE_EXTENSION_FUNCTION("webViewInternal.overrideUserAgent",
291 WEBVIEWINTERNAL_OVERRIDEUSERAGENT);
293 WebViewInternalOverrideUserAgentFunction();
295 protected:
296 ~WebViewInternalOverrideUserAgentFunction() override;
298 private:
299 // WebViewInternalExtensionFunction implementation.
300 bool RunAsyncSafe(WebViewGuest* guest) override;
302 DISALLOW_COPY_AND_ASSIGN(WebViewInternalOverrideUserAgentFunction);
305 class WebViewInternalStopFunction : public WebViewInternalExtensionFunction {
306 public:
307 DECLARE_EXTENSION_FUNCTION("webViewInternal.stop", WEBVIEWINTERNAL_STOP);
309 WebViewInternalStopFunction();
311 protected:
312 ~WebViewInternalStopFunction() override;
314 private:
315 // WebViewInternalExtensionFunction implementation.
316 bool RunAsyncSafe(WebViewGuest* guest) override;
318 DISALLOW_COPY_AND_ASSIGN(WebViewInternalStopFunction);
321 class WebViewInternalTerminateFunction
322 : public WebViewInternalExtensionFunction {
323 public:
324 DECLARE_EXTENSION_FUNCTION("webViewInternal.terminate",
325 WEBVIEWINTERNAL_TERMINATE);
327 WebViewInternalTerminateFunction();
329 protected:
330 ~WebViewInternalTerminateFunction() override;
332 private:
333 // WebViewInternalExtensionFunction implementation.
334 bool RunAsyncSafe(WebViewGuest* guest) override;
336 DISALLOW_COPY_AND_ASSIGN(WebViewInternalTerminateFunction);
339 class WebViewInternalClearDataFunction
340 : public WebViewInternalExtensionFunction {
341 public:
342 DECLARE_EXTENSION_FUNCTION("webViewInternal.clearData",
343 WEBVIEWINTERNAL_CLEARDATA);
345 WebViewInternalClearDataFunction();
347 protected:
348 ~WebViewInternalClearDataFunction() override;
350 private:
351 // WebViewInternalExtensionFunction implementation.
352 bool RunAsyncSafe(WebViewGuest* guest) override;
354 uint32 GetRemovalMask();
355 void ClearDataDone();
357 // Removal start time.
358 base::Time remove_since_;
359 // Removal mask, corresponds to StoragePartition::RemoveDataMask enum.
360 uint32 remove_mask_;
361 // Tracks any data related or parse errors.
362 bool bad_message_;
364 DISALLOW_COPY_AND_ASSIGN(WebViewInternalClearDataFunction);
367 } // namespace extensions
369 #endif // CHROME_BROWSER_EXTENSIONS_API_WEB_VIEW_WEB_VIEW_INTERNAL_API_H_