Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

Commit

Permalink
Ensure streams aren't intercepted unless their associated plugin is e…
Browse files Browse the repository at this point in the history
…nabled

Previously streams would be intercepted even if the MimeHandlerView plugin
associated with them was disabled which would prevent the resource
from being download if a plugin wasn't being enabled to handle it.

BUG=459383

Review URL: https://codereview.chromium.org/933093002

Cr-Commit-Position: refs/heads/master@{#317673}
  • Loading branch information
raymes authored and Commit bot committed Feb 23, 2015
1 parent 856e771 commit 553cec8
Showing 1 changed file with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "chrome/browser/download/download_request_limiter.h"
#include "chrome/browser/download/download_resource_throttle.h"
#include "chrome/browser/net/resource_prefetch_predictor_observer.h"
#include "chrome/browser/plugins/plugin_prefs.h"
#include "chrome/browser/prefetch/prefetch.h"
#include "chrome/browser/prerender/prerender_manager.h"
#include "chrome/browser/prerender/prerender_manager_factory.h"
Expand All @@ -37,6 +38,8 @@
#include "components/variations/net/variations_http_header_provider.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/plugin_service.h"
#include "content/public/browser/plugin_service_filter.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/resource_context.h"
Expand Down Expand Up @@ -207,6 +210,36 @@ void SendExecuteMimeTypeHandlerEvent(scoped_ptr<content::StreamInfo> stream,
extension_id, web_contents, stream.Pass(), view_id, expected_content_size,
embedded, render_process_id, render_frame_id);
}

// TODO(raymes): This won't return the right result if plugins haven't been
// loaded yet. Fixing this properly really requires fixing crbug.com/443466.
bool IsPluginEnabledForExtension(const Extension* extension,
const ResourceRequestInfo* info,
const std::string& mime_type,
const GURL& url) {
content::PluginService* service = content::PluginService::GetInstance();
std::vector<content::WebPluginInfo> plugins;
service->GetPluginInfoArray(url, mime_type, true, &plugins, nullptr);
content::PluginServiceFilter* filter = service->GetFilter();

for (auto& plugin : plugins) {
// Check that the plugin is running the extension.
if (plugin.path !=
base::FilePath::FromUTF8Unsafe(extension->url().spec())) {
continue;
}
// Check that the plugin is actually enabled.
if (!filter || filter->IsPluginAvailable(info->GetChildID(),
info->GetRenderFrameID(),
info->GetContext(),
url,
GURL(),
&plugin)) {
return true;
}
}
return false;
}
#endif // !defined(ENABLE_EXTENSIONS)

#if !defined(OS_ANDROID)
Expand Down Expand Up @@ -627,6 +660,13 @@ bool ChromeResourceDispatcherHostDelegate::ShouldInterceptResourceAsStream(
*origin = Extension::GetBaseURLFromExtensionId(extension_id);
target_info.extension_id = extension_id;
if (!handler->handler_url().empty()) {
// This is reached in the case of MimeHandlerViews. If the
// MimeHandlerView plugin is disabled, then we shouldn't intercept the
// stream.
if (!IsPluginEnabledForExtension(extension, info, mime_type,
request->url())) {
continue;
}
target_info.view_id = base::GenerateGUID();
*payload = target_info.view_id;
}
Expand Down

0 comments on commit 553cec8

Please sign in to comment.