| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 EXTENSIONS_RENDERER_GUEST_VIEW_MIME_HANDLER_VIEW_CONTAINER_H_ | 5 #ifndef EXTENSIONS_RENDERER_GUEST_VIEW_MIME_HANDLER_VIEW_CONTAINER_H_ |
| 6 #define EXTENSIONS_RENDERER_GUEST_VIEW_MIME_HANDLER_VIEW_CONTAINER_H_ | 6 #define EXTENSIONS_RENDERER_GUEST_VIEW_MIME_HANDLER_VIEW_CONTAINER_H_ |
| 7 | 7 |
| 8 #include "base/memory/weak_ptr.h" |
| 8 #include "extensions/renderer/guest_view/guest_view_container.h" | 9 #include "extensions/renderer/guest_view/guest_view_container.h" |
| 10 #include "extensions/renderer/scoped_persistent.h" |
| 9 #include "third_party/WebKit/public/platform/WebURLLoader.h" | 11 #include "third_party/WebKit/public/platform/WebURLLoader.h" |
| 10 #include "third_party/WebKit/public/platform/WebURLLoaderClient.h" | 12 #include "third_party/WebKit/public/platform/WebURLLoaderClient.h" |
| 11 #include "url/gurl.h" | 13 #include "url/gurl.h" |
| 14 #include "v8/include/v8.h" |
| 12 | 15 |
| 13 namespace extensions { | 16 namespace extensions { |
| 14 | 17 |
| 15 // A container for loading up an extension inside a BrowserPlugin to handle a | 18 // 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 | 19 // 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 | 20 // 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 | 21 // 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 | 22 // request, the case where the plugin is embedded and the case where it is top |
| 20 // level: | 23 // level: |
| 21 // 1) In the top level case a URL request for the data to load has already been | 24 // 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 | 25 // made by the renderer on behalf of the plugin. The |DidReceiveData| and |
| 23 // |DidFinishLoading| callbacks (from BrowserPluginDelegate) will be called | 26 // |DidFinishLoading| callbacks (from BrowserPluginDelegate) will be called |
| 24 // when data is received and when it has finished being received, | 27 // when data is received and when it has finished being received, |
| 25 // respectively. | 28 // respectively. |
| 26 // 2) In the embedded case, no URL request is automatically made by the | 29 // 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 | 30 // renderer. We make a URL request for the data inside the container using |
| 28 // a WebURLLoader. In this case, the |didReceiveData| and |didFinishLoading| | 31 // a WebURLLoader. In this case, the |didReceiveData| and |didFinishLoading| |
| 29 // (from WebURLLoaderClient) when data is received and when it has finished | 32 // (from WebURLLoaderClient) when data is received and when it has finished |
| 30 // being received. | 33 // being received. |
| 31 class MimeHandlerViewContainer : public GuestViewContainer, | 34 class MimeHandlerViewContainer : public GuestViewContainer, |
| 32 public blink::WebURLLoaderClient { | 35 public blink::WebURLLoaderClient { |
| 33 public: | 36 public: |
| 34 MimeHandlerViewContainer(content::RenderFrame* render_frame, | 37 MimeHandlerViewContainer(content::RenderFrame* render_frame, |
| 35 const std::string& mime_type, | 38 const std::string& mime_type, |
| 36 const GURL& original_url); | 39 const GURL& original_url); |
| 37 ~MimeHandlerViewContainer() override; | 40 ~MimeHandlerViewContainer() override; |
| 38 | 41 |
| 39 // BrowserPluginDelegate implementation. | 42 // BrowserPluginDelegate implementation. |
| 43 void Ready() override; |
| 40 void DidFinishLoading() override; | 44 void DidFinishLoading() override; |
| 41 void DidReceiveData(const char* data, int data_length) override; | 45 void DidReceiveData(const char* data, int data_length) override; |
| 42 bool OnMessageReceived(const IPC::Message& message) override; | 46 bool OnMessageReceived(const IPC::Message& message) override; |
| 43 void Ready() override; | 47 v8::Local<v8::Object> V8ScriptableObject(v8::Isolate*) override; |
| 44 | 48 |
| 45 // WebURLLoaderClient overrides. | 49 // WebURLLoaderClient overrides. |
| 46 void didReceiveData(blink::WebURLLoader* loader, | 50 void didReceiveData(blink::WebURLLoader* loader, |
| 47 const char* data, | 51 const char* data, |
| 48 int data_length, | 52 int data_length, |
| 49 int encoded_data_length) override; | 53 int encoded_data_length) override; |
| 50 void didFinishLoading(blink::WebURLLoader* loader, | 54 void didFinishLoading(blink::WebURLLoader* loader, |
| 51 double finish_time, | 55 double finish_time, |
| 52 int64_t total_encoded_data_length) override; | 56 int64_t total_encoded_data_length) override; |
| 53 | 57 |
| 58 // Post a JavaScript message to the guest. |
| 59 void PostMessage(v8::Isolate* isolate, |
| 60 v8::Handle<v8::Value> message); |
| 61 |
| 54 private: | 62 private: |
| 55 // Message handlers. | 63 // Message handlers. |
| 56 void OnCreateMimeHandlerViewGuestACK(int element_instance_id); | 64 void OnCreateMimeHandlerViewGuestACK(int element_instance_id); |
| 65 void OnGuestAttached(int element_instance_id, |
| 66 int guest_proxy_routing_id); |
| 57 | 67 |
| 58 void CreateMimeHandlerViewGuest(); | 68 void CreateMimeHandlerViewGuest(); |
| 59 | 69 |
| 60 // The MIME type of the plugin. | 70 // The MIME type of the plugin. |
| 61 const std::string mime_type_; | 71 const std::string mime_type_; |
| 62 | 72 |
| 63 // The URL of the extension to navigate to. | 73 // The URL of the extension to navigate to. |
| 64 std::string html_string_; | 74 std::string html_string_; |
| 65 | 75 |
| 66 // Whether the plugin is embedded or not. | 76 // Whether the plugin is embedded or not. |
| 67 bool is_embedded_; | 77 bool is_embedded_; |
| 68 | 78 |
| 69 // The original URL of the plugin. | 79 // The original URL of the plugin. |
| 70 GURL original_url_; | 80 GURL original_url_; |
| 71 | 81 |
| 82 // The RenderView routing ID of the guest. |
| 83 int guest_proxy_routing_id_; |
| 84 |
| 72 // A URL loader to load the |original_url_| when the plugin is embedded. In | 85 // A URL loader to load the |original_url_| when the plugin is embedded. In |
| 73 // the embedded case, no URL request is made automatically. | 86 // the embedded case, no URL request is made automatically. |
| 74 scoped_ptr<blink::WebURLLoader> loader_; | 87 scoped_ptr<blink::WebURLLoader> loader_; |
| 75 | 88 |
| 89 // The scriptable object that backs the plugin. |
| 90 ScopedPersistent<v8::Object> scriptable_object_; |
| 91 |
| 92 base::WeakPtrFactory<MimeHandlerViewContainer> weak_factory_; |
| 93 |
| 76 DISALLOW_COPY_AND_ASSIGN(MimeHandlerViewContainer); | 94 DISALLOW_COPY_AND_ASSIGN(MimeHandlerViewContainer); |
| 77 }; | 95 }; |
| 78 | 96 |
| 79 } // namespace extensions | 97 } // namespace extensions |
| 80 | 98 |
| 81 #endif // EXTENSIONS_RENDERER_GUEST_VIEW_MIME_HANDLER_VIEW_CONTAINER_H_ | 99 #endif // EXTENSIONS_RENDERER_GUEST_VIEW_MIME_HANDLER_VIEW_CONTAINER_H_ |
| OLD | NEW |