| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_RESOURCE_THROTTLE_H_ | |
| 6 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_RESOURCE_THROTTLE_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/compiler_specific.h" | |
| 11 #include "base/memory/ref_counted.h" | |
| 12 #include "base/memory/scoped_ptr.h" | |
| 13 #include "content/public/browser/resource_throttle.h" | |
| 14 #include "googleurl/src/gurl.h" | |
| 15 | |
| 16 class ExtensionInfoMap; | |
| 17 class ExtensionSet; | |
| 18 | |
| 19 namespace net { | |
| 20 class URLRequest; | |
| 21 } | |
| 22 | |
| 23 // Resource throttle that intercepts URL requests that can be handled by an | |
| 24 // installed, white-listed file browser handler extension. | |
| 25 // The requests are intercepted before processing the response because the | |
| 26 // request's MIME type is needed to determine if it can be handled by a file | |
| 27 // browser handler. It the request can be handled by a file browser handler | |
| 28 // extension, it gets canceled and the extension is notified to handle | |
| 29 // the requested URL. | |
| 30 class FileBrowserResourceThrottle : public content::ResourceThrottle { | |
| 31 public: | |
| 32 // Used to dispatch fileBrowserHandler events to notify an extension it should | |
| 33 // handle an URL request. | |
| 34 // Can be used on any thread. The actual dispatch tasks will be posted to the | |
| 35 // UI thread. | |
| 36 class FileBrowserHandlerEventRouter { | |
| 37 public: | |
| 38 virtual ~FileBrowserHandlerEventRouter() {} | |
| 39 | |
| 40 // Used to dispatch fileBrowserHandler.onExecuteContentHandler to the | |
| 41 // extension with id |extension_id|. |mime_type| and |request_url| are the | |
| 42 // URL request's parameters that should be handed to the extension. | |
| 43 // |render_process_id| and |render_view_id| are used to determine the | |
| 44 // profile from which the URL request came and in which the event should be | |
| 45 // dispatched. | |
| 46 virtual void DispatchMimeTypeHandlerEvent( | |
| 47 int render_process_id, | |
| 48 int render_view_id, | |
| 49 const std::string& mime_type, | |
| 50 const GURL& request_url, | |
| 51 const std::string& extension_id) = 0; | |
| 52 }; | |
| 53 | |
| 54 // Creates a FileBrowserResourceThrottle for the |request|. | |
| 55 // The throtlle's |mime_type_| and |url_request_| members are extracted from | |
| 56 // the request. | |
| 57 // The throttle's |event_router_| is created and set (it's a | |
| 58 // FileBrowserHandlerEventRouterImpl instance; see the .cc file). | |
| 59 static FileBrowserResourceThrottle* Create( | |
| 60 int render_process_id, | |
| 61 int render_view_id, | |
| 62 net::URLRequest* request, | |
| 63 bool profile_is_incognito, | |
| 64 const ExtensionInfoMap* extension_info_map); | |
| 65 | |
| 66 // Creates a FileBrowserResourceThrottle to be used in a test. | |
| 67 // |event_router| can hold NULL, in which case the throttle's |event_router_| | |
| 68 // member is set to a FileBrowserHandlerEventRouterImpl instance, just like in | |
| 69 // FileBrowserResourceThrottle::Create. | |
| 70 static FileBrowserResourceThrottle* CreateForTest( | |
| 71 int render_process_id, | |
| 72 int renser_view_id, | |
| 73 const std::string& mime_type, | |
| 74 const GURL& request_url, | |
| 75 bool profile_is_incognito, | |
| 76 const ExtensionInfoMap* extension_info_map, | |
| 77 scoped_ptr<FileBrowserHandlerEventRouter> event_router); | |
| 78 | |
| 79 virtual ~FileBrowserResourceThrottle(); | |
| 80 | |
| 81 // content::ResourceThrottle implementation. | |
| 82 // Calls |MaybeInterceptWithExtension| for all extension_id's white-listed to | |
| 83 // use file browser handler MIME type filters. | |
| 84 virtual void WillProcessResponse(bool* defer) OVERRIDE; | |
| 85 | |
| 86 private: | |
| 87 // Use Create* methods to create a FileBrowserResourceThrottle instance. | |
| 88 FileBrowserResourceThrottle( | |
| 89 int render_process_id, | |
| 90 int render_view_id, | |
| 91 const std::string& mime_type, | |
| 92 const GURL& request_url, | |
| 93 bool profile_is_incognito, | |
| 94 const ExtensionInfoMap* extension_info_map, | |
| 95 scoped_ptr<FileBrowserHandlerEventRouter> event_router); | |
| 96 | |
| 97 // Checks if the extension has a registered file browser handler that can | |
| 98 // handle the request's mime_type. If this is the case, the request is | |
| 99 // canceled and fileBrowserHandler.onExtecuteContentHandler event is | |
| 100 // dispatched to the extension. | |
| 101 // Returns whether the URL request has been intercepted. | |
| 102 bool MaybeInterceptWithExtension(const std::string& extension_id); | |
| 103 | |
| 104 // Render process id from which the request came. | |
| 105 int render_process_id_; | |
| 106 // Render view id from which the request came. | |
| 107 int render_view_id_; | |
| 108 // The request's MIME type. | |
| 109 std::string mime_type_; | |
| 110 // The request's URL. | |
| 111 GURL request_url_; | |
| 112 // Whether the request came from an incognito profile. | |
| 113 bool profile_is_incognito_; | |
| 114 // Map holding list of installed extensions. Must be used exclusively on IO | |
| 115 // thread. | |
| 116 const scoped_refptr<const ExtensionInfoMap> extension_info_map_; | |
| 117 | |
| 118 // Event router to be used to dispatch the fileBrowserHandler events. | |
| 119 scoped_ptr<FileBrowserHandlerEventRouter> event_router_; | |
| 120 }; | |
| 121 | |
| 122 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_RESOURCE_THROTTLE_H_ | |
| OLD | NEW |