| Index: chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc
|
| diff --git a/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc b/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc
|
| index bf74c49c721d55c63148b6fbb5884d63ef83a0c3..79e000ac6bbad7569725fd4ad32c9473cc0d7cad 100644
|
| --- a/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc
|
| +++ b/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc
|
| @@ -13,6 +13,9 @@
|
| #include "chrome/browser/download/download_request_limiter.h"
|
| #include "chrome/browser/download/download_resource_throttle.h"
|
| #include "chrome/browser/download/download_util.h"
|
| +#include "chrome/browser/extensions/event_router.h"
|
| +#include "chrome/browser/extensions/extension_info_map.h"
|
| +#include "chrome/browser/extensions/extension_system.h"
|
| #include "chrome/browser/extensions/user_script_listener.h"
|
| #include "chrome/browser/external_protocol/external_protocol_handler.h"
|
| #include "chrome/browser/google/google_util.h"
|
| @@ -22,6 +25,7 @@
|
| #include "chrome/browser/prerender/prerender_manager.h"
|
| #include "chrome/browser/prerender/prerender_tracker.h"
|
| #include "chrome/browser/prerender/prerender_util.h"
|
| +#include "chrome/browser/profiles/profile.h"
|
| #include "chrome/browser/profiles/profile_io_data.h"
|
| #include "chrome/browser/renderer_host/chrome_url_request_user_data.h"
|
| #include "chrome/browser/renderer_host/safe_browsing_resource_throttle_factory.h"
|
| @@ -39,6 +43,7 @@
|
| #include "content/public/browser/resource_context.h"
|
| #include "content/public/browser/resource_dispatcher_host.h"
|
| #include "content/public/browser/resource_request_info.h"
|
| +#include "extensions/common/constants.h"
|
| #include "net/base/load_flags.h"
|
| #include "net/base/ssl_config_service.h"
|
| #include "net/http/http_response_headers.h"
|
| @@ -59,6 +64,7 @@
|
| #endif
|
|
|
| #if defined(OS_CHROMEOS)
|
| +#include "chrome/browser/chromeos/extensions/file_browser_handler.h"
|
| #include "chrome/browser/chromeos/extensions/file_browser_resource_throttle.h"
|
| // TODO(oshima): Enable this for other platforms.
|
| #include "chrome/browser/renderer_host/offline_resource_throttle.h"
|
| @@ -68,6 +74,9 @@ using content::BrowserThread;
|
| using content::RenderViewHost;
|
| using content::ResourceDispatcherHostLoginDelegate;
|
| using content::ResourceRequestInfo;
|
| +using extensions::Event;
|
| +using extensions::Extension;
|
| +using extensions::ExtensionSystem;
|
|
|
| namespace {
|
|
|
| @@ -83,6 +92,77 @@ void NotifyDownloadInitiatedOnUI(int render_process_id, int render_view_id) {
|
| content::NotificationService::NoDetails());
|
| }
|
|
|
| +#if defined(OS_CHROMEOS)
|
| +const char* const kOnExecuteContentHandlerEvent =
|
| + "fileBrowserHandler.onExecuteContentHandler";
|
| +
|
| +// Goes through the extension's file browser handlers and checks it there is one
|
| +// that can handle the |mime_type|.
|
| +// |extension| must not be NULL.
|
| +bool CanHandleMimeType(const Extension* extension,
|
| + const std::string& mime_type) {
|
| + FileBrowserHandler::List* handlers =
|
| + FileBrowserHandler::GetHandlers(extension);
|
| + if (!handlers)
|
| + return false;
|
| +
|
| + for (FileBrowserHandler::List::const_iterator handler = handlers->begin();
|
| + handler != handlers->end();
|
| + ++handler) {
|
| + if ((*handler)->CanHandleMIMEType(mime_type)) {
|
| + return true;
|
| + }
|
| + }
|
| +
|
| + return false;
|
| +}
|
| +
|
| +// Retrieves Profile for a render view host specified by |render_process_id| and
|
| +// |render_view_id|.
|
| +Profile* GetProfile(int render_process_id, int render_view_id) {
|
| + content::RenderViewHost* render_view_host =
|
| + content::RenderViewHost::FromID(render_process_id, render_view_id);
|
| + if (!render_view_host)
|
| + return NULL;
|
| +
|
| + content::WebContents* web_contents =
|
| + content::WebContents::FromRenderViewHost(render_view_host);
|
| + if (!web_contents)
|
| + return NULL;
|
| +
|
| + content::BrowserContext* browser_context = web_contents->GetBrowserContext();
|
| + if (!browser_context)
|
| + return NULL;
|
| +
|
| + return Profile::FromBrowserContext(browser_context);
|
| +}
|
| +
|
| +void DispatchEventOnUIThread(const std::string& mime_type,
|
| + const GURL& request_url,
|
| + const GURL& original_url,
|
| + int render_process_id,
|
| + int render_view_id,
|
| + const std::string& extension_id) {
|
| + DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
|
| +
|
| + Profile* profile = GetProfile(render_process_id, render_view_id);
|
| + if (!profile)
|
| + return;
|
| +
|
| + // Create the event's arguments value.
|
| + scoped_ptr<ListValue> event_args(new ListValue());
|
| + event_args->Append(new base::StringValue(mime_type));
|
| + event_args->Append(new base::StringValue(original_url.spec()));
|
| + event_args->Append(new base::StringValue(request_url.spec()));
|
| +
|
| + scoped_ptr<Event> event(new Event(kOnExecuteContentHandlerEvent,
|
| + event_args.Pass()));
|
| +
|
| + ExtensionSystem::Get(profile)->event_router()->DispatchEventToExtension(
|
| + extension_id, event.Pass());
|
| +}
|
| +#endif
|
| +
|
| } // end namespace
|
|
|
| ChromeResourceDispatcherHostDelegate::ChromeResourceDispatcherHostDelegate(
|
| @@ -368,6 +448,87 @@ bool ChromeResourceDispatcherHostDelegate::ShouldForceDownloadResource(
|
| return extensions::UserScript::IsURLUserScript(url, mime_type);
|
| }
|
|
|
| +bool ChromeResourceDispatcherHostDelegate::ShouldCreateStream(
|
| + content::ResourceContext* resource_context,
|
| + const GURL& url,
|
| + const std::string& mime_type,
|
| + GURL* security_origin) {
|
| +#if defined(OS_CHROMEOS)
|
| + ProfileIOData* io_data =
|
| + ProfileIOData::FromResourceContext(resource_context);
|
| + bool profile_is_incognito = io_data->is_incognito();
|
| + const scoped_refptr<const ExtensionInfoMap> extension_info_map(
|
| + io_data->GetExtensionInfoMap());
|
| + std::vector<std::string> whitelist =
|
| + FileBrowserHandler::GetMIMETypeWhitelist();
|
| + // Go through the white-listed extensions and try to use them to intercept
|
| + // the URL request.
|
| + for (size_t i = 0; i < whitelist.size(); ++i) {
|
| + const char* extension_id = whitelist[i].c_str();
|
| + const Extension* extension =
|
| + extension_info_map->extensions().GetByID(extension_id);
|
| + // The white-listed extension may not be installed, so we have to NULL check
|
| + // |extension|.
|
| + if (!extension ||
|
| + (profile_is_incognito &&
|
| + !extension_info_map->IsIncognitoEnabled(extension_id))) {
|
| + continue;
|
| + }
|
| +
|
| + if (CanHandleMimeType(extension, mime_type)) {
|
| + *security_origin = Extension::GetBaseURLFromExtensionId(extension_id);
|
| + return true;
|
| + }
|
| + }
|
| +#endif
|
| + return false;
|
| +}
|
| +
|
| +void ChromeResourceDispatcherHostDelegate::OnStreamCreated(
|
| + content::ResourceContext* resource_context,
|
| + int render_process_id,
|
| + int render_view_id,
|
| + const GURL& stream_url,
|
| + const std::string& mime_type,
|
| + const GURL& original_url) {
|
| +#if defined(OS_CHROMEOS)
|
| + ProfileIOData* io_data =
|
| + ProfileIOData::FromResourceContext(resource_context);
|
| + bool profile_is_incognito = io_data->is_incognito();
|
| + const scoped_refptr<const ExtensionInfoMap> extension_info_map(
|
| + io_data->GetExtensionInfoMap());
|
| + std::vector<std::string> whitelist =
|
| + FileBrowserHandler::GetMIMETypeWhitelist();
|
| + // Go through the white-listed extensions and try to use them to intercept
|
| + // the URL request.
|
| + for (size_t i = 0; i < whitelist.size(); ++i) {
|
| + const char* extension_id = whitelist[i].c_str();
|
| + const Extension* extension =
|
| + extension_info_map->extensions().GetByID(extension_id);
|
| + // The white-listed extension may not be installed, so we have to NULL check
|
| + // |extension|.
|
| + if (!extension ||
|
| + (profile_is_incognito &&
|
| + !extension_info_map->IsIncognitoEnabled(extension_id))) {
|
| + continue;
|
| + }
|
| +
|
| + if (CanHandleMimeType(extension, mime_type)) {
|
| + GURL extension_url(Extension::GetBaseURLFromExtensionId(extension_id));
|
| +
|
| + // The event must be dispatched on the UI thread.
|
| + // TODO(zork): stream_url()
|
| + content::BrowserThread::PostTask(
|
| + content::BrowserThread::UI, FROM_HERE,
|
| + base::Bind(&DispatchEventOnUIThread, mime_type, stream_url,
|
| + original_url, render_process_id, render_view_id,
|
| + extension->id()));
|
| + return;
|
| + }
|
| + }
|
| +#endif
|
| +}
|
| +
|
| void ChromeResourceDispatcherHostDelegate::OnResponseStarted(
|
| net::URLRequest* request,
|
| content::ResourceContext* resource_context,
|
|
|