Commit fd694982 authored by brettw@chromium.org's avatar brettw@chromium.org

Move RenderViewHostManager back to tab_contents. Moving it to renderer_host

was a bad idea because of its significant dependencies on NavigationController
and NavigationEntry. I'm trying to make renderer_host not depend on tab_contents
at all.

Remove the dependency on TabContents pointers for notifications from the
ResourceDispatcherHost. Instead of having the broadcast code in the
ResourceDispatcherHost, I made it call a RenderViewHostDelegate callback. Then
TabContents implements the notification, so that it's really from the
TabContents.
Review URL: http://codereview.chromium.org/150069

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19909 0039d316-1c4b-4281-b951-d872f2087c98
parent 87666f9f
......@@ -24,6 +24,7 @@ class NavigationEntry;
class Profile;
class RenderProcessHost;
class RenderViewHost;
class ResourceRequestDetails;
class SkBitmap;
class TabContents;
class WebKeyboardEvent;
......@@ -221,11 +222,30 @@ class RenderViewHostDelegate {
bool is_main_frame,
const GURL& url) { }
// Notification by the resource loading system (not the renderer) that it has
// started receiving a resource response. This is different than
// DidStartProvisionalLoadForFrame above because this is called for every
// resource (images, automatically loaded subframes, etc.) and provisional
// loads are only for user-initiated navigations.
//
// The pointer ownership is NOT transferred.
virtual void DidStartReceivingResourceResponse(
ResourceRequestDetails* details) {}
// Sent when a provisional load is redirected.
virtual void DidRedirectProvisionalLoad(int32 page_id,
const GURL& source_url,
const GURL& target_url) { }
// Notification by the resource loading system (not the renderer) that a
// resource was redirected. This is different than DidRedirectProvisionalLoad
// above because this is called for every resource (images, automatically
// loaded subframes, etc.) and provisional loads are only for user-initiated
// navigations.
//
// The pointer ownership is NOT transferred.
virtual void DidRedirectResource(ResourceRequestDetails* details) {}
// The RenderView loaded a resource from an in-memory cache.
// |security_info| contains the security info if this resource was originally
// loaded over a secure connection.
......
......@@ -30,13 +30,14 @@
#include "chrome/browser/renderer_host/cross_site_resource_handler.h"
#include "chrome/browser/renderer_host/download_resource_handler.h"
#include "chrome/browser/renderer_host/render_view_host.h"
#include "chrome/browser/renderer_host/render_view_host_delegate.h"
#include "chrome/browser/renderer_host/resource_request_details.h"
#include "chrome/browser/renderer_host/safe_browsing_resource_handler.h"
#include "chrome/browser/renderer_host/save_file_resource_handler.h"
#include "chrome/browser/renderer_host/sync_resource_handler.h"
#include "chrome/browser/ssl/ssl_client_auth_handler.h"
#include "chrome/browser/ssl/ssl_manager.h"
#include "chrome/browser/tab_contents/tab_util.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/notification_service.h"
#include "chrome/common/render_messages.h"
......@@ -108,6 +109,48 @@ const int kMaxPendingDataMessages = 20;
// This bound is 25MB, which allows for around 6000 outstanding requests.
const int kMaxOutstandingRequestsCostPerProcess = 26214400;
// A NotificationTask proxies a resource dispatcher notification from the IO
// thread to the RenderViewHostDelegate on the UI thread. It should be
// constructed on the IO thread and run in the UI thread.
class NotificationTask : public Task {
public:
// Supply the originating URLRequest, a function on RenderViewHostDelegate
// to call, and the details to use as the parameter to the given function.
//
// This object will take ownership of the details pointer, which must be
// allocated on the heap.
NotificationTask(
URLRequest* request,
void (RenderViewHostDelegate::* function)(ResourceRequestDetails*),
ResourceRequestDetails* details)
: function_(function),
details_(details) {
if (!ResourceDispatcherHost::RenderViewForRequest(request,
&render_process_host_id_,
&render_view_host_id_))
NOTREACHED();
}
virtual void Run() {
RenderViewHost* rvh = RenderViewHost::FromID(render_process_host_id_,
render_view_host_id_);
if (rvh)
(rvh->delegate()->*function_)(details_.get());
}
private:
int render_process_host_id_;
int render_view_host_id_;
// The function to call on RenderViewHostDelegate on the UI thread.
void (RenderViewHostDelegate::* function_)(ResourceRequestDetails*);
// The details for the notification.
scoped_ptr<ResourceRequestDetails> details_;
DISALLOW_COPY_AND_ASSIGN(NotificationTask);
};
// Consults the RendererSecurity policy to determine whether the
// ResourceDispatcherHost should service this request. A request might be
// disallowed if the renderer is not authorized to restrive the request URL or
......@@ -1325,46 +1368,6 @@ URLRequest* ResourceDispatcherHost::GetURLRequest(
return i->second;
}
// A NotificationTask proxies a resource dispatcher notification from the IO
// thread to the UI thread. It should be constructed on the IO thread and run
// in the UI thread. Takes ownership of |details|.
class NotificationTask : public Task {
public:
NotificationTask(NotificationType type,
URLRequest* request,
ResourceRequestDetails* details)
: type_(type),
details_(details) {
if (!ResourceDispatcherHost::RenderViewForRequest(request,
&process_id_,
&tab_contents_id_))
NOTREACHED();
}
void Run() {
// Find the tab associated with this request.
TabContents* tab_contents =
tab_util::GetTabContentsByID(process_id_, tab_contents_id_);
if (tab_contents) {
// Issue the notification.
NotificationService::current()->Notify(
type_,
Source<NavigationController>(&tab_contents->controller()),
Details<ResourceRequestDetails>(details_.get()));
}
}
private:
// These IDs let us find the correct tab on the UI thread.
int process_id_;
int tab_contents_id_;
// The type and details of the notification.
NotificationType type_;
scoped_ptr<ResourceRequestDetails> details_;
};
static int GetCertID(URLRequest* request, int process_id) {
if (request->ssl_info().cert) {
return CertStore::GetSharedInstance()->StoreCert(request->ssl_info().cert,
......@@ -1388,10 +1391,10 @@ void ResourceDispatcherHost::NotifyResponseStarted(URLRequest* request,
FOR_EACH_OBSERVER(Observer, observer_list_, OnRequestStarted(this, request));
// Notify the observers on the UI thread.
ui_loop_->PostTask(FROM_HERE,
new NotificationTask(NotificationType::RESOURCE_RESPONSE_STARTED, request,
new ResourceRequestDetails(request,
GetCertID(request, process_id))));
ui_loop_->PostTask(FROM_HERE, new NotificationTask(request,
&RenderViewHostDelegate::DidStartReceivingResourceResponse,
new ResourceRequestDetails(request,
GetCertID(request, process_id))));
}
void ResourceDispatcherHost::NotifyResponseCompleted(
......@@ -1400,13 +1403,6 @@ void ResourceDispatcherHost::NotifyResponseCompleted(
// Notify the observers on the IO thread.
FOR_EACH_OBSERVER(Observer, observer_list_,
OnResponseCompleted(this, request));
// Notify the observers on the UI thread.
ui_loop_->PostTask(FROM_HERE,
new NotificationTask(NotificationType::RESOURCE_RESPONSE_COMPLETED,
request,
new ResourceRequestDetails(request,
GetCertID(request, process_id))));
}
void ResourceDispatcherHost::NotifyReceivedRedirect(URLRequest* request,
......@@ -1420,8 +1416,8 @@ void ResourceDispatcherHost::NotifyReceivedRedirect(URLRequest* request,
// Notify the observers on the UI thread.
ui_loop_->PostTask(FROM_HERE,
new NotificationTask(NotificationType::RESOURCE_RECEIVED_REDIRECT,
request,
new NotificationTask(request,
&RenderViewHostDelegate::DidRedirectResource,
new ResourceRedirectDetails(request,
cert_id,
new_url)));
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/renderer_host/render_view_host_manager.h"
#include "chrome/browser/tab_contents/render_view_host_manager.h"
#include "base/command_line.h"
#include "base/logging.h"
......
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_RENDERER_HOST_RENDER_VIEW_HOST_MANAGER_H_
#define CHROME_BROWSER_RENDERER_HOST_RENDER_VIEW_HOST_MANAGER_H_
#ifndef CHROME_BROWSER_TAB_CONTENTS_RENDER_VIEW_HOST_MANAGER_H_
#define CHROME_BROWSER_TAB_CONTENTS_RENDER_VIEW_HOST_MANAGER_H_
#include "base/basictypes.h"
#include "base/scoped_ptr.h"
......@@ -264,4 +264,4 @@ struct RenderViewHostSwitchedDetails {
RenderViewHost* new_host;
};
#endif // CHROME_BROWSER_RENDERER_HOST_RENDER_VIEW_HOST_MANAGER_H_
#endif // CHROME_BROWSER_TAB_CONTENTS_RENDER_VIEW_HOST_MANAGER_H_
......@@ -5,7 +5,7 @@
#include "chrome/browser/renderer_host/test_render_view_host.h"
#include "chrome/browser/tab_contents/navigation_controller.h"
#include "chrome/browser/tab_contents/navigation_entry.h"
#include "chrome/browser/renderer_host/render_view_host_manager.h"
#include "chrome/browser/tab_contents/render_view_host_manager.h"
#include "chrome/common/ipc_message.h"
#include "chrome/common/render_messages.h"
#include "chrome/common/url_constants.h"
......
......@@ -32,6 +32,7 @@
#include "chrome/browser/plugin_installer.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/renderer_host/render_widget_host_view.h"
#include "chrome/browser/renderer_host/resource_request_details.h"
#include "chrome/browser/renderer_host/web_cache_manager.h"
#include "chrome/browser/tab_contents/infobar_delegate.h"
#include "chrome/browser/tab_contents/interstitial_page.h"
......@@ -1716,6 +1717,14 @@ void TabContents::DidStartProvisionalLoadForFrame(
Details<ProvisionalLoadDetails>(&details));
}
void TabContents::DidStartReceivingResourceResponse(
ResourceRequestDetails* details) {
NotificationService::current()->Notify(
NotificationType::RESOURCE_RESPONSE_STARTED,
Source<NavigationController>(&controller()),
Details<ResourceRequestDetails>(details));
}
void TabContents::DidRedirectProvisionalLoad(int32 page_id,
const GURL& source_url,
const GURL& target_url) {
......@@ -1729,6 +1738,13 @@ void TabContents::DidRedirectProvisionalLoad(int32 page_id,
entry->set_url(target_url);
}
void TabContents::DidRedirectResource(ResourceRequestDetails* details) {
NotificationService::current()->Notify(
NotificationType::RESOURCE_RECEIVED_REDIRECT,
Source<NavigationController>(&controller()),
Details<ResourceRequestDetails>(details));
}
void TabContents::DidLoadResourceFromMemoryCache(
const GURL& url,
const std::string& frame_origin,
......
......@@ -23,11 +23,11 @@
#include "chrome/browser/find_notification_details.h"
#include "chrome/browser/shell_dialogs.h"
#include "chrome/browser/renderer_host/render_view_host_delegate.h"
#include "chrome/browser/renderer_host/render_view_host_manager.h"
#include "chrome/browser/tab_contents/constrained_window.h"
#include "chrome/browser/tab_contents/infobar_delegate.h"
#include "chrome/browser/tab_contents/navigation_controller.h"
#include "chrome/browser/tab_contents/page_navigator.h"
#include "chrome/browser/tab_contents/render_view_host_manager.h"
#include "chrome/common/url_constants.h"
#include "chrome/common/gears_api.h"
#include "chrome/common/navigation_types.h"
......@@ -768,9 +768,12 @@ class TabContents : public PageNavigator,
virtual void DidStartProvisionalLoadForFrame(RenderViewHost* render_view_host,
bool is_main_frame,
const GURL& url);
virtual void DidStartReceivingResourceResponse(
ResourceRequestDetails* details);
virtual void DidRedirectProvisionalLoad(int32 page_id,
const GURL& source_url,
const GURL& target_url);
virtual void DidRedirectResource(ResourceRequestDetails* details);
virtual void DidLoadResourceFromMemoryCache(
const GURL& url,
const std::string& frame_origin,
......
......@@ -1339,8 +1339,6 @@
'browser/renderer_host/render_view_host_delegate.h',
'browser/renderer_host/render_view_host_factory.cc',
'browser/renderer_host/render_view_host_factory.h',
'browser/renderer_host/render_view_host_manager.cc',
'browser/renderer_host/render_view_host_manager.h',
'browser/renderer_host/render_widget_helper.cc',
'browser/renderer_host/render_widget_helper.h',
'browser/renderer_host/render_widget_host.cc',
......@@ -1482,6 +1480,8 @@
'browser/tab_contents/render_view_context_menu_mac.h',
'browser/tab_contents/render_view_host_delegate_helper.cc',
'browser/tab_contents/render_view_host_delegate_helper.h',
'browser/tab_contents/render_view_host_manager.cc',
'browser/tab_contents/render_view_host_manager.h',
'browser/tab_contents/repost_form_warning.h',
'browser/tab_contents/security_style.h',
'browser/tab_contents/tab_contents.cc',
......@@ -3528,7 +3528,6 @@
'browser/profile_manager_unittest.cc',
'browser/renderer_host/audio_renderer_host_unittest.cc',
'browser/renderer_host/file_system_accessor_unittest.cc',
'browser/renderer_host/render_view_host_manager_unittest.cc',
'browser/renderer_host/render_view_host_unittest.cc',
'browser/renderer_host/render_widget_host_unittest.cc',
'browser/renderer_host/resource_dispatcher_host_unittest.cc',
......@@ -3557,6 +3556,7 @@
'browser/ssl/ssl_host_state_unittest.cc',
'browser/tab_contents/navigation_controller_unittest.cc',
'browser/tab_contents/navigation_entry_unittest.cc',
'browser/tab_contents/render_view_host_manager_unittest.cc',
'browser/tab_contents/thumbnail_generator_unittest.cc',
'browser/tab_contents/web_contents_unittest.cc',
'browser/tabs/tab_strip_model_unittest.cc',
......
......@@ -120,12 +120,6 @@ class NotificationType {
// object are provided.
RESOURCE_RESPONSE_STARTED,
// The response to a resource request has completed. The source will be a
// Source<NavigationController> corresponding to the tab in which the
// request was issued. Details in the form of a ResourceRequestDetails
// object are provided.
RESOURCE_RESPONSE_COMPLETED,
// A redirect was received while requesting a resource. The source will be
// a Source<NavigationController> corresponding to the tab in which the
// request was issued. Details in the form of a ResourceRedirectDetails
......
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