Index: content/browser/loader/replacing_resource_handler.h |
diff --git a/content/browser/loader/replacing_resource_handler.h b/content/browser/loader/replacing_resource_handler.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..aa15c18774f9dbb9a91636e117479c2e13a3a924 |
--- /dev/null |
+++ b/content/browser/loader/replacing_resource_handler.h |
@@ -0,0 +1,97 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CONTENT_BROWSER_LOADER_REPLACING_RESOURCE_HANDLER_H_ |
+#define CONTENT_BROWSER_LOADER_REPLACING_RESOURCE_HANDLER_H_ |
+ |
+#include <string> |
+#include <vector> |
+ |
+#include "base/macros.h" |
+#include "base/memory/weak_ptr.h" |
+#include "content/browser/loader/layered_resource_handler.h" |
+#include "content/common/content_export.h" |
+ |
+namespace net { |
+class URLRequest; |
+} |
+ |
+namespace content { |
+class PluginService; |
+class ResourceDispatcherHostImpl; |
+struct WebPluginInfo; |
+ |
+// ResourceHandler that initiates special handling of the response if needed, |
+// based on the response's MIME type (starts downloads, sends data to some |
+// plugin types via a special channel). |
+class CONTENT_EXPORT ReplacingResourceHandler : public LayeredResourceHandler { |
mmenke
2016/06/09 18:09:29
I'm not a big fan of this name. ResourceHandlerRe
clamy
2016/06/21 16:14:15
Done.
|
+ public: |
+ // If ENABLE_PLUGINS is defined, |plugin_service| must not be NULL. |
+ ReplacingResourceHandler(std::unique_ptr<ResourceHandler> next_handler, |
+ ResourceDispatcherHostImpl* host, |
+ PluginService* plugin_service, |
+ net::URLRequest* request); |
+ ~ReplacingResourceHandler() override; |
+ |
+ private: |
+ enum class State { |
mmenke
2016/06/09 18:09:29
I think these states need some documentation.
clamy
2016/06/21 16:14:15
Done.
|
+ STARTING, |
+ WAITING_FOR_NEW_HANDLER, |
mmenke
2016/06/09 18:09:29
We only keep this state when we're waiting to get
clamy
2016/06/21 16:14:15
Done.
|
+ WAITING_FOR_BUFFER_COPY, |
mmenke
2016/06/09 18:09:29
This state is only needed because the MimeTypeReso
clamy
2016/06/21 16:14:15
Done.
|
+ CHOICE_MADE, |
mmenke
2016/06/09 18:09:29
We've also made the choice in WAITING_FOR_BUFFER_C
clamy
2016/06/21 16:14:15
I've called it DONE, since the InterceptingResourc
|
+ }; |
mmenke
2016/06/09 18:09:29
nit: Suggest a blank line here.
clamy
2016/06/21 16:14:15
Done.
|
+ // ResourceHandler implementation: |
+ bool OnResponseStarted(ResourceResponse* response, bool* defer) override; |
+ bool OnWillRead(scoped_refptr<net::IOBuffer>* buf, |
+ int* buf_size, |
+ int min_size) override; |
+ bool OnReadCompleted(int bytes_read, bool* defer) override; |
+ |
+ bool MakeHandlerChoice(bool* defer); |
+ |
+ // Determines whether a plugin will handle the current request, and if so, |
+ // sets up the handler to direct the response to that plugin. Returns false |
+ // if there is an error and the request should be cancelled and true |
+ // otherwise. |defer| is set to true if plugin data is stale and needs to be |
+ // refreshed before the request can be handled (in this case the function |
+ // still returns true). If the request is directed to a plugin, |
+ // |handled_by_plugin| is set to true. |
+ bool SelectPluginHandler(bool* defer, bool* handled_by_plugin); |
+ // Returns false if the request should be cancelled. |
+ bool SelectNextHandler(bool* defer); |
+ bool UseAlternateNextHandler(std::unique_ptr<ResourceHandler> handler, |
+ const std::string& payload_for_old_handler); |
+ |
+ bool MustDownload(); |
+ |
+ // Called on the IO thread once the list of plugins has been loaded. |
+ void OnPluginsLoaded(const std::vector<WebPluginInfo>& plugins); |
+ |
+ bool CopyReadBufferToNextHandler(); |
+ |
+ State state_; |
+ |
+ ResourceDispatcherHostImpl* host_; |
+#if defined(ENABLE_PLUGINS) |
+ PluginService* plugin_service_; |
+#endif |
+ |
+ bool switched_handler_; |
+ |
+ bool must_download_; |
+ bool must_download_is_set_; |
+ |
+ // Used to copy data to the new next ResourceHandler. |
+ scoped_refptr<ResourceResponse> response_; |
+ scoped_refptr<net::IOBuffer> read_buffer_; |
+ int bytes_read_; |
+ |
+ base::WeakPtrFactory<ReplacingResourceHandler> weak_ptr_factory_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(ReplacingResourceHandler); |
+}; |
+ |
+} // namespace content |
+ |
+#endif // CONTENT_BROWSER_LOADER_REPLACING_RESOURCE_HANDLER_H_ |