Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / extensions / renderer / guest_view / mime_handler_view / mime_handler_view_container.h
blob329b58b6f56b02699ceff0e0e122a64be747696c
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.
5 #ifndef EXTENSIONS_RENDERER_GUEST_VIEW_MIME_HANDLER_VIEW_MIME_HANDLER_VIEW_CONTAINER_H_
6 #define EXTENSIONS_RENDERER_GUEST_VIEW_MIME_HANDLER_VIEW_MIME_HANDLER_VIEW_CONTAINER_H_
8 #include <string>
9 #include <vector>
11 #include "base/memory/linked_ptr.h"
12 #include "base/memory/weak_ptr.h"
13 #include "extensions/renderer/guest_view/guest_view_container.h"
14 #include "third_party/WebKit/public/platform/WebURLLoader.h"
15 #include "third_party/WebKit/public/platform/WebURLLoaderClient.h"
16 #include "ui/gfx/geometry/size.h"
17 #include "url/gurl.h"
18 #include "v8/include/v8.h"
20 namespace extensions {
22 // A container for loading up an extension inside a BrowserPlugin to handle a
23 // MIME type. A request for the URL of the data to load inside the container is
24 // made and a url is sent back in response which points to the URL which the
25 // container should be navigated to. There are two cases for making this URL
26 // request, the case where the plugin is embedded and the case where it is top
27 // level:
28 // 1) In the top level case a URL request for the data to load has already been
29 // made by the renderer on behalf of the plugin. The |DidReceiveData| and
30 // |DidFinishLoading| callbacks (from BrowserPluginDelegate) will be called
31 // when data is received and when it has finished being received,
32 // respectively.
33 // 2) In the embedded case, no URL request is automatically made by the
34 // renderer. We make a URL request for the data inside the container using
35 // a WebURLLoader. In this case, the |didReceiveData| and |didFinishLoading|
36 // (from WebURLLoaderClient) when data is received and when it has finished
37 // being received.
38 class MimeHandlerViewContainer : public GuestViewContainer,
39 public blink::WebURLLoaderClient {
40 public:
41 MimeHandlerViewContainer(content::RenderFrame* render_frame,
42 const std::string& mime_type,
43 const GURL& original_url);
44 ~MimeHandlerViewContainer() override;
46 static std::vector<MimeHandlerViewContainer*> FromRenderFrame(
47 content::RenderFrame* render_frame);
49 // BrowserPluginDelegate implementation.
50 void Ready() override;
51 void DidFinishLoading() override;
52 void DidReceiveData(const char* data, int data_length) override;
53 void DidResizeElement(const gfx::Size& old_size,
54 const gfx::Size& new_size) override;
55 bool OnMessageReceived(const IPC::Message& message) override;
56 v8::Local<v8::Object> V8ScriptableObject(v8::Isolate*) override;
58 // WebURLLoaderClient overrides.
59 void didReceiveData(blink::WebURLLoader* loader,
60 const char* data,
61 int data_length,
62 int encoded_data_length) override;
63 void didFinishLoading(blink::WebURLLoader* loader,
64 double finish_time,
65 int64_t total_encoded_data_length) override;
67 // GuestViewContainer overrides.
68 void OnRenderFrameDestroyed() override;
70 // Post a JavaScript message to the guest.
71 void PostMessage(v8::Isolate* isolate,
72 v8::Handle<v8::Value> message);
74 // Post |message| to the guest.
75 void PostMessageFromValue(const base::Value& message);
77 private:
78 // Message handlers.
79 void OnCreateMimeHandlerViewGuestACK(int element_instance_id);
80 void OnGuestAttached(int element_instance_id,
81 int guest_proxy_routing_id);
82 void OnMimeHandlerViewGuestOnLoadCompleted(int element_instance_id);
84 void CreateMimeHandlerViewGuest();
86 // The MIME type of the plugin.
87 const std::string mime_type_;
89 // The URL of the extension to navigate to.
90 std::string view_id_;
92 // Whether the plugin is embedded or not.
93 bool is_embedded_;
95 // The original URL of the plugin.
96 GURL original_url_;
98 // The RenderView routing ID of the guest.
99 int guest_proxy_routing_id_;
101 // A URL loader to load the |original_url_| when the plugin is embedded. In
102 // the embedded case, no URL request is made automatically.
103 scoped_ptr<blink::WebURLLoader> loader_;
105 // The scriptable object that backs the plugin.
106 v8::Global<v8::Object> scriptable_object_;
108 // Pending postMessage messages that need to be sent to the guest. These are
109 // queued while the guest is loading and once it is fully loaded they are
110 // delivered so that messages aren't lost.
111 std::vector<linked_ptr<v8::Global<v8::Value>>> pending_messages_;
113 // True if the guest page has fully loaded and its JavaScript onload function
114 // has been called.
115 bool guest_loaded_;
117 // The size of the element.
118 gfx::Size element_size_;
120 base::WeakPtrFactory<MimeHandlerViewContainer> weak_factory_;
122 DISALLOW_COPY_AND_ASSIGN(MimeHandlerViewContainer);
125 } // namespace extensions
127 #endif // EXTENSIONS_RENDERER_GUEST_VIEW_MIME_HANDLER_VIEW_MIME_HANDLER_VIEW_CONTAINER_H_