diff options
author | bauerb@chromium.org <bauerb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-02 20:08:47 +0000 |
---|---|---|
committer | bauerb@chromium.org <bauerb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-02 20:08:47 +0000 |
commit | e0379d56b61dc1bca0ee1c66b93b9c19279332b3 (patch) | |
tree | 60962418d15fd8073fe59abe8472ab6bd9899cd0 /chrome | |
parent | f49f5aa4139b80e4457587910d49199a9f9fe666 (diff) | |
download | chromium_src-e0379d56b61dc1bca0ee1c66b93b9c19279332b3.zip chromium_src-e0379d56b61dc1bca0ee1c66b93b9c19279332b3.tar.gz chromium_src-e0379d56b61dc1bca0ee1c66b93b9c19279332b3.tar.bz2 |
Use PluginPrefs to find out whether the PDF plugin is enabled in GViewRequestInterceptor.
BUG=80794
TEST=GViewRequestInterceptorTest.*
Review URL: http://codereview.chromium.org/7541076
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@99433 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/chromeos/gview_request_interceptor.cc | 34 | ||||
-rw-r--r-- | chrome/browser/chromeos/gview_request_interceptor.h | 2 | ||||
-rw-r--r-- | chrome/browser/chromeos/gview_request_interceptor_unittest.cc | 108 | ||||
-rw-r--r-- | chrome/browser/extensions/user_script_listener_unittest.cc | 63 | ||||
-rw-r--r-- | chrome/browser/plugin_prefs.cc | 14 | ||||
-rw-r--r-- | chrome/browser/plugin_prefs.h | 13 | ||||
-rw-r--r-- | chrome/browser/ui/webui/plugins_ui.cc | 8 |
7 files changed, 128 insertions, 114 deletions
diff --git a/chrome/browser/chromeos/gview_request_interceptor.cc b/chrome/browser/chromeos/gview_request_interceptor.cc index 3beab22..730767f 100644 --- a/chrome/browser/chromeos/gview_request_interceptor.cc +++ b/chrome/browser/chromeos/gview_request_interceptor.cc @@ -6,7 +6,10 @@ #include "base/file_path.h" #include "base/path_service.h" +#include "chrome/browser/chrome_plugin_service_filter.h" #include "chrome/common/chrome_paths.h" +#include "content/browser/renderer_host/resource_dispatcher_host.h" +#include "content/browser/renderer_host/resource_dispatcher_host_request_info.h" #include "googleurl/src/gurl.h" #include "net/base/escape.h" #include "net/base/load_flags.h" @@ -52,6 +55,26 @@ net::URLRequestJob* GViewRequestInterceptor::MaybeInterceptRedirect( return NULL; } +bool GViewRequestInterceptor::ShouldUsePdfPlugin( + net::URLRequest* request) const { + FilePath pdf_path; + PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_path); + ResourceDispatcherHostRequestInfo* info = + ResourceDispatcherHost::InfoForRequest(request); + if (!info) + return false; + + webkit::WebPluginInfo plugin; + if (!webkit::npapi::PluginList::Singleton()->GetPluginInfoByPath( + pdf_path, &plugin)) { + return false; + } + + return ChromePluginServiceFilter::GetInstance()->ShouldUsePlugin( + info->child_id(), info->route_id(), info->context(), + request->url(), GURL(), &plugin); +} + net::URLRequestJob* GViewRequestInterceptor::MaybeInterceptResponse( net::URLRequest* request) const { // Do not intercept this request if it is a download. @@ -63,15 +86,8 @@ net::URLRequestJob* GViewRequestInterceptor::MaybeInterceptResponse( request->GetMimeType(&mime_type); // If the local PDF viewing plug-in is installed and enabled, don't // redirect PDF files to Google Document Viewer. - if (mime_type == kPdfMimeType) { - FilePath pdf_path; - webkit::WebPluginInfo info; - PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_path); - if (webkit::npapi::PluginList::Singleton()->GetPluginInfoByPath( - pdf_path, &info) && - webkit::IsPluginEnabled(info)) - return NULL; - } + if (mime_type == kPdfMimeType && ShouldUsePdfPlugin(request)) + return NULL; // If supported, build the URL to the Google Document Viewer // including the origial document's URL, then create a new job that // will redirect the browser to this new URL. diff --git a/chrome/browser/chromeos/gview_request_interceptor.h b/chrome/browser/chromeos/gview_request_interceptor.h index eee5472..f42d1bc 100644 --- a/chrome/browser/chromeos/gview_request_interceptor.h +++ b/chrome/browser/chromeos/gview_request_interceptor.h @@ -39,6 +39,8 @@ class GViewRequestInterceptor : public net::URLRequestJobFactory::Interceptor { net::URLRequest* request) const; private: + bool ShouldUsePdfPlugin(net::URLRequest* request) const; + // The list of supported mime types. base::hash_set<std::string> supported_mime_types_; }; diff --git a/chrome/browser/chromeos/gview_request_interceptor_unittest.cc b/chrome/browser/chromeos/gview_request_interceptor_unittest.cc index 4e4d204..97eb568 100644 --- a/chrome/browser/chromeos/gview_request_interceptor_unittest.cc +++ b/chrome/browser/chromeos/gview_request_interceptor_unittest.cc @@ -5,9 +5,15 @@ #include <string> #include "base/message_loop.h" +#include "chrome/browser/chrome_plugin_service_filter.h" #include "chrome/browser/chromeos/gview_request_interceptor.h" +#include "chrome/browser/plugin_prefs.h" #include "chrome/common/chrome_paths.h" +#include "chrome/test/base/testing_pref_service.h" +#include "content/browser/mock_resource_context.h" #include "content/browser/plugin_service.h" +#include "content/browser/renderer_host/dummy_resource_handler.h" +#include "content/browser/renderer_host/resource_dispatcher_host_request_info.h" #include "net/base/load_flags.h" #include "net/url_request/url_request.h" #include "net/url_request/url_request_job.h" @@ -63,12 +69,42 @@ class GViewRequestProtocolFactory class GViewRequestInterceptorTest : public testing::Test { public: + GViewRequestInterceptorTest() + : ui_thread_(BrowserThread::UI, &message_loop_), + io_thread_(BrowserThread::IO, &message_loop_) {} + virtual void SetUp() { + content::ResourceContext* resource_context = + content::MockResourceContext::GetInstance(); + net::URLRequestContext* request_context = + resource_context->request_context(); + old_factory_ = request_context->job_factory(); job_factory_.SetProtocolHandler("http", new GViewRequestProtocolFactory); job_factory_.AddInterceptor(new GViewRequestInterceptor); - request_context_ = new TestURLRequestContext; - request_context_->set_job_factory(&job_factory_); + request_context->set_job_factory(&job_factory_); + PluginPrefs::RegisterPrefs(&prefs_); + plugin_prefs_ = new PluginPrefs(); + plugin_prefs_->SetPrefs(&prefs_); + ChromePluginServiceFilter* filter = + ChromePluginServiceFilter::GetInstance(); + filter->RegisterResourceContext(plugin_prefs_, resource_context); + PluginService::GetInstance()->set_filter(filter); + ASSERT_TRUE(PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_path_)); + + handler_ = new content::DummyResourceHandler(); + } + + virtual void TearDown() { + content::ResourceContext* resource_context = + content::MockResourceContext::GetInstance(); + net::URLRequestContext* request_context = + resource_context->request_context(); + request_context->set_job_factory(old_factory_); + ChromePluginServiceFilter* filter = + ChromePluginServiceFilter::GetInstance(); + filter->UnregisterResourceContext(resource_context); + PluginService::GetInstance()->set_filter(NULL); } void RegisterPDFPlugin() { @@ -84,7 +120,7 @@ class GViewRequestInterceptorTest : public testing::Test { webkit::npapi::PluginList::Singleton()->RefreshPlugins(); } - void SetPDFPluginLoadedState(bool want_loaded, bool* out_is_enabled) { + void SetPDFPluginLoadedState(bool want_loaded) { webkit::WebPluginInfo info; bool is_loaded = webkit::npapi::PluginList::Singleton()->GetPluginInfoByPath( @@ -102,20 +138,47 @@ class GViewRequestInterceptorTest : public testing::Test { pdf_path_, &info); } EXPECT_EQ(want_loaded, is_loaded); - *out_is_enabled = webkit::IsPluginEnabled(info); + } + + void SetupRequest(net::URLRequest* request) { + content::ResourceContext* context = + content::MockResourceContext::GetInstance(); + ResourceDispatcherHostRequestInfo* info = + new ResourceDispatcherHostRequestInfo(handler_, + ChildProcessInfo::RENDER_PROCESS, + -1, // child_id + MSG_ROUTING_NONE, + 0, // origin_pid + request->identifier(), + false, // is_main_frame + -1, // frame_id + ResourceType::MAIN_FRAME, + PageTransition::LINK, + 0, // upload_size + false, // is_download + true, // allow_download + false, // has_user_gesture + context); + request->SetUserData(NULL, info); + request->set_context(context->request_context()); } protected: MessageLoopForIO message_loop_; + BrowserThread ui_thread_; + BrowserThread io_thread_; + TestingPrefService prefs_; + scoped_refptr<PluginPrefs> plugin_prefs_; net::URLRequestJobFactory job_factory_; - scoped_refptr<TestURLRequestContext> request_context_; + const net::URLRequestJobFactory* old_factory_; + scoped_refptr<ResourceHandler> handler_; TestDelegate test_delegate_; FilePath pdf_path_; }; TEST_F(GViewRequestInterceptorTest, DoNotInterceptHtml) { net::URLRequest request(GURL("http://foo.com/index.html"), &test_delegate_); - request.set_context(request_context_); + SetupRequest(&request); request.Start(); MessageLoop::current()->Run(); EXPECT_EQ(0, test_delegate_.received_redirect_count()); @@ -124,7 +187,7 @@ TEST_F(GViewRequestInterceptorTest, DoNotInterceptHtml) { TEST_F(GViewRequestInterceptorTest, DoNotInterceptDownload) { net::URLRequest request(GURL("http://foo.com/file.pdf"), &test_delegate_); - request.set_context(request_context_); + SetupRequest(&request); request.set_load_flags(net::LOAD_IS_DOWNLOAD); request.Start(); MessageLoop::current()->Run(); @@ -133,17 +196,11 @@ TEST_F(GViewRequestInterceptorTest, DoNotInterceptDownload) { } TEST_F(GViewRequestInterceptorTest, DoNotInterceptPdfWhenEnabled) { - bool enabled; - SetPDFPluginLoadedState(true, &enabled); - - if (!enabled) { - bool pdf_plugin_enabled = - webkit::npapi::PluginList::Singleton()->EnablePlugin(pdf_path_); - EXPECT_TRUE(pdf_plugin_enabled); - } + SetPDFPluginLoadedState(true); + webkit::npapi::PluginList::Singleton()->EnablePlugin(pdf_path_); net::URLRequest request(GURL("http://foo.com/file.pdf"), &test_delegate_); - request.set_context(request_context_); + SetupRequest(&request); request.Start(); MessageLoop::current()->Run(); EXPECT_EQ(0, test_delegate_.received_redirect_count()); @@ -151,17 +208,11 @@ TEST_F(GViewRequestInterceptorTest, DoNotInterceptPdfWhenEnabled) { } TEST_F(GViewRequestInterceptorTest, InterceptPdfWhenDisabled) { - bool enabled; - SetPDFPluginLoadedState(true, &enabled); - - if (enabled) { - bool pdf_plugin_disabled = - webkit::npapi::PluginList::Singleton()->DisablePlugin(pdf_path_); - EXPECT_TRUE(pdf_plugin_disabled); - } + SetPDFPluginLoadedState(true); + webkit::npapi::PluginList::Singleton()->DisablePlugin(pdf_path_); net::URLRequest request(GURL("http://foo.com/file.pdf"), &test_delegate_); - request.set_context(request_context_); + SetupRequest(&request); request.Start(); MessageLoop::current()->Run(); EXPECT_EQ(1, test_delegate_.received_redirect_count()); @@ -171,11 +222,10 @@ TEST_F(GViewRequestInterceptorTest, InterceptPdfWhenDisabled) { } TEST_F(GViewRequestInterceptorTest, InterceptPdfWithNoPlugin) { - bool enabled; - SetPDFPluginLoadedState(false, &enabled); + SetPDFPluginLoadedState(false); net::URLRequest request(GURL("http://foo.com/file.pdf"), &test_delegate_); - request.set_context(request_context_); + SetupRequest(&request); request.Start(); MessageLoop::current()->Run(); EXPECT_EQ(1, test_delegate_.received_redirect_count()); @@ -185,7 +235,7 @@ TEST_F(GViewRequestInterceptorTest, InterceptPdfWithNoPlugin) { TEST_F(GViewRequestInterceptorTest, InterceptPowerpoint) { net::URLRequest request(GURL("http://foo.com/file.ppt"), &test_delegate_); - request.set_context(request_context_); + SetupRequest(&request); request.Start(); MessageLoop::current()->Run(); EXPECT_EQ(1, test_delegate_.received_redirect_count()); diff --git a/chrome/browser/extensions/user_script_listener_unittest.cc b/chrome/browser/extensions/user_script_listener_unittest.cc index efe8d76..e7e6213 100644 --- a/chrome/browser/extensions/user_script_listener_unittest.cc +++ b/chrome/browser/extensions/user_script_listener_unittest.cc @@ -10,9 +10,9 @@ #include "chrome/common/chrome_paths.h" #include "chrome/common/extensions/extension_file_util.h" #include "content/browser/mock_resource_context.h" +#include "content/browser/renderer_host/dummy_resource_handler.h" #include "content/browser/renderer_host/global_request_id.h" #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h" -#include "content/browser/renderer_host/resource_handler.h" #include "content/browser/renderer_host/resource_queue.h" #include "content/common/notification_service.h" #include "net/url_request/url_request.h" @@ -22,71 +22,14 @@ class Profile; +using content::DummyResourceHandler; + namespace { const char kMatchingUrl[] = "http://google.com/"; const char kNotMatchingUrl[] = "http://example.com/"; const char kTestData[] = "Hello, World!"; -// Dummy ResourceHandler required for ResourceDispatcherHostRequestInfo. -class DummyResourceHandler : public ResourceHandler { - public: - DummyResourceHandler() { - } - - virtual bool OnUploadProgress(int request_id, uint64 position, uint64 size) { - NOTREACHED(); - return true; - } - - - virtual bool OnRequestRedirected(int request_id, const GURL& url, - ResourceResponse* response, - bool* defer) { - NOTREACHED(); - return true; - } - - virtual bool OnResponseStarted(int request_id, - ResourceResponse* response) { - NOTREACHED(); - return true; - } - - virtual bool OnWillStart(int request_id, - const GURL& url, - bool* defer) { - NOTREACHED(); - return true; - } - - virtual bool OnWillRead(int request_id, - net::IOBuffer** buf, - int* buf_size, - int min_size) { - NOTREACHED(); - return true; - } - - virtual bool OnReadCompleted(int request_id, int* bytes_read) { - NOTREACHED(); - return true; - } - - virtual bool OnResponseCompleted(int request_id, - const net::URLRequestStatus& status, - const std::string& security_info) { - NOTREACHED(); - return true; - } - - virtual void OnRequestClosed() { - } - - private: - DISALLOW_COPY_AND_ASSIGN(DummyResourceHandler); -}; - ResourceDispatcherHostRequestInfo* CreateRequestInfo(int request_id) { return new ResourceDispatcherHostRequestInfo( new DummyResourceHandler(), ChildProcessInfo::RENDER_PROCESS, 0, 0, 0, diff --git a/chrome/browser/plugin_prefs.cc b/chrome/browser/plugin_prefs.cc index 7b2ce4d..28468b2 100644 --- a/chrome/browser/plugin_prefs.cc +++ b/chrome/browser/plugin_prefs.cc @@ -182,8 +182,8 @@ void PluginPrefs::ListValueToStringSet(const ListValue* src, } } -void PluginPrefs::SetProfile(Profile* profile) { - prefs_ = profile->GetPrefs(); +void PluginPrefs::SetPrefs(PrefService* prefs) { + prefs_ = prefs; bool update_internal_dir = false; FilePath last_internal_dir = prefs_->GetFilePath(prefs::kPluginsLastInternalDirectory); @@ -355,7 +355,7 @@ PluginPrefs::Factory::Factory() ProfileKeyedService* PluginPrefs::Factory::BuildServiceInstanceFor( Profile* profile) const { scoped_refptr<PluginPrefs> plugin_prefs(new PluginPrefs()); - plugin_prefs->SetProfile(profile); + plugin_prefs->SetPrefs(profile->GetPrefs()); return new PluginPrefsWrapper(plugin_prefs); } @@ -452,6 +452,14 @@ void PluginPrefs::RegisterPrefs(PrefService* prefs) { prefs->RegisterFilePathPref(prefs::kPluginsLastInternalDirectory, internal_dir, PrefService::UNSYNCABLE_PREF); + prefs->RegisterBooleanPref(prefs::kPluginsEnabledInternalPDF, + false, + PrefService::UNSYNCABLE_PREF); + prefs->RegisterBooleanPref(prefs::kPluginsEnabledNaCl, + false, + PrefService::UNSYNCABLE_PREF); + prefs->RegisterListPref(prefs::kPluginsPluginsList, + PrefService::UNSYNCABLE_PREF); prefs->RegisterListPref(prefs::kPluginsDisabledPlugins, PrefService::UNSYNCABLE_PREF); prefs->RegisterListPref(prefs::kPluginsDisabledPluginsExceptions, diff --git a/chrome/browser/plugin_prefs.h b/chrome/browser/plugin_prefs.h index ae19ad4..d55a600 100644 --- a/chrome/browser/plugin_prefs.h +++ b/chrome/browser/plugin_prefs.h @@ -46,8 +46,16 @@ class PluginPrefs : public base::RefCountedThreadSafe<PluginPrefs>, // This should be called before the first profile is created. static void Initialize(); + // Returns the instance associated with |profile|, creating it if necessary. static PluginPrefs* GetForProfile(Profile* profile); + // Creates a new instance. This method should only be used for testing. + PluginPrefs(); + + // Associates this instance with |prefs|. This enables or disables + // plugin groups as defined by the user's preferences. + void SetPrefs(PrefService* prefs); + // Enable or disable a plugin group. void EnablePluginGroup(bool enable, const string16& group_name); @@ -74,13 +82,8 @@ class PluginPrefs : public base::RefCountedThreadSafe<PluginPrefs>, class Factory; - PluginPrefs(); virtual ~PluginPrefs(); - // Associates the PluginPrefs with |profile|. This enables or disables - // plugin groups as defined by the user's preferences. - void SetProfile(Profile* profile); - // Called on the file thread to get the data necessary to update the saved // preferences. void GetPreferencesDataOnFileThread(); diff --git a/chrome/browser/ui/webui/plugins_ui.cc b/chrome/browser/ui/webui/plugins_ui.cc index f2fc958..710f423 100644 --- a/chrome/browser/ui/webui/plugins_ui.cc +++ b/chrome/browser/ui/webui/plugins_ui.cc @@ -330,14 +330,6 @@ RefCountedMemory* PluginsUI::GetFaviconResourceBytes() { // static void PluginsUI::RegisterUserPrefs(PrefService* prefs) { - prefs->RegisterListPref(prefs::kPluginsPluginsList, - PrefService::UNSYNCABLE_PREF); - prefs->RegisterBooleanPref(prefs::kPluginsEnabledInternalPDF, - false, - PrefService::UNSYNCABLE_PREF); - prefs->RegisterBooleanPref(prefs::kPluginsEnabledNaCl, - false, - PrefService::UNSYNCABLE_PREF); prefs->RegisterBooleanPref(prefs::kPluginsShowDetails, false, PrefService::UNSYNCABLE_PREF); |