Implement HasPermission() method in PermissionService.
This patch implements the HasPermission() method in the mojo PermissionService. This methiod will be required for the Permissions API, see https://w3c.github.io/permissions/ BUG=430238 Committed: https://crrev.com/277b23d74855b51ebe67ae0da7cd9e0b053044cf Cr-Commit-Position: refs/heads/master@{#307302} Committed: https://crrev.com/14570267ac4d5dc473d29f256e8d044e9bfcc8d2 Cr-Commit-Position: refs/heads/master@{#307504} Review URL: https://codereview.chromium.org/750633003 Cr-Commit-Position: refs/heads/master@{#307948}
This commit is contained in:
chrome/browser
content
browser
permissions
renderer_host
common
content.gypcontent_app.gypicontent_browser.gypicontent_child.gypicontent_common_mojo_bindings.gypcontent_ppapi_plugin.gypicontent_renderer.gypicontent_tests.gypipublic
@ -599,6 +599,24 @@ void GetGuestViewDefaultContentSettingRules(
|
||||
}
|
||||
#endif // defined(ENALBE_EXTENSIONS)
|
||||
|
||||
content::PermissionStatus
|
||||
ContentSettingToPermissionStatus(ContentSetting setting) {
|
||||
switch (setting) {
|
||||
case CONTENT_SETTING_ALLOW:
|
||||
case CONTENT_SETTING_SESSION_ONLY:
|
||||
return content::PERMISSION_STATUS_GRANTED;
|
||||
case CONTENT_SETTING_BLOCK:
|
||||
return content::PERMISSION_STATUS_DENIED;
|
||||
case CONTENT_SETTING_ASK:
|
||||
return content::PERMISSION_STATUS_ASK;
|
||||
case CONTENT_SETTING_DEFAULT:
|
||||
case CONTENT_SETTING_NUM_SETTINGS:
|
||||
break;
|
||||
}
|
||||
NOTREACHED();
|
||||
return content::PERMISSION_STATUS_DENIED;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace chrome {
|
||||
@ -1917,6 +1935,49 @@ void ChromeContentBrowserClient::RequestPermission(
|
||||
}
|
||||
}
|
||||
|
||||
content::PermissionStatus ChromeContentBrowserClient::GetPermissionStatus(
|
||||
content::PermissionType permission,
|
||||
content::BrowserContext* browser_context,
|
||||
const GURL& requesting_origin,
|
||||
const GURL& embedding_origin) {
|
||||
DCHECK(browser_context);
|
||||
Profile* profile = Profile::FromBrowserContext(browser_context);
|
||||
|
||||
PermissionContextBase* context = nullptr;
|
||||
switch (permission) {
|
||||
case content::PERMISSION_MIDI_SYSEX:
|
||||
context = MidiPermissionContextFactory::GetForProfile(profile);
|
||||
break;
|
||||
case content::PERMISSION_NOTIFICATIONS:
|
||||
#if defined(ENABLE_NOTIFICATIONS)
|
||||
context = DesktopNotificationServiceFactory::GetForProfile(profile);
|
||||
#else
|
||||
NOTIMPLEMENTED();
|
||||
#endif
|
||||
break;
|
||||
case content::PERMISSION_GEOLOCATION:
|
||||
context = GeolocationPermissionContextFactory::GetForProfile(profile);
|
||||
break;
|
||||
case content::PERMISSION_PROTECTED_MEDIA:
|
||||
NOTIMPLEMENTED();
|
||||
break;
|
||||
case content::PERMISSION_PUSH_MESSAGING:
|
||||
context = gcm::PushMessagingPermissionContextFactory::GetForProfile(
|
||||
profile);
|
||||
break;
|
||||
case content::PERMISSION_NUM:
|
||||
NOTREACHED() << "Invalid RequestPermission for " << permission;
|
||||
break;
|
||||
}
|
||||
|
||||
ContentSetting result = context
|
||||
? context->GetPermissionStatus(requesting_origin.GetOrigin(),
|
||||
embedding_origin.GetOrigin())
|
||||
: CONTENT_SETTING_DEFAULT;
|
||||
|
||||
return ContentSettingToPermissionStatus(result);
|
||||
}
|
||||
|
||||
void ChromeContentBrowserClient::CancelPermissionRequest(
|
||||
content::PermissionType permission,
|
||||
content::WebContents* web_contents,
|
||||
|
@ -189,6 +189,11 @@ class ChromeContentBrowserClient : public content::ContentBrowserClient {
|
||||
const GURL& requesting_frame,
|
||||
bool user_gesture,
|
||||
const base::Callback<void(bool)>& result_callback) override;
|
||||
content::PermissionStatus GetPermissionStatus(
|
||||
content::PermissionType permission,
|
||||
content::BrowserContext* browser_context,
|
||||
const GURL& requesting_origin,
|
||||
const GURL& embedding_origin) override;
|
||||
void CancelPermissionRequest(content::PermissionType permission,
|
||||
content::WebContents* web_contents,
|
||||
int bridge_id,
|
||||
|
2
content/browser/permissions/OWNERS
Normal file
2
content/browser/permissions/OWNERS
Normal file
@ -0,0 +1,2 @@
|
||||
mlamouri@chromium.org
|
||||
timvolodine@chromium.org
|
@ -7,6 +7,7 @@
|
||||
#include "content/browser/permissions/permission_service_impl.h"
|
||||
#include "content/public/browser/navigation_details.h"
|
||||
#include "content/public/browser/render_frame_host.h"
|
||||
#include "content/public/browser/render_process_host.h"
|
||||
#include "content/public/browser/web_contents.h"
|
||||
|
||||
namespace content {
|
||||
@ -14,7 +15,15 @@ namespace content {
|
||||
PermissionServiceContext::PermissionServiceContext(
|
||||
RenderFrameHost* render_frame_host)
|
||||
: WebContentsObserver(WebContents::FromRenderFrameHost(render_frame_host)),
|
||||
render_frame_host_(render_frame_host) {
|
||||
render_frame_host_(render_frame_host),
|
||||
render_process_host_(nullptr) {
|
||||
}
|
||||
|
||||
PermissionServiceContext::PermissionServiceContext(
|
||||
RenderProcessHost* render_process_host)
|
||||
: WebContentsObserver(nullptr),
|
||||
render_frame_host_(nullptr),
|
||||
render_process_host_(render_process_host) {
|
||||
}
|
||||
|
||||
PermissionServiceContext::~PermissionServiceContext() {
|
||||
@ -60,4 +69,17 @@ void PermissionServiceContext::CancelPendingRequests(
|
||||
service->CancelPendingRequests();
|
||||
}
|
||||
|
||||
BrowserContext* PermissionServiceContext::GetBrowserContext() const {
|
||||
if (!web_contents()) {
|
||||
DCHECK(render_process_host_);
|
||||
return render_process_host_->GetBrowserContext();
|
||||
}
|
||||
return web_contents()->GetBrowserContext();
|
||||
}
|
||||
|
||||
GURL PermissionServiceContext::GetEmbeddingOrigin() const {
|
||||
return web_contents() ? web_contents()->GetLastCommittedURL().GetOrigin()
|
||||
: GURL();
|
||||
}
|
||||
|
||||
} // namespace content
|
||||
|
@ -15,6 +15,7 @@ namespace content {
|
||||
class PermissionService;
|
||||
class PermissionServiceImpl;
|
||||
class RenderFrameHost;
|
||||
class RenderProcessHost;
|
||||
|
||||
// Provides information to a PermissionService. It is used by the
|
||||
// PermissionService to handle request permission UI.
|
||||
@ -23,6 +24,7 @@ class RenderFrameHost;
|
||||
class PermissionServiceContext : public WebContentsObserver {
|
||||
public:
|
||||
explicit PermissionServiceContext(RenderFrameHost* render_frame_host);
|
||||
explicit PermissionServiceContext(RenderProcessHost* render_process_host);
|
||||
virtual ~PermissionServiceContext();
|
||||
|
||||
void CreateService(mojo::InterfaceRequest<PermissionService> request);
|
||||
@ -31,6 +33,9 @@ class PermissionServiceContext : public WebContentsObserver {
|
||||
// connection error in order to get unregistered and killed.
|
||||
void ServiceHadConnectionError(PermissionServiceImpl* service);
|
||||
|
||||
BrowserContext* GetBrowserContext() const;
|
||||
GURL GetEmbeddingOrigin() const;
|
||||
|
||||
private:
|
||||
// WebContentsObserver
|
||||
void RenderFrameDeleted(RenderFrameHost* render_frame_host) override;
|
||||
@ -41,6 +46,7 @@ class PermissionServiceContext : public WebContentsObserver {
|
||||
void CancelPendingRequests(RenderFrameHost*) const;
|
||||
|
||||
RenderFrameHost* render_frame_host_;
|
||||
RenderProcessHost* render_process_host_;
|
||||
ScopedVector<PermissionServiceImpl> services_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(PermissionServiceContext);
|
||||
|
@ -109,7 +109,16 @@ void PermissionServiceImpl::HasPermission(
|
||||
PermissionName permission,
|
||||
const mojo::String& origin,
|
||||
const mojo::Callback<void(PermissionStatus)>& callback) {
|
||||
NOTIMPLEMENTED();
|
||||
DCHECK(context_->GetBrowserContext());
|
||||
|
||||
// If the embedding_origin is empty we'll use |origin| instead.
|
||||
GURL embedding_origin = context_->GetEmbeddingOrigin();
|
||||
|
||||
callback.Run(GetContentClient()->browser()->GetPermissionStatus(
|
||||
PermissionNameToPermissionType(permission),
|
||||
context_->GetBrowserContext(),
|
||||
GURL(origin),
|
||||
embedding_origin.is_empty() ? GURL(origin) : embedding_origin));
|
||||
}
|
||||
|
||||
} // namespace content
|
||||
|
@ -456,7 +456,7 @@ RenderProcessHostImpl::RenderProcessHostImpl(
|
||||
within_process_died_observer_(false),
|
||||
power_monitor_broadcaster_(this),
|
||||
worker_ref_count_(0),
|
||||
permission_service_context_(new PermissionServiceContext(nullptr)),
|
||||
permission_service_context_(new PermissionServiceContext(this)),
|
||||
weak_factory_(this) {
|
||||
widget_helper_ = new RenderWidgetHelper();
|
||||
|
||||
|
@ -4,11 +4,7 @@
|
||||
|
||||
module content;
|
||||
|
||||
enum PermissionStatus {
|
||||
GRANTED,
|
||||
DENIED,
|
||||
ASK
|
||||
};
|
||||
import "content/public/common/permission_status.mojom";
|
||||
|
||||
enum PermissionName {
|
||||
GEOLOCATION,
|
||||
|
@ -25,7 +25,6 @@
|
||||
['OS != "ios"', {
|
||||
'includes': [
|
||||
'../build/win_precompile.gypi',
|
||||
'content_common_mojo_bindings.gypi',
|
||||
'content_resources.gypi',
|
||||
],
|
||||
}],
|
||||
@ -75,7 +74,6 @@
|
||||
['OS != "ios"', {
|
||||
'dependencies': [
|
||||
'content_child',
|
||||
'content_common_mojo_bindings',
|
||||
'content_gpu',
|
||||
'content_plugin',
|
||||
'content_ppapi_plugin',
|
||||
@ -175,7 +173,6 @@
|
||||
}],
|
||||
['OS != "ios"', {
|
||||
'dependencies': [
|
||||
'content_common_mojo_bindings',
|
||||
'content_resources',
|
||||
],
|
||||
}],
|
||||
@ -192,7 +189,6 @@
|
||||
'conditions': [
|
||||
['OS != "ios"', {
|
||||
'dependencies': [
|
||||
'content_common_mojo_bindings',
|
||||
'content_resources',
|
||||
],
|
||||
}],
|
||||
@ -312,11 +308,6 @@
|
||||
'../v8/src/third_party/vtune/v8vtune.gyp:v8_vtune',
|
||||
],
|
||||
}],
|
||||
['OS != "ios"', {
|
||||
'dependencies': [
|
||||
'content_common_mojo_bindings',
|
||||
]
|
||||
}]
|
||||
],
|
||||
'includes': [
|
||||
'content_app.gypi',
|
||||
|
@ -10,9 +10,12 @@
|
||||
'../base/base.gyp:base',
|
||||
'../base/base.gyp:base_i18n',
|
||||
'../crypto/crypto.gyp:crypto',
|
||||
'../mojo/edk/mojo_edk.gyp:mojo_system_impl',
|
||||
'../mojo/mojo_base.gyp:mojo_environment_chromium',
|
||||
'../ui/base/ui_base.gyp:ui_base',
|
||||
'../ui/gfx/gfx.gyp:gfx',
|
||||
'../ui/gfx/gfx.gyp:gfx_geometry',
|
||||
'content_common_mojo_bindings.gyp:content_common_mojo_bindings',
|
||||
],
|
||||
'sources': [
|
||||
'app/android/app_jni_registrar.cc',
|
||||
@ -63,11 +66,6 @@
|
||||
'app/mojo/mojo_init.cc',
|
||||
'app/mojo/mojo_init.h',
|
||||
],
|
||||
}, { # OS!="ios"
|
||||
'dependencies': [
|
||||
'../mojo/edk/mojo_edk.gyp:mojo_system_impl',
|
||||
'../mojo/mojo_base.gyp:mojo_environment_chromium',
|
||||
],
|
||||
}],
|
||||
],
|
||||
}
|
||||
|
@ -29,6 +29,7 @@
|
||||
'../ui/snapshot/snapshot.gyp:snapshot',
|
||||
'browser/service_worker/service_worker_proto.gyp:proto',
|
||||
'browser/speech/proto/speech_proto.gyp:speech_proto',
|
||||
'content_common_mojo_bindings.gyp:content_common_mojo_bindings',
|
||||
],
|
||||
'export_dependent_settings': [
|
||||
'../ui/accessibility/accessibility.gyp:ax_gen',
|
||||
@ -38,6 +39,7 @@
|
||||
'../third_party/WebKit/public/blink_headers.gyp:blink_headers',
|
||||
# The public render_widget_host.h needs to re-export skia defines.
|
||||
'../skia/skia.gyp:skia',
|
||||
'content_common_mojo_bindings.gyp:content_common_mojo_bindings',
|
||||
],
|
||||
'include_dirs': [
|
||||
'..',
|
||||
|
@ -13,6 +13,7 @@
|
||||
'../ui/gfx/gfx.gyp:gfx',
|
||||
'../ui/gfx/gfx.gyp:gfx_geometry',
|
||||
'../url/url.gyp:url_lib',
|
||||
'content_common_mojo_bindings.gyp:content_common_mojo_bindings',
|
||||
],
|
||||
'include_dirs': [
|
||||
'..',
|
||||
|
@ -17,6 +17,7 @@
|
||||
# NOTE: Sources duplicated in
|
||||
# //content/public/common/BUILD.gn:mojo_bindings.
|
||||
'public/common/mojo_geoposition.mojom',
|
||||
'public/common/permission_status.mojom',
|
||||
],
|
||||
},
|
||||
'includes': [ '../mojo/public/tools/bindings/mojom_bindings_generator_explicit.gypi' ],
|
@ -12,6 +12,7 @@
|
||||
'../ui/gfx/gfx.gyp:gfx',
|
||||
'../ui/gfx/gfx.gyp:gfx_geometry',
|
||||
'../third_party/WebKit/public/blink.gyp:blink',
|
||||
'content_common_mojo_bindings.gyp:content_common_mojo_bindings',
|
||||
],
|
||||
'sources': [
|
||||
'ppapi_plugin/broker_process_dispatcher.cc',
|
||||
|
@ -36,6 +36,7 @@
|
||||
'../ui/surface/surface.gyp:surface',
|
||||
'../v8/tools/gyp/v8.gyp:v8',
|
||||
'../webkit/common/gpu/webkit_gpu.gyp:webkit_gpu',
|
||||
'content_common_mojo_bindings.gyp:content_common_mojo_bindings',
|
||||
],
|
||||
'include_dirs': [
|
||||
'..',
|
||||
|
@ -199,6 +199,8 @@
|
||||
'target_name': 'test_support_content',
|
||||
'type': 'static_library',
|
||||
'dependencies': [
|
||||
'../mojo/edk/mojo_edk.gyp:mojo_system_impl',
|
||||
'../mojo/mojo_base.gyp:mojo_environment_chromium',
|
||||
'../net/net.gyp:net_test_support',
|
||||
'../skia/skia.gyp:skia',
|
||||
'../storage/storage_common.gyp:storage_common',
|
||||
@ -375,6 +377,7 @@
|
||||
'browser/speech/proto/speech_proto.gyp:speech_proto',
|
||||
'content.gyp:content_browser',
|
||||
'content.gyp:content_common',
|
||||
'content_common_mojo_bindings.gyp:content_common_mojo_bindings',
|
||||
'test_support_content',
|
||||
'../base/base.gyp:test_support_base',
|
||||
'../crypto/crypto.gyp:crypto',
|
||||
@ -1155,6 +1158,7 @@
|
||||
'content.gyp:content_renderer',
|
||||
'content.gyp:content_resources',
|
||||
'content_browser_test_support',
|
||||
'content_common_mojo_bindings.gyp:content_common_mojo_bindings',
|
||||
'content_shell_lib',
|
||||
'content_shell_pak',
|
||||
'test_support_content',
|
||||
|
@ -226,6 +226,14 @@ void ContentBrowserClient::RequestPermission(
|
||||
result_callback.Run(true);
|
||||
}
|
||||
|
||||
PermissionStatus ContentBrowserClient::GetPermissionStatus(
|
||||
PermissionType permission,
|
||||
BrowserContext* browser_context,
|
||||
const GURL& requesting_origin,
|
||||
const GURL& embedding_origin) {
|
||||
return PERMISSION_STATUS_DENIED;
|
||||
}
|
||||
|
||||
bool ContentBrowserClient::CanCreateWindow(
|
||||
const GURL& opener_url,
|
||||
const GURL& opener_top_level_frame_url,
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include "content/public/browser/permission_type.h"
|
||||
#include "content/public/common/content_client.h"
|
||||
#include "content/public/common/media_stream_request.h"
|
||||
#include "content/public/common/permission_status.mojom.h"
|
||||
#include "content/public/common/resource_type.h"
|
||||
#include "content/public/common/socket_permission_request.h"
|
||||
#include "content/public/common/window_container_type.h"
|
||||
@ -438,6 +439,12 @@ class CONTENT_EXPORT ContentBrowserClient {
|
||||
const GURL& frame_url,
|
||||
const GURL& main_frame_url) {}
|
||||
|
||||
virtual PermissionStatus GetPermissionStatus(
|
||||
PermissionType permission,
|
||||
BrowserContext* browser_context,
|
||||
const GURL& requesting_origin,
|
||||
const GURL& embedding_origin);
|
||||
|
||||
// Returns true if the given page is allowed to open a window of the given
|
||||
// type. If true is returned, |no_javascript_access| will indicate whether
|
||||
// the window that is created should be scriptable/in the same process.
|
||||
|
@ -52,5 +52,6 @@ source_set("common_sources") {
|
||||
mojom("mojo_bindings") {
|
||||
sources = [
|
||||
"mojo_geoposition.mojom",
|
||||
"permission_status.mojom",
|
||||
]
|
||||
}
|
||||
|
11
content/public/common/permission_status.mojom
Normal file
11
content/public/common/permission_status.mojom
Normal file
@ -0,0 +1,11 @@
|
||||
// Copyright 2014 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
module content;
|
||||
|
||||
enum PermissionStatus {
|
||||
GRANTED,
|
||||
DENIED,
|
||||
ASK
|
||||
};
|
Reference in New Issue
Block a user