Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(833)

Side by Side Diff: chrome/browser/guest_view/web_view/web_view_guest.h

Issue 347113002: Refactor PluginPermissionHelper as WebViewPermissionHelper (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changes are made. Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_GUEST_H_ 5 #ifndef CHROME_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_GUEST_H_
6 #define CHROME_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_GUEST_H_ 6 #define CHROME_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_GUEST_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/observer_list.h" 10 #include "base/observer_list.h"
11 #include "chrome/browser/extensions/tab_helper.h" 11 #include "chrome/browser/extensions/tab_helper.h"
12 #include "chrome/browser/guest_view/guest_view.h" 12 #include "chrome/browser/guest_view/guest_view.h"
13 #include "chrome/browser/guest_view/web_view/javascript_dialog_helper.h" 13 #include "chrome/browser/guest_view/web_view/javascript_dialog_helper.h"
14 #include "chrome/browser/guest_view/web_view/web_view_find_helper.h" 14 #include "chrome/browser/guest_view/web_view/web_view_find_helper.h"
15 #include "chrome/browser/guest_view/web_view/web_view_permission_helper.h"
15 #include "chrome/browser/guest_view/web_view/web_view_permission_types.h" 16 #include "chrome/browser/guest_view/web_view/web_view_permission_types.h"
16 #include "chrome/common/extensions/api/web_view_internal.h" 17 #include "chrome/common/extensions/api/web_view_internal.h"
17 #include "content/public/browser/javascript_dialog_manager.h" 18 #include "content/public/browser/javascript_dialog_manager.h"
18 #include "content/public/browser/notification_registrar.h" 19 #include "content/public/browser/notification_registrar.h"
19 #include "third_party/WebKit/public/web/WebFindOptions.h" 20 #include "third_party/WebKit/public/web/WebFindOptions.h"
20 21
21 #if defined(OS_CHROMEOS) 22 #if defined(OS_CHROMEOS)
22 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" 23 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
23 #endif 24 #endif
24 25
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 void RequestGeolocationPermission(int bridge_id, 197 void RequestGeolocationPermission(int bridge_id,
197 const GURL& requesting_frame, 198 const GURL& requesting_frame,
198 bool user_gesture, 199 bool user_gesture,
199 const base::Callback<void(bool)>& callback); 200 const base::Callback<void(bool)>& callback);
200 void CancelGeolocationPermissionRequest(int bridge_id); 201 void CancelGeolocationPermissionRequest(int bridge_id);
201 202
202 void RequestFileSystemPermission(const GURL& url, 203 void RequestFileSystemPermission(const GURL& url,
203 bool allowed_by_default, 204 bool allowed_by_default,
204 const base::Callback<void(bool)>& callback); 205 const base::Callback<void(bool)>& callback);
205 206
206 enum PermissionResponseAction {
207 DENY,
208 ALLOW,
209 DEFAULT
210 };
211
212 enum SetPermissionResult {
213 SET_PERMISSION_INVALID,
214 SET_PERMISSION_ALLOWED,
215 SET_PERMISSION_DENIED
216 };
217
218 // Responds to the permission request |request_id| with |action| and
219 // |user_input|. Returns whether there was a pending request for the provided
220 // |request_id|.
221 SetPermissionResult SetPermission(int request_id,
222 PermissionResponseAction action,
223 const std::string& user_input);
224
225 // Overrides the user agent for this guest. 207 // Overrides the user agent for this guest.
226 // This affects subsequent guest navigations. 208 // This affects subsequent guest navigations.
227 void SetUserAgentOverride(const std::string& user_agent_override); 209 void SetUserAgentOverride(const std::string& user_agent_override);
228 210
229 // Stop loading the guest. 211 // Stop loading the guest.
230 void Stop(); 212 void Stop();
231 213
232 // Kill the guest process. 214 // Kill the guest process.
233 void Terminate(); 215 void Terminate();
234 216
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 // perform an explicit action. 252 // perform an explicit action.
271 // If access was blocked due to the page's content settings, 253 // If access was blocked due to the page's content settings,
272 // |blocked_by_policy| should be true, and this function should invoke 254 // |blocked_by_policy| should be true, and this function should invoke
273 // OnContentBlocked. 255 // OnContentBlocked.
274 static void FileSystemAccessedSync(int render_process_id, 256 static void FileSystemAccessedSync(int render_process_id,
275 int render_frame_id, 257 int render_frame_id,
276 const GURL& url, 258 const GURL& url,
277 bool blocked_by_policy, 259 bool blocked_by_policy,
278 IPC::Message* reply_msg); 260 IPC::Message* reply_msg);
279 261
262 WebViewPermissionHelper* GetWebViewPermissionHelper() {
263 return web_view_permission_helper_.get();
264 }
280 private: 265 private:
281 virtual ~WebViewGuest(); 266 virtual ~WebViewGuest();
282 267
283 // A map to store the callback for a request keyed by the request's id.
284 struct PermissionResponseInfo {
285 PermissionResponseCallback callback;
286 WebViewPermissionType permission_type;
287 bool allowed_by_default;
288 PermissionResponseInfo();
289 PermissionResponseInfo(const PermissionResponseCallback& callback,
290 WebViewPermissionType permission_type,
291 bool allowed_by_default);
292 ~PermissionResponseInfo();
293 };
294
295 static void RecordUserInitiatedUMA(const PermissionResponseInfo& info,
296 bool allow);
297
298 // Returns the top level items (ignoring submenus) as Value. 268 // Returns the top level items (ignoring submenus) as Value.
299 static scoped_ptr<base::ListValue> MenuModelToValue( 269 static scoped_ptr<base::ListValue> MenuModelToValue(
300 const ui::SimpleMenuModel& menu_model); 270 const ui::SimpleMenuModel& menu_model);
301 271
302 void OnWebViewGeolocationPermissionResponse(
303 int bridge_id,
304 bool user_gesture,
305 const base::Callback<void(bool)>& callback,
306 bool allow,
307 const std::string& user_input);
308
309 void OnWebViewFileSystemPermissionResponse(
310 const base::Callback<void(bool)>& callback,
311 bool allow,
312 const std::string& user_input);
313
314 void OnWebViewMediaPermissionResponse(
315 const content::MediaStreamRequest& request,
316 const content::MediaResponseCallback& callback,
317 bool allow,
318 const std::string& user_input);
319
320 void OnWebViewDownloadPermissionResponse(
321 const base::Callback<void(bool)>& callback,
322 bool allow,
323 const std::string& user_input);
324
325 void OnWebViewPointerLockPermissionResponse(
326 const base::Callback<void(bool)>& callback,
327 bool allow,
328 const std::string& user_input);
329
330 void OnWebViewNewWindowResponse(int new_window_instance_id, 272 void OnWebViewNewWindowResponse(int new_window_instance_id,
331 bool allow, 273 bool allow,
332 const std::string& user_input); 274 const std::string& user_input);
333 275
334 static void FileSystemAccessedAsyncResponse(int render_process_id,
335 int render_frame_id,
336 int request_id,
337 const GURL& url,
338 bool allowed);
339
340 static void FileSystemAccessedSyncResponse(int render_process_id,
341 int render_frame_id,
342 const GURL& url,
343 IPC::Message* reply_msg,
344 bool allowed);
345
346 // WebContentsObserver implementation. 276 // WebContentsObserver implementation.
347 virtual void DidCommitProvisionalLoadForFrame( 277 virtual void DidCommitProvisionalLoadForFrame(
348 content::RenderFrameHost* render_frame_host, 278 content::RenderFrameHost* render_frame_host,
349 const GURL& url, 279 const GURL& url,
350 content::PageTransition transition_type) OVERRIDE; 280 content::PageTransition transition_type) OVERRIDE;
351 virtual void DidFailProvisionalLoad( 281 virtual void DidFailProvisionalLoad(
352 content::RenderFrameHost* render_frame_host, 282 content::RenderFrameHost* render_frame_host,
353 const GURL& validated_url, 283 const GURL& validated_url,
354 int error_code, 284 int error_code,
355 const base::string16& error_description) OVERRIDE; 285 const base::string16& error_description) OVERRIDE;
(...skipping 28 matching lines...) Expand all
384 content::WebContents* web_contents); 314 content::WebContents* web_contents);
385 315
386 #if defined(OS_CHROMEOS) 316 #if defined(OS_CHROMEOS)
387 // Notification of a change in the state of an accessibility setting. 317 // Notification of a change in the state of an accessibility setting.
388 void OnAccessibilityStatusChanged( 318 void OnAccessibilityStatusChanged(
389 const chromeos::AccessibilityStatusEventDetails& details); 319 const chromeos::AccessibilityStatusEventDetails& details);
390 #endif 320 #endif
391 321
392 void InjectChromeVoxIfNeeded(content::RenderViewHost* render_view_host); 322 void InjectChromeVoxIfNeeded(content::RenderViewHost* render_view_host);
393 323
394 // Bridge IDs correspond to a geolocation request. This method will remove
395 // the bookkeeping for a particular geolocation request associated with the
396 // provided |bridge_id|. It returns the request ID of the geolocation request.
397 int RemoveBridgeID(int bridge_id);
398
399 void LoadURLWithParams(const GURL& url, 324 void LoadURLWithParams(const GURL& url,
400 const content::Referrer& referrer, 325 const content::Referrer& referrer,
401 content::PageTransition transition_type, 326 content::PageTransition transition_type,
402 content::WebContents* web_contents); 327 content::WebContents* web_contents);
403 328
404 void RequestNewWindowPermission( 329 void RequestNewWindowPermission(
405 WindowOpenDisposition disposition, 330 WindowOpenDisposition disposition,
406 const gfx::Rect& initial_bounds, 331 const gfx::Rect& initial_bounds,
407 bool user_gesture, 332 bool user_gesture,
408 content::WebContents* new_contents); 333 content::WebContents* new_contents);
(...skipping 24 matching lines...) Expand all
433 ObserverList<extensions::TabHelper::ScriptExecutionObserver> 358 ObserverList<extensions::TabHelper::ScriptExecutionObserver>
434 script_observers_; 359 script_observers_;
435 scoped_ptr<extensions::ScriptExecutor> script_executor_; 360 scoped_ptr<extensions::ScriptExecutor> script_executor_;
436 361
437 content::NotificationRegistrar notification_registrar_; 362 content::NotificationRegistrar notification_registrar_;
438 363
439 // A counter to generate a unique request id for a context menu request. 364 // A counter to generate a unique request id for a context menu request.
440 // We only need the ids to be unique for a given WebViewGuest. 365 // We only need the ids to be unique for a given WebViewGuest.
441 int pending_context_menu_request_id_; 366 int pending_context_menu_request_id_;
442 367
443 // A counter to generate a unique request id for a permission request.
444 // We only need the ids to be unique for a given WebViewGuest.
445 int next_permission_request_id_;
446
447 typedef std::map<int, PermissionResponseInfo> RequestMap;
448 RequestMap pending_permission_requests_;
449
450 // True if the user agent is overridden. 368 // True if the user agent is overridden.
451 bool is_overriding_user_agent_; 369 bool is_overriding_user_agent_;
452 370
453 // Main frame ID of last committed page. 371 // Main frame ID of last committed page.
454 int64 main_frame_id_; 372 int64 main_frame_id_;
455 373
456 // Set to |true| if ChromeVox was already injected in main frame. 374 // Set to |true| if ChromeVox was already injected in main frame.
457 bool chromevox_injected_; 375 bool chromevox_injected_;
458 376
459 // Stores the current zoom factor. 377 // Stores the current zoom factor.
460 double current_zoom_factor_; 378 double current_zoom_factor_;
461 379
462 // Stores the window name of the main frame of the guest. 380 // Stores the window name of the main frame of the guest.
463 std::string name_; 381 std::string name_;
464 382
465 // Handles find requests and replies for the webview find API. 383 // Handles find requests and replies for the webview find API.
466 WebViewFindHelper find_helper_; 384 WebViewFindHelper find_helper_;
467 385
468 // Handles the JavaScript dialog requests. 386 // Handles the JavaScript dialog requests.
469 JavaScriptDialogHelper javascript_dialog_helper_; 387 JavaScriptDialogHelper javascript_dialog_helper_;
470 388
389 // Handels permission requests.
390 scoped_ptr<WebViewPermissionHelper> web_view_permission_helper_;
391
471 friend void WebViewFindHelper::DispatchFindUpdateEvent(bool canceled, 392 friend void WebViewFindHelper::DispatchFindUpdateEvent(bool canceled,
472 bool final_update); 393 bool final_update);
473 394
474 // Holds the RenderViewContextMenu that has been built but yet to be 395 // Holds the RenderViewContextMenu that has been built but yet to be
475 // shown. This is .Reset() after ShowContextMenu(). 396 // shown. This is .Reset() after ShowContextMenu().
476 scoped_ptr<RenderViewContextMenu> pending_menu_; 397 scoped_ptr<RenderViewContextMenu> pending_menu_;
477 398
478 #if defined(OS_CHROMEOS) 399 #if defined(OS_CHROMEOS)
479 // Subscription to receive notifications on changes to a11y settings. 400 // Subscription to receive notifications on changes to a11y settings.
480 scoped_ptr<chromeos::AccessibilityStatusSubscription> 401 scoped_ptr<chromeos::AccessibilityStatusSubscription>
481 accessibility_subscription_; 402 accessibility_subscription_;
482 #endif 403 #endif
483 404
484 std::map<int, int> bridge_id_to_request_id_map_;
485
486 // Tracks the name, and target URL of the new window. Once the first 405 // Tracks the name, and target URL of the new window. Once the first
487 // navigation commits, we no longer track this information. 406 // navigation commits, we no longer track this information.
488 struct NewWindowInfo { 407 struct NewWindowInfo {
489 GURL url; 408 GURL url;
490 std::string name; 409 std::string name;
491 bool changed; 410 bool changed;
492 NewWindowInfo(const GURL& url, const std::string& name) : 411 NewWindowInfo(const GURL& url, const std::string& name) :
493 url(url), 412 url(url),
494 name(name), 413 name(name),
495 changed(false) {} 414 changed(false) {}
496 }; 415 };
497 416
498 typedef std::map<WebViewGuest*, NewWindowInfo> PendingWindowMap; 417 typedef std::map<WebViewGuest*, NewWindowInfo> PendingWindowMap;
499 PendingWindowMap pending_new_windows_; 418 PendingWindowMap pending_new_windows_;
500 419
501 DISALLOW_COPY_AND_ASSIGN(WebViewGuest); 420 DISALLOW_COPY_AND_ASSIGN(WebViewGuest);
502 }; 421 };
503 422
504 #endif // CHROME_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_GUEST_H_ 423 #endif // CHROME_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_GUEST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698