| 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 #include "extensions/renderer/guest_view/mime_handler_view/mime_handler_view_con
tainer.h" | 5 #include "extensions/renderer/guest_view/mime_handler_view/mime_handler_view_con
tainer.h" |
| 6 | 6 |
| 7 #include "content/public/renderer/render_frame.h" | 7 #include "content/public/renderer/render_frame.h" |
| 8 #include "extensions/common/extension_messages.h" | 8 #include "extensions/common/extension_messages.h" |
| 9 #include "extensions/common/guest_view/guest_view_constants.h" | 9 #include "extensions/common/guest_view/guest_view_constants.h" |
| 10 #include "third_party/WebKit/public/web/WebDocument.h" | 10 #include "third_party/WebKit/public/web/WebDocument.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 void MimeHandlerViewContainer::DidFinishLoading() { | 31 void MimeHandlerViewContainer::DidFinishLoading() { |
| 32 DCHECK(!is_embedded_); | 32 DCHECK(!is_embedded_); |
| 33 CreateMimeHandlerViewGuest(); | 33 CreateMimeHandlerViewGuest(); |
| 34 } | 34 } |
| 35 | 35 |
| 36 void MimeHandlerViewContainer::DidReceiveData(const char* data, | 36 void MimeHandlerViewContainer::DidReceiveData(const char* data, |
| 37 int data_length) { | 37 int data_length) { |
| 38 html_string_ += std::string(data, data_length); | 38 html_string_ += std::string(data, data_length); |
| 39 } | 39 } |
| 40 | 40 |
| 41 bool MimeHandlerViewContainer::OnMessageReceived(const IPC::Message& message) { |
| 42 bool handled = true; |
| 43 IPC_BEGIN_MESSAGE_MAP(MimeHandlerViewContainer, message) |
| 44 IPC_MESSAGE_HANDLER(ExtensionMsg_CreateMimeHandlerViewGuestACK, |
| 45 OnCreateMimeHandlerViewGuestACK) |
| 46 IPC_MESSAGE_UNHANDLED(handled = false) |
| 47 IPC_END_MESSAGE_MAP() |
| 48 return handled; |
| 49 } |
| 50 |
| 41 void MimeHandlerViewContainer::Ready() { | 51 void MimeHandlerViewContainer::Ready() { |
| 42 blink::WebFrame* frame = render_frame()->GetWebFrame(); | 52 blink::WebFrame* frame = render_frame()->GetWebFrame(); |
| 43 blink::WebURLLoaderOptions options; | 53 blink::WebURLLoaderOptions options; |
| 44 // The embedded plugin is allowed to be cross-origin. | 54 // The embedded plugin is allowed to be cross-origin. |
| 45 options.crossOriginRequestPolicy = | 55 options.crossOriginRequestPolicy = |
| 46 blink::WebURLLoaderOptions::CrossOriginRequestPolicyAllow; | 56 blink::WebURLLoaderOptions::CrossOriginRequestPolicyAllow; |
| 47 DCHECK(!loader_); | 57 DCHECK(!loader_); |
| 48 loader_.reset(frame->createAssociatedURLLoader(options)); | 58 loader_.reset(frame->createAssociatedURLLoader(options)); |
| 49 | 59 |
| 50 blink::WebURLRequest request(original_url_); | 60 blink::WebURLRequest request(original_url_); |
| 51 request.setRequestContext(blink::WebURLRequest::RequestContextObject); | 61 request.setRequestContext(blink::WebURLRequest::RequestContextObject); |
| 52 loader_->loadAsynchronously(request, this); | 62 loader_->loadAsynchronously(request, this); |
| 53 } | 63 } |
| 54 | 64 |
| 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 */, | 65 void MimeHandlerViewContainer::didReceiveData(blink::WebURLLoader* /* unused */, |
| 70 const char* data, | 66 const char* data, |
| 71 int data_length, | 67 int data_length, |
| 72 int /* unused */) { | 68 int /* unused */) { |
| 73 html_string_ += std::string(data, data_length); | 69 html_string_ += std::string(data, data_length); |
| 74 } | 70 } |
| 75 | 71 |
| 76 void MimeHandlerViewContainer::didFinishLoading( | 72 void MimeHandlerViewContainer::didFinishLoading( |
| 77 blink::WebURLLoader* /* unused */, | 73 blink::WebURLLoader* /* unused */, |
| 78 double /* unused */, | 74 double /* unused */, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 90 | 86 |
| 91 void MimeHandlerViewContainer::CreateMimeHandlerViewGuest() { | 87 void MimeHandlerViewContainer::CreateMimeHandlerViewGuest() { |
| 92 // The loader has completed loading |html_string_| so we can dispose it. | 88 // The loader has completed loading |html_string_| so we can dispose it. |
| 93 loader_.reset(); | 89 loader_.reset(); |
| 94 | 90 |
| 95 // Parse the stream URL to ensure it's valid. | 91 // Parse the stream URL to ensure it's valid. |
| 96 GURL stream_url(html_string_); | 92 GURL stream_url(html_string_); |
| 97 | 93 |
| 98 DCHECK_NE(element_instance_id(), guestview::kInstanceIDNone); | 94 DCHECK_NE(element_instance_id(), guestview::kInstanceIDNone); |
| 99 render_frame()->Send(new ExtensionHostMsg_CreateMimeHandlerViewGuest( | 95 render_frame()->Send(new ExtensionHostMsg_CreateMimeHandlerViewGuest( |
| 100 routing_id(), stream_url.spec(), original_url_.spec(), mime_type_, | 96 render_frame()->GetRoutingID(), stream_url.spec(), original_url_.spec(), |
| 101 element_instance_id())); | 97 mime_type_, element_instance_id())); |
| 102 } | 98 } |
| 103 | 99 |
| 104 } // namespace extensions | 100 } // namespace extensions |
| OLD | NEW |