| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 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 EXTENSIONS_RENDERER_GUEST_VIEW_MIME_HANDLER_VIEW_CONTAINER_H_ | |
| 6 #define EXTENSIONS_RENDERER_GUEST_VIEW_MIME_HANDLER_VIEW_CONTAINER_H_ | |
| 7 | |
| 8 #include "extensions/renderer/guest_view/guest_view_container.h" | |
| 9 #include "third_party/WebKit/public/platform/WebURLLoader.h" | |
| 10 #include "third_party/WebKit/public/platform/WebURLLoaderClient.h" | |
| 11 #include "url/gurl.h" | |
| 12 | |
| 13 namespace extensions { | |
| 14 | |
| 15 // A container for loading up an extension inside a BrowserPlugin to handle a | |
| 16 // MIME type. A request for the URL of the data to load inside the container is | |
| 17 // made and a url is sent back in response which points to the URL which the | |
| 18 // container should be navigated to. There are two cases for making this URL | |
| 19 // request, the case where the plugin is embedded and the case where it is top | |
| 20 // level: | |
| 21 // 1) In the top level case a URL request for the data to load has already been | |
| 22 // made by the renderer on behalf of the plugin. The |DidReceiveData| and | |
| 23 // |DidFinishLoading| callbacks (from BrowserPluginDelegate) will be called | |
| 24 // when data is received and when it has finished being received, | |
| 25 // respectively. | |
| 26 // 2) In the embedded case, no URL request is automatically made by the | |
| 27 // renderer. We make a URL request for the data inside the container using | |
| 28 // a WebURLLoader. In this case, the |didReceiveData| and |didFinishLoading| | |
| 29 // (from WebURLLoaderClient) when data is received and when it has finished | |
| 30 // being received. | |
| 31 class MimeHandlerViewContainer : public GuestViewContainer, | |
| 32 public blink::WebURLLoaderClient { | |
| 33 public: | |
| 34 MimeHandlerViewContainer(content::RenderFrame* render_frame, | |
| 35 const std::string& mime_type, | |
| 36 const GURL& original_url); | |
| 37 ~MimeHandlerViewContainer() override; | |
| 38 | |
| 39 // BrowserPluginDelegate implementation. | |
| 40 void DidFinishLoading() override; | |
| 41 void DidReceiveData(const char* data, int data_length) override; | |
| 42 void Ready() override; | |
| 43 | |
| 44 // GuestViewContainer overrides. | |
| 45 bool HandlesMessage(const IPC::Message& message) override; | |
| 46 bool OnMessage(const IPC::Message& message) override; | |
| 47 | |
| 48 // WebURLLoaderClient overrides. | |
| 49 void didReceiveData(blink::WebURLLoader* loader, | |
| 50 const char* data, | |
| 51 int data_length, | |
| 52 int encoded_data_length) override; | |
| 53 void didFinishLoading(blink::WebURLLoader* loader, | |
| 54 double finish_time, | |
| 55 int64_t total_encoded_data_length) override; | |
| 56 | |
| 57 private: | |
| 58 // Message handlers. | |
| 59 void OnCreateMimeHandlerViewGuestACK(int element_instance_id); | |
| 60 | |
| 61 void CreateMimeHandlerViewGuest(); | |
| 62 | |
| 63 // The MIME type of the plugin. | |
| 64 const std::string mime_type_; | |
| 65 | |
| 66 // The URL of the extension to navigate to. | |
| 67 std::string html_string_; | |
| 68 | |
| 69 // Whether the plugin is embedded or not. | |
| 70 bool is_embedded_; | |
| 71 | |
| 72 // The original URL of the plugin. | |
| 73 GURL original_url_; | |
| 74 | |
| 75 // A URL loader to load the |original_url_| when the plugin is embedded. In | |
| 76 // the embedded case, no URL request is made automatically. | |
| 77 scoped_ptr<blink::WebURLLoader> loader_; | |
| 78 | |
| 79 DISALLOW_COPY_AND_ASSIGN(MimeHandlerViewContainer); | |
| 80 }; | |
| 81 | |
| 82 } // namespace extensions | |
| 83 | |
| 84 #endif // EXTENSIONS_RENDERER_GUEST_VIEW_MIME_HANDLER_VIEW_CONTAINER_H_ | |
| OLD | NEW |