OLD | NEW |
| (Empty) |
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. | |
4 | |
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_ | |
7 | |
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" | |
12 | |
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 { | |
20 | |
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 | |
23 // subclasses. | |
24 class WebViewInternalExtensionFunction : public AsyncExtensionFunction { | |
25 public: | |
26 WebViewInternalExtensionFunction() {} | |
27 | |
28 protected: | |
29 virtual ~WebViewInternalExtensionFunction() {} | |
30 | |
31 // ExtensionFunction implementation. | |
32 virtual bool RunAsync() OVERRIDE FINAL; | |
33 | |
34 private: | |
35 virtual bool RunAsyncSafe(WebViewGuest* guest) = 0; | |
36 }; | |
37 | |
38 class WebViewInternalContextMenusCreateFunction | |
39 : public AsyncExtensionFunction { | |
40 public: | |
41 DECLARE_EXTENSION_FUNCTION("webViewInternal.contextMenusCreate", | |
42 WEBVIEWINTERNAL_CONTEXTMENUSCREATE); | |
43 WebViewInternalContextMenusCreateFunction() {} | |
44 | |
45 protected: | |
46 virtual ~WebViewInternalContextMenusCreateFunction() {} | |
47 | |
48 // ExtensionFunction implementation. | |
49 virtual bool RunAsync() OVERRIDE; | |
50 | |
51 private: | |
52 DISALLOW_COPY_AND_ASSIGN(WebViewInternalContextMenusCreateFunction); | |
53 }; | |
54 | |
55 class WebViewInternalContextMenusUpdateFunction | |
56 : public AsyncExtensionFunction { | |
57 public: | |
58 DECLARE_EXTENSION_FUNCTION("webViewInternal.contextMenusUpdate", | |
59 WEBVIEWINTERNAL_CONTEXTMENUSUPDATE); | |
60 WebViewInternalContextMenusUpdateFunction() {} | |
61 | |
62 protected: | |
63 virtual ~WebViewInternalContextMenusUpdateFunction() {} | |
64 | |
65 // ExtensionFunction implementation. | |
66 virtual bool RunAsync() OVERRIDE; | |
67 | |
68 private: | |
69 DISALLOW_COPY_AND_ASSIGN(WebViewInternalContextMenusUpdateFunction); | |
70 }; | |
71 | |
72 class WebViewInternalContextMenusRemoveFunction | |
73 : public AsyncExtensionFunction { | |
74 public: | |
75 DECLARE_EXTENSION_FUNCTION("webViewInternal.contextMenusRemove", | |
76 WEBVIEWINTERNAL_CONTEXTMENUSREMOVE); | |
77 WebViewInternalContextMenusRemoveFunction() {} | |
78 | |
79 protected: | |
80 virtual ~WebViewInternalContextMenusRemoveFunction() {} | |
81 | |
82 // ExtensionFunction implementation. | |
83 virtual bool RunAsync() OVERRIDE; | |
84 | |
85 private: | |
86 DISALLOW_COPY_AND_ASSIGN(WebViewInternalContextMenusRemoveFunction); | |
87 }; | |
88 | |
89 class WebViewInternalContextMenusRemoveAllFunction | |
90 : public AsyncExtensionFunction { | |
91 public: | |
92 DECLARE_EXTENSION_FUNCTION("webViewInternal.contextMenusRemoveAll", | |
93 WEBVIEWINTERNAL_CONTEXTMENUSREMOVEALL); | |
94 WebViewInternalContextMenusRemoveAllFunction() {} | |
95 | |
96 protected: | |
97 virtual ~WebViewInternalContextMenusRemoveAllFunction() {} | |
98 | |
99 // ExtensionFunction implementation. | |
100 virtual bool RunAsync() OVERRIDE; | |
101 | |
102 private: | |
103 DISALLOW_COPY_AND_ASSIGN(WebViewInternalContextMenusRemoveAllFunction); | |
104 }; | |
105 | |
106 class WebViewInternalNavigateFunction | |
107 : public WebViewInternalExtensionFunction { | |
108 public: | |
109 DECLARE_EXTENSION_FUNCTION("webViewInternal.navigate", | |
110 WEBVIEWINTERNAL_NAVIGATE); | |
111 WebViewInternalNavigateFunction() {} | |
112 | |
113 protected: | |
114 virtual ~WebViewInternalNavigateFunction() {} | |
115 | |
116 private: | |
117 // WebViewInternalExtensionFunction implementation. | |
118 virtual bool RunAsyncSafe(WebViewGuest* guest) OVERRIDE; | |
119 | |
120 DISALLOW_COPY_AND_ASSIGN(WebViewInternalNavigateFunction); | |
121 }; | |
122 | |
123 class WebViewInternalClearDataFunction | |
124 : public WebViewInternalExtensionFunction { | |
125 public: | |
126 DECLARE_EXTENSION_FUNCTION("webViewInternal.clearData", | |
127 WEBVIEWINTERNAL_CLEARDATA); | |
128 | |
129 WebViewInternalClearDataFunction(); | |
130 | |
131 protected: | |
132 virtual ~WebViewInternalClearDataFunction(); | |
133 | |
134 private: | |
135 // WebViewInternalExtensionFunction implementation. | |
136 virtual bool RunAsyncSafe(WebViewGuest* guest) OVERRIDE; | |
137 | |
138 uint32 GetRemovalMask(); | |
139 void ClearDataDone(); | |
140 | |
141 // Removal start time. | |
142 base::Time remove_since_; | |
143 // Removal mask, corresponds to StoragePartition::RemoveDataMask enum. | |
144 uint32 remove_mask_; | |
145 // Tracks any data related or parse errors. | |
146 bool bad_message_; | |
147 | |
148 DISALLOW_COPY_AND_ASSIGN(WebViewInternalClearDataFunction); | |
149 }; | |
150 | |
151 class WebViewInternalExecuteCodeFunction | |
152 : public extensions::ExecuteCodeFunction<AsyncExtensionFunction> { | |
153 public: | |
154 WebViewInternalExecuteCodeFunction(); | |
155 | |
156 protected: | |
157 virtual ~WebViewInternalExecuteCodeFunction(); | |
158 | |
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; | |
167 | |
168 private: | |
169 // Contains extension resource built from path of file which is | |
170 // specified in JSON arguments. | |
171 extensions::ExtensionResource resource_; | |
172 | |
173 int guest_instance_id_; | |
174 | |
175 GURL guest_src_; | |
176 | |
177 DISALLOW_COPY_AND_ASSIGN(WebViewInternalExecuteCodeFunction); | |
178 }; | |
179 | |
180 class WebViewInternalExecuteScriptFunction | |
181 : public WebViewInternalExecuteCodeFunction { | |
182 public: | |
183 WebViewInternalExecuteScriptFunction(); | |
184 | |
185 protected: | |
186 virtual ~WebViewInternalExecuteScriptFunction() {} | |
187 | |
188 virtual void OnExecuteCodeFinished(const std::string& error, | |
189 const GURL& on_url, | |
190 const base::ListValue& result) OVERRIDE; | |
191 | |
192 DECLARE_EXTENSION_FUNCTION("webViewInternal.executeScript", | |
193 WEBVIEWINTERNAL_EXECUTESCRIPT) | |
194 | |
195 private: | |
196 DISALLOW_COPY_AND_ASSIGN(WebViewInternalExecuteScriptFunction); | |
197 }; | |
198 | |
199 class WebViewInternalInsertCSSFunction | |
200 : public WebViewInternalExecuteCodeFunction { | |
201 public: | |
202 WebViewInternalInsertCSSFunction(); | |
203 | |
204 protected: | |
205 virtual ~WebViewInternalInsertCSSFunction() {} | |
206 | |
207 virtual bool ShouldInsertCSS() const OVERRIDE; | |
208 | |
209 DECLARE_EXTENSION_FUNCTION("webViewInternal.insertCSS", | |
210 WEBVIEWINTERNAL_INSERTCSS) | |
211 | |
212 private: | |
213 DISALLOW_COPY_AND_ASSIGN(WebViewInternalInsertCSSFunction); | |
214 }; | |
215 | |
216 class WebViewInternalCaptureVisibleRegionFunction | |
217 : public extensions::CaptureWebContentsFunction<AsyncExtensionFunction> { | |
218 DECLARE_EXTENSION_FUNCTION("webViewInternal.captureVisibleRegion", | |
219 WEBVIEWINTERNAL_CAPTUREVISIBLEREGION); | |
220 | |
221 WebViewInternalCaptureVisibleRegionFunction(); | |
222 | |
223 protected: | |
224 virtual ~WebViewInternalCaptureVisibleRegionFunction(); | |
225 | |
226 private: | |
227 // extensions::CaptureWebContentsFunction implementation. | |
228 virtual bool IsScreenshotEnabled() OVERRIDE; | |
229 virtual content::WebContents* GetWebContentsForID(int id) OVERRIDE; | |
230 virtual void OnCaptureFailure(FailureReason reason) OVERRIDE; | |
231 | |
232 DISALLOW_COPY_AND_ASSIGN(WebViewInternalCaptureVisibleRegionFunction); | |
233 }; | |
234 | |
235 class WebViewInternalSetNameFunction : public WebViewInternalExtensionFunction { | |
236 public: | |
237 DECLARE_EXTENSION_FUNCTION("webViewInternal.setName", | |
238 WEBVIEWINTERNAL_SETNAME); | |
239 | |
240 WebViewInternalSetNameFunction(); | |
241 | |
242 protected: | |
243 virtual ~WebViewInternalSetNameFunction(); | |
244 | |
245 private: | |
246 virtual bool RunAsyncSafe(WebViewGuest* guest) OVERRIDE; | |
247 | |
248 DISALLOW_COPY_AND_ASSIGN(WebViewInternalSetNameFunction); | |
249 }; | |
250 | |
251 class WebViewInternalSetZoomFunction : public WebViewInternalExtensionFunction { | |
252 public: | |
253 DECLARE_EXTENSION_FUNCTION("webViewInternal.setZoom", | |
254 WEBVIEWINTERNAL_SETZOOM); | |
255 | |
256 WebViewInternalSetZoomFunction(); | |
257 | |
258 protected: | |
259 virtual ~WebViewInternalSetZoomFunction(); | |
260 | |
261 private: | |
262 virtual bool RunAsyncSafe(WebViewGuest* guest) OVERRIDE; | |
263 | |
264 DISALLOW_COPY_AND_ASSIGN(WebViewInternalSetZoomFunction); | |
265 }; | |
266 | |
267 class WebViewInternalGetZoomFunction : public WebViewInternalExtensionFunction { | |
268 public: | |
269 DECLARE_EXTENSION_FUNCTION("webViewInternal.getZoom", | |
270 WEBVIEWINTERNAL_GETZOOM); | |
271 | |
272 WebViewInternalGetZoomFunction(); | |
273 | |
274 protected: | |
275 virtual ~WebViewInternalGetZoomFunction(); | |
276 | |
277 private: | |
278 virtual bool RunAsyncSafe(WebViewGuest* guest) OVERRIDE; | |
279 | |
280 DISALLOW_COPY_AND_ASSIGN(WebViewInternalGetZoomFunction); | |
281 }; | |
282 | |
283 class WebViewInternalFindFunction : public WebViewInternalExtensionFunction { | |
284 public: | |
285 DECLARE_EXTENSION_FUNCTION("webViewInternal.find", WEBVIEWINTERNAL_FIND); | |
286 | |
287 WebViewInternalFindFunction(); | |
288 | |
289 // Exposes SendResponse() for use by WebViewInternalFindHelper. | |
290 using WebViewInternalExtensionFunction::SendResponse; | |
291 | |
292 protected: | |
293 virtual ~WebViewInternalFindFunction(); | |
294 | |
295 private: | |
296 // WebViewInternalExtensionFunction implementation. | |
297 virtual bool RunAsyncSafe(WebViewGuest* guest) OVERRIDE; | |
298 | |
299 DISALLOW_COPY_AND_ASSIGN(WebViewInternalFindFunction); | |
300 }; | |
301 | |
302 class WebViewInternalStopFindingFunction | |
303 : public WebViewInternalExtensionFunction { | |
304 public: | |
305 DECLARE_EXTENSION_FUNCTION("webViewInternal.stopFinding", | |
306 WEBVIEWINTERNAL_STOPFINDING); | |
307 | |
308 WebViewInternalStopFindingFunction(); | |
309 | |
310 protected: | |
311 virtual ~WebViewInternalStopFindingFunction(); | |
312 | |
313 private: | |
314 // WebViewInternalExtensionFunction implementation. | |
315 virtual bool RunAsyncSafe(WebViewGuest* guest) OVERRIDE; | |
316 | |
317 DISALLOW_COPY_AND_ASSIGN(WebViewInternalStopFindingFunction); | |
318 }; | |
319 | |
320 class WebViewInternalGoFunction : public WebViewInternalExtensionFunction { | |
321 public: | |
322 DECLARE_EXTENSION_FUNCTION("webViewInternal.go", WEBVIEWINTERNAL_GO); | |
323 | |
324 WebViewInternalGoFunction(); | |
325 | |
326 protected: | |
327 virtual ~WebViewInternalGoFunction(); | |
328 | |
329 private: | |
330 // WebViewInternalExtensionFunction implementation. | |
331 virtual bool RunAsyncSafe(WebViewGuest* guest) OVERRIDE; | |
332 | |
333 DISALLOW_COPY_AND_ASSIGN(WebViewInternalGoFunction); | |
334 }; | |
335 | |
336 class WebViewInternalReloadFunction : public WebViewInternalExtensionFunction { | |
337 public: | |
338 DECLARE_EXTENSION_FUNCTION("webViewInternal.reload", WEBVIEWINTERNAL_RELOAD); | |
339 | |
340 WebViewInternalReloadFunction(); | |
341 | |
342 protected: | |
343 virtual ~WebViewInternalReloadFunction(); | |
344 | |
345 private: | |
346 // WebViewInternalExtensionFunction implementation. | |
347 virtual bool RunAsyncSafe(WebViewGuest* guest) OVERRIDE; | |
348 | |
349 DISALLOW_COPY_AND_ASSIGN(WebViewInternalReloadFunction); | |
350 }; | |
351 | |
352 class WebViewInternalSetPermissionFunction | |
353 : public WebViewInternalExtensionFunction { | |
354 public: | |
355 DECLARE_EXTENSION_FUNCTION("webViewInternal.setPermission", | |
356 WEBVIEWINTERNAL_SETPERMISSION); | |
357 | |
358 WebViewInternalSetPermissionFunction(); | |
359 | |
360 protected: | |
361 virtual ~WebViewInternalSetPermissionFunction(); | |
362 | |
363 private: | |
364 // WebViewInternalExtensionFunction implementation. | |
365 virtual bool RunAsyncSafe(WebViewGuest* guest) OVERRIDE; | |
366 | |
367 DISALLOW_COPY_AND_ASSIGN(WebViewInternalSetPermissionFunction); | |
368 }; | |
369 | |
370 class WebViewInternalShowContextMenuFunction | |
371 : public WebViewInternalExtensionFunction { | |
372 public: | |
373 DECLARE_EXTENSION_FUNCTION("webViewInternal.showContextMenu", | |
374 WEBVIEWINTERNAL_SHOWCONTEXTMENU); | |
375 | |
376 WebViewInternalShowContextMenuFunction(); | |
377 | |
378 protected: | |
379 virtual ~WebViewInternalShowContextMenuFunction(); | |
380 | |
381 private: | |
382 // WebViewInternalExtensionFunction implementation. | |
383 virtual bool RunAsyncSafe(WebViewGuest* guest) OVERRIDE; | |
384 | |
385 DISALLOW_COPY_AND_ASSIGN(WebViewInternalShowContextMenuFunction); | |
386 }; | |
387 | |
388 class WebViewInternalOverrideUserAgentFunction | |
389 : public WebViewInternalExtensionFunction { | |
390 public: | |
391 DECLARE_EXTENSION_FUNCTION("webViewInternal.overrideUserAgent", | |
392 WEBVIEWINTERNAL_OVERRIDEUSERAGENT); | |
393 | |
394 WebViewInternalOverrideUserAgentFunction(); | |
395 | |
396 protected: | |
397 virtual ~WebViewInternalOverrideUserAgentFunction(); | |
398 | |
399 private: | |
400 // WebViewInternalExtensionFunction implementation. | |
401 virtual bool RunAsyncSafe(WebViewGuest* guest) OVERRIDE; | |
402 | |
403 DISALLOW_COPY_AND_ASSIGN(WebViewInternalOverrideUserAgentFunction); | |
404 }; | |
405 | |
406 class WebViewInternalStopFunction : public WebViewInternalExtensionFunction { | |
407 public: | |
408 DECLARE_EXTENSION_FUNCTION("webViewInternal.stop", WEBVIEWINTERNAL_STOP); | |
409 | |
410 WebViewInternalStopFunction(); | |
411 | |
412 protected: | |
413 virtual ~WebViewInternalStopFunction(); | |
414 | |
415 private: | |
416 // WebViewInternalExtensionFunction implementation. | |
417 virtual bool RunAsyncSafe(WebViewGuest* guest) OVERRIDE; | |
418 | |
419 DISALLOW_COPY_AND_ASSIGN(WebViewInternalStopFunction); | |
420 }; | |
421 | |
422 class WebViewInternalTerminateFunction | |
423 : public WebViewInternalExtensionFunction { | |
424 public: | |
425 DECLARE_EXTENSION_FUNCTION("webViewInternal.terminate", | |
426 WEBVIEWINTERNAL_TERMINATE); | |
427 | |
428 WebViewInternalTerminateFunction(); | |
429 | |
430 protected: | |
431 virtual ~WebViewInternalTerminateFunction(); | |
432 | |
433 private: | |
434 // WebViewInternalExtensionFunction implementation. | |
435 virtual bool RunAsyncSafe(WebViewGuest* guest) OVERRIDE; | |
436 | |
437 DISALLOW_COPY_AND_ASSIGN(WebViewInternalTerminateFunction); | |
438 }; | |
439 | |
440 } // namespace extensions | |
441 | |
442 #endif // CHROME_BROWSER_EXTENSIONS_API_WEB_VIEW_WEB_VIEW_INTERNAL_API_H_ | |
OLD | NEW |