Commit 7adb26a7 authored by hanxi@chromium.org's avatar hanxi@chromium.org

WebViewGuest is growing fairly large (~ 1600 lines). This CL aims to move all...

WebViewGuest is growing fairly large (~ 1600 lines). This CL aims to move all permission related code to a new helper class WebViewPermissionHelper:

- Rename PluginPermissionHelper to WebViewPermissionHelper;
- Move permission request code:
--- Include permissions: Download, PointerLock, Media, Geolocation, FileSystem, Plugin;
--- Not include: New Window API, Dialog API.

Review URL: https://codereview.chromium.org/347113002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@282080 0039d316-1c4b-4281-b951-d872f2087c98
parent f695672d
......@@ -9,6 +9,7 @@
#include "chrome/browser/extensions/api/context_menus/context_menus_api.h"
#include "chrome/browser/extensions/api/context_menus/context_menus_api_helpers.h"
#include "chrome/browser/extensions/tab_helper.h"
#include "chrome/browser/guest_view/web_view/web_view_permission_helper.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/extensions/api/web_view_internal.h"
#include "content/public/browser/render_process_host.h"
......@@ -505,13 +506,14 @@ bool WebViewInternalSetPermissionFunction::RunAsyncSafe(WebViewGuest* guest) {
webview::SetPermission::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params.get());
WebViewGuest::PermissionResponseAction action = WebViewGuest::DEFAULT;
WebViewPermissionHelper::PermissionResponseAction action =
WebViewPermissionHelper::DEFAULT;
switch (params->action) {
case Params::ACTION_ALLOW:
action = WebViewGuest::ALLOW;
action = WebViewPermissionHelper::ALLOW;
break;
case Params::ACTION_DENY:
action = WebViewGuest::DENY;
action = WebViewPermissionHelper::DENY;
break;
case Params::ACTION_DEFAULT:
break;
......@@ -523,13 +525,18 @@ bool WebViewInternalSetPermissionFunction::RunAsyncSafe(WebViewGuest* guest) {
if (params->user_input)
user_input = *params->user_input;
WebViewGuest::SetPermissionResult result =
guest->SetPermission(params->request_id, action, user_input);
WebViewPermissionHelper* web_view_permission_helper =
WebViewPermissionHelper:: FromWebContents(guest->guest_web_contents());
EXTENSION_FUNCTION_VALIDATE(result != WebViewGuest::SET_PERMISSION_INVALID);
WebViewPermissionHelper::SetPermissionResult result =
web_view_permission_helper->SetPermission(
params->request_id, action, user_input);
EXTENSION_FUNCTION_VALIDATE(
result != WebViewPermissionHelper::SET_PERMISSION_INVALID);
SetResult(base::Value::CreateBooleanValue(
result == WebViewGuest::SET_PERMISSION_ALLOWED));
result == WebViewPermissionHelper::SET_PERMISSION_ALLOWED));
SendResponse(true);
return true;
}
......
......@@ -9,7 +9,7 @@
#if defined(ENABLE_EXTENSIONS)
#include "chrome/browser/content_settings/permission_request_id.h"
#include "chrome/browser/extensions/suggest_permission_util.h"
#include "chrome/browser/guest_view/web_view/web_view_guest.h"
#include "chrome/browser/guest_view/web_view/web_view_permission_helper.h"
#include "chrome/browser/profiles/profile.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/process_map.h"
......@@ -41,12 +41,11 @@ bool GeolocationPermissionContextExtensions::RequestPermission(
#if defined(ENABLE_EXTENSIONS)
GURL requesting_frame_origin = requesting_frame.GetOrigin();
WebViewGuest* guest = WebViewGuest::FromWebContents(web_contents);
if (guest) {
guest->RequestGeolocationPermission(bridge_id,
requesting_frame,
user_gesture,
callback);
WebViewPermissionHelper* web_view_permission_helper =
WebViewPermissionHelper::FromWebContents(web_contents);
if (web_view_permission_helper) {
web_view_permission_helper->RequestGeolocationPermission(
bridge_id, requesting_frame, user_gesture, callback);
*permission_set = false;
*new_permission = false;
return true;
......@@ -91,10 +90,11 @@ bool GeolocationPermissionContextExtensions::CancelPermissionRequest(
content::WebContents* web_contents,
int bridge_id) {
#if defined(ENABLE_EXTENSIONS)
WebViewGuest* guest =
web_contents ? WebViewGuest::FromWebContents(web_contents) : NULL;
if (guest) {
guest->CancelGeolocationPermissionRequest(bridge_id);
WebViewPermissionHelper* web_view_permission_helper =
web_contents ? WebViewPermissionHelper::FromWebContents(web_contents)
: NULL;
if (web_view_permission_helper) {
web_view_permission_helper->CancelGeolocationPermissionRequest(bridge_id);
return true;
}
#endif // defined(ENABLE_EXTENSIONS)
......
......@@ -302,7 +302,7 @@ GuestViewBase::~GuestViewBase() {
pending_events_.clear();
}
void GuestViewBase::DispatchEvent(Event* event) {
void GuestViewBase::DispatchEventToEmbedder(Event* event) {
scoped_ptr<Event> event_ptr(event);
if (!in_extension()) {
NOTREACHED();
......@@ -337,7 +337,7 @@ void GuestViewBase::SendQueuedEvents() {
while (!pending_events_.empty()) {
linked_ptr<Event> event_ptr = pending_events_.front();
pending_events_.pop_front();
DispatchEvent(event_ptr.release());
DispatchEventToEmbedder(event_ptr.release());
}
}
......
......@@ -204,15 +204,15 @@ class GuestViewBase : public content::BrowserPluginGuestDelegate,
content::WebContents* embedder_web_contents,
const base::DictionaryValue& extra_params) OVERRIDE FINAL;
// Dispatches an event |event_name| to the embedder with the |event| fields.
void DispatchEventToEmbedder(Event* event);
protected:
GuestViewBase(content::BrowserContext* browser_context,
int guest_instance_id);
virtual ~GuestViewBase();
// Dispatches an event |event_name| to the embedder with the |event| fields.
void DispatchEvent(Event* event);
private:
class EmbedderWebContentsObserver;
......
......@@ -9,6 +9,7 @@
#include "chrome/browser/guest_view/guest_view_constants.h"
#include "chrome/browser/guest_view/web_view/web_view_constants.h"
#include "chrome/browser/guest_view/web_view/web_view_guest.h"
#include "chrome/browser/guest_view/web_view/web_view_permission_helper.h"
#include "chrome/browser/guest_view/web_view/web_view_permission_types.h"
namespace {
......@@ -31,7 +32,7 @@ std::string JavaScriptMessageTypeToString(
} // namespace
JavaScriptDialogHelper::JavaScriptDialogHelper(WebViewGuest* guest)
: webview_guest_(guest) {
: web_view_guest_(guest) {
}
JavaScriptDialogHelper::~JavaScriptDialogHelper() {
......@@ -56,7 +57,9 @@ void JavaScriptDialogHelper::RunJavaScriptDialog(
new base::StringValue(
JavaScriptMessageTypeToString(javascript_message_type)));
request_info.Set(guestview::kUrl, new base::StringValue(origin_url.spec()));
webview_guest_->RequestPermission(
WebViewPermissionHelper* web_view_permission_helper =
WebViewPermissionHelper::FromWebContents(web_contents);
web_view_permission_helper->RequestPermission(
WEB_VIEW_PERMISSION_TYPE_JAVASCRIPT_DIALOG,
request_info,
base::Bind(&JavaScriptDialogHelper::OnPermissionResponse,
......@@ -94,6 +97,6 @@ void JavaScriptDialogHelper::OnPermissionResponse(
const DialogClosedCallback& callback,
bool allow,
const std::string& user_input) {
callback.Run(allow && webview_guest_->attached(),
callback.Run(allow && web_view_guest_->attached(),
base::UTF8ToUTF16(user_input));
}
......@@ -45,7 +45,7 @@ class JavaScriptDialogHelper : public content::JavaScriptDialogManager {
const std::string& user_input);
// Pointer to the webview that is being helped.
WebViewGuest* const webview_guest_;
WebViewGuest* const web_view_guest_;
DISALLOW_COPY_AND_ASSIGN(JavaScriptDialogHelper);
};
......
// 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.
#include "chrome/browser/guest_view/web_view/plugin_permission_helper.h"
#include "chrome/browser/guest_view/web_view/web_view_guest.h"
#include "chrome/browser/guest_view/web_view/web_view_permission_types.h"
#include "chrome/browser/plugins/chrome_plugin_service_filter.h"
#include "chrome/common/render_messages.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/user_metrics.h"
using content::BrowserPluginGuestDelegate;
using content::RenderViewHost;
using content::WebContents;
DEFINE_WEB_CONTENTS_USER_DATA_KEY(PluginPermissionHelper);
PluginPermissionHelper::PluginPermissionHelper(WebContents* contents)
: content::WebContentsObserver(contents),
weak_factory_(this) {
}
PluginPermissionHelper::~PluginPermissionHelper() {
}
bool PluginPermissionHelper::OnMessageReceived(
const IPC::Message& message,
content::RenderFrameHost* render_frame_host) {
IPC_BEGIN_MESSAGE_MAP(PluginPermissionHelper, message)
IPC_MESSAGE_HANDLER(ChromeViewHostMsg_BlockedOutdatedPlugin,
OnBlockedOutdatedPlugin)
IPC_MESSAGE_HANDLER(ChromeViewHostMsg_BlockedUnauthorizedPlugin,
OnBlockedUnauthorizedPlugin)
IPC_MESSAGE_HANDLER(ChromeViewHostMsg_NPAPINotSupported,
OnNPAPINotSupported)
#if defined(ENABLE_PLUGIN_INSTALLATION)
IPC_MESSAGE_HANDLER(ChromeViewHostMsg_FindMissingPlugin,
OnFindMissingPlugin)
#endif
IPC_MESSAGE_UNHANDLED(return false)
IPC_END_MESSAGE_MAP()
return true;
}
bool PluginPermissionHelper::OnMessageReceived(const IPC::Message& message) {
IPC_BEGIN_MESSAGE_MAP(PluginPermissionHelper, message)
IPC_MESSAGE_HANDLER(ChromeViewHostMsg_CouldNotLoadPlugin,
OnCouldNotLoadPlugin)
IPC_MESSAGE_HANDLER(ChromeViewHostMsg_OpenAboutPlugins,
OnOpenAboutPlugins)
#if defined(ENABLE_PLUGIN_INSTALLATION)
IPC_MESSAGE_HANDLER(ChromeViewHostMsg_RemovePluginPlaceholderHost,
OnRemovePluginPlaceholderHost)
#endif
IPC_MESSAGE_UNHANDLED(return false)
IPC_END_MESSAGE_MAP()
return true;
}
void PluginPermissionHelper::OnBlockedUnauthorizedPlugin(
const base::string16& name,
const std::string& identifier) {
const char kPluginName[] = "name";
const char kPluginIdentifier[] = "identifier";
WebViewGuest* webview = WebViewGuest::FromWebContents(web_contents());
if (!webview)
return;
base::DictionaryValue info;
info.SetString(std::string(kPluginName), name);
info.SetString(std::string(kPluginIdentifier), identifier);
webview->RequestPermission(
WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN,
info,
base::Bind(&PluginPermissionHelper::OnPermissionResponse,
weak_factory_.GetWeakPtr(),
identifier),
true /* allowed_by_default */);
content::RecordAction(
base::UserMetricsAction("WebView.Guest.PluginLoadRequest"));
}
void PluginPermissionHelper::OnCouldNotLoadPlugin(
const base::FilePath& plugin_path) {
}
void PluginPermissionHelper::OnBlockedOutdatedPlugin(
int placeholder_id,
const std::string& identifier) {
}
void PluginPermissionHelper::OnNPAPINotSupported(const std::string& id) {
}
void PluginPermissionHelper::OnOpenAboutPlugins() {
}
#if defined(ENABLE_PLUGIN_INSTALLATION)
void PluginPermissionHelper::OnFindMissingPlugin(int placeholder_id,
const std::string& mime_type) {
Send(new ChromeViewMsg_DidNotFindMissingPlugin(placeholder_id));
}
void PluginPermissionHelper::OnRemovePluginPlaceholderHost(int placeholder_id) {
}
#endif // defined(ENABLE_PLUGIN_INSTALLATION)
void PluginPermissionHelper::OnPermissionResponse(const std::string& identifier,
bool allow,
const std::string& input) {
if (allow) {
ChromePluginServiceFilter::GetInstance()->AuthorizeAllPlugins(
web_contents(), true, identifier);
}
}
// 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.
#ifndef CHROME_BROWSER_GUEST_VIEW_WEB_VIEW_PLUGIN_PERMISSION_HELPER_H_
#define CHROME_BROWSER_GUEST_VIEW_WEB_VIEW_PLUGIN_PERMISSION_HELPER_H_
#include "base/memory/weak_ptr.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/browser/web_contents_user_data.h"
class PluginPermissionHelper
: public content::WebContentsUserData<PluginPermissionHelper>,
public content::WebContentsObserver {
public:
virtual ~PluginPermissionHelper();
private:
explicit PluginPermissionHelper(content::WebContents* web_contents);
friend class content::WebContentsUserData<PluginPermissionHelper>;
// content::WebContentsObserver implementation.
virtual bool OnMessageReceived(
const IPC::Message& message,
content::RenderFrameHost* render_frame_host) OVERRIDE;
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
// Message handlers:
void OnBlockedUnauthorizedPlugin(const base::string16& name,
const std::string& identifier);
void OnCouldNotLoadPlugin(const base::FilePath& plugin_path);
void OnBlockedOutdatedPlugin(int placeholder_id,
const std::string& identifier);
void OnNPAPINotSupported(const std::string& identifier);
void OnOpenAboutPlugins();
#if defined(ENABLE_PLUGIN_INSTALLATION)
void OnFindMissingPlugin(int placeholder_id, const std::string& mime_type);
void OnRemovePluginPlaceholderHost(int placeholder_id);
#endif
void OnPermissionResponse(const std::string& identifier,
bool allow,
const std::string& user_input);
base::WeakPtrFactory<PluginPermissionHelper> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(PluginPermissionHelper);
};
#endif // CHROME_BROWSER_GUEST_VIEW_WEB_VIEW_PLUGIN_PERMISSION_HELPER_H_
......@@ -35,7 +35,7 @@ void WebViewFindHelper::DispatchFindUpdateEvent(bool canceled,
args->SetBoolean(webview::kFindCanceled, canceled);
args->SetBoolean(webview::kFindFinalUpdate, final_update);
DCHECK(webview_guest_);
webview_guest_->DispatchEvent(
webview_guest_->DispatchEventToEmbedder(
new GuestViewBase::Event(webview::kEventFindReply, args.Pass()));
}
......
......@@ -12,6 +12,7 @@
#include "chrome/browser/guest_view/guest_view.h"
#include "chrome/browser/guest_view/web_view/javascript_dialog_helper.h"
#include "chrome/browser/guest_view/web_view/web_view_find_helper.h"
#include "chrome/browser/guest_view/web_view/web_view_permission_helper.h"
#include "chrome/browser/guest_view/web_view/web_view_permission_types.h"
#include "chrome/common/extensions/api/web_view_internal.h"
#include "content/public/browser/javascript_dialog_manager.h"
......@@ -203,25 +204,6 @@ class WebViewGuest : public GuestView<WebViewGuest>,
bool allowed_by_default,
const base::Callback<void(bool)>& callback);
enum PermissionResponseAction {
DENY,
ALLOW,
DEFAULT
};
enum SetPermissionResult {
SET_PERMISSION_INVALID,
SET_PERMISSION_ALLOWED,
SET_PERMISSION_DENIED
};
// Responds to the permission request |request_id| with |action| and
// |user_input|. Returns whether there was a pending request for the provided
// |request_id|.
SetPermissionResult SetPermission(int request_id,
PermissionResponseAction action,
const std::string& user_input);
// Overrides the user agent for this guest.
// This affects subsequent guest navigations.
void SetUserAgentOverride(const std::string& user_agent_override);
......@@ -244,105 +226,20 @@ class WebViewGuest : public GuestView<WebViewGuest>,
return script_executor_.get();
}
// Called when file system access is requested by the guest content using the
// asynchronous HTML5 file system API. The request is plumbed through the
// <webview> permission request API. The request will be:
// - Allowed if the embedder explicitly allowed it.
// - Denied if the embedder explicitly denied.
// - Determined by the guest's content settings if the embedder does not
// perform an explicit action.
// If access was blocked due to the page's content settings,
// |blocked_by_policy| should be true, and this function should invoke
// OnContentBlocked.
static void FileSystemAccessedAsync(int render_process_id,
int render_frame_id,
int request_id,
const GURL& url,
bool blocked_by_policy);
// Called when file system access is requested by the guest content using the
// synchronous HTML5 file system API in a worker thread or shared worker. The
// request is plumbed through the <webview> permission request API. The
// request will be:
// - Allowed if the embedder explicitly allowed it.
// - Denied if the embedder explicitly denied.
// - Determined by the guest's content settings if the embedder does not
// perform an explicit action.
// If access was blocked due to the page's content settings,
// |blocked_by_policy| should be true, and this function should invoke
// OnContentBlocked.
static void FileSystemAccessedSync(int render_process_id,
int render_frame_id,
const GURL& url,
bool blocked_by_policy,
IPC::Message* reply_msg);
private:
friend class WebViewPermissionHelper;
virtual ~WebViewGuest();
// A map to store the callback for a request keyed by the request's id.
struct PermissionResponseInfo {
PermissionResponseCallback callback;
WebViewPermissionType permission_type;
bool allowed_by_default;
PermissionResponseInfo();
PermissionResponseInfo(const PermissionResponseCallback& callback,
WebViewPermissionType permission_type,
bool allowed_by_default);
~PermissionResponseInfo();
};
static void RecordUserInitiatedUMA(const PermissionResponseInfo& info,
bool allow);
// Returns the top level items (ignoring submenus) as Value.
static scoped_ptr<base::ListValue> MenuModelToValue(
const ui::SimpleMenuModel& menu_model);
void OnWebViewGeolocationPermissionResponse(
int bridge_id,
bool user_gesture,
const base::Callback<void(bool)>& callback,
bool allow,
const std::string& user_input);
void OnWebViewFileSystemPermissionResponse(
const base::Callback<void(bool)>& callback,
bool allow,
const std::string& user_input);
void OnWebViewMediaPermissionResponse(
const content::MediaStreamRequest& request,
const content::MediaResponseCallback& callback,
bool allow,
const std::string& user_input);
void OnWebViewDownloadPermissionResponse(
const base::Callback<void(bool)>& callback,
bool allow,
const std::string& user_input);
void OnWebViewPointerLockPermissionResponse(
const base::Callback<void(bool)>& callback,
bool allow,
const std::string& user_input);
void AttachWebViewHelpers(content::WebContents* contents);
void OnWebViewNewWindowResponse(int new_window_instance_id,
bool allow,
const std::string& user_input);
static void FileSystemAccessedAsyncResponse(int render_process_id,
int render_frame_id,
int request_id,
const GURL& url,
bool allowed);
static void FileSystemAccessedSyncResponse(int render_process_id,
int render_frame_id,
const GURL& url,
IPC::Message* reply_msg,
bool allowed);
// WebContentsObserver implementation.
virtual void DidCommitProvisionalLoadForFrame(
content::RenderFrameHost* render_frame_host,
......@@ -390,11 +287,6 @@ class WebViewGuest : public GuestView<WebViewGuest>,
void InjectChromeVoxIfNeeded(content::RenderViewHost* render_view_host);
// Bridge IDs correspond to a geolocation request. This method will remove
// the bookkeeping for a particular geolocation request associated with the
// provided |bridge_id|. It returns the request ID of the geolocation request.
int RemoveBridgeID(int bridge_id);
void LoadURLWithParams(const GURL& url,
const content::Referrer& referrer,
content::PageTransition transition_type,
......@@ -439,13 +331,6 @@ class WebViewGuest : public GuestView<WebViewGuest>,
// We only need the ids to be unique for a given WebViewGuest.
int pending_context_menu_request_id_;
// A counter to generate a unique request id for a permission request.
// We only need the ids to be unique for a given WebViewGuest.
int next_permission_request_id_;
typedef std::map<int, PermissionResponseInfo> RequestMap;
RequestMap pending_permission_requests_;
// True if the user agent is overridden.
bool is_overriding_user_agent_;
......@@ -464,6 +349,9 @@ class WebViewGuest : public GuestView<WebViewGuest>,
// Handles the JavaScript dialog requests.
JavaScriptDialogHelper javascript_dialog_helper_;
// Handels permission requests.
scoped_ptr<WebViewPermissionHelper> web_view_permission_helper_;
friend void WebViewFindHelper::DispatchFindUpdateEvent(bool canceled,
bool final_update);
......@@ -477,8 +365,6 @@ class WebViewGuest : public GuestView<WebViewGuest>,
accessibility_subscription_;
#endif
std::map<int, int> bridge_id_to_request_id_map_;
// Tracks the name, and target URL of the new window. Once the first
// navigation commits, we no longer track this information.
struct NewWindowInfo {
......
// 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.
#ifndef CHROME_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_PERMISSION_HELPER_H_
#define CHROME_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_PERMISSION_HELPER_H_
#include "base/memory/weak_ptr.h"
#include "base/metrics/user_metrics_action.h"
#include "chrome/browser/guest_view/guest_view_constants.h"
#include "chrome/browser/guest_view/web_view/web_view_permission_types.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/common/media_stream_request.h"
using base::UserMetricsAction;
class WebViewGuest;
// WebViewPermissionHelper manages <webview> permission requests. This helper
// class is owned by WebViewGuest. Its purpose is to request permission for
// various operations from the <webview> embedder, and reply back via callbacks
// to the callers on a response from the embedder.
class WebViewPermissionHelper
: public content::WebContentsObserver {
public:
explicit WebViewPermissionHelper(WebViewGuest* guest);
virtual ~WebViewPermissionHelper();
typedef base::Callback<
void(bool /* allow */, const std::string& /* user_input */)>
PermissionResponseCallback;
// A map to store the callback for a request keyed by the request's id.
struct PermissionResponseInfo {
PermissionResponseCallback callback;
WebViewPermissionType permission_type;
bool allowed_by_default;
PermissionResponseInfo();
PermissionResponseInfo(const PermissionResponseCallback& callback,
WebViewPermissionType permission_type,
bool allowed_by_default);
~PermissionResponseInfo();
};
typedef std::map<int, PermissionResponseInfo> RequestMap;
int RequestPermission(WebViewPermissionType permission_type,
const base::DictionaryValue& request_info,
const PermissionResponseCallback& callback,
bool allowed_by_default);
static WebViewPermissionHelper* FromWebContents(
content::WebContents* web_contents);
static WebViewPermissionHelper* FromFrameID(int render_process_id,
int render_frame_id);
void RequestMediaAccessPermission(
content::WebContents* source,
const content::MediaStreamRequest& request,
const content::MediaResponseCallback& callback);
void CanDownload(content::RenderViewHost* render_view_host,
const GURL& url,
const std::string& request_method,
const base::Callback<void(bool)>& callback);
void RequestPointerLockPermission(bool user_gesture,
bool last_unlocked_by_target,
const base::Callback<void(bool)>& callback);
// Requests Geolocation Permission from the embedder.
void RequestGeolocationPermission(int bridge_id,
const GURL& requesting_frame,
bool user_gesture,
const base::Callback<void(bool)>& callback);
void CancelGeolocationPermissionRequest(int bridge_id);
void RequestFileSystemPermission(const GURL& url,
bool allowed_by_default,
const base::Callback<void(bool)>& callback);
// Called when file system access is requested by the guest content using the
// asynchronous HTML5 file system API. The request is plumbed through the
// <webview> permission request API. The request will be:
// - Allowed if the embedder explicitly allowed it.
// - Denied if the embedder explicitly denied.
// - Determined by the guest's content settings if the embedder does not
// perform an explicit action.
// If access was blocked due to the page's content settings,
// |blocked_by_policy| should be true, and this function should invoke
// OnContentBlocked.
void FileSystemAccessedAsync(int render_process_id,
int render_frame_id,
int request_id,
const GURL& url,
bool blocked_by_policy);
// Called when file system access is requested by the guest content using the
// synchronous HTML5 file system API in a worker thread or shared worker. The
// request is plumbed through the <webview> permission request API. The
// request will be:
// - Allowed if the embedder explicitly allowed it.
// - Denied if the embedder explicitly denied.
// - Determined by the guest's content settings if the embedder does not
// perform an explicit action.
// If access was blocked due to the page's content settings,
// |blocked_by_policy| should be true, and this function should invoke
// OnContentBlocked.
void FileSystemAccessedSync(int render_process_id,
int render_frame_id,
const GURL& url,
bool blocked_by_policy,
IPC::Message* reply_msg);
enum PermissionResponseAction { DENY, ALLOW, DEFAULT };
enum SetPermissionResult {
SET_PERMISSION_INVALID,
SET_PERMISSION_ALLOWED,
SET_PERMISSION_DENIED
};
// Responds to the permission request |request_id| with |action| and
// |user_input|. Returns whether there was a pending request for the provided
// |request_id|.
SetPermissionResult SetPermission(int request_id,
PermissionResponseAction action,
const std::string& user_input);
private:
#if defined(ENABLE_PLUGINS)
// content::WebContentsObserver implementation.
virtual bool OnMessageReceived(
const IPC::Message& message,
content::RenderFrameHost* render_frame_host) OVERRIDE;
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
// Message handlers:
void OnBlockedUnauthorizedPlugin(const base::string16& name,
const std::string& identifier);
void OnCouldNotLoadPlugin(const base::FilePath& plugin_path);
void OnBlockedOutdatedPlugin(int placeholder_id,
const std::string& identifier);
void OnNPAPINotSupported(const std::string& identifier);
void OnOpenAboutPlugins();
#if defined(ENABLE_PLUGIN_INSTALLATION)
void OnFindMissingPlugin(int placeholder_id, const std::string& mime_type);
void OnRemovePluginPlaceholderHost(int placeholder_id);
#endif // defined(ENABLE_PLUGIN_INSTALLATION)
void OnPermissionResponse(const std::string& identifier,
bool allow,
const std::string& user_input);
#endif // defiend(ENABLE_PLUGINS)
void OnGeolocationPermissionResponse(
int bridge_id,
bool user_gesture,
const base::Callback<void(bool)>& callback,
bool allow,
const std::string& user_input);
void OnFileSystemPermissionResponse(
const base::Callback<void(bool)>& callback,
bool allow,
const std::string& user_input);
void OnMediaPermissionResponse(
const content::MediaStreamRequest& request,
const content::MediaResponseCallback& callback,
bool allow,
const std::string& user_input);
void OnDownloadPermissionResponse(
const base::Callback<void(bool)>& callback,
bool allow,
const std::string& user_input);
void OnPointerLockPermissionResponse(
const base::Callback<void(bool)>& callback,
bool allow,
const std::string& user_input);
// Bridge IDs correspond to a geolocation request. This method will remove
// the bookkeeping for a particular geolocation request associated with the
// provided |bridge_id|. It returns the request ID of the geolocation request.
int RemoveBridgeID(int bridge_id);
void FileSystemAccessedAsyncResponse(int render_process_id,
int render_frame_id,
int request_id,
const GURL& url,
bool allowed);
void FileSystemAccessedSyncResponse(int render_process_id,
int render_frame_id,
const GURL& url,
IPC::Message* reply_msg,
bool allowed);
// A counter to generate a unique request id for a permission request.
// We only need the ids to be unique for a given WebViewGuest.
int next_permission_request_id_;
WebViewPermissionHelper::RequestMap pending_permission_requests_;
std::map<int, int> bridge_id_to_request_id_map_;
WebViewGuest* web_view_guest_;
base::WeakPtrFactory<WebViewPermissionHelper> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(WebViewPermissionHelper);
};
#endif // CHROME_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_PERMISSION_HELPER_H_
......@@ -14,7 +14,7 @@
#include "chrome/browser/content_settings/tab_specific_content_settings.h"
#if defined(ENABLE_EXTENSIONS)
#include "chrome/browser/guest_view/web_view/web_view_guest.h"
#include "chrome/browser/guest_view/web_view/web_view_permission_helper.h"
#include "chrome/browser/guest_view/web_view/web_view_renderer_state.h"
#endif
......@@ -208,14 +208,16 @@ void ChromeRenderMessageFilter::OnRequestFileSystemAccessSync(
WebViewRendererState::GetInstance()->IsGuest(render_process_id_);
if (is_web_view_guest) {
// Record access to file system for potential display in UI.
BrowserThread::PostTask(BrowserThread::UI,
FROM_HERE,
base::Bind(&WebViewGuest::FileSystemAccessedSync,
render_process_id_,
render_frame_id,
origin_url,
!allowed,
reply_msg));
BrowserThread::PostTask(
BrowserThread::UI,
FROM_HERE,
base::Bind(&ChromeRenderMessageFilter::
FileSystemAccessedSyncOnUIThread,
render_process_id_,
render_frame_id,
origin_url,
!allowed,
reply_msg));
return;
}
#endif
......@@ -233,6 +235,24 @@ void ChromeRenderMessageFilter::OnRequestFileSystemAccessSync(
!allowed));
}
#if defined(ENABLE_EXTENSIONS)
void ChromeRenderMessageFilter::FileSystemAccessedSyncOnUIThread(
int render_process_id,
int render_frame_id,
const GURL& url,
bool blocked_by_policy,
IPC::Message* reply_msg) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
WebViewPermissionHelper* web_view_permission_helper =
WebViewPermissionHelper::FromFrameID(render_process_id, render_frame_id);
web_view_permission_helper->FileSystemAccessedSync(render_process_id,
render_frame_id,
url,
blocked_by_policy,
reply_msg);
}
#endif
void ChromeRenderMessageFilter::OnRequestFileSystemAccessAsync(
int render_frame_id,
int request_id,
......@@ -248,14 +268,16 @@ void ChromeRenderMessageFilter::OnRequestFileSystemAccessAsync(
WebViewRendererState::GetInstance()->IsGuest(render_process_id_);
if (is_web_view_guest) {
// Record access to file system for potential display in UI.
BrowserThread::PostTask(BrowserThread::UI,
FROM_HERE,
base::Bind(&WebViewGuest::FileSystemAccessedAsync,
render_process_id_,
render_frame_id,
request_id,
origin_url,
!allowed));
BrowserThread::PostTask(
BrowserThread::UI,
FROM_HERE,
base::Bind(&ChromeRenderMessageFilter::
FileSystemAccessedAsyncOnUIThread,
render_process_id_,
render_frame_id,
request_id,
origin_url,
!allowed));
return;
}
#endif
......@@ -273,6 +295,24 @@ void ChromeRenderMessageFilter::OnRequestFileSystemAccessAsync(
!allowed));
}
#if defined(ENABLE_EXTENSIONS)
void ChromeRenderMessageFilter::FileSystemAccessedAsyncOnUIThread(
int render_process_id,
int render_frame_id,
int request_id,
const GURL& url,
bool blocked_by_policy) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
WebViewPermissionHelper* web_view_permission_helper =
WebViewPermissionHelper::FromFrameID(render_process_id, render_frame_id);
web_view_permission_helper->FileSystemAccessedAsync(render_process_id,
render_frame_id,
request_id,
url,
blocked_by_policy);
}
#endif
void ChromeRenderMessageFilter::OnAllowIndexedDB(int render_frame_id,
const GURL& origin_url,
const GURL& top_origin_url,
......
......@@ -76,10 +76,27 @@ class ChromeRenderMessageFilter : public content::BrowserMessageFilter {
const GURL& origin_url,
const GURL& top_origin_url,
IPC::Message* message);
#if defined(ENABLE_EXTENSIONS)
static void FileSystemAccessedSyncOnUIThread(
int render_process_id,
int render_frame_id,
const GURL& url,
bool blocked_by_policy,
IPC::Message* reply_msg);
#endif
void OnRequestFileSystemAccessAsync(int render_frame_id,
int request_id,
const GURL& origin_url,
const GURL& top_origin_url);
#if defined(ENABLE_EXTENSIONS)
static void FileSystemAccessedAsyncOnUIThread(
int render_process_id,
int render_frame_id,
int request_id,
const GURL& url,
bool blocked_by_policy);
#endif
void OnAllowIndexedDB(int render_frame_id,
const GURL& origin_url,
const GURL& top_origin_url,
......
......@@ -1526,6 +1526,8 @@
'browser/guest_view/web_view/web_view_guest.cc',
'browser/guest_view/web_view/web_view_guest.h',
'browser/guest_view/web_view/web_view_permission_types.h',
'browser/guest_view/web_view/web_view_permission_helper.cc',
'browser/guest_view/web_view/web_view_permission_helper.h',
'browser/guest_view/web_view/web_view_renderer_state.cc',
'browser/guest_view/web_view/web_view_renderer_state.h',
'browser/infobars/infobar_extension_api.cc',
......@@ -1761,8 +1763,6 @@
],
# See also the plugin_installation_sources list below.
'chrome_browser_plugins_sources': [
'browser/guest_view/web_view/plugin_permission_helper.cc',
'browser/guest_view/web_view/plugin_permission_helper.h',
'browser/metrics/plugin_metrics_provider.cc',
'browser/metrics/plugin_metrics_provider.h',
'browser/pepper_broker_infobar_delegate.cc',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment