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