| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 ScriptableObject* scriptable_object = | 43 ScriptableObject* scriptable_object = |
| 44 new ScriptableObject(isolate, container); | 44 new ScriptableObject(isolate, container); |
| 45 return gin::CreateHandle(isolate, scriptable_object).ToV8()->ToObject(); | 45 return gin::CreateHandle(isolate, scriptable_object).ToV8()->ToObject(); |
| 46 } | 46 } |
| 47 | 47 |
| 48 // gin::NamedPropertyInterceptor | 48 // gin::NamedPropertyInterceptor |
| 49 v8::Local<v8::Value> GetNamedProperty( | 49 v8::Local<v8::Value> GetNamedProperty( |
| 50 v8::Isolate* isolate, | 50 v8::Isolate* isolate, |
| 51 const std::string& identifier) override { | 51 const std::string& identifier) override { |
| 52 if (identifier == kPostMessageName) { | 52 if (identifier == kPostMessageName) { |
| 53 return gin::CreateFunctionTemplate(isolate, | 53 if (post_message_function_template_.IsEmpty()) { |
| 54 base::Bind(&MimeHandlerViewContainer::PostMessage, | 54 post_message_function_template_.Reset( |
| 55 container_, isolate))->GetFunction(); | 55 isolate, |
| 56 gin::CreateFunctionTemplate( |
| 57 isolate, base::Bind(&MimeHandlerViewContainer::PostMessage, |
| 58 container_, isolate))); |
| 59 } |
| 60 return v8::Local<v8::FunctionTemplate>::New( |
| 61 isolate, post_message_function_template_)->GetFunction(); |
| 56 } | 62 } |
| 57 return v8::Local<v8::Value>(); | 63 return v8::Local<v8::Value>(); |
| 58 } | 64 } |
| 59 | 65 |
| 60 private: | 66 private: |
| 61 ScriptableObject(v8::Isolate* isolate, | 67 ScriptableObject(v8::Isolate* isolate, |
| 62 base::WeakPtr<MimeHandlerViewContainer> container) | 68 base::WeakPtr<MimeHandlerViewContainer> container) |
| 63 : gin::NamedPropertyInterceptor(isolate, this), | 69 : gin::NamedPropertyInterceptor(isolate, this), |
| 64 container_(container) {} | 70 container_(container) {} |
| 65 | 71 |
| 66 // gin::Wrappable | 72 // gin::Wrappable |
| 67 gin::ObjectTemplateBuilder GetObjectTemplateBuilder( | 73 gin::ObjectTemplateBuilder GetObjectTemplateBuilder( |
| 68 v8::Isolate* isolate) override { | 74 v8::Isolate* isolate) override { |
| 69 return gin::Wrappable<ScriptableObject>::GetObjectTemplateBuilder(isolate) | 75 return gin::Wrappable<ScriptableObject>::GetObjectTemplateBuilder(isolate) |
| 70 .AddNamedPropertyInterceptor(); | 76 .AddNamedPropertyInterceptor(); |
| 71 } | 77 } |
| 72 | 78 |
| 73 base::WeakPtr<MimeHandlerViewContainer> container_; | 79 base::WeakPtr<MimeHandlerViewContainer> container_; |
| 80 v8::Persistent<v8::FunctionTemplate> post_message_function_template_; |
| 74 }; | 81 }; |
| 75 | 82 |
| 76 // static | 83 // static |
| 77 gin::WrapperInfo ScriptableObject::kWrapperInfo = { gin::kEmbedderNativeGin }; | 84 gin::WrapperInfo ScriptableObject::kWrapperInfo = { gin::kEmbedderNativeGin }; |
| 78 | 85 |
| 79 // Maps from content::RenderFrame to the set of MimeHandlerViewContainers within | 86 // Maps from content::RenderFrame to the set of MimeHandlerViewContainers within |
| 80 // it. | 87 // it. |
| 81 base::LazyInstance< | 88 base::LazyInstance< |
| 82 std::map<content::RenderFrame*, std::set<MimeHandlerViewContainer*>>> | 89 std::map<content::RenderFrame*, std::set<MimeHandlerViewContainer*>>> |
| 83 g_mime_handler_view_container_map = LAZY_INSTANCE_INITIALIZER; | 90 g_mime_handler_view_container_map = LAZY_INSTANCE_INITIALIZER; |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 | 308 |
| 302 if (!render_frame()) | 309 if (!render_frame()) |
| 303 return; | 310 return; |
| 304 | 311 |
| 305 render_frame()->Send(new GuestViewHostMsg_CreateMimeHandlerViewGuest( | 312 render_frame()->Send(new GuestViewHostMsg_CreateMimeHandlerViewGuest( |
| 306 render_frame()->GetRoutingID(), view_id_, element_instance_id(), | 313 render_frame()->GetRoutingID(), view_id_, element_instance_id(), |
| 307 element_size_)); | 314 element_size_)); |
| 308 } | 315 } |
| 309 | 316 |
| 310 } // namespace extensions | 317 } // namespace extensions |
| OLD | NEW |