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 /chrome/common | |
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
Diffstat (limited to 'chrome/common')
-rw-r--r-- | chrome/common/extensions/extension_localization_peer.cc (renamed from chrome/common/extensions/extension_message_filter_peer.cc) | 38 | ||||
-rw-r--r-- | chrome/common/extensions/extension_localization_peer.h (renamed from chrome/common/extensions/extension_message_filter_peer.h) | 32 | ||||
-rw-r--r-- | chrome/common/extensions/extension_localization_peer_unittest.cc (renamed from chrome/common/extensions/extension_message_filter_peer_unittest.cc) | 75 | ||||
-rw-r--r-- | chrome/common/filter_policy.h | 51 | ||||
-rw-r--r-- | chrome/common/render_messages.h | 47 | ||||
-rw-r--r-- | chrome/common/resource_dispatcher.cc | 39 | ||||
-rw-r--r-- | chrome/common/resource_dispatcher.h | 5 | ||||
-rw-r--r-- | chrome/common/resource_dispatcher_unittest.cc | 4 | ||||
-rw-r--r-- | chrome/common/resource_response.h | 10 | ||||
-rw-r--r-- | chrome/common/security_filter_peer.cc | 118 | ||||
-rw-r--r-- | chrome/common/security_filter_peer.h | 26 |
11 files changed, 87 insertions, 358 deletions
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__ |