web_contents_permission_helper.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright (c) 2016 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #ifndef ATOM_BROWSER_WEB_CONTENTS_PERMISSION_HELPER_H_
  5. #define ATOM_BROWSER_WEB_CONTENTS_PERMISSION_HELPER_H_
  6. #include "content/public/browser/permission_type.h"
  7. #include "content/public/browser/web_contents_user_data.h"
  8. #include "content/public/common/media_stream_request.h"
  9. namespace atom {
  10. // Applies the permission requested for WebContents.
  11. class WebContentsPermissionHelper
  12. : public content::WebContentsUserData<WebContentsPermissionHelper> {
  13. public:
  14. ~WebContentsPermissionHelper() override;
  15. enum class PermissionType {
  16. POINTER_LOCK = static_cast<int>(content::PermissionType::NUM) + 1,
  17. FULLSCREEN,
  18. OPEN_EXTERNAL,
  19. };
  20. void RequestFullscreenPermission(const base::Callback<void(bool)>& callback);
  21. void RequestMediaAccessPermission(
  22. const content::MediaStreamRequest& request,
  23. const content::MediaResponseCallback& callback);
  24. void RequestWebNotificationPermission(
  25. const base::Callback<void(bool)>& callback);
  26. void RequestPointerLockPermission(bool user_gesture);
  27. void RequestOpenExternalPermission(const base::Callback<void(bool)>& callback,
  28. bool user_gesture,
  29. const GURL& url);
  30. private:
  31. explicit WebContentsPermissionHelper(content::WebContents* web_contents);
  32. friend class content::WebContentsUserData<WebContentsPermissionHelper>;
  33. void RequestPermission(content::PermissionType permission,
  34. const base::Callback<void(bool)>& callback,
  35. bool user_gesture = false,
  36. const base::DictionaryValue* details = nullptr);
  37. content::WebContents* web_contents_;
  38. DISALLOW_COPY_AND_ASSIGN(WebContentsPermissionHelper);
  39. };
  40. } // namespace atom
  41. #endif // ATOM_BROWSER_WEB_CONTENTS_PERMISSION_HELPER_H_