diff options
author | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-18 18:38:09 +0000 |
---|---|---|
committer | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-18 18:38:09 +0000 |
commit | 8a58f9a5e0b7e62d38ceef9c6a3b691a8593e7d9 (patch) | |
tree | 36f7876f1b49e7edf492198c79a587090e7e6233 | |
parent | 6e42e7275a6eb6d374e74367aa6c55c1df36568a (diff) | |
download | chromium_src-8a58f9a5e0b7e62d38ceef9c6a3b691a8593e7d9.zip chromium_src-8a58f9a5e0b7e62d38ceef9c6a3b691a8593e7d9.tar.gz chromium_src-8a58f9a5e0b7e62d38ceef9c6a3b691a8593e7d9.tar.bz2 |
Remove the mostly-unused FilterPolicy class. Convert the only actually-used bit, FILTER_EXTENSION_MESSAGES, into a bool that's only passed to places that really need it.
Also renames ExtensionMessageFilterPeer to ExtensionLocalizationPeer in hopes of making its one use more apparent. I added a couple comments too.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/2105006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@47533 0039d316-1c4b-4281-b951-d872f2087c98
25 files changed, 148 insertions, 506 deletions
diff --git a/chrome/browser/renderer_host/resource_dispatcher_host.cc b/chrome/browser/renderer_host/resource_dispatcher_host.cc index 2301720..17bdf4e 100644 --- a/chrome/browser/renderer_host/resource_dispatcher_host.cc +++ b/chrome/browser/renderer_host/resource_dispatcher_host.cc @@ -150,14 +150,15 @@ bool ShouldServiceRequest(ChildProcessInfo::ProcessType process_type, } void PopulateResourceResponse(URLRequest* request, - FilterPolicy::Type filter_policy, + bool replace_extension_localization_templates, ResourceResponse* response) { response->response_head.status = request->status(); response->response_head.request_time = request->request_time(); response->response_head.response_time = request->response_time(); response->response_head.headers = request->response_headers(); request->GetCharset(&response->response_head.charset); - response->response_head.filter_policy = filter_policy; + response->response_head.replace_extension_localization_templates = + replace_extension_localization_templates; response->response_head.content_length = request->GetExpectedContentSize(); request->GetMimeType(&response->response_head.mime_type); response->response_head.was_fetched_via_spdy = @@ -465,9 +466,8 @@ void ResourceDispatcherHost::BeginRequest( ResourceType::IsFrame(request_data.resource_type), // allow_download request_data.host_renderer_id, request_data.host_render_view_id); - ApplyExtensionMessageFilterPolicy(request_data.url, - request_data.resource_type, - extra_info); + ApplyExtensionLocalizationFilter(request_data.url, request_data.resource_type, + extra_info); SetRequestInfo(request, extra_info); // Request takes ownership. chrome_browser_net::SetOriginProcessUniqueIDForRequest( request_data.origin_child_id, request); @@ -934,7 +934,8 @@ void ResourceDispatcherHost::OnReceivedRedirect(URLRequest* request, } scoped_refptr<ResourceResponse> response = new ResourceResponse; - PopulateResourceResponse(request, info->filter_policy(), response); + PopulateResourceResponse(request, + info->replace_extension_localization_templates(), response); if (!info->resource_handler()->OnRequestRedirected(info->request_id(), new_url, response, defer_redirect)) @@ -1031,7 +1032,8 @@ bool ResourceDispatcherHost::CompleteResponseStarted(URLRequest* request) { ResourceDispatcherHostRequestInfo* info = InfoForRequest(request); scoped_refptr<ResourceResponse> response = new ResourceResponse; - PopulateResourceResponse(request, info->filter_policy(), response); + PopulateResourceResponse(request, + info->replace_extension_localization_templates(), response); if (request->ssl_info().cert) { int cert_id = @@ -1757,17 +1759,14 @@ bool ResourceDispatcherHost::IsResourceDispatcherHostMessage( } // static -void ResourceDispatcherHost::ApplyExtensionMessageFilterPolicy( +void ResourceDispatcherHost::ApplyExtensionLocalizationFilter( const GURL& url, const ResourceType::Type& resource_type, ResourceDispatcherHostRequestInfo* request_info) { - // Apply filter only to chrome extension css files that don't have - // security filter already set. + // Apply filter to chrome extension CSS files. if (url.SchemeIs(chrome::kExtensionScheme) && - request_info->filter_policy() == FilterPolicy::DONT_FILTER && - resource_type == ResourceType::STYLESHEET) { - request_info->set_filter_policy(FilterPolicy::FILTER_EXTENSION_MESSAGES); - } + resource_type == ResourceType::STYLESHEET) + request_info->set_replace_extension_localization_templates(); } // static diff --git a/chrome/browser/renderer_host/resource_dispatcher_host.h b/chrome/browser/renderer_host/resource_dispatcher_host.h index 79bf277..bce21e8 100644 --- a/chrome/browser/renderer_host/resource_dispatcher_host.h +++ b/chrome/browser/renderer_host/resource_dispatcher_host.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -274,14 +274,10 @@ class ResourceDispatcherHost : public URLRequest::Delegate { IncrementOutstandingRequestsMemoryCost); FRIEND_TEST(ResourceDispatcherHostTest, CalculateApproximateMemoryCost); - FRIEND_TEST(ApplyExtensionMessageFilterPolicyTest, WrongScheme); - FRIEND_TEST(ApplyExtensionMessageFilterPolicyTest, GoodScheme); - FRIEND_TEST(ApplyExtensionMessageFilterPolicyTest, - GoodSchemeWithSecurityFilter); - FRIEND_TEST(ApplyExtensionMessageFilterPolicyTest, + FRIEND_TEST(ApplyExtensionLocalizationFilterTest, WrongScheme); + FRIEND_TEST(ApplyExtensionLocalizationFilterTest, GoodScheme); + FRIEND_TEST(ApplyExtensionLocalizationFilterTest, GoodSchemeWrongResourceType); - FRIEND_TEST(ApplyExtensionMessageFilterPolicyTest, - WrongSchemeResourceAndFilter); class ShutdownTask; @@ -408,9 +404,9 @@ class ResourceDispatcherHost : public URLRequest::Delegate { // Returns true if the message passed in is a resource related message. static bool IsResourceDispatcherHostMessage(const IPC::Message&); - // Applies FilterPolicy::FILTER_EXTENSION_MESSAGES to all text/css requests - // that have "chrome-extension://" scheme. - static void ApplyExtensionMessageFilterPolicy( + // Sets replace_extension_localization_templates on all text/css requests that + // have "chrome-extension://" scheme. + static void ApplyExtensionLocalizationFilter( const GURL& url, const ResourceType::Type& resource_type, ResourceDispatcherHostRequestInfo* request_info); diff --git a/chrome/browser/renderer_host/resource_dispatcher_host_request_info.cc b/chrome/browser/renderer_host/resource_dispatcher_host_request_info.cc index 23ba684..67c8c96 100644 --- a/chrome/browser/renderer_host/resource_dispatcher_host_request_info.cc +++ b/chrome/browser/renderer_host/resource_dispatcher_host_request_info.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -35,7 +35,7 @@ ResourceDispatcherHostRequestInfo::ResourceDispatcherHostRequestInfo( frame_origin_(frame_origin), main_frame_origin_(main_frame_origin), resource_type_(resource_type), - filter_policy_(FilterPolicy::DONT_FILTER), + replace_extension_localization_templates_(false), last_load_state_(net::LOAD_STATE_IDLE), upload_size_(upload_size), last_upload_position_(0), diff --git a/chrome/browser/renderer_host/resource_dispatcher_host_request_info.h b/chrome/browser/renderer_host/resource_dispatcher_host_request_info.h index affd32d..4630568 100644 --- a/chrome/browser/renderer_host/resource_dispatcher_host_request_info.h +++ b/chrome/browser/renderer_host/resource_dispatcher_host_request_info.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -10,7 +10,6 @@ #include "base/basictypes.h" #include "base/time.h" #include "chrome/common/child_process_info.h" -#include "chrome/common/filter_policy.h" #include "net/base/load_states.h" #include "net/url_request/url_request.h" #include "webkit/glue/resource_type.h" @@ -115,12 +114,15 @@ class ResourceDispatcherHostRequestInfo : public URLRequest::UserData { // Identifies the type of resource, such as subframe, media, etc. ResourceType::Type resource_type() const { return resource_type_; } - // Whether the content for this request should be filtered (on the renderer - // side) to make it more secure: images are stamped, frame content is - // replaced with an error message and all other resources are entirely - // filtered out. - FilterPolicy::Type filter_policy() const { return filter_policy_; } - void set_filter_policy(FilterPolicy::Type policy) { filter_policy_ = policy; } + // Whether we should apply a filter to this resource that replaces + // localization templates with the appropriate localized strings. This is set + // for CSS resources used by extensions. + bool replace_extension_localization_templates() const { + return replace_extension_localization_templates_; + } + void set_replace_extension_localization_templates() { + replace_extension_localization_templates_ = true; + } // Returns the last updated state of the load. This is updated periodically // by the ResourceDispatcherHost and tracked here so we don't send out @@ -209,7 +211,7 @@ class ResourceDispatcherHostRequestInfo : public URLRequest::UserData { std::string frame_origin_; std::string main_frame_origin_; ResourceType::Type resource_type_; - FilterPolicy::Type filter_policy_; + bool replace_extension_localization_templates_; net::LoadState last_load_state_; uint64 upload_size_; uint64 last_upload_position_; diff --git a/chrome/browser/renderer_host/resource_dispatcher_host_unittest.cc b/chrome/browser/renderer_host/resource_dispatcher_host_unittest.cc index ef133b2..2af376e 100644 --- a/chrome/browser/renderer_host/resource_dispatcher_host_unittest.cc +++ b/chrome/browser/renderer_host/resource_dispatcher_host_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -984,7 +984,7 @@ class DummyResourceHandler : public ResourceHandler { DISALLOW_COPY_AND_ASSIGN(DummyResourceHandler); }; -class ApplyExtensionMessageFilterPolicyTest : public testing::Test { +class ApplyExtensionLocalizationFilterTest : public testing::Test { protected: void SetUp() { url_.reset(new GURL( @@ -1007,45 +1007,25 @@ class ApplyExtensionMessageFilterPolicyTest : public testing::Test { scoped_ptr<ResourceDispatcherHostRequestInfo> request_info_; }; -TEST_F(ApplyExtensionMessageFilterPolicyTest, WrongScheme) { +TEST_F(ApplyExtensionLocalizationFilterTest, WrongScheme) { url_.reset(new GURL("html://behllobkkfkfnphdnhnkndlbkcpglgmj/popup.html")); - ResourceDispatcherHost::ApplyExtensionMessageFilterPolicy( - *url_, resource_type_, request_info_.get()); + ResourceDispatcherHost::ApplyExtensionLocalizationFilter(*url_, + resource_type_, request_info_.get()); - EXPECT_EQ(FilterPolicy::DONT_FILTER, request_info_->filter_policy()); + EXPECT_FALSE(request_info_->replace_extension_localization_templates()); } -TEST_F(ApplyExtensionMessageFilterPolicyTest, GoodScheme) { - ResourceDispatcherHost::ApplyExtensionMessageFilterPolicy( - *url_, resource_type_, request_info_.get()); +TEST_F(ApplyExtensionLocalizationFilterTest, GoodScheme) { + ResourceDispatcherHost::ApplyExtensionLocalizationFilter(*url_, + resource_type_, request_info_.get()); - EXPECT_EQ(FilterPolicy::FILTER_EXTENSION_MESSAGES, - request_info_->filter_policy()); + EXPECT_TRUE(request_info_->replace_extension_localization_templates()); } -TEST_F(ApplyExtensionMessageFilterPolicyTest, GoodSchemeWithSecurityFilter) { - request_info_->set_filter_policy(FilterPolicy::FILTER_ALL_EXCEPT_IMAGES); - ResourceDispatcherHost::ApplyExtensionMessageFilterPolicy( - *url_, resource_type_, request_info_.get()); - - EXPECT_EQ(FilterPolicy::FILTER_ALL_EXCEPT_IMAGES, - request_info_->filter_policy()); -} - -TEST_F(ApplyExtensionMessageFilterPolicyTest, GoodSchemeWrongResourceType) { +TEST_F(ApplyExtensionLocalizationFilterTest, GoodSchemeWrongResourceType) { resource_type_ = ResourceType::MAIN_FRAME; - ResourceDispatcherHost::ApplyExtensionMessageFilterPolicy( - *url_, resource_type_, request_info_.get()); - - EXPECT_EQ(FilterPolicy::DONT_FILTER, request_info_->filter_policy()); -} - -TEST_F(ApplyExtensionMessageFilterPolicyTest, WrongSchemeResourceAndFilter) { - url_.reset(new GURL("html://behllobkkfkfnphdnhnkndlbkcpglgmj/popup.html")); - resource_type_ = ResourceType::MEDIA; - request_info_->set_filter_policy(FilterPolicy::FILTER_ALL); - ResourceDispatcherHost::ApplyExtensionMessageFilterPolicy( - *url_, resource_type_, request_info_.get()); + ResourceDispatcherHost::ApplyExtensionLocalizationFilter(*url_, + resource_type_, request_info_.get()); - EXPECT_EQ(FilterPolicy::FILTER_ALL, request_info_->filter_policy()); + EXPECT_FALSE(request_info_->replace_extension_localization_templates()); } diff --git a/chrome/browser/renderer_host/resource_request_details.h b/chrome/browser/renderer_host/resource_request_details.h index 600decd..5310b5b 100644 --- a/chrome/browser/renderer_host/resource_request_details.h +++ b/chrome/browser/renderer_host/resource_request_details.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -39,7 +39,6 @@ class ResourceRequestDetails { resource_type_ = info->resource_type(); frame_origin_ = info->frame_origin(); main_frame_origin_ = info->main_frame_origin(); - filter_policy_ = info->filter_policy(); // If request is from the worker process on behalf of a renderer, use // the renderer process id, since it consumes the notification response @@ -75,7 +74,6 @@ class ResourceRequestDetails { int ssl_cert_id() const { return ssl_cert_id_; } int ssl_cert_status() const { return ssl_cert_status_; } ResourceType::Type resource_type() const { return resource_type_; } - FilterPolicy::Type filter_policy() const { return filter_policy_; } private: GURL url_; @@ -91,7 +89,6 @@ class ResourceRequestDetails { int ssl_cert_id_; int ssl_cert_status_; ResourceType::Type resource_type_; - FilterPolicy::Type filter_policy_; }; // Details about a redirection of a resource request. diff --git a/chrome/browser/renderer_host/sync_resource_handler.cc b/chrome/browser/renderer_host/sync_resource_handler.cc index 11d776b..9674648 100644 --- a/chrome/browser/renderer_host/sync_resource_handler.cc +++ b/chrome/browser/renderer_host/sync_resource_handler.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -14,7 +14,6 @@ SyncResourceHandler::SyncResourceHandler( receiver_(receiver), result_message_(result_message) { result_.final_url = url; - result_.filter_policy = FilterPolicy::DONT_FILTER; } SyncResourceHandler::~SyncResourceHandler() { diff --git a/chrome/browser/ssl/ssl_error_handler.cc b/chrome/browser/ssl/ssl_error_handler.cc index 09594ac..e77ab15 100644 --- a/chrome/browser/ssl/ssl_error_handler.cc +++ b/chrome/browser/ssl/ssl_error_handler.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -41,8 +41,8 @@ SSLErrorHandler::SSLErrorHandler(ResourceDispatcherHost* rdh, // This makes sure we don't disappear on the IO thread until we've given an // answer to the URLRequest. // - // Release in CompleteCancelRequest, CompleteContinueRequest, - // CompleteStartRequest or CompleteTakeNoAction. + // Release in CompleteCancelRequest, CompleteContinueRequest, or + // CompleteTakeNoAction. AddRef(); } @@ -97,16 +97,6 @@ void SSLErrorHandler::ContinueRequest() { NewRunnableMethod(this, &SSLErrorHandler::CompleteContinueRequest)); } -void SSLErrorHandler::StartRequest(FilterPolicy::Type filter_policy) { - DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); - - // We need to complete this task on the IO thread. - ChromeThread::PostTask( - ChromeThread::IO, FROM_HERE, - NewRunnableMethod( - this, &SSLErrorHandler::CompleteStartRequest, filter_policy)); -} - void SSLErrorHandler::TakeNoAction() { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); @@ -166,34 +156,6 @@ void SSLErrorHandler::CompleteContinueRequest() { Release(); } -void SSLErrorHandler::CompleteStartRequest(FilterPolicy::Type filter_policy) { - DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); - - // It is important that we notify the URLRequest only once. If we try to - // notify the request twice, it may no longer exist and |this| might have - // already have been deleted. - DCHECK(!request_has_been_notified_); - if (request_has_been_notified_) - return; - - URLRequest* request = resource_dispatcher_host_->GetURLRequest(request_id_); - if (request) { - // The request can be NULL if it was cancelled by the renderer (as the - // result of the user navigating to a new page from the location bar). - DLOG(INFO) << "CompleteStartRequest() url: " << request->url().spec(); - // The request should not have been started (SUCCESS is the initial state). - DCHECK(request->status().status() == URLRequestStatus::SUCCESS); - ResourceDispatcherHostRequestInfo* info = - ResourceDispatcherHost::InfoForRequest(request); - info->set_filter_policy(filter_policy); - request->Start(); - } - request_has_been_notified_ = true; - - // We're done with this object on the IO thread. - Release(); -} - void SSLErrorHandler::CompleteTakeNoAction() { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); diff --git a/chrome/browser/ssl/ssl_error_handler.h b/chrome/browser/ssl/ssl_error_handler.h index 2589f5d..5fcc4f4 100644 --- a/chrome/browser/ssl/ssl_error_handler.h +++ b/chrome/browser/ssl/ssl_error_handler.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -11,7 +11,6 @@ #include "base/ref_counted.h" #include "chrome/browser/renderer_host/global_request_id.h" #include "chrome/browser/ssl/ssl_manager.h" -#include "chrome/common/filter_policy.h" #include "googleurl/src/gurl.h" #include "webkit/glue/resource_type.h" @@ -25,8 +24,8 @@ class URLRequest; // UI thread. Subclasses should override the OnDispatched/OnDispatchFailed // methods to implement the actions that should be taken on the UI thread. // These methods can call the different convenience methods ContinueRequest/ -// CancelRequest/StartRequest to perform any required action on the URLRequest -// the ErrorHandler was created with. +// CancelRequest to perform any required action on the URLRequest the +// ErrorHandler was created with. // // IMPORTANT NOTE: // @@ -77,14 +76,6 @@ class SSLErrorHandler : public base::RefCountedThreadSafe<SSLErrorHandler> { // This method can be called from OnDispatchFailed and OnDispatched. void DenyRequest(); - // Starts the associated URLRequest. |filter_policy| specifies whether the - // ResourceDispatcher should attempt to filter the loaded content in order - // to make it secure (ex: images are made slightly transparent and are - // stamped). - // Should only be called when the URLRequest has not already been started. - // This method can be called from OnDispatchFailed and OnDispatched. - void StartRequest(FilterPolicy::Type filter_policy); - // Does nothing on the URLRequest but ensures the current instance ref // count is decremented appropriately. Subclasses that do not want to // take any specific actions in their OnDispatched/OnDispatchFailed should @@ -129,10 +120,6 @@ class SSLErrorHandler : public base::RefCountedThreadSafe<SSLErrorHandler> { // Call on the IO thread. void CompleteContinueRequest(); - // Completes the StartRequest operation on the IO thread. - // Call on the IO thread. - void CompleteStartRequest(FilterPolicy::Type filter_policy); - // Derefs this instance. // Call on the IO thread. void CompleteTakeNoAction(); diff --git a/chrome/browser/ssl/ssl_manager.cc b/chrome/browser/ssl/ssl_manager.cc index 333d8b2..dbff09e 100644 --- a/chrome/browser/ssl/ssl_manager.cc +++ b/chrome/browser/ssl/ssl_manager.cc @@ -202,14 +202,13 @@ void SSLManager::DidLoadFromMemoryCache(LoadFromMemoryCacheDetails* details) { // Simulate loading this resource through the usual path. // Note that we specify SUB_RESOURCE as the resource type as WebCore only // caches sub-resources. - // This resource must have been loaded with FilterPolicy::DONT_FILTER because - // filtered resouces aren't cachable. + // This resource must have been loaded with no filtering because filtered + // resouces aren't cachable. scoped_refptr<SSLRequestInfo> info = new SSLRequestInfo( details->url(), ResourceType::SUB_RESOURCE, details->frame_origin(), details->main_frame_origin(), - FilterPolicy::DONT_FILTER, details->pid(), details->ssl_cert_id(), details->ssl_cert_status()); @@ -238,7 +237,6 @@ void SSLManager::DidStartResourceResponse(ResourceRequestDetails* details) { details->resource_type(), details->frame_origin(), details->main_frame_origin(), - details->filter_policy(), details->origin_child_id(), details->ssl_cert_id(), details->ssl_cert_status()); diff --git a/chrome/browser/ssl/ssl_policy.h b/chrome/browser/ssl/ssl_policy.h index 8c8a5f8..1f1766b 100644 --- a/chrome/browser/ssl/ssl_policy.h +++ b/chrome/browser/ssl/ssl_policy.h @@ -8,7 +8,6 @@ #include <string> #include "chrome/browser/ssl/ssl_blocking_page.h" -#include "chrome/common/filter_policy.h" #include "webkit/glue/resource_type.h" class NavigationEntry; diff --git a/chrome/browser/ssl/ssl_request_info.h b/chrome/browser/ssl/ssl_request_info.h index 8964490..c495cd2 100644 --- a/chrome/browser/ssl/ssl_request_info.h +++ b/chrome/browser/ssl/ssl_request_info.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -7,7 +7,6 @@ #include <string> -#include "chrome/common/filter_policy.h" #include "googleurl/src/gurl.h" #include "webkit/glue/resource_type.h" @@ -20,7 +19,6 @@ class SSLRequestInfo : public base::RefCounted<SSLRequestInfo> { ResourceType::Type resource_type, const std::string& frame_origin, const std::string& main_frame_origin, - FilterPolicy::Type filter_policy, int child_id, int ssl_cert_id, int ssl_cert_status) @@ -28,7 +26,6 @@ class SSLRequestInfo : public base::RefCounted<SSLRequestInfo> { resource_type_(resource_type), frame_origin_(frame_origin), main_frame_origin_(main_frame_origin), - filter_policy_(filter_policy), child_id_(child_id), ssl_cert_id_(ssl_cert_id), ssl_cert_status_(ssl_cert_status) { @@ -38,7 +35,6 @@ class SSLRequestInfo : public base::RefCounted<SSLRequestInfo> { ResourceType::Type resource_type() const { return resource_type_; } const std::string& frame_origin() const { return frame_origin_; } const std::string& main_frame_origin() const { return main_frame_origin_; } - FilterPolicy::Type filter_policy() const { return filter_policy_; } int child_id() const { return child_id_; } int ssl_cert_id() const { return ssl_cert_id_; } int ssl_cert_status() const { return ssl_cert_status_; } @@ -52,7 +48,6 @@ class SSLRequestInfo : public base::RefCounted<SSLRequestInfo> { ResourceType::Type resource_type_; std::string frame_origin_; std::string main_frame_origin_; - FilterPolicy::Type filter_policy_; int child_id_; int ssl_cert_id_; int ssl_cert_status_; diff --git a/chrome/chrome_common.gypi b/chrome/chrome_common.gypi index ccc0af6..389f2a3 100644 --- a/chrome/chrome_common.gypi +++ b/chrome/chrome_common.gypi @@ -157,10 +157,10 @@ 'common/extensions/extension_file_util.h', 'common/extensions/extension_l10n_util.cc', 'common/extensions/extension_l10n_util.h', + 'common/extensions/extension_localization_peer.cc', + 'common/extensions/extension_localization_peer.h', 'common/extensions/extension_message_bundle.cc', 'common/extensions/extension_message_bundle.h', - 'common/extensions/extension_message_filter_peer.cc', - 'common/extensions/extension_message_filter_peer.h', 'common/extensions/extension_resource.cc', 'common/extensions/extension_resource.h', 'common/extensions/extension_unpacker.cc', @@ -195,7 +195,6 @@ 'common/dom_storage_common.h', 'common/deprecated/event_sys-inl.h', 'common/deprecated/event_sys.h', - 'common/filter_policy.h', 'common/gears_api.h', 'common/gpu_plugin.cc', 'common/gpu_plugin.h', diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index a9c0dec..4b51194 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -973,9 +973,9 @@ 'common/extensions/extension_extent_unittest.cc', 'common/extensions/extension_file_util_unittest.cc', 'common/extensions/extension_l10n_util_unittest.cc', + 'common/extensions/extension_localization_peer_unittest.cc', 'common/extensions/extension_manifests_unittest.cc', 'common/extensions/extension_message_bundle_unittest.cc', - 'common/extensions/extension_message_filter_peer_unittest.cc', 'common/extensions/extension_resource_unittest.cc', 'common/extensions/extension_unittest.cc', 'common/extensions/extension_unpacker_unittest.cc', diff --git a/chrome/common/extensions/extension_message_filter_peer.cc b/chrome/common/extensions/extension_localization_peer.cc index 8d58378..36e44ce 100644 --- a/chrome/common/extensions/extension_message_filter_peer.cc +++ b/chrome/common/extensions/extension_localization_peer.cc @@ -2,19 +2,20 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/common/extensions/extension_message_filter_peer.h" +#include "chrome/common/extensions/extension_localization_peer.h" #include "app/l10n_util.h" #include "base/string_util.h" #include "chrome/common/extensions/extension_message_bundle.h" #include "chrome/common/render_messages.h" +#include "chrome/common/url_constants.h" #include "grit/generated_resources.h" #include "grit/renderer_resources.h" #include "net/base/net_errors.h" #include "net/http/http_response_headers.h" #include "webkit/glue/webkit_glue.h" -ExtensionMessageFilterPeer::ExtensionMessageFilterPeer( +ExtensionLocalizationPeer::ExtensionLocalizationPeer( webkit_glue::ResourceLoaderBridge::Peer* peer, IPC::Message::Sender* message_sender, const GURL& request_url) @@ -23,34 +24,29 @@ ExtensionMessageFilterPeer::ExtensionMessageFilterPeer( request_url_(request_url) { } -ExtensionMessageFilterPeer::~ExtensionMessageFilterPeer() { +ExtensionLocalizationPeer::~ExtensionLocalizationPeer() { } // static -ExtensionMessageFilterPeer* -ExtensionMessageFilterPeer::CreateExtensionMessageFilterPeer( +ExtensionLocalizationPeer* +ExtensionLocalizationPeer::CreateExtensionLocalizationPeer( webkit_glue::ResourceLoaderBridge::Peer* peer, IPC::Message::Sender* message_sender, const std::string& mime_type, - FilterPolicy::Type filter_policy, const GURL& request_url) { - if (filter_policy != FilterPolicy::FILTER_EXTENSION_MESSAGES) - return NULL; - - if (StartsWithASCII(mime_type, "text/css", false)) - return new ExtensionMessageFilterPeer(peer, message_sender, request_url); - // Return NULL if content is not text/css or it doesn't belong to extension // scheme. - return NULL; + return (request_url.SchemeIs(chrome::kExtensionScheme) && + StartsWithASCII(mime_type, "text/css", false)) ? + new ExtensionLocalizationPeer(peer, message_sender, request_url) : NULL; } -void ExtensionMessageFilterPeer::OnUploadProgress( +void ExtensionLocalizationPeer::OnUploadProgress( uint64 position, uint64 size) { NOTREACHED(); } -bool ExtensionMessageFilterPeer::OnReceivedRedirect( +bool ExtensionLocalizationPeer::OnReceivedRedirect( const GURL& new_url, const webkit_glue::ResourceLoaderBridge::ResponseInfo& info, bool* has_new_first_party_for_cookies, @@ -59,20 +55,20 @@ bool ExtensionMessageFilterPeer::OnReceivedRedirect( return false; } -void ExtensionMessageFilterPeer::OnReceivedResponse( +void ExtensionLocalizationPeer::OnReceivedResponse( const webkit_glue::ResourceLoaderBridge::ResponseInfo& info, bool content_filtered) { response_info_ = info; } -void ExtensionMessageFilterPeer::OnReceivedData(const char* data, int len) { +void ExtensionLocalizationPeer::OnReceivedData(const char* data, int len) { data_.append(data, len); } -void ExtensionMessageFilterPeer::OnCompletedRequest( +void ExtensionLocalizationPeer::OnCompletedRequest( const URLRequestStatus& status, const std::string& security_info) { // Make sure we delete ourselves at the end of this call. - scoped_ptr<ExtensionMessageFilterPeer> this_deleter(this); + scoped_ptr<ExtensionLocalizationPeer> this_deleter(this); // Give sub-classes a chance at altering the data. if (status.status() != URLRequestStatus::SUCCESS) { @@ -92,11 +88,11 @@ void ExtensionMessageFilterPeer::OnCompletedRequest( original_peer_->OnCompletedRequest(status, security_info); } -GURL ExtensionMessageFilterPeer::GetURLForDebugging() const { +GURL ExtensionLocalizationPeer::GetURLForDebugging() const { return original_peer_->GetURLForDebugging(); } -void ExtensionMessageFilterPeer::ReplaceMessages() { +void ExtensionLocalizationPeer::ReplaceMessages() { if (!message_sender_ || data_.empty()) return; diff --git a/chrome/common/extensions/extension_message_filter_peer.h b/chrome/common/extensions/extension_localization_peer.h index 137ab36..aa49166 100644 --- a/chrome/common/extensions/extension_message_filter_peer.h +++ b/chrome/common/extensions/extension_localization_peer.h @@ -3,30 +3,30 @@ // found in the LICENSE file. -#ifndef CHROME_COMMON_EXTENSIONS_EXTENSION_MESSAGE_FILTER_PEER_H_ -#define CHROME_COMMON_EXTENSIONS_EXTENSION_MESSAGE_FILTER_PEER_H_ +#ifndef CHROME_COMMON_EXTENSIONS_EXTENSION_LOCALIZATION_PEER_H_ +#define CHROME_COMMON_EXTENSIONS_EXTENSION_LOCALIZATION_PEER_H_ #include <string> -#include "chrome/common/filter_policy.h" #include "ipc/ipc_message.h" #include "webkit/glue/resource_loader_bridge.h" -// The ExtensionMessageFilterPeer is a proxy to a +// The ExtensionLocalizationPeer is a proxy to a // webkit_glue::ResourceLoaderBridge::Peer instance. It is used to pre-process -// extension resources (such as css files). -// Call the factory method CreateExtensionMessageFilterPeer() to obtain an -// instance of ExtensionMessageFilterPeer based on the original Peer. -class ExtensionMessageFilterPeer +// CSS files requested by extensions to replace localization templates with the +// appropriate localized strings. +// +// Call the factory method CreateExtensionLocalizationPeer() to obtain an +// instance of ExtensionLocalizationPeer based on the original Peer. +class ExtensionLocalizationPeer : public webkit_glue::ResourceLoaderBridge::Peer { public: - virtual ~ExtensionMessageFilterPeer(); + virtual ~ExtensionLocalizationPeer(); - static ExtensionMessageFilterPeer* CreateExtensionMessageFilterPeer( + static ExtensionLocalizationPeer* CreateExtensionLocalizationPeer( webkit_glue::ResourceLoaderBridge::Peer* peer, IPC::Message::Sender* message_sender, const std::string& mime_type, - FilterPolicy::Type filter_policy, const GURL& request_url); // ResourceLoaderBridge::Peer methods. @@ -45,10 +45,10 @@ class ExtensionMessageFilterPeer virtual GURL GetURLForDebugging() const; private: - friend class ExtensionMessageFilterPeerTest; + friend class ExtensionLocalizationPeerTest; - // Use CreateExtensionMessageFilterPeer to create an instance. - ExtensionMessageFilterPeer( + // Use CreateExtensionLocalizationPeer to create an instance. + ExtensionLocalizationPeer( webkit_glue::ResourceLoaderBridge::Peer* peer, IPC::Message::Sender* message_sender, const GURL& request_url); @@ -74,7 +74,7 @@ class ExtensionMessageFilterPeer GURL request_url_; private: - DISALLOW_COPY_AND_ASSIGN(ExtensionMessageFilterPeer); + DISALLOW_COPY_AND_ASSIGN(ExtensionLocalizationPeer); }; -#endif // CHROME_COMMON_EXTENSIONS_EXTENSION_MESSAGE_FILTER_PEER_H_ +#endif // CHROME_COMMON_EXTENSIONS_EXTENSION_LOCALIZATION_PEER_H_ diff --git a/chrome/common/extensions/extension_message_filter_peer_unittest.cc b/chrome/common/extensions/extension_localization_peer_unittest.cc index cf7d10f..fe9ee0a 100644 --- a/chrome/common/extensions/extension_message_filter_peer_unittest.cc +++ b/chrome/common/extensions/extension_localization_peer_unittest.cc @@ -7,8 +7,7 @@ #include "base/scoped_ptr.h" #include "chrome/common/extensions/extension_message_bundle.h" -#include "chrome/common/extensions/extension_message_filter_peer.h" -#include "chrome/common/filter_policy.h" +#include "chrome/common/extensions/extension_localization_peer.h" #include "ipc/ipc_message.h" #include "ipc/ipc_sync_message.h" #include "net/base/net_errors.h" @@ -76,32 +75,30 @@ class MockResourceLoaderBridgePeer DISALLOW_COPY_AND_ASSIGN(MockResourceLoaderBridgePeer); }; -class ExtensionMessageFilterPeerTest : public testing::Test { +class ExtensionLocalizationPeerTest : public testing::Test { protected: virtual void SetUp() { sender_.reset(new MockIpcMessageSender()); original_peer_.reset(new MockResourceLoaderBridgePeer()); filter_peer_.reset( - ExtensionMessageFilterPeer::CreateExtensionMessageFilterPeer( + ExtensionLocalizationPeer::CreateExtensionLocalizationPeer( original_peer_.get(), sender_.get(), "text/css", - FilterPolicy::FILTER_EXTENSION_MESSAGES, GURL(kExtensionUrl_1))); + GURL(kExtensionUrl_1))); } - ExtensionMessageFilterPeer* CreateExtensionMessageFilterPeer( + ExtensionLocalizationPeer* CreateExtensionLocalizationPeer( const std::string& mime_type, - FilterPolicy::Type filter_policy, const GURL& request_url) { - return ExtensionMessageFilterPeer::CreateExtensionMessageFilterPeer( - original_peer_.get(), sender_.get(), - mime_type, filter_policy, request_url); + return ExtensionLocalizationPeer::CreateExtensionLocalizationPeer( + original_peer_.get(), sender_.get(), mime_type, request_url); } - std::string GetData(ExtensionMessageFilterPeer* filter_peer) { + std::string GetData(ExtensionLocalizationPeer* filter_peer) { EXPECT_TRUE(NULL != filter_peer); return filter_peer->data_; } - void SetData(ExtensionMessageFilterPeer* filter_peer, + void SetData(ExtensionLocalizationPeer* filter_peer, const std::string& data) { EXPECT_TRUE(NULL != filter_peer); filter_peer->data_ = data; @@ -109,28 +106,20 @@ class ExtensionMessageFilterPeerTest : public testing::Test { scoped_ptr<MockIpcMessageSender> sender_; scoped_ptr<MockResourceLoaderBridgePeer> original_peer_; - scoped_ptr<ExtensionMessageFilterPeer> filter_peer_; + scoped_ptr<ExtensionLocalizationPeer> filter_peer_; }; -TEST_F(ExtensionMessageFilterPeerTest, CreateWithWrongFilterPolicy) { - filter_peer_.reset(CreateExtensionMessageFilterPeer( - "text/css", FilterPolicy::DONT_FILTER, GURL(kExtensionUrl_1))); +TEST_F(ExtensionLocalizationPeerTest, CreateWithWrongMimeType) { + filter_peer_.reset( + CreateExtensionLocalizationPeer("text/html", GURL(kExtensionUrl_1))); EXPECT_TRUE(NULL == filter_peer_.get()); } -TEST_F(ExtensionMessageFilterPeerTest, CreateWithWrongMimeType) { - filter_peer_.reset(CreateExtensionMessageFilterPeer( - "text/html", - FilterPolicy::FILTER_EXTENSION_MESSAGES, - GURL(kExtensionUrl_1))); - EXPECT_TRUE(NULL == filter_peer_.get()); -} - -TEST_F(ExtensionMessageFilterPeerTest, CreateWithValidInput) { +TEST_F(ExtensionLocalizationPeerTest, CreateWithValidInput) { EXPECT_TRUE(NULL != filter_peer_.get()); } -TEST_F(ExtensionMessageFilterPeerTest, OnReceivedData) { +TEST_F(ExtensionLocalizationPeerTest, OnReceivedData) { EXPECT_TRUE(GetData(filter_peer_.get()).empty()); const std::string data_chunk("12345"); @@ -144,9 +133,9 @@ TEST_F(ExtensionMessageFilterPeerTest, OnReceivedData) { MATCHER_P(IsURLRequestEqual, status, "") { return arg.status() == status; } -TEST_F(ExtensionMessageFilterPeerTest, OnCompletedRequestBadURLRequestStatus) { +TEST_F(ExtensionLocalizationPeerTest, OnCompletedRequestBadURLRequestStatus) { // It will self-delete once it exits OnCompletedRequest. - ExtensionMessageFilterPeer* filter_peer = filter_peer_.release(); + ExtensionLocalizationPeer* filter_peer = filter_peer_.release(); EXPECT_CALL(*original_peer_, OnReceivedResponse(_, true)); EXPECT_CALL(*original_peer_, OnCompletedRequest( @@ -157,9 +146,9 @@ TEST_F(ExtensionMessageFilterPeerTest, OnCompletedRequestBadURLRequestStatus) { filter_peer->OnCompletedRequest(status, ""); } -TEST_F(ExtensionMessageFilterPeerTest, OnCompletedRequestEmptyData) { +TEST_F(ExtensionLocalizationPeerTest, OnCompletedRequestEmptyData) { // It will self-delete once it exits OnCompletedRequest. - ExtensionMessageFilterPeer* filter_peer = filter_peer_.release(); + ExtensionLocalizationPeer* filter_peer = filter_peer_.release(); EXPECT_CALL(*original_peer_, GetURLForDebugging()).Times(0); EXPECT_CALL(*original_peer_, OnReceivedData(_, _)).Times(0); @@ -174,9 +163,9 @@ TEST_F(ExtensionMessageFilterPeerTest, OnCompletedRequestEmptyData) { filter_peer->OnCompletedRequest(status, ""); } -TEST_F(ExtensionMessageFilterPeerTest, OnCompletedRequestNoCatalogs) { +TEST_F(ExtensionLocalizationPeerTest, OnCompletedRequestNoCatalogs) { // It will self-delete once it exits OnCompletedRequest. - ExtensionMessageFilterPeer* filter_peer = filter_peer_.release(); + ExtensionLocalizationPeer* filter_peer = filter_peer_.release(); SetData(filter_peer, "some text"); @@ -197,20 +186,16 @@ TEST_F(ExtensionMessageFilterPeerTest, OnCompletedRequestNoCatalogs) { // Test if Send gets called again (it shouldn't be) when first call returned // an empty dictionary. - filter_peer = CreateExtensionMessageFilterPeer( - "text/css", - FilterPolicy::FILTER_EXTENSION_MESSAGES, - GURL(kExtensionUrl_1)); + filter_peer = + CreateExtensionLocalizationPeer("text/css", GURL(kExtensionUrl_1)); SetData(filter_peer, "some text"); filter_peer->OnCompletedRequest(status, ""); } -TEST_F(ExtensionMessageFilterPeerTest, OnCompletedRequestWithCatalogs) { +TEST_F(ExtensionLocalizationPeerTest, OnCompletedRequestWithCatalogs) { // It will self-delete once it exits OnCompletedRequest. - ExtensionMessageFilterPeer* filter_peer = CreateExtensionMessageFilterPeer( - "text/css", - FilterPolicy::FILTER_EXTENSION_MESSAGES, - GURL(kExtensionUrl_2)); + ExtensionLocalizationPeer* filter_peer = + CreateExtensionLocalizationPeer("text/css", GURL(kExtensionUrl_2)); L10nMessagesMap messages; messages.insert(std::make_pair("text", "new text")); @@ -238,12 +223,10 @@ TEST_F(ExtensionMessageFilterPeerTest, OnCompletedRequestWithCatalogs) { filter_peer->OnCompletedRequest(status, ""); } -TEST_F(ExtensionMessageFilterPeerTest, OnCompletedRequestReplaceMessagesFails) { +TEST_F(ExtensionLocalizationPeerTest, OnCompletedRequestReplaceMessagesFails) { // It will self-delete once it exits OnCompletedRequest. - ExtensionMessageFilterPeer* filter_peer = CreateExtensionMessageFilterPeer( - "text/css", - FilterPolicy::FILTER_EXTENSION_MESSAGES, - GURL(kExtensionUrl_3)); + ExtensionLocalizationPeer* filter_peer = + CreateExtensionLocalizationPeer("text/css", GURL(kExtensionUrl_3)); L10nMessagesMap messages; messages.insert(std::make_pair("text", "new text")); diff --git a/chrome/common/filter_policy.h b/chrome/common/filter_policy.h deleted file mode 100644 index 7bf17d2..0000000 --- a/chrome/common/filter_policy.h +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (c) 2010 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_COMMON_FILTER_POLICY_H__ -#define CHROME_COMMON_FILTER_POLICY_H__ - -#include "base/basictypes.h" - -// When an insecure resource (insecure content or bad HTTPS) is loaded, the -// browser can decide to filter it. The filtering is done in the renderer. -// This class enumerates the different policy that can be used for the -// filtering. It is passed along with resource response messages. -// It can be used for content post-processing, like message replacement within -// extension css files. -class FilterPolicy { - public: - enum Type { - // Pass all types of resources through unmodified. - DONT_FILTER = 0, - - // Post-process extension css files. - FILTER_EXTENSION_MESSAGES, - - // Block all types of resources, except images. For images, modify them to - // indicate that they have been filtered. - // TODO(abarth): This is a misleading name for this enum value. We should - // change it to something more suggestive of what this - // actually does. - FILTER_ALL_EXCEPT_IMAGES, - - // Block all types of resources. - FILTER_ALL - }; - - static bool ValidType(int32 type) { - return type >= DONT_FILTER && type <= FILTER_ALL; - } - - static Type FromInt(int32 type) { - return static_cast<Type>(type); - } - - private: - // Don't instantiate this class. - FilterPolicy(); - ~FilterPolicy(); - -}; - -#endif // CHROME_COMMON_FILTER_POLICY_H__ diff --git a/chrome/common/render_messages.h b/chrome/common/render_messages.h index 1b546e2..e1f8791 100644 --- a/chrome/common/render_messages.h +++ b/chrome/common/render_messages.h @@ -22,7 +22,6 @@ #include "chrome/common/edit_command.h" #include "chrome/common/extensions/extension_extent.h" #include "chrome/common/extensions/url_pattern.h" -#include "chrome/common/filter_policy.h" #include "chrome/common/navigation_gesture.h" #include "chrome/common/page_transition_types.h" #include "chrome/common/renderer_preferences.h" @@ -701,40 +700,6 @@ struct ParamTraits<ResourceType::Type> { }; template <> -struct ParamTraits<FilterPolicy::Type> { - typedef FilterPolicy::Type param_type; - static void Write(Message* m, const param_type& p) { - m->WriteInt(p); - } - static bool Read(const Message* m, void** iter, param_type* p) { - int type; - if (!m->ReadInt(iter, &type) || !FilterPolicy::ValidType(type)) - return false; - *p = FilterPolicy::FromInt(type); - return true; - } - static void Log(const param_type& p, std::wstring* l) { - std::wstring type; - switch (p) { - case FilterPolicy::DONT_FILTER: - type = L"DONT_FILTER"; - break; - case FilterPolicy::FILTER_ALL: - type = L"FILTER_ALL"; - break; - case FilterPolicy::FILTER_ALL_EXCEPT_IMAGES: - type = L"FILTER_ALL_EXCEPT_IMAGES"; - break; - default: - type = L"UNKNOWN"; - break; - } - - LogParam(type, l); - } -}; - -template <> struct ParamTraits<ViewHostMsg_ImeControl> { typedef ViewHostMsg_ImeControl param_type; static void Write(Message* m, const param_type& p) { @@ -1407,15 +1372,13 @@ struct ParamTraits<ResourceResponseHead> { static void Write(Message* m, const param_type& p) { ParamTraits<webkit_glue::ResourceLoaderBridge::ResponseInfo>::Write(m, p); WriteParam(m, p.status); - WriteParam(m, p.filter_policy); + WriteParam(m, p.replace_extension_localization_templates); } static bool Read(const Message* m, void** iter, param_type* r) { - return - ParamTraits<webkit_glue::ResourceLoaderBridge::ResponseInfo>::Read(m, - iter, - r) && - ReadParam(m, iter, &r->status) && - ReadParam(m, iter, &r->filter_policy); + return ParamTraits<webkit_glue::ResourceLoaderBridge::ResponseInfo>::Read( + m, iter, r) && + ReadParam(m, iter, &r->status) && + ReadParam(m, iter, &r->replace_extension_localization_templates); } static void Log(const param_type& p, std::wstring* l) { // log more? diff --git a/chrome/common/resource_dispatcher.cc b/chrome/common/resource_dispatcher.cc index b8f306c..7b2e96d 100644 --- a/chrome/common/resource_dispatcher.cc +++ b/chrome/common/resource_dispatcher.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -12,7 +12,7 @@ #include "base/message_loop.h" #include "base/shared_memory.h" #include "base/string_util.h" -#include "chrome/common/extensions/extension_message_filter_peer.h" +#include "chrome/common/extensions/extension_localization_peer.h" #include "chrome/common/render_messages.h" #include "chrome/common/security_filter_peer.h" #include "net/base/net_errors.h" @@ -336,35 +336,18 @@ void ResourceDispatcher::OnReceivedResponse( } PendingRequestInfo& request_info = it->second; - request_info.filter_policy = response_head.filter_policy; - webkit_glue::ResourceLoaderBridge::Peer* peer = request_info.peer; - webkit_glue::ResourceLoaderBridge::Peer* new_peer = NULL; - if (request_info.filter_policy == FilterPolicy::FILTER_EXTENSION_MESSAGES) { - new_peer = ExtensionMessageFilterPeer::CreateExtensionMessageFilterPeer( - peer, - message_sender(), - response_head.mime_type, - request_info.filter_policy, - request_info.url); - } else if (request_info.filter_policy != FilterPolicy::DONT_FILTER) { - // TODO(jcampan): really pass the loader bridge. - new_peer = SecurityFilterPeer::CreateSecurityFilterPeer( - NULL, - peer, - request_info.resource_type, - response_head.mime_type, - request_info.filter_policy, - net::ERR_INSECURE_RESPONSE); - } - - if (new_peer) { - request_info.peer = new_peer; - peer = new_peer; + if (response_head.replace_extension_localization_templates) { + webkit_glue::ResourceLoaderBridge::Peer* new_peer = + ExtensionLocalizationPeer::CreateExtensionLocalizationPeer( + request_info.peer, message_sender(), response_head.mime_type, + request_info.url); + if (new_peer) + request_info.peer = new_peer; } RESOURCE_LOG("Dispatching response for " << - peer->GetURLForDebugging().possibly_invalid_spec()); - peer->OnReceivedResponse(response_head, false); + request_info.peer->GetURLForDebugging().possibly_invalid_spec()); + request_info.peer->OnReceivedResponse(response_head, false); } void ResourceDispatcher::OnReceivedCachedMetadata( diff --git a/chrome/common/resource_dispatcher.h b/chrome/common/resource_dispatcher.h index cf050a2..c98b11a 100644 --- a/chrome/common/resource_dispatcher.h +++ b/chrome/common/resource_dispatcher.h @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -13,7 +13,6 @@ #include "base/hash_tables.h" #include "base/shared_memory.h" #include "base/task.h" -#include "chrome/common/filter_policy.h" #include "ipc/ipc_channel.h" #include "webkit/glue/resource_loader_bridge.h" @@ -70,14 +69,12 @@ class ResourceDispatcher { const GURL& request_url) : peer(peer), resource_type(resource_type), - filter_policy(FilterPolicy::DONT_FILTER), is_deferred(false), url(request_url) { } ~PendingRequestInfo() { } webkit_glue::ResourceLoaderBridge::Peer* peer; ResourceType::Type resource_type; - FilterPolicy::Type filter_policy; MessageQueue deferred_message_queue; bool is_deferred; GURL url; diff --git a/chrome/common/resource_dispatcher_unittest.cc b/chrome/common/resource_dispatcher_unittest.cc index 4149900..323a6e421 100644 --- a/chrome/common/resource_dispatcher_unittest.cc +++ b/chrome/common/resource_dispatcher_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -9,7 +9,6 @@ #include "base/process.h" #include "base/process_util.h" #include "base/scoped_ptr.h" -#include "chrome/common/filter_policy.h" #include "chrome/common/render_messages.h" #include "chrome/common/resource_dispatcher.h" #include "testing/gtest/include/gtest/gtest.h" @@ -109,7 +108,6 @@ class ResourceDispatcherTest : public testing::Test, response.headers = new net::HttpResponseHeaders(raw_headers); response.mime_type = test_page_mime_type; response.charset = test_page_charset; - response.filter_policy = FilterPolicy::DONT_FILTER; dispatcher_->OnReceivedResponse(request_id, response); // received data message with the test contents diff --git a/chrome/common/resource_response.h b/chrome/common/resource_response.h index 840b864..1c9b766 100644 --- a/chrome/common/resource_response.h +++ b/chrome/common/resource_response.h @@ -10,7 +10,6 @@ #include <string> #include "base/ref_counted.h" -#include "chrome/common/filter_policy.h" #include "googleurl/src/gurl.h" #include "net/url_request/url_request_status.h" #include "webkit/glue/resource_loader_bridge.h" @@ -18,14 +17,15 @@ // Parameters for a resource response header. struct ResourceResponseHead : webkit_glue::ResourceLoaderBridge::ResponseInfo { - ResourceResponseHead() : filter_policy(FilterPolicy::DONT_FILTER) {} + ResourceResponseHead() : replace_extension_localization_templates(false) {} // The response status. URLRequestStatus status; - // Specifies if the resource should be filtered before being displayed - // (insecure resources can be filtered to keep the page secure). - FilterPolicy::Type filter_policy; + // Whether we should apply a filter to this resource that replaces + // localization templates with the appropriate localized strings. This is set + // for CSS resources used by extensions. + bool replace_extension_localization_templates; }; // Parameters for a synchronous resource response. diff --git a/chrome/common/security_filter_peer.cc b/chrome/common/security_filter_peer.cc index 180c491..6448d206c 100644 --- a/chrome/common/security_filter_peer.cc +++ b/chrome/common/security_filter_peer.cc @@ -1,22 +1,13 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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/common/security_filter_peer.h" #include "app/l10n_util.h" -#include "app/resource_bundle.h" -#include "base/string_util.h" -#include "gfx/codec/png_codec.h" -#include "gfx/size.h" #include "grit/generated_resources.h" -#include "grit/renderer_resources.h" #include "net/base/net_errors.h" #include "net/http/http_response_headers.h" -#include "third_party/skia/include/core/SkCanvas.h" -#include "third_party/skia/include/core/SkBitmap.h" -#include "third_party/skia/include/core/SkDevice.h" -#include "webkit/glue/webkit_glue.h" SecurityFilterPeer::SecurityFilterPeer( webkit_glue::ResourceLoaderBridge* resource_loader_bridge, @@ -29,36 +20,6 @@ SecurityFilterPeer::~SecurityFilterPeer() { } // static -SecurityFilterPeer* SecurityFilterPeer::CreateSecurityFilterPeer( - webkit_glue::ResourceLoaderBridge* resource_loader_bridge, - webkit_glue::ResourceLoaderBridge::Peer* peer, - ResourceType::Type resource_type, - const std::string& mime_type, - FilterPolicy::Type filter_policy, - int os_error) { - if (filter_policy == FilterPolicy::DONT_FILTER) { - NOTREACHED(); - return NULL; - } - - if (StartsWithASCII(mime_type, "image/", false)) { - // What we do with images depends on details of the |filter_policy|. - if (filter_policy == FilterPolicy::FILTER_ALL_EXCEPT_IMAGES) - return new ImageFilterPeer(resource_loader_bridge, peer); - // Otherwise, fall through to blocking images hard. - } - - // Regardless of what a frame contents replace it with our error message, - // so it is visible it's been filtered-out. - if (ResourceType::IsFrame(resource_type)) - return CreateSecurityFilterPeerForFrame(peer, os_error); - - // Any other content is entirely filtered-out. - return new ReplaceContentPeer(resource_loader_bridge, peer, - std::string(), std::string()); -} - -// static SecurityFilterPeer* SecurityFilterPeer::CreateSecurityFilterPeerForDeniedRequest( ResourceType::Type resource_type, @@ -247,80 +208,3 @@ void ReplaceContentPeer::OnCompletedRequest(const URLRequestStatus& status, // The request processing is complete, we must delete ourselves. delete this; } - -//////////////////////////////////////////////////////////////////////////////// -// ImageFilterPeer - -ImageFilterPeer::ImageFilterPeer( - webkit_glue::ResourceLoaderBridge* resource_loader_bridge, - webkit_glue::ResourceLoaderBridge::Peer* peer) - : BufferedPeer(resource_loader_bridge, peer, "image/png") { -} - -ImageFilterPeer::~ImageFilterPeer() { -} - -bool ImageFilterPeer::DataReady() { - static SkBitmap* stamp_bitmap = NULL; - if (!stamp_bitmap) { - ResourceBundle& rb = ResourceBundle::GetSharedInstance(); - stamp_bitmap = rb.GetBitmapNamed(IDR_INSECURE_CONTENT_STAMP); - if (!stamp_bitmap) { - NOTREACHED(); - return false; - } - } - - // Let's decode the image we have been given. - SkBitmap image; - if (!webkit_glue::DecodeImage(data_, &image)) - return false; // We could not decode that image. - - // Let's create a new canvas to modify the image. - SkBitmap canvas_bitmap; - canvas_bitmap.setConfig(SkBitmap::kARGB_8888_Config, - image.width(), image.height()); - canvas_bitmap.allocPixels(); - SkCanvas canvas(canvas_bitmap); - - // Let's paint the actual image with an alpha. - SkRect rect; - rect.fLeft = 0; - rect.fTop = 0; - rect.fRight = SkIntToScalar(image.width()); - rect.fBottom = SkIntToScalar(image.height()); - - SkPaint paint; - paint.setAlpha(80); - canvas.drawBitmapRect(image, NULL, rect, &paint); - - // Then stamp-it. - paint.setAlpha(150); - int visible_row_count = image.height() / stamp_bitmap->height(); - if (image.height() % stamp_bitmap->height() != 0) - visible_row_count++; - - for (int row = 0; row < visible_row_count; row++) { - for (int x = (row % 2 == 0) ? 0 : stamp_bitmap->width(); x < image.width(); - x += stamp_bitmap->width() * 2) { - canvas.drawBitmap(*stamp_bitmap, - SkIntToScalar(x), - SkIntToScalar(row * stamp_bitmap->height()), - &paint); - } - } - - // Now encode it to a PNG. - std::vector<unsigned char> output; - if (!gfx::PNGCodec::EncodeBGRASkBitmap( - canvas.getDevice()->accessBitmap(false), false, &output)) { - return false; - } - - // Copy the vector content to data_ which is a string. - data_.clear(); - data_.resize(output.size()); - std::copy(output.begin(), output.end(), data_.begin()); - - return true; -} diff --git a/chrome/common/security_filter_peer.h b/chrome/common/security_filter_peer.h index c3d3513..4a44be3 100644 --- a/chrome/common/security_filter_peer.h +++ b/chrome/common/security_filter_peer.h @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -6,7 +6,6 @@ #ifndef CHROME_COMMON_SECURITY_FILTER_PEER_H__ #define CHROME_COMMON_SECURITY_FILTER_PEER_H__ -#include "chrome/common/filter_policy.h" #include "webkit/glue/resource_loader_bridge.h" // The SecurityFilterPeer is a proxy to a @@ -20,14 +19,6 @@ class SecurityFilterPeer : public webkit_glue::ResourceLoaderBridge::Peer { public: virtual ~SecurityFilterPeer(); - static SecurityFilterPeer* CreateSecurityFilterPeer( - webkit_glue::ResourceLoaderBridge* resource_loader_bridge, - webkit_glue::ResourceLoaderBridge::Peer* peer, - ResourceType::Type resource_type, - const std::string& mime_type, - FilterPolicy::Type filter_policy, - int os_error); - static SecurityFilterPeer* CreateSecurityFilterPeerForDeniedRequest( ResourceType::Type resource_type, webkit_glue::ResourceLoaderBridge::Peer* peer, @@ -128,19 +119,4 @@ class ReplaceContentPeer : public SecurityFilterPeer { DISALLOW_COPY_AND_ASSIGN(ReplaceContentPeer); }; -// This class filters insecure image by replacing them with a transparent and -// stamped image. -class ImageFilterPeer : public BufferedPeer { - public: - ImageFilterPeer(webkit_glue::ResourceLoaderBridge* resource_loader_bridge, - webkit_glue::ResourceLoaderBridge::Peer* peer); - virtual ~ImageFilterPeer(); - - protected: - virtual bool DataReady(); - - private: - DISALLOW_COPY_AND_ASSIGN(ImageFilterPeer); -}; - #endif // CHROME_COMMON_SECURITY_FILTER_PEER_H__ |