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

Unified Diff: chrome/browser/download/download_request_limiter.cc

Issue 13037003: permissionrequest API for guest Download. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync. Created 7 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/download/download_request_limiter.cc
diff --git a/chrome/browser/download/download_request_limiter.cc b/chrome/browser/download/download_request_limiter.cc
index f09ff68e59a6e8288f4b80abfcc5d627bdaf7917..a22987698de171ce4655698d19d930036db078d3 100644
--- a/chrome/browser/download/download_request_limiter.cc
+++ b/chrome/browser/download/download_request_limiter.cc
@@ -16,6 +16,7 @@
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/notification_source.h"
#include "content/public/browser/notification_types.h"
+#include "content/public/browser/render_process_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_delegate.h"
@@ -208,7 +209,8 @@ void DownloadRequestLimiter::TabDownloadState::NotifyCallbacks(bool allow) {
// DownloadRequestLimiter ------------------------------------------------------
-DownloadRequestLimiter::DownloadRequestLimiter() {
+DownloadRequestLimiter::DownloadRequestLimiter()
+ : factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
}
DownloadRequestLimiter::~DownloadRequestLimiter() {
@@ -273,6 +275,36 @@ void DownloadRequestLimiter::CanDownload(int render_process_host_id,
return;
}
+ if (!originating_contents->GetDelegate()) {
+ ScheduleNotification(callback, false);
+ return;
+ }
+
+ if (originating_contents->GetRenderProcessHost()->IsGuest()) {
+ // Decide asynchronously for BrowserPluginGuest.
+ base::Callback<void(bool)> wrapped_callback = base::Bind(
+ &DownloadRequestLimiter::OnCanDownloadDecidedAsync,
+ factory_.GetWeakPtr(),
+ originating_contents, request_id, request_method, callback);
+ originating_contents->GetDelegate()->CanDownloadAsync(
+ originating_contents->GetRenderViewHost(),
+ request_id,
+ request_method,
+ wrapped_callback);
+ return;
+ } else {
+ // FYI: Chrome Frame overrides CanDownload in ExternalTabContainer in order
+ // to cancel the download operation in chrome and let the host browser
+ // take care of it.
+ if (!originating_contents->GetDelegate()->CanDownload(
+ originating_contents->GetRenderViewHost(),
+ request_id,
+ request_method)) {
+ ScheduleNotification(callback, false);
+ return;
+ }
+ }
+
CanDownloadImpl(
originating_contents,
request_id,
@@ -280,24 +312,28 @@ void DownloadRequestLimiter::CanDownload(int render_process_host_id,
callback);
}
+void DownloadRequestLimiter::OnCanDownloadDecidedAsync(
+ WebContents* originating_contents,
+ int request_id,
+ const std::string& request_method,
+ const Callback& orig_callback, bool allow) {
+ if (!allow) {
+ ScheduleNotification(orig_callback, false);
+ return;
+ }
+
+ CanDownloadImpl(originating_contents,
+ request_id,
+ request_method,
+ orig_callback);
+}
+
void DownloadRequestLimiter::CanDownloadImpl(WebContents* originating_contents,
int request_id,
const std::string& request_method,
const Callback& callback) {
DCHECK(originating_contents);
- // FYI: Chrome Frame overrides CanDownload in ExternalTabContainer in order
- // to cancel the download operation in chrome and let the host browser
- // take care of it.
- if (originating_contents->GetDelegate() &&
- !originating_contents->GetDelegate()->CanDownload(
- originating_contents->GetRenderViewHost(),
- request_id,
- request_method)) {
- ScheduleNotification(callback, false);
- return;
- }
-
// If the tab requesting the download is a constrained popup that is not
// shown, treat the request as if it came from the parent.
WebContents* effective_contents = originating_contents;

Powered by Google App Engine
This is Rietveld 408576698