Chromium Code Reviews| 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 19 matching lines...) Expand all Loading... | |
| 113 void MimeHandlerViewContainer::DidReceiveData(const char* data, | 114 void MimeHandlerViewContainer::DidReceiveData(const char* data, |
| 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) |
| 124 IPC_MESSAGE_HANDLER(ExtensionMsg_MimeHandlerViewGuestOnLoadCompleted, | |
| 125 OnMimeHandlerViewGuestOnLoadCompleted) | |
| 123 IPC_MESSAGE_HANDLER(ExtensionMsg_GuestAttached, OnGuestAttached) | 126 IPC_MESSAGE_HANDLER(ExtensionMsg_GuestAttached, OnGuestAttached) |
| 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 = |
| (...skipping 13 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) { |
| 156 content::RenderView* guest_proxy_render_view = | 159 if (!guest_loaded_) { |
| 157 content::RenderView::FromRoutingID(guest_proxy_routing_id_); | 160 linked_ptr<ScopedPersistent<v8::Value>> scoped_persistent( |
| 158 if (!guest_proxy_render_view) | 161 new ScopedPersistent<v8::Value>(isolate, message)); |
| 162 pending_messages_.push_back(scoped_persistent); | |
| 159 return; | 163 return; |
| 160 blink::WebFrame* guest_proxy_frame = | 164 } |
| 161 guest_proxy_render_view->GetWebView()->mainFrame(); | 165 |
| 166 blink::WebFrame* guest_proxy_frame = render_frame()->GetWebFrame(); | |
|
Sam McNally
2014/12/19 03:54:03
Change the other one, not this one.
| |
| 162 if (!guest_proxy_frame) | 167 if (!guest_proxy_frame) |
| 163 return; | 168 return; |
| 164 | 169 |
| 165 v8::Local<v8::Object> guest_proxy_window = | 170 v8::Local<v8::Object> guest_proxy_window = |
| 166 guest_proxy_frame->mainWorldScriptContext()->Global(); | 171 guest_proxy_frame->mainWorldScriptContext()->Global(); |
| 167 gin::Dictionary window_object(isolate, guest_proxy_window); | 172 gin::Dictionary window_object(isolate, guest_proxy_window); |
| 168 v8::Handle<v8::Function> post_message; | 173 v8::Handle<v8::Function> post_message; |
| 169 if (!window_object.Get(std::string(kPostMessageName), &post_message)) | 174 if (!window_object.Get(std::string(kPostMessageName), &post_message)) |
| 170 return; | 175 return; |
| 171 | 176 |
| 172 v8::Handle<v8::Value> args[] = { | 177 v8::Handle<v8::Value> args[] = { |
| 173 message, | 178 message, |
| 174 // Post the message to any domain inside the browser plugin. The embedder | 179 // Post the message to any domain inside the browser plugin. The embedder |
| 175 // should already know what is embedded. | 180 // should already know what is embedded. |
| 176 gin::StringToV8(isolate, "*") | 181 gin::StringToV8(isolate, "*") |
| 177 }; | 182 }; |
| 178 post_message.As<v8::Function>()->Call( | 183 post_message.As<v8::Function>()->Call( |
| 179 guest_proxy_window, arraysize(args), args); | 184 guest_proxy_window, arraysize(args), args); |
| 180 } | 185 } |
| 181 | 186 |
| 182 void MimeHandlerViewContainer::OnCreateMimeHandlerViewGuestACK( | 187 void MimeHandlerViewContainer::OnCreateMimeHandlerViewGuestACK( |
| 183 int element_instance_id) { | 188 int element_instance_id) { |
| 184 DCHECK_NE(this->element_instance_id(), guestview::kInstanceIDNone); | 189 DCHECK_NE(this->element_instance_id(), guestview::kInstanceIDNone); |
| 185 DCHECK_EQ(this->element_instance_id(), element_instance_id); | 190 DCHECK_EQ(this->element_instance_id(), element_instance_id); |
| 186 render_frame()->AttachGuest(element_instance_id); | 191 render_frame()->AttachGuest(element_instance_id); |
| 187 } | 192 } |
| 188 | 193 |
| 194 void MimeHandlerViewContainer::OnMimeHandlerViewGuestOnLoadCompleted( | |
| 195 int /* unused */) { | |
| 196 guest_loaded_ = true; | |
| 197 if (pending_messages_.empty()) | |
| 198 return; | |
| 199 | |
| 200 // Now that the guest has loaded, flush any unsent messages. | |
| 201 content::RenderView* render_view = | |
| 202 content::RenderView::FromRoutingID(render_view_routing_id()); | |
| 203 if (!render_view) | |
| 204 return; | |
| 205 blink::WebFrame* frame = render_view->GetWebView()->mainFrame(); | |
| 206 if (!frame) | |
| 207 return; | |
| 208 | |
| 209 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | |
| 210 v8::HandleScope handle_scope(isolate); | |
| 211 v8::Context::Scope context_scope(frame->mainWorldScriptContext()); | |
| 212 for (const auto& pending_message : pending_messages_) | |
| 213 PostMessage(isolate, pending_message->NewHandle(isolate)); | |
| 214 | |
| 215 pending_messages_.clear(); | |
| 216 } | |
| 217 | |
| 189 void MimeHandlerViewContainer::OnGuestAttached(int /* unused */, | 218 void MimeHandlerViewContainer::OnGuestAttached(int /* unused */, |
| 190 int guest_proxy_routing_id) { | 219 int guest_proxy_routing_id) { |
| 191 // Save the RenderView routing ID of the guest here so it can be used to route | 220 // Save the RenderView routing ID of the guest here so it can be used to route |
| 192 // PostMessage calls. | 221 // PostMessage calls. |
| 193 guest_proxy_routing_id_ = guest_proxy_routing_id; | 222 guest_proxy_routing_id_ = guest_proxy_routing_id; |
| 194 } | 223 } |
| 195 | 224 |
| 196 void MimeHandlerViewContainer::CreateMimeHandlerViewGuest() { | 225 void MimeHandlerViewContainer::CreateMimeHandlerViewGuest() { |
| 197 // The loader has completed loading |html_string_| so we can dispose it. | 226 // The loader has completed loading |html_string_| so we can dispose it. |
| 198 loader_.reset(); | 227 loader_.reset(); |
| 199 | 228 |
| 200 // Parse the stream URL to ensure it's valid. | 229 // Parse the stream URL to ensure it's valid. |
| 201 GURL stream_url(html_string_); | 230 GURL stream_url(html_string_); |
| 202 | 231 |
| 203 DCHECK_NE(element_instance_id(), guestview::kInstanceIDNone); | 232 DCHECK_NE(element_instance_id(), guestview::kInstanceIDNone); |
| 204 render_frame()->Send(new ExtensionHostMsg_CreateMimeHandlerViewGuest( | 233 render_frame()->Send(new ExtensionHostMsg_CreateMimeHandlerViewGuest( |
| 205 render_frame()->GetRoutingID(), stream_url.spec(), original_url_.spec(), | 234 render_frame()->GetRoutingID(), stream_url.spec(), original_url_.spec(), |
| 206 mime_type_, element_instance_id())); | 235 mime_type_, element_instance_id())); |
| 207 } | 236 } |
| 208 | 237 |
| 209 } // namespace extensions | 238 } // namespace extensions |
| OLD | NEW |