| 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 "content/public/renderer/render_view.h" | 8 #include "content/public/renderer/render_view.h" |
| 9 #include "extensions/common/extension_messages.h" | 9 #include "extensions/common/extension_messages.h" |
| 10 #include "extensions/common/guest_view/guest_view_constants.h" | 10 #include "extensions/common/guest_view/guest_view_constants.h" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 } // namespace | 74 } // namespace |
| 75 | 75 |
| 76 MimeHandlerViewContainer::MimeHandlerViewContainer( | 76 MimeHandlerViewContainer::MimeHandlerViewContainer( |
| 77 content::RenderFrame* render_frame, | 77 content::RenderFrame* render_frame, |
| 78 const std::string& mime_type, | 78 const std::string& mime_type, |
| 79 const GURL& original_url) | 79 const GURL& original_url) |
| 80 : GuestViewContainer(render_frame), | 80 : GuestViewContainer(render_frame), |
| 81 mime_type_(mime_type), | 81 mime_type_(mime_type), |
| 82 original_url_(original_url), | 82 original_url_(original_url), |
| 83 guest_proxy_routing_id_(-1), | 83 guest_proxy_routing_id_(-1), |
| 84 guest_loaded_(false), |
| 84 weak_factory_(this) { | 85 weak_factory_(this) { |
| 85 DCHECK(!mime_type_.empty()); | 86 DCHECK(!mime_type_.empty()); |
| 86 is_embedded_ = !render_frame->GetWebFrame()->document().isPluginDocument(); | 87 is_embedded_ = !render_frame->GetWebFrame()->document().isPluginDocument(); |
| 87 } | 88 } |
| 88 | 89 |
| 89 MimeHandlerViewContainer::~MimeHandlerViewContainer() { | 90 MimeHandlerViewContainer::~MimeHandlerViewContainer() { |
| 90 if (loader_) | 91 if (loader_) |
| 91 loader_->cancel(); | 92 loader_->cancel(); |
| 92 } | 93 } |
| 93 | 94 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 114 int data_length) { | 115 int data_length) { |
| 115 html_string_ += std::string(data, data_length); | 116 html_string_ += std::string(data, data_length); |
| 116 } | 117 } |
| 117 | 118 |
| 118 bool MimeHandlerViewContainer::OnMessageReceived(const IPC::Message& message) { | 119 bool MimeHandlerViewContainer::OnMessageReceived(const IPC::Message& message) { |
| 119 bool handled = true; | 120 bool handled = true; |
| 120 IPC_BEGIN_MESSAGE_MAP(MimeHandlerViewContainer, message) | 121 IPC_BEGIN_MESSAGE_MAP(MimeHandlerViewContainer, message) |
| 121 IPC_MESSAGE_HANDLER(ExtensionMsg_CreateMimeHandlerViewGuestACK, | 122 IPC_MESSAGE_HANDLER(ExtensionMsg_CreateMimeHandlerViewGuestACK, |
| 122 OnCreateMimeHandlerViewGuestACK) | 123 OnCreateMimeHandlerViewGuestACK) |
| 123 IPC_MESSAGE_HANDLER(ExtensionMsg_GuestAttached, OnGuestAttached) | 124 IPC_MESSAGE_HANDLER(ExtensionMsg_GuestAttached, OnGuestAttached) |
| 125 IPC_MESSAGE_HANDLER(ExtensionMsg_MimeHandlerViewGuestOnLoadCompleted, |
| 126 OnMimeHandlerViewGuestOnLoadCompleted) |
| 124 IPC_MESSAGE_UNHANDLED(handled = false) | 127 IPC_MESSAGE_UNHANDLED(handled = false) |
| 125 IPC_END_MESSAGE_MAP() | 128 IPC_END_MESSAGE_MAP() |
| 126 return handled; | 129 return handled; |
| 127 } | 130 } |
| 128 | 131 |
| 129 v8::Local<v8::Object> MimeHandlerViewContainer::V8ScriptableObject( | 132 v8::Local<v8::Object> MimeHandlerViewContainer::V8ScriptableObject( |
| 130 v8::Isolate* isolate) { | 133 v8::Isolate* isolate) { |
| 131 if (scriptable_object_.IsEmpty()) { | 134 if (scriptable_object_.IsEmpty()) { |
| 132 v8::Local<v8::Object> object = | 135 v8::Local<v8::Object> object = |
| 133 ScriptableObject::Create(isolate, weak_factory_.GetWeakPtr()); | 136 ScriptableObject::Create(isolate, weak_factory_.GetWeakPtr()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 146 void MimeHandlerViewContainer::didFinishLoading( | 149 void MimeHandlerViewContainer::didFinishLoading( |
| 147 blink::WebURLLoader* /* unused */, | 150 blink::WebURLLoader* /* unused */, |
| 148 double /* unused */, | 151 double /* unused */, |
| 149 int64_t /* unused */) { | 152 int64_t /* unused */) { |
| 150 DCHECK(is_embedded_); | 153 DCHECK(is_embedded_); |
| 151 CreateMimeHandlerViewGuest(); | 154 CreateMimeHandlerViewGuest(); |
| 152 } | 155 } |
| 153 | 156 |
| 154 void MimeHandlerViewContainer::PostMessage(v8::Isolate* isolate, | 157 void MimeHandlerViewContainer::PostMessage(v8::Isolate* isolate, |
| 155 v8::Handle<v8::Value> message) { | 158 v8::Handle<v8::Value> message) { |
| 159 if (!guest_loaded_) { |
| 160 linked_ptr<ScopedPersistent<v8::Value>> scoped_persistent( |
| 161 new ScopedPersistent<v8::Value>(isolate, message)); |
| 162 pending_messages_.push_back(scoped_persistent); |
| 163 return; |
| 164 } |
| 165 |
| 156 content::RenderView* guest_proxy_render_view = | 166 content::RenderView* guest_proxy_render_view = |
| 157 content::RenderView::FromRoutingID(guest_proxy_routing_id_); | 167 content::RenderView::FromRoutingID(guest_proxy_routing_id_); |
| 158 if (!guest_proxy_render_view) | 168 if (!guest_proxy_render_view) |
| 159 return; | 169 return; |
| 160 blink::WebFrame* guest_proxy_frame = | 170 blink::WebFrame* guest_proxy_frame = |
| 161 guest_proxy_render_view->GetWebView()->mainFrame(); | 171 guest_proxy_render_view->GetWebView()->mainFrame(); |
| 162 if (!guest_proxy_frame) | 172 if (!guest_proxy_frame) |
| 163 return; | 173 return; |
| 164 | 174 |
| 165 v8::Local<v8::Object> guest_proxy_window = | 175 v8::Local<v8::Object> guest_proxy_window = |
| (...skipping 20 matching lines...) Expand all Loading... |
| 186 render_frame()->AttachGuest(element_instance_id); | 196 render_frame()->AttachGuest(element_instance_id); |
| 187 } | 197 } |
| 188 | 198 |
| 189 void MimeHandlerViewContainer::OnGuestAttached(int /* unused */, | 199 void MimeHandlerViewContainer::OnGuestAttached(int /* unused */, |
| 190 int guest_proxy_routing_id) { | 200 int guest_proxy_routing_id) { |
| 191 // Save the RenderView routing ID of the guest here so it can be used to route | 201 // Save the RenderView routing ID of the guest here so it can be used to route |
| 192 // PostMessage calls. | 202 // PostMessage calls. |
| 193 guest_proxy_routing_id_ = guest_proxy_routing_id; | 203 guest_proxy_routing_id_ = guest_proxy_routing_id; |
| 194 } | 204 } |
| 195 | 205 |
| 206 void MimeHandlerViewContainer::OnMimeHandlerViewGuestOnLoadCompleted( |
| 207 int /* unused */) { |
| 208 guest_loaded_ = true; |
| 209 if (pending_messages_.empty()) |
| 210 return; |
| 211 |
| 212 // Now that the guest has loaded, flush any unsent messages. |
| 213 blink::WebFrame* frame = render_frame()->GetWebFrame(); |
| 214 if (!frame) |
| 215 return; |
| 216 |
| 217 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 218 v8::HandleScope handle_scope(isolate); |
| 219 v8::Context::Scope context_scope(frame->mainWorldScriptContext()); |
| 220 for (const auto& pending_message : pending_messages_) |
| 221 PostMessage(isolate, pending_message->NewHandle(isolate)); |
| 222 |
| 223 pending_messages_.clear(); |
| 224 } |
| 225 |
| 196 void MimeHandlerViewContainer::CreateMimeHandlerViewGuest() { | 226 void MimeHandlerViewContainer::CreateMimeHandlerViewGuest() { |
| 197 // The loader has completed loading |html_string_| so we can dispose it. | 227 // The loader has completed loading |html_string_| so we can dispose it. |
| 198 loader_.reset(); | 228 loader_.reset(); |
| 199 | 229 |
| 200 // Parse the stream URL to ensure it's valid. | 230 // Parse the stream URL to ensure it's valid. |
| 201 GURL stream_url(html_string_); | 231 GURL stream_url(html_string_); |
| 202 | 232 |
| 203 DCHECK_NE(element_instance_id(), guestview::kInstanceIDNone); | 233 DCHECK_NE(element_instance_id(), guestview::kInstanceIDNone); |
| 204 render_frame()->Send(new ExtensionHostMsg_CreateMimeHandlerViewGuest( | 234 render_frame()->Send(new ExtensionHostMsg_CreateMimeHandlerViewGuest( |
| 205 render_frame()->GetRoutingID(), stream_url.spec(), original_url_.spec(), | 235 render_frame()->GetRoutingID(), stream_url.spec(), original_url_.spec(), |
| 206 mime_type_, element_instance_id())); | 236 mime_type_, element_instance_id())); |
| 207 } | 237 } |
| 208 | 238 |
| 209 } // namespace extensions | 239 } // namespace extensions |
| OLD | NEW |