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 #include "extensions/renderer/guest_view/mime_handler_view_container.h" | |
6 | |
7 #include "content/public/renderer/render_frame.h" | |
8 #include "extensions/common/extension_messages.h" | |
9 #include "extensions/common/guest_view/guest_view_constants.h" | |
10 #include "third_party/WebKit/public/web/WebDocument.h" | |
11 #include "third_party/WebKit/public/web/WebLocalFrame.h" | |
12 | |
13 namespace extensions { | |
14 | |
15 MimeHandlerViewContainer::MimeHandlerViewContainer( | |
16 content::RenderFrame* render_frame, | |
17 const std::string& mime_type, | |
18 const GURL& original_url) | |
19 : GuestViewContainer(render_frame), | |
20 mime_type_(mime_type), | |
21 original_url_(original_url) { | |
22 DCHECK(!mime_type_.empty()); | |
23 is_embedded_ = !render_frame->GetWebFrame()->document().isPluginDocument(); | |
24 } | |
25 | |
26 MimeHandlerViewContainer::~MimeHandlerViewContainer() { | |
27 if (loader_) | |
28 loader_->cancel(); | |
29 } | |
30 | |
31 void MimeHandlerViewContainer::DidFinishLoading() { | |
32 DCHECK(!is_embedded_); | |
33 CreateMimeHandlerViewGuest(); | |
34 } | |
35 | |
36 void MimeHandlerViewContainer::DidReceiveData(const char* data, | |
37 int data_length) { | |
38 html_string_ += std::string(data, data_length); | |
39 } | |
40 | |
41 void MimeHandlerViewContainer::Ready() { | |
42 blink::WebFrame* frame = render_frame()->GetWebFrame(); | |
43 blink::WebURLLoaderOptions options; | |
44 // The embedded plugin is allowed to be cross-origin. | |
45 options.crossOriginRequestPolicy = | |
46 blink::WebURLLoaderOptions::CrossOriginRequestPolicyAllow; | |
47 DCHECK(!loader_); | |
48 loader_.reset(frame->createAssociatedURLLoader()); | |
49 | |
50 // TODO(raymes): Currently this URL request won't be correctly intercepted as | |
51 // a stream. | |
52 loader_->loadAsynchronously(blink::WebURLRequest(original_url_), this); | |
53 } | |
54 | |
55 bool MimeHandlerViewContainer::HandlesMessage(const IPC::Message& message) { | |
56 return message.type() == ExtensionMsg_CreateMimeHandlerViewGuestACK::ID; | |
57 } | |
58 | |
59 bool MimeHandlerViewContainer::OnMessage(const IPC::Message& message) { | |
60 bool handled = true; | |
61 IPC_BEGIN_MESSAGE_MAP(MimeHandlerViewContainer, message) | |
62 IPC_MESSAGE_HANDLER(ExtensionMsg_CreateMimeHandlerViewGuestACK, | |
63 OnCreateMimeHandlerViewGuestACK) | |
64 IPC_MESSAGE_UNHANDLED(handled = false) | |
65 IPC_END_MESSAGE_MAP() | |
66 return handled; | |
67 } | |
68 | |
69 void MimeHandlerViewContainer::didReceiveData(blink::WebURLLoader* /* unused */, | |
70 const char* data, | |
71 int data_length, | |
72 int /* unused */) { | |
73 html_string_ += std::string(data, data_length); | |
74 } | |
75 | |
76 void MimeHandlerViewContainer::didFinishLoading( | |
77 blink::WebURLLoader* /* unused */, | |
78 double /* unused */, | |
79 int64_t /* unused */) { | |
80 DCHECK(is_embedded_); | |
81 CreateMimeHandlerViewGuest(); | |
82 } | |
83 | |
84 void MimeHandlerViewContainer::OnCreateMimeHandlerViewGuestACK( | |
85 int element_instance_id) { | |
86 DCHECK_NE(this->element_instance_id(), guestview::kInstanceIDNone); | |
87 DCHECK_EQ(this->element_instance_id(), element_instance_id); | |
88 render_frame()->AttachGuest(element_instance_id); | |
89 } | |
90 | |
91 void MimeHandlerViewContainer::CreateMimeHandlerViewGuest() { | |
92 // The loader has completed loading |html_string_| so we can dispose it. | |
93 loader_.reset(); | |
94 | |
95 // Parse the stream URL to ensure it's valid. | |
96 GURL stream_url(html_string_); | |
97 | |
98 DCHECK_NE(element_instance_id(), guestview::kInstanceIDNone); | |
99 render_frame()->Send(new ExtensionHostMsg_CreateMimeHandlerViewGuest( | |
100 routing_id(), stream_url.spec(), mime_type_, element_instance_id())); | |
101 } | |
102 | |
103 } // namespace extensions | |
OLD | NEW |