summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authortommi@chromium.org <tommi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-07 02:35:04 +0000
committertommi@chromium.org <tommi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-07 02:35:04 +0000
commitfc6fb7fbf9aca6b58f8c99a08a6c376b95bbc1a3 (patch)
treeca9186ed7ddbeb19604b495430d9c9814df57471 /chrome
parentcfc076ec466fc48e91c309448c4e5be3467b42c7 (diff)
downloadchromium_src-fc6fb7fbf9aca6b58f8c99a08a6c376b95bbc1a3.zip
chromium_src-fc6fb7fbf9aca6b58f8c99a08a6c376b95bbc1a3.tar.gz
chromium_src-fc6fb7fbf9aca6b58f8c99a08a6c376b95bbc1a3.tar.bz2
Basic wiring to enable downloads for CF's host browser network stack. A notable change here is that url automation job id's no longer exist and instead a request id is used. There's a 1 to 1 relation between a job and a request so this is more convenient.
Review URL: http://codereview.chromium.org/355036 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31363 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/automation/automation_resource_message_filter.cc5
-rw-r--r--chrome/browser/automation/automation_resource_message_filter.h7
-rw-r--r--chrome/browser/automation/url_request_automation_job.cc36
-rw-r--r--chrome/browser/automation/url_request_automation_job.h6
-rw-r--r--chrome/browser/download/download_request_manager.cc8
-rw-r--r--chrome/browser/download/download_request_manager.h1
-rw-r--r--chrome/browser/download/download_request_manager_unittest.cc4
-rw-r--r--chrome/browser/external_tab_container.cc21
-rw-r--r--chrome/browser/external_tab_container.h3
-rw-r--r--chrome/browser/renderer_host/download_throttling_resource_handler.cc4
-rw-r--r--chrome/browser/renderer_host/download_throttling_resource_handler.h5
-rw-r--r--chrome/browser/tab_contents/tab_contents.cc7
-rw-r--r--chrome/browser/tab_contents/tab_contents.h4
-rw-r--r--chrome/browser/tab_contents/tab_contents_delegate.h4
-rw-r--r--chrome/test/automation/automation_messages_internal.h6
15 files changed, 85 insertions, 36 deletions
diff --git a/chrome/browser/automation/automation_resource_message_filter.cc b/chrome/browser/automation/automation_resource_message_filter.cc
index 953061e..e0512ca 100644
--- a/chrome/browser/automation/automation_resource_message_filter.cc
+++ b/chrome/browser/automation/automation_resource_message_filter.cc
@@ -20,7 +20,6 @@
AutomationResourceMessageFilter::RenderViewMap
AutomationResourceMessageFilter::filtered_render_views_;
-int AutomationResourceMessageFilter::unique_request_id_ = 1;
AutomationResourceMessageFilter::AutomationResourceMessageFilter()
: channel_(NULL) {
@@ -64,8 +63,8 @@ void AutomationResourceMessageFilter::OnChannelClosing() {
// Called on the IPC thread:
bool AutomationResourceMessageFilter::OnMessageReceived(
const IPC::Message& message) {
- int request_id = URLRequestAutomationJob::MayFilterMessage(message);
- if (request_id) {
+ int request_id;
+ if (URLRequestAutomationJob::MayFilterMessage(message, &request_id)) {
RequestMap::iterator it = request_map_.find(request_id);
if (it != request_map_.end()) {
URLRequestAutomationJob* job = it->second;
diff --git a/chrome/browser/automation/automation_resource_message_filter.h b/chrome/browser/automation/automation_resource_message_filter.h
index beb5fa8..ceb6115 100644
--- a/chrome/browser/automation/automation_resource_message_filter.h
+++ b/chrome/browser/automation/automation_resource_message_filter.h
@@ -39,10 +39,6 @@ class AutomationResourceMessageFilter
AutomationResourceMessageFilter();
virtual ~AutomationResourceMessageFilter();
- int NewRequestId() {
- return base::subtle::Barrier_AtomicIncrement(&unique_request_id_, 1);
- }
-
// IPC::ChannelProxy::MessageFilter methods:
virtual void OnFilterAdded(IPC::Channel* channel);
virtual void OnChannelConnected(int32 peer_pid);
@@ -98,9 +94,6 @@ class AutomationResourceMessageFilter
// owned by this class.
IPC::Channel* channel_;
- // A unique request id per process.
- static int unique_request_id_;
-
// Map of outstanding requests.
RequestMap request_map_;
diff --git a/chrome/browser/automation/url_request_automation_job.cc b/chrome/browser/automation/url_request_automation_job.cc
index 715e292..ead7aab 100644
--- a/chrome/browser/automation/url_request_automation_job.cc
+++ b/chrome/browser/automation/url_request_automation_job.cc
@@ -49,17 +49,16 @@ URLRequest::ProtocolFactory* URLRequestAutomationJob::old_http_factory_
URLRequest::ProtocolFactory* URLRequestAutomationJob::old_https_factory_
= NULL;
-URLRequestAutomationJob::URLRequestAutomationJob(
- URLRequest* request, int tab, AutomationResourceMessageFilter* filter)
- : URLRequestJob(request), id_(0), tab_(tab), message_filter_(filter),
- pending_buf_size_(0), redirect_status_(0) {
+URLRequestAutomationJob::URLRequestAutomationJob(URLRequest* request, int tab,
+ int request_id, AutomationResourceMessageFilter* filter)
+ : URLRequestJob(request),
+ id_(request_id),
+ tab_(tab),
+ message_filter_(filter),
+ pending_buf_size_(0),
+ redirect_status_(0) {
DLOG(INFO) << "URLRequestAutomationJob create. Count: " << ++instance_count_;
- if (message_filter_) {
- id_ = message_filter_->NewRequestId();
- DCHECK(id_);
- } else {
- NOTREACHED();
- }
+ DCHECK_NE(id_, -1);
}
URLRequestAutomationJob::~URLRequestAutomationJob() {
@@ -97,7 +96,7 @@ URLRequestJob* URLRequestAutomationJob::Factory(URLRequest* request,
if (AutomationResourceMessageFilter::LookupRegisteredRenderView(
request_info->child_id(), request_info->route_id(), &details)) {
URLRequestAutomationJob* job = new URLRequestAutomationJob(request,
- details.tab_handle, details.filter);
+ details.tab_handle, request_info->request_id(), details.filter);
return job;
}
}
@@ -202,23 +201,22 @@ bool URLRequestAutomationJob::IsRedirectResponse(
return false;
}
-int URLRequestAutomationJob::MayFilterMessage(const IPC::Message& message) {
+bool URLRequestAutomationJob::MayFilterMessage(const IPC::Message& message,
+ int* request_id) {
switch (message.type()) {
case AutomationMsg_RequestStarted::ID:
case AutomationMsg_RequestData::ID:
case AutomationMsg_RequestEnd::ID: {
void* iter = NULL;
int tab = 0;
- int id = 0;
- if (message.ReadInt(&iter, &tab) && message.ReadInt(&iter, &id)) {
- DCHECK(id);
- return id;
+ if (message.ReadInt(&iter, &tab) && message.ReadInt(&iter, request_id)) {
+ return true;
}
break;
}
}
- return 0;
+ return false;
}
void URLRequestAutomationJob::OnMessage(const IPC::Message& message) {
@@ -229,8 +227,8 @@ void URLRequestAutomationJob::OnMessage(const IPC::Message& message) {
IPC_END_MESSAGE_MAP()
}
-void URLRequestAutomationJob::OnRequestStarted(
- int tab, int id, const IPC::AutomationURLResponse& response) {
+void URLRequestAutomationJob::OnRequestStarted(int tab, int id,
+ const IPC::AutomationURLResponse& response) {
DLOG(INFO) << "URLRequestAutomationJob: " <<
request_->url().spec() << " - response started.";
set_expected_content_size(response.content_length);
diff --git a/chrome/browser/automation/url_request_automation_job.h b/chrome/browser/automation/url_request_automation_job.h
index d4ed0f0..0edd876 100644
--- a/chrome/browser/automation/url_request_automation_job.h
+++ b/chrome/browser/automation/url_request_automation_job.h
@@ -22,8 +22,8 @@ struct AutomationURLResponse;
// automation.
class URLRequestAutomationJob : public URLRequestJob {
public:
- URLRequestAutomationJob(
- URLRequest* request, int tab, AutomationResourceMessageFilter* filter);
+ URLRequestAutomationJob(URLRequest* request, int tab, int request_id,
+ AutomationResourceMessageFilter* filter);
// Register our factory for HTTP/HTTPs requests.
static bool EnsureProtocolFactoryRegistered();
@@ -40,7 +40,7 @@ class URLRequestAutomationJob : public URLRequestJob {
virtual bool IsRedirectResponse(GURL* location, int* http_status_code);
// Peek and process automation messages for URL requests.
- static int MayFilterMessage(const IPC::Message& message);
+ static bool MayFilterMessage(const IPC::Message& message, int* request_id);
void OnMessage(const IPC::Message& message);
int id() const {
diff --git a/chrome/browser/download/download_request_manager.cc b/chrome/browser/download/download_request_manager.cc
index bcb4214..8cb21c9 100644
--- a/chrome/browser/download/download_request_manager.cc
+++ b/chrome/browser/download/download_request_manager.cc
@@ -227,6 +227,14 @@ void DownloadRequestManager::CanDownload(int render_process_host_id,
void DownloadRequestManager::CanDownloadImpl(
TabContents* originating_tab,
Callback* callback) {
+ // 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_tab->CanDownload(callback->GetRequestId())) {
+ 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.
TabContents* effective_tab = originating_tab;
diff --git a/chrome/browser/download/download_request_manager.h b/chrome/browser/download/download_request_manager.h
index 2b03572..c8d4a34 100644
--- a/chrome/browser/download/download_request_manager.h
+++ b/chrome/browser/download/download_request_manager.h
@@ -56,6 +56,7 @@ class DownloadRequestManager :
public:
virtual void ContinueDownload() = 0;
virtual void CancelDownload() = 0;
+ virtual int GetRequestId() = 0;
};
// TabDownloadState maintains the download state for a particular tab.
diff --git a/chrome/browser/download/download_request_manager_unittest.cc b/chrome/browser/download/download_request_manager_unittest.cc
index c55bea4..bd52631 100644
--- a/chrome/browser/download/download_request_manager_unittest.cc
+++ b/chrome/browser/download/download_request_manager_unittest.cc
@@ -39,6 +39,10 @@ class DownloadRequestManagerTest
cancel_count_++;
}
+ virtual int GetRequestId() {
+ return -1;
+ }
+
void CanDownload() {
download_request_manager_->CanDownloadImpl(
controller().tab_contents(), this);
diff --git a/chrome/browser/external_tab_container.cc b/chrome/browser/external_tab_container.cc
index 4da768f..d200891 100644
--- a/chrome/browser/external_tab_container.cc
+++ b/chrome/browser/external_tab_container.cc
@@ -17,6 +17,7 @@
#include "chrome/browser/page_info_window.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/renderer_host/render_process_host.h"
+#include "chrome/browser/renderer_host/resource_dispatcher_host_request_info.h"
#include "chrome/browser/tab_contents/provisional_load_details.h"
#include "chrome/browser/views/tab_contents/render_view_context_menu_external_win.h"
#include "chrome/browser/tab_contents/tab_contents.h"
@@ -394,12 +395,28 @@ bool ExternalTabContainer::TakeFocus(bool reverse) {
return true;
}
+bool ExternalTabContainer::CanDownload(int request_id) {
+ if (load_requests_via_automation_) {
+ if (automation_) {
+ // NOTE: The request_id must be the same id as used by corresponding
+ // URLRequestAutomationJob instance to communicate with the host.
+ automation_->Send(new AutomationMsg_DownloadRequestInHost(0, tab_handle_,
+ request_id));
+ }
+ } else {
+ DLOG(WARNING) << "Downloads are only supported with host browser network "
+ "stack enabled.";
+ }
+
+ // Never allow downloads.
+ return false;
+}
+
void ExternalTabContainer::ShowPageInfo(Profile* profile,
const GURL& url,
const NavigationEntry::SSLStatus& ssl,
bool show_history) {
- browser::ShowPageInfo(GetNativeView(), profile, url, ssl,
- show_history);
+ browser::ShowPageInfo(GetNativeView(), profile, url, ssl, show_history);
}
bool ExternalTabContainer::HandleContextMenu(const ContextMenuParams& params) {
diff --git a/chrome/browser/external_tab_container.h b/chrome/browser/external_tab_container.h
index 738cd0c..3c97233 100644
--- a/chrome/browser/external_tab_container.h
+++ b/chrome/browser/external_tab_container.h
@@ -122,6 +122,9 @@ class ExternalTabContainer : public TabContentsDelegate,
virtual bool HandleKeyboardEvent(const NativeWebKeyboardEvent& event);
virtual bool TakeFocus(bool reverse);
+
+ virtual bool CanDownload(int request_id);
+
virtual bool OnGoToEntryOffset(int offset);
virtual void ShowPageInfo(Profile* profile,
diff --git a/chrome/browser/renderer_host/download_throttling_resource_handler.cc b/chrome/browser/renderer_host/download_throttling_resource_handler.cc
index ee286db..b49bc87 100644
--- a/chrome/browser/renderer_host/download_throttling_resource_handler.cc
+++ b/chrome/browser/renderer_host/download_throttling_resource_handler.cc
@@ -148,6 +148,10 @@ void DownloadThrottlingResourceHandler::ContinueDownload() {
host_->PauseRequest(render_process_host_id_, request_id_, false);
}
+int DownloadThrottlingResourceHandler::GetRequestId() {
+ return request_id_;
+}
+
void DownloadThrottlingResourceHandler::CopyTmpBufferToDownloadHandler() {
// Copy over the tmp buffer.
net::IOBuffer* buffer;
diff --git a/chrome/browser/renderer_host/download_throttling_resource_handler.h b/chrome/browser/renderer_host/download_throttling_resource_handler.h
index 8a110f3..3b04bd8 100644
--- a/chrome/browser/renderer_host/download_throttling_resource_handler.h
+++ b/chrome/browser/renderer_host/download_throttling_resource_handler.h
@@ -50,8 +50,9 @@ class DownloadThrottlingResourceHandler
const std::string& security_info);
// DownloadRequestManager::Callback implementation:
- void CancelDownload();
- void ContinueDownload();
+ virtual void CancelDownload();
+ virtual void ContinueDownload();
+ virtual int GetRequestId();
private:
virtual ~DownloadThrottlingResourceHandler();
diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc
index 4e45553..0d2ba96 100644
--- a/chrome/browser/tab_contents/tab_contents.cc
+++ b/chrome/browser/tab_contents/tab_contents.cc
@@ -1034,6 +1034,13 @@ void TabContents::ToolbarSizeChanged(bool is_animating) {
d->ToolbarSizeChanged(this, is_animating);
}
+bool TabContents::CanDownload(int request_id) {
+ TabContentsDelegate* d = delegate();
+ if (d)
+ return d->CanDownload(request_id);
+ return true;
+}
+
void TabContents::OnStartDownload(DownloadItem* download) {
DCHECK(download);
diff --git a/chrome/browser/tab_contents/tab_contents.h b/chrome/browser/tab_contents/tab_contents.h
index ad5de2f..ee25ef3 100644
--- a/chrome/browser/tab_contents/tab_contents.h
+++ b/chrome/browser/tab_contents/tab_contents.h
@@ -435,6 +435,10 @@ class TabContents : public PageNavigator,
// Returns whether the extension shelf should be visible.
virtual bool IsExtensionShelfAlwaysVisible();
+ // Notifies the delegate that a download is about to be started.
+ // This notification is fired before a local temporary file has been created.
+ bool CanDownload(int request_id);
+
// Notifies the delegate that a download started.
void OnStartDownload(DownloadItem* download);
diff --git a/chrome/browser/tab_contents/tab_contents_delegate.h b/chrome/browser/tab_contents/tab_contents_delegate.h
index 5f084ed..f5fdfcf 100644
--- a/chrome/browser/tab_contents/tab_contents_delegate.h
+++ b/chrome/browser/tab_contents/tab_contents_delegate.h
@@ -186,6 +186,10 @@ class TabContentsDelegate {
return 0;
}
+ virtual bool CanDownload(int request_id) {
+ return true;
+ }
+
virtual void OnStartDownload(DownloadItem* download) {
}
diff --git a/chrome/test/automation/automation_messages_internal.h b/chrome/test/automation/automation_messages_internal.h
index e8f215c..f7ded561 100644
--- a/chrome/test/automation/automation_messages_internal.h
+++ b/chrome/test/automation/automation_messages_internal.h
@@ -1162,4 +1162,10 @@ IPC_BEGIN_MESSAGES(Automation)
// gfx::Point - the location to move to
IPC_MESSAGE_ROUTED2(AutomationMsg_WindowMouseMove, int, gfx::Point)
+ // Called when requests should be downloaded using a host browser's
+ // download mechanism when chrome is being embedded.
+ IPC_MESSAGE_ROUTED2(AutomationMsg_DownloadRequestInHost,
+ int /* tab_handle */,
+ int /* request_id */)
+
IPC_END_MESSAGES(Automation)