Skip to content

Commit

Permalink
Remove blink permission request patch
Browse files Browse the repository at this point in the history
  • Loading branch information
darkdh committed Jul 31, 2018
1 parent 8f07aee commit 2d27548
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 47 deletions.
13 changes: 0 additions & 13 deletions patches/third_party-blink-renderer-core-html-BUILD.gn.patch

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,31 +1,11 @@
diff --git a/third_party/blink/renderer/core/html/media/autoplay_policy.cc b/third_party/blink/renderer/core/html/media/autoplay_policy.cc
index b46d047161d41aae70b8485a2b95a38bbb8c3e4d..b58cb1e920cc86b2999f72f5f7f09bbcb19d2613 100644
index b46d047161d41aae70b8485a2b95a38bbb8c3e4d..bd9057ae0f16e75e14d03469deea0301a0cb68c9 100644
--- a/third_party/blink/renderer/core/html/media/autoplay_policy.cc
+++ b/third_party/blink/renderer/core/html/media/autoplay_policy.cc
@@ -5,6 +5,7 @@
#include "third_party/blink/renderer/core/html/media/autoplay_policy.h"

#include "third_party/blink/public/mojom/feature_policy/feature_policy.mojom-blink.h"
+#include "third_party/blink/public/platform/modules/permissions/permission.mojom-blink.h"
#include "third_party/blink/public/platform/autoplay.mojom-blink.h"
#include "third_party/blink/public/platform/web_media_player.h"
#include "third_party/blink/public/web/web_settings.h"
@@ -17,6 +18,7 @@
#include "third_party/blink/renderer/core/html/media/html_media_element.h"
#include "third_party/blink/renderer/core/inspector/console_message.h"
#include "third_party/blink/renderer/core/page/page.h"
+#include "third_party/blink/renderer/modules/permissions/permission_utils.h"
#include "third_party/blink/renderer/platform/network/network_state_notifier.h"
#include "third_party/blink/renderer/platform/runtime_enabled_features.h"
#include "third_party/blink/renderer/platform/wtf/assertions.h"
@@ -341,6 +343,15 @@ bool AutoplayPolicy::IsGestureNeededForPlaybackIfPendingUserGestureIsLocked()
@@ -341,6 +341,11 @@ bool AutoplayPolicy::IsGestureNeededForPlaybackIfPendingUserGestureIsLocked()
if (element_->GetLoadType() == WebMediaPlayer::kLoadTypeMediaStream)
return false;

+ // brave(darkdh): default allow local files
+ if (element_->GetDocument().origin() == String("null") || element_->GetDocument().origin() == String("file://"))
+ return false;
+
+#if defined(BRAVE_CHROMIUM_BUILD)
+ if (IsAutoplayAllowedPerSettings())
+ return false;
Expand All @@ -34,21 +14,10 @@ index b46d047161d41aae70b8485a2b95a38bbb8c3e4d..b58cb1e920cc86b2999f72f5f7f09bbc
// We want to allow muted video to autoplay if:
// - the flag is enabled;
// - Data Saver is not enabled;
@@ -414,6 +425,18 @@ bool AutoplayPolicy::IsAutoplayAllowedPerSettings() const {
@@ -414,6 +419,7 @@ bool AutoplayPolicy::IsAutoplayAllowedPerSettings() const {
LocalFrame* frame = element_->GetDocument().GetFrame();
if (!frame)
return false;
+
+ mojom::blink::PermissionServicePtr permission_service;
+
+ ConnectToPermissionService(element_->GetDocument().ContextDocument(),
+ mojo::MakeRequest(&permission_service));
+
+ if (permission_service.get()) {
+ permission_service->RequestPermission(
+ CreatePermissionDescriptor(mojom::blink::PermissionName::AUTOPLAY),
+ true, base::DoNothing());
+ }
+
return frame->GetContentSettingsClient()->AllowAutoplay(true);
}
Expand Down
23 changes: 23 additions & 0 deletions renderer/brave_content_settings_observer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
#include "content/public/renderer/render_frame.h"
#include "services/service_manager/public/cpp/interface_provider.h"
#include "third_party/blink/public/platform/web_url.h"
#include "third_party/blink/public/platform/modules/permissions/permission.mojom-blink.h"
#include "third_party/blink/public/web/web_document.h"
#include "third_party/blink/public/web/web_local_frame.h"
#include "url/url_constants.h"

BraveContentSettingsObserver::BraveContentSettingsObserver(
content::RenderFrame* render_frame,
Expand Down Expand Up @@ -190,3 +192,24 @@ bool BraveContentSettingsObserver::AllowFingerprinting(

return allow;
}
bool BraveContentSettingsObserver::AllowAutoplay(bool default_value) {
blink::WebLocalFrame* frame = render_frame()->GetWebFrame();
auto origin = frame->GetDocument().GetSecurityOrigin();
// default allow local files
if (origin.IsNull() || origin.Protocol().Ascii() == url::kFileScheme)
return true;

blink::mojom::blink::PermissionServicePtr permission_service;

render_frame()->GetRemoteInterfaces()
->GetInterface(mojo::MakeRequest(&permission_service));

if (permission_service.get()) {
auto descriptor = blink::mojom::blink::PermissionDescriptor::New();
descriptor->name = blink::mojom::blink::PermissionName::AUTOPLAY;
permission_service->RequestPermission(std::move(descriptor), true,
base::DoNothing());
}

return ContentSettingsObserver::AllowAutoplay(default_value);
}
2 changes: 2 additions & 0 deletions renderer/brave_content_settings_observer.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class BraveContentSettingsObserver

bool AllowFingerprinting(bool enabled_per_settings) override;

bool AllowAutoplay(bool default_value) override;

void BraveSpecificDidBlockJavaScript(
const base::string16& details);

Expand Down

0 comments on commit 2d27548

Please sign in to comment.