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 <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "content/public/child/v8_value_converter.h" | 10 #include "content/public/child/v8_value_converter.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 | 31 |
32 const char kPostMessageName[] = "postMessage"; | 32 const char kPostMessageName[] = "postMessage"; |
33 | 33 |
34 // The gin-backed scriptable object which is exposed by the BrowserPlugin for | 34 // The gin-backed scriptable object which is exposed by the BrowserPlugin for |
35 // MimeHandlerViewContainer. This currently only implements "postMessage". | 35 // MimeHandlerViewContainer. This currently only implements "postMessage". |
36 class ScriptableObject : public gin::Wrappable<ScriptableObject>, | 36 class ScriptableObject : public gin::Wrappable<ScriptableObject>, |
37 public gin::NamedPropertyInterceptor { | 37 public gin::NamedPropertyInterceptor { |
38 public: | 38 public: |
39 static gin::WrapperInfo kWrapperInfo; | 39 static gin::WrapperInfo kWrapperInfo; |
40 | 40 |
41 static v8::Handle<v8::Object> Create( | 41 static v8::Local<v8::Object> Create( |
42 v8::Isolate* isolate, | 42 v8::Isolate* isolate, |
43 base::WeakPtr<MimeHandlerViewContainer> container) { | 43 base::WeakPtr<MimeHandlerViewContainer> container) { |
44 ScriptableObject* scriptable_object = | 44 ScriptableObject* scriptable_object = |
45 new ScriptableObject(isolate, container); | 45 new ScriptableObject(isolate, container); |
46 return gin::CreateHandle(isolate, scriptable_object).ToV8()->ToObject(); | 46 return gin::CreateHandle(isolate, scriptable_object).ToV8()->ToObject(); |
47 } | 47 } |
48 | 48 |
49 // gin::NamedPropertyInterceptor | 49 // gin::NamedPropertyInterceptor |
50 v8::Local<v8::Value> GetNamedProperty( | 50 v8::Local<v8::Value> GetNamedProperty( |
51 v8::Isolate* isolate, | 51 v8::Isolate* isolate, |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 | 202 |
203 void MimeHandlerViewContainer::didFinishLoading( | 203 void MimeHandlerViewContainer::didFinishLoading( |
204 blink::WebURLLoader* /* unused */, | 204 blink::WebURLLoader* /* unused */, |
205 double /* unused */, | 205 double /* unused */, |
206 int64_t /* unused */) { | 206 int64_t /* unused */) { |
207 DCHECK(is_embedded_); | 207 DCHECK(is_embedded_); |
208 CreateMimeHandlerViewGuest(); | 208 CreateMimeHandlerViewGuest(); |
209 } | 209 } |
210 | 210 |
211 void MimeHandlerViewContainer::PostMessage(v8::Isolate* isolate, | 211 void MimeHandlerViewContainer::PostMessage(v8::Isolate* isolate, |
212 v8::Handle<v8::Value> message) { | 212 v8::Local<v8::Value> message) { |
213 if (!guest_loaded_) { | 213 if (!guest_loaded_) { |
214 linked_ptr<v8::Global<v8::Value>> global( | 214 linked_ptr<v8::Global<v8::Value>> global( |
215 new v8::Global<v8::Value>(isolate, message)); | 215 new v8::Global<v8::Value>(isolate, message)); |
216 pending_messages_.push_back(global); | 216 pending_messages_.push_back(global); |
217 return; | 217 return; |
218 } | 218 } |
219 | 219 |
220 content::RenderView* guest_proxy_render_view = | 220 content::RenderView* guest_proxy_render_view = |
221 content::RenderView::FromRoutingID(guest_proxy_routing_id_); | 221 content::RenderView::FromRoutingID(guest_proxy_routing_id_); |
222 if (!guest_proxy_render_view) | 222 if (!guest_proxy_render_view) |
223 return; | 223 return; |
224 blink::WebFrame* guest_proxy_frame = | 224 blink::WebFrame* guest_proxy_frame = |
225 guest_proxy_render_view->GetWebView()->mainFrame(); | 225 guest_proxy_render_view->GetWebView()->mainFrame(); |
226 if (!guest_proxy_frame) | 226 if (!guest_proxy_frame) |
227 return; | 227 return; |
228 | 228 |
229 v8::Context::Scope context_scope( | 229 v8::Context::Scope context_scope( |
230 render_frame()->GetWebFrame()->mainWorldScriptContext()); | 230 render_frame()->GetWebFrame()->mainWorldScriptContext()); |
231 v8::Local<v8::Object> guest_proxy_window = | 231 v8::Local<v8::Object> guest_proxy_window = |
232 guest_proxy_frame->mainWorldScriptContext()->Global(); | 232 guest_proxy_frame->mainWorldScriptContext()->Global(); |
233 gin::Dictionary window_object(isolate, guest_proxy_window); | 233 gin::Dictionary window_object(isolate, guest_proxy_window); |
234 v8::Handle<v8::Function> post_message; | 234 v8::Local<v8::Function> post_message; |
235 if (!window_object.Get(std::string(kPostMessageName), &post_message)) | 235 if (!window_object.Get(std::string(kPostMessageName), &post_message)) |
236 return; | 236 return; |
237 | 237 |
238 v8::Handle<v8::Value> args[] = { | 238 v8::Local<v8::Value> args[] = { |
239 message, | 239 message, |
240 // Post the message to any domain inside the browser plugin. The embedder | 240 // Post the message to any domain inside the browser plugin. The embedder |
241 // should already know what is embedded. | 241 // should already know what is embedded. |
242 gin::StringToV8(isolate, "*") | 242 gin::StringToV8(isolate, "*")}; |
243 }; | |
244 guest_proxy_frame->callFunctionEvenIfScriptDisabled( | 243 guest_proxy_frame->callFunctionEvenIfScriptDisabled( |
245 post_message.As<v8::Function>(), | 244 post_message.As<v8::Function>(), |
246 guest_proxy_window, | 245 guest_proxy_window, |
247 arraysize(args), | 246 arraysize(args), |
248 args); | 247 args); |
249 } | 248 } |
250 | 249 |
251 void MimeHandlerViewContainer::PostMessageFromValue( | 250 void MimeHandlerViewContainer::PostMessageFromValue( |
252 const base::Value& message) { | 251 const base::Value& message) { |
253 blink::WebFrame* frame = render_frame()->GetWebFrame(); | 252 blink::WebFrame* frame = render_frame()->GetWebFrame(); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 if (!render_frame()) | 312 if (!render_frame()) |
314 return; | 313 return; |
315 | 314 |
316 render_frame()->Send( | 315 render_frame()->Send( |
317 new ExtensionsGuestViewHostMsg_CreateMimeHandlerViewGuest( | 316 new ExtensionsGuestViewHostMsg_CreateMimeHandlerViewGuest( |
318 render_frame()->GetRoutingID(), view_id_, element_instance_id(), | 317 render_frame()->GetRoutingID(), view_id_, element_instance_id(), |
319 element_size_)); | 318 element_size_)); |
320 } | 319 } |
321 | 320 |
322 } // namespace extensions | 321 } // namespace extensions |
OLD | NEW |