1 // Copyright 2018 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_PLUGINS_PLUGIN_RESPONSE_INTERCEPTOR_URL_LOADER_THROTTLE_H_ 6 #define CHROME_BROWSER_PLUGINS_PLUGIN_RESPONSE_INTERCEPTOR_URL_LOADER_THROTTLE_H_ 7 8 #include <string> 9 10 #include "base/macros.h" 11 #include "base/memory/weak_ptr.h" 12 #include "third_party/blink/public/common/loader/url_loader_throttle.h" 13 14 // Used to watch navigation responses to look for mime types that are handled by 15 // extensions. When it finds such a response, it will intercept it by extracting 16 // the URLLoader interface pointer. It will create a random string and send that 17 // to the extension which handles the mime type. It will also write that string 18 // into the object tag for the plugin, which will cause the pepper plugin to 19 // make a request for that URL. The renderer would have gotten a 20 // TransferrableURLLoader that allows it to map from that URL to the original 21 // URLLoader interface pointer. 22 class PluginResponseInterceptorURLLoaderThrottle 23 : public blink::URLLoaderThrottle { 24 public: 25 PluginResponseInterceptorURLLoaderThrottle( 26 int resource_type, 27 int frame_tree_node_id); 28 ~PluginResponseInterceptorURLLoaderThrottle() override; 29 30 private: 31 // blink::URLLoaderThrottle overrides; 32 void WillProcessResponse(const GURL& response_url, 33 network::mojom::URLResponseHead* response_head, 34 bool* defer) override; 35 // Resumes loading for an intercepted response. This would give the extension 36 // layer chance to initialize its browser side state. 37 void ResumeLoad(); 38 39 const int resource_type_; 40 const int frame_tree_node_id_; 41 42 base::WeakPtrFactory<PluginResponseInterceptorURLLoaderThrottle> 43 weak_factory_{this}; 44 45 DISALLOW_COPY_AND_ASSIGN(PluginResponseInterceptorURLLoaderThrottle); 46 }; 47 48 #endif // CHROME_BROWSER_PLUGINS_PLUGIN_RESPONSE_INTERCEPTOR_URL_LOADER_THROTTLE_H_ 49