diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-07 18:05:26 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-07 18:05:26 +0000 |
commit | 620161e8a6feabda90783efa40b1dec2d08754a5 (patch) | |
tree | 4b657db4f0163b5f997d266e9a0f871b3d9ffe97 | |
parent | 34ebb250424e57b08876129ed8adf35b20b471c2 (diff) | |
download | chromium_src-620161e8a6feabda90783efa40b1dec2d08754a5.zip chromium_src-620161e8a6feabda90783efa40b1dec2d08754a5.tar.gz chromium_src-620161e8a6feabda90783efa40b1dec2d08754a5.tar.bz2 |
Move ResourceDispatcher to content. I've moved the Chrome-specific SecurityFilterPeer to renderer directory, and factored out its creation so that it's the same as how we create ExtensionLocalizationPeer.
Review URL: http://codereview.chromium.org/6626046
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@77156 0039d316-1c4b-4281-b951-d872f2087c98
17 files changed, 98 insertions, 69 deletions
diff --git a/chrome/chrome_common.gypi b/chrome/chrome_common.gypi index f1dd3cb..3c19e3c 100644 --- a/chrome/chrome_common.gypi +++ b/chrome/chrome_common.gypi @@ -334,10 +334,6 @@ 'common/render_messages_params.h', 'common/renderer_preferences.cc', 'common/renderer_preferences.h', - 'common/resource_dispatcher.cc', - 'common/resource_dispatcher.h', - 'common/security_filter_peer.cc', - 'common/security_filter_peer.h', 'common/security_style.h', 'common/service_messages.cc', 'common/service_messages.h', @@ -607,12 +603,12 @@ 'sources': [ '../webkit/glue/webkit_glue_dummy.cc', 'common/file_system/file_system_dispatcher_dummy.cc', - 'common/resource_dispatcher_dummy.cc', 'common/socket_stream_dispatcher_dummy.cc', 'common/url_constants.cc', # TODO(jam): remove me once child_thread (which uses this) is moved # out of chrome_common. '../content/common/message_router.cc', + '../content/common/resource_dispatcher_dummy.cc', ], 'export_dependent_settings': [ '../app/app.gyp:app_base_nacl_win64', diff --git a/chrome/chrome_renderer.gypi b/chrome/chrome_renderer.gypi index 47d6189..daee5a9 100644 --- a/chrome/chrome_renderer.gypi +++ b/chrome/chrome_renderer.gypi @@ -240,6 +240,8 @@ 'renderer/searchbox.h', 'renderer/searchbox_extension.cc', 'renderer/searchbox_extension.h', + 'renderer/security_filter_peer.cc', + 'renderer/security_filter_peer.h', 'renderer/speech_input_dispatcher.cc', 'renderer/speech_input_dispatcher.h', 'renderer/spellchecker/spellcheck_provider.cc', diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 7a4fb5f..3196847 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -1763,7 +1763,6 @@ 'common/process_watcher_unittest.cc', 'common/property_bag_unittest.cc', 'common/render_messages_unittest.cc', - 'common/resource_dispatcher_unittest.cc', 'common/sandbox_mac_diraccess_unittest.mm', 'common/sandbox_mac_fontloading_unittest.mm', 'common/sandbox_mac_unittest_helper.h', @@ -1856,6 +1855,7 @@ '../content/browser/tab_contents/render_view_host_manager_unittest.cc', '../content/browser/webui/web_ui_unittest.cc', '../content/common/notification_service_unittest.cc', + '../content/common/resource_dispatcher_unittest.cc', '../testing/gtest_mac_unittest.mm', '../third_party/cld/encodings/compact_lang_det/compact_lang_det_unittest_small.cc', '../webkit/fileapi/file_system_dir_url_request_job_unittest.cc', diff --git a/chrome/common/child_thread.cc b/chrome/common/child_thread.cc index dd74aee..9d6a71c 100644 --- a/chrome/common/child_thread.cc +++ b/chrome/common/child_thread.cc @@ -12,8 +12,8 @@ #include "chrome/common/file_system/file_system_dispatcher.h" #include "chrome/common/notification_service.h" #include "chrome/common/plugin_messages.h" -#include "chrome/common/resource_dispatcher.h" #include "chrome/common/socket_stream_dispatcher.h" +#include "content/common/resource_dispatcher.h" #include "ipc/ipc_logging.h" #include "ipc/ipc_message.h" #include "ipc/ipc_sync_channel.h" diff --git a/chrome/plugin/chrome_plugin_host.cc b/chrome/plugin/chrome_plugin_host.cc index 7dc24e9..c0a7582 100644 --- a/chrome/plugin/chrome_plugin_host.cc +++ b/chrome/plugin/chrome_plugin_host.cc @@ -17,9 +17,9 @@ #include "chrome/common/chrome_plugin_util.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/plugin_messages.h" -#include "chrome/common/resource_dispatcher.h" #include "chrome/plugin/plugin_thread.h" #include "chrome/plugin/webplugin_proxy.h" +#include "content/common/resource_dispatcher.h" #include "net/base/data_url.h" #include "net/base/io_buffer.h" #include "net/base/upload_data.h" diff --git a/chrome/renderer/render_thread.cc b/chrome/renderer/render_thread.cc index 5b68787..c90724e 100644 --- a/chrome/renderer/render_thread.cc +++ b/chrome/renderer/render_thread.cc @@ -29,6 +29,7 @@ #include "chrome/common/db_message_filter.h" #include "chrome/common/dom_storage_messages.h" #include "chrome/common/extensions/extension.h" +#include "chrome/common/extensions/extension_localization_peer.h" #include "chrome/common/extensions/extension_set.h" #include "chrome/common/gpu_messages.h" #include "chrome/common/plugin_messages.h" @@ -63,11 +64,14 @@ #include "chrome/renderer/safe_browsing/phishing_classifier_delegate.h" #include "chrome/renderer/search_extension.h" #include "chrome/renderer/searchbox_extension.h" +#include "chrome/renderer/security_filter_peer.h" #include "chrome/renderer/spellchecker/spellcheck.h" #include "chrome/renderer/user_script_slave.h" +#include "content/common/resource_dispatcher.h" #include "content/common/resource_messages.h" #include "ipc/ipc_channel_handle.h" #include "ipc/ipc_platform_file.h" +#include "net/base/net_errors.h" #include "net/base/net_util.h" #include "third_party/sqlite/sqlite3.h" #include "third_party/tcmalloc/chromium/src/google/malloc_extension.h" @@ -217,6 +221,37 @@ class RenderViewZoomer : public RenderViewVisitor { DISALLOW_COPY_AND_ASSIGN(RenderViewZoomer); }; +class RenderResourceObserver : public ResourceDispatcher::Observer { + public: + RenderResourceObserver() { + } + + virtual webkit_glue::ResourceLoaderBridge::Peer* OnRequestComplete( + webkit_glue::ResourceLoaderBridge::Peer* current_peer, + ResourceType::Type resource_type, + const net::URLRequestStatus& status) { + if (status.status() != net::URLRequestStatus::CANCELED || + status.os_error() == net::ERR_ABORTED) { + return NULL; + } + + // Resource canceled with a specific error are filtered. + return SecurityFilterPeer::CreateSecurityFilterPeerForDeniedRequest( + resource_type, current_peer, status.os_error()); + } + + virtual webkit_glue::ResourceLoaderBridge::Peer* OnReceivedResponse( + webkit_glue::ResourceLoaderBridge::Peer* current_peer, + const std::string& mime_type, + const GURL& url) { + return ExtensionLocalizationPeer::CreateExtensionLocalizationPeer( + current_peer, RenderThread::current(), mime_type, url); + } + + private: + DISALLOW_COPY_AND_ASSIGN(RenderResourceObserver); +}; + } // namespace // When we run plugins in process, we actually run them on the render thread, @@ -257,6 +292,8 @@ void RenderThread::Init() { kInitialExtensionIdleHandlerDelayS : kInitialIdleHandlerDelayS; task_factory_.reset(new ScopedRunnableMethodFactory<RenderThread>(this)); + resource_dispatcher()->set_observer(new RenderResourceObserver()); + visited_link_slave_.reset(new VisitedLinkSlave()); user_script_slave_.reset(new UserScriptSlave(&extensions_)); renderer_net_predictor_.reset(new RendererNetPredictor()); diff --git a/chrome/renderer/renderer_glue.cc b/chrome/renderer/renderer_glue.cc index 0671581..7ba91ff 100644 --- a/chrome/renderer/renderer_glue.cc +++ b/chrome/renderer/renderer_glue.cc @@ -18,7 +18,6 @@ #include "base/utf_string_conversions.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_version_info.h" -#include "chrome/common/extensions/extension_localization_peer.h" #include "chrome/common/render_messages.h" #include "chrome/common/socket_stream_dispatcher.h" #include "chrome/common/url_constants.h" @@ -282,14 +281,6 @@ void UserMetricsRecordAction(const std::string& action) { new ViewHostMsg_UserMetricsRecordAction(action)); } -webkit_glue::ResourceLoaderBridge::Peer* ReplacePeer( - webkit_glue::ResourceLoaderBridge::Peer* current_peer, - const std::string& mime_type, - const GURL& url) { - return ExtensionLocalizationPeer::CreateExtensionLocalizationPeer( - current_peer, RenderThread::current(), mime_type, url); -} - #if !defined(DISABLE_NACL) bool LaunchSelLdr(const char* alleged_url, int socket_count, void* imc_handles, void* nacl_process_handle, int* nacl_process_id) { diff --git a/chrome/common/security_filter_peer.cc b/chrome/renderer/security_filter_peer.cc index 24c8cd9..d1d6a5a 100644 --- a/chrome/common/security_filter_peer.cc +++ b/chrome/renderer/security_filter_peer.cc @@ -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/common/security_filter_peer.h" +#include "chrome/renderer/security_filter_peer.h" #include "grit/generated_resources.h" #include "net/base/net_errors.h" diff --git a/chrome/common/security_filter_peer.h b/chrome/renderer/security_filter_peer.h index 0386e66..464a593 100644 --- a/chrome/common/security_filter_peer.h +++ b/chrome/renderer/security_filter_peer.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_COMMON_SECURITY_FILTER_PEER_H_ -#define CHROME_COMMON_SECURITY_FILTER_PEER_H_ +#ifndef CHROME_RENDERER_SECURITY_FILTER_PEER_H_ +#define CHROME_RENDERER_SECURITY_FILTER_PEER_H_ #pragma once #include "webkit/glue/resource_loader_bridge.h" @@ -119,4 +119,4 @@ class ReplaceContentPeer : public SecurityFilterPeer { DISALLOW_COPY_AND_ASSIGN(ReplaceContentPeer); }; -#endif // CHROME_COMMON_SECURITY_FILTER_PEER_H_ +#endif // CHROME_RENDERER_SECURITY_FILTER_PEER_H_ diff --git a/chrome/common/resource_dispatcher.cc b/content/common/resource_dispatcher.cc index f6b1966..d9a7016 100644 --- a/chrome/common/resource_dispatcher.cc +++ b/content/common/resource_dispatcher.cc @@ -4,7 +4,7 @@ // See http://dev.chromium.org/developers/design-documents/multi-process-resource-loading -#include "chrome/common/resource_dispatcher.h" +#include "content/common/resource_dispatcher.h" #include "base/basictypes.h" #include "base/compiler_specific.h" @@ -12,9 +12,8 @@ #include "base/message_loop.h" #include "base/shared_memory.h" #include "base/string_util.h" -#include "chrome/common/security_filter_peer.h" -#include "content/common/resource_response.h" #include "content/common/resource_messages.h" +#include "content/common/resource_response.h" #include "net/base/net_errors.h" #include "net/base/net_util.h" #include "net/base/upload_data.h" @@ -243,6 +242,12 @@ void IPCResourceLoaderBridge::SyncLoad(SyncLoadResponse* response) { // ResourceDispatcher --------------------------------------------------------- +ResourceDispatcher::Observer::Observer() { +} + +ResourceDispatcher::Observer::~Observer() { +} + ResourceDispatcher::ResourceDispatcher(IPC::Message::Sender* sender) : message_sender_(sender), ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { @@ -325,10 +330,13 @@ void ResourceDispatcher::OnReceivedResponse( if (!request_info) return; - webkit_glue::ResourceLoaderBridge::Peer* new_peer = webkit_glue::ReplacePeer( - request_info->peer, response_head.mime_type, request_info->url); - if (new_peer) - request_info->peer = new_peer; + if (observer_.get()) { + webkit_glue::ResourceLoaderBridge::Peer* new_peer = + observer_->OnReceivedResponse( + request_info->peer, response_head.mime_type, request_info->url); + if (new_peer) + request_info->peer = new_peer; + } request_info->peer->OnReceivedResponse(response_head); } @@ -429,18 +437,12 @@ void ResourceDispatcher::OnRequestComplete(int request_id, webkit_glue::ResourceLoaderBridge::Peer* peer = request_info->peer; - if (status.status() == net::URLRequestStatus::CANCELED && - status.os_error() != net::ERR_ABORTED) { - // Resource canceled with a specific error are filtered. - SecurityFilterPeer* new_peer = - SecurityFilterPeer::CreateSecurityFilterPeerForDeniedRequest( - request_info->resource_type, - request_info->peer, - status.os_error()); - if (new_peer) { + if (observer_.get()) { + webkit_glue::ResourceLoaderBridge::Peer* new_peer = + observer_->OnRequestComplete( + request_info->peer, request_info->resource_type, status); + if (new_peer) request_info->peer = new_peer; - peer = new_peer; - } } // The request ID will be removed from our pending list in the destructor. diff --git a/chrome/common/resource_dispatcher.h b/content/common/resource_dispatcher.h index c9c4be5..754446d 100644 --- a/chrome/common/resource_dispatcher.h +++ b/content/common/resource_dispatcher.h @@ -4,8 +4,8 @@ // See http://dev.chromium.org/developers/design-documents/multi-process-resource-loading -#ifndef CHROME_COMMON_RESOURCE_DISPATCHER_H_ -#define CHROME_COMMON_RESOURCE_DISPATCHER_H_ +#ifndef CONTENT_COMMON_RESOURCE_DISPATCHER_H_ +#define CONTENT_COMMON_RESOURCE_DISPATCHER_H_ #pragma once #include <deque> @@ -25,6 +25,24 @@ struct ResourceResponseHead; // the child process. It can be used from any child process. class ResourceDispatcher : public IPC::Channel::Listener { public: + // Interface that allows observing request events and optionally replacing the + // peer. + class Observer { + public: + Observer(); + virtual ~Observer(); + + virtual webkit_glue::ResourceLoaderBridge::Peer* OnRequestComplete( + webkit_glue::ResourceLoaderBridge::Peer* current_peer, + ResourceType::Type resource_type, + const net::URLRequestStatus& status) = 0; + + virtual webkit_glue::ResourceLoaderBridge::Peer* OnReceivedResponse( + webkit_glue::ResourceLoaderBridge::Peer* current_peer, + const std::string& mime_type, + const GURL& url) = 0; + }; + explicit ResourceDispatcher(IPC::Message::Sender* sender); ~ResourceDispatcher(); @@ -59,6 +77,9 @@ class ResourceDispatcher : public IPC::Channel::Listener { // Toggles the is_deferred attribute for the specified request. void SetDefersLoading(int request_id, bool value); + // Takes ownership of the object. + void set_observer(Observer* observer) { observer_.reset(observer); } + private: friend class ResourceDispatcherTest; @@ -146,7 +167,9 @@ class ResourceDispatcher : public IPC::Channel::Listener { ScopedRunnableMethodFactory<ResourceDispatcher> method_factory_; + scoped_ptr<Observer> observer_; + DISALLOW_COPY_AND_ASSIGN(ResourceDispatcher); }; -#endif // CHROME_COMMON_RESOURCE_DISPATCHER_H_ +#endif // CONTENT_COMMON_RESOURCE_DISPATCHER_H_ diff --git a/chrome/common/resource_dispatcher_dummy.cc b/content/common/resource_dispatcher_dummy.cc index f047b34..e87101e 100644 --- a/chrome/common/resource_dispatcher_dummy.cc +++ b/content/common/resource_dispatcher_dummy.cc @@ -4,7 +4,7 @@ // See http://dev.chromium.org/developers/design-documents/multi-process-resource-loading -#include "chrome/common/resource_dispatcher.h" +#include "content/common/resource_dispatcher.h" #include "base/compiler_specific.h" diff --git a/chrome/common/resource_dispatcher_unittest.cc b/content/common/resource_dispatcher_unittest.cc index 6bdd72d..9633cf0 100644 --- a/chrome/common/resource_dispatcher_unittest.cc +++ b/content/common/resource_dispatcher_unittest.cc @@ -9,11 +9,9 @@ #include "base/process.h" #include "base/process_util.h" #include "base/scoped_ptr.h" -#include "chrome/common/render_messages.h" -#include "chrome/common/render_messages_params.h" -#include "chrome/common/resource_dispatcher.h" -#include "content/common/resource_response.h" +#include "content/common/resource_dispatcher.h" #include "content/common/resource_messages.h" +#include "content/common/resource_response.h" #include "net/base/upload_data.h" #include "net/http/http_response_headers.h" #include "testing/gtest/include/gtest/gtest.h" diff --git a/content/content_common.gypi b/content/content_common.gypi index 8fc382a..b253e05 100644 --- a/content/content_common.gypi +++ b/content/content_common.gypi @@ -37,6 +37,8 @@ 'common/p2p_messages.h', 'common/p2p_sockets.cc', 'common/p2p_sockets.h', + 'common/resource_dispatcher.cc', + 'common/resource_dispatcher.h', 'common/resource_messages.h', 'common/resource_response.cc', 'common/resource_response.h', diff --git a/webkit/glue/webkit_glue.h b/webkit/glue/webkit_glue.h index 8e318c3..d2cdd5f 100644 --- a/webkit/glue/webkit_glue.h +++ b/webkit/glue/webkit_glue.h @@ -20,7 +20,6 @@ #include "third_party/WebKit/Source/WebKit/chromium/public/WebCanvas.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileError.h" #include "ui/base/clipboard/clipboard.h" -#include "webkit/glue/resource_loader_bridge.h" class GURL; class SkBitmap; @@ -282,13 +281,6 @@ void EnableSpdy(bool enable); // Notifies the browser that the given action has been performed. void UserMetricsRecordAction(const std::string& action); -// Allows the embedder to swap the peer for a request through the resource -// loader. Return NULL to keep the existing peer. -webkit_glue::ResourceLoaderBridge::Peer* ReplacePeer( - webkit_glue::ResourceLoaderBridge::Peer* current_peer, - const std::string& mime_type, - const GURL& url); - #if !defined(DISABLE_NACL) // Launch NaCl's sel_ldr process. bool LaunchSelLdr(const char* alleged_url, int socket_count, void* imc_handles, diff --git a/webkit/support/webkit_support_glue.cc b/webkit/support/webkit_support_glue.cc index 40e46f1..562b989 100644 --- a/webkit/support/webkit_support_glue.cc +++ b/webkit/support/webkit_support_glue.cc @@ -99,13 +99,6 @@ void EnableSpdy(bool enable) { void UserMetricsRecordAction(const std::string& action) { } -webkit_glue::ResourceLoaderBridge::Peer* ReplacePeer( - webkit_glue::ResourceLoaderBridge::Peer* current_peer, - const std::string& mime_type, - const GURL& url) { - return NULL; -} - #if defined(OS_LINUX) int MatchFontWithFallback(const std::string& face, bool bold, bool italic, int charset) { diff --git a/webkit/tools/test_shell/test_shell.cc b/webkit/tools/test_shell/test_shell.cc index 31f9e68..f106c35 100644 --- a/webkit/tools/test_shell/test_shell.cc +++ b/webkit/tools/test_shell/test_shell.cc @@ -690,13 +690,6 @@ void EnableSpdy(bool enable) { void UserMetricsRecordAction(const std::string& action) { } -webkit_glue::ResourceLoaderBridge::Peer* ReplacePeer( - webkit_glue::ResourceLoaderBridge::Peer* current_peer, - const std::string& mime_type, - const GURL& url) { - return NULL; -} - std::string GetProductVersion() { return std::string("Chrome/0.0.0.0"); } |