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/extensions_guest_view_container.h" | 5 #include "extensions/renderer/guest_view/extensions_guest_view_container.h" |
6 | 6 |
| 7 #include "base/command_line.h" |
| 8 #include "content/public/common/content_switches.h" |
7 #include "content/public/renderer/render_frame.h" | 9 #include "content/public/renderer/render_frame.h" |
8 #include "content/public/renderer/render_view.h" | 10 #include "content/public/renderer/render_view.h" |
| 11 #include "extensions/common/guest_view/extensions_guest_view_messages.h" |
9 #include "extensions/common/guest_view/guest_view_constants.h" | 12 #include "extensions/common/guest_view/guest_view_constants.h" |
10 #include "extensions/common/guest_view/guest_view_messages.h" | 13 #include "extensions/common/guest_view/guest_view_messages.h" |
11 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 14 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
12 #include "third_party/WebKit/public/web/WebScopedMicrotaskSuppression.h" | 15 #include "third_party/WebKit/public/web/WebScopedMicrotaskSuppression.h" |
13 #include "third_party/WebKit/public/web/WebView.h" | 16 #include "third_party/WebKit/public/web/WebView.h" |
14 | 17 |
15 namespace { | 18 namespace { |
16 typedef std::map<int, extensions::ExtensionsGuestViewContainer*> | 19 typedef std::map<int, extensions::ExtensionsGuestViewContainer*> |
17 ExtensionsGuestViewContainerMap; | 20 ExtensionsGuestViewContainerMap; |
18 static base::LazyInstance<ExtensionsGuestViewContainerMap> | 21 static base::LazyInstance<ExtensionsGuestViewContainerMap> |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 return; | 55 return; |
53 | 56 |
54 v8::Context::Scope context_scope(context); | 57 v8::Context::Scope context_scope(context); |
55 blink::WebScopedMicrotaskSuppression suppression; | 58 blink::WebScopedMicrotaskSuppression suppression; |
56 | 59 |
57 // Call the AttachGuest API's callback with the guest proxy as the first | 60 // Call the AttachGuest API's callback with the guest proxy as the first |
58 // parameter. | 61 // parameter. |
59 callback->Call(context->Global(), argc, argv.get()); | 62 callback->Call(context->Global(), argc, argv.get()); |
60 } | 63 } |
61 | 64 |
| 65 ExtensionsGuestViewContainer::AttachIframeRequest::AttachIframeRequest( |
| 66 GuestViewContainer* container, |
| 67 int guest_instance_id, |
| 68 v8::Handle<v8::Function> callback, |
| 69 v8::Isolate* isolate) |
| 70 : Request(container, callback, isolate), |
| 71 guest_instance_id_(guest_instance_id) { |
| 72 } |
| 73 |
| 74 ExtensionsGuestViewContainer::AttachIframeRequest::~AttachIframeRequest() { |
| 75 } |
| 76 |
| 77 void ExtensionsGuestViewContainer::AttachIframeRequest::PerformRequest() { |
| 78 LOG(WARNING) << "AttachIframeRequest::PerformRequest, guest_instance_id: " |
| 79 << guest_instance_id_; |
| 80 // Only store callback. |
| 81 DCHECK(container()->render_frame()); |
| 82 } |
| 83 |
| 84 void ExtensionsGuestViewContainer::AttachIframeRequest::HandleResponse( |
| 85 const IPC::Message& message) { |
| 86 ExtensionsGuestViewMsg_ContentWindowReady::Param param; |
| 87 bool message_read_status = |
| 88 ExtensionsGuestViewMsg_ContentWindowReady::Read(&message, ¶m); |
| 89 DCHECK(message_read_status); |
| 90 |
| 91 // If we don't have a callback then there's nothing more to do. |
| 92 if (!HasCallback()) { |
| 93 LOG(WARNING) << "AttachIframeRequest, no callback, bail out"; |
| 94 return; |
| 95 } |
| 96 |
| 97 int render_view_proxy_routing_id = get<1>(param); |
| 98 content::RenderView* guest_proxy_render_view = |
| 99 content::RenderView::FromRoutingID(render_view_proxy_routing_id); |
| 100 |
| 101 // TODO(fsamuel): Should we be reporting an error to JavaScript or DCHECKing? |
| 102 if (!guest_proxy_render_view) { |
| 103 LOG(ERROR) << "Guest proxy render view not found, routing ID was" << |
| 104 render_view_proxy_routing_id; |
| 105 return; |
| 106 } |
| 107 |
| 108 v8::HandleScope handle_scope(isolate()); |
| 109 blink::WebFrame* frame = guest_proxy_render_view->GetWebView()->mainFrame(); |
| 110 v8::Local<v8::Value> window = frame->mainWorldScriptContext()->Global(); |
| 111 |
| 112 const int argc = 1; |
| 113 scoped_ptr<v8::Handle<v8::Value>[]> argv(new v8::Handle<v8::Value>[argc]); |
| 114 argv[0] = window; |
| 115 |
| 116 ExecuteCallbackIfAvailable(argc, argv.Pass()); |
| 117 } |
| 118 |
62 ExtensionsGuestViewContainer::AttachRequest::AttachRequest( | 119 ExtensionsGuestViewContainer::AttachRequest::AttachRequest( |
63 GuestViewContainer* container, | 120 GuestViewContainer* container, |
64 int guest_instance_id, | 121 int guest_instance_id, |
65 scoped_ptr<base::DictionaryValue> params, | 122 scoped_ptr<base::DictionaryValue> params, |
66 v8::Handle<v8::Function> callback, | 123 v8::Handle<v8::Function> callback, |
67 v8::Isolate* isolate) | 124 v8::Isolate* isolate) |
68 : Request(container, callback, isolate), | 125 : Request(container, callback, isolate), |
69 guest_instance_id_(guest_instance_id), | 126 guest_instance_id_(guest_instance_id), |
70 params_(params.Pass()) { | 127 params_(params.Pass()) { |
71 } | 128 } |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 ExecuteCallbackIfAvailable(0 /* argc */, nullptr); | 189 ExecuteCallbackIfAvailable(0 /* argc */, nullptr); |
133 } | 190 } |
134 | 191 |
135 ExtensionsGuestViewContainer::ExtensionsGuestViewContainer( | 192 ExtensionsGuestViewContainer::ExtensionsGuestViewContainer( |
136 content::RenderFrame* render_frame) | 193 content::RenderFrame* render_frame) |
137 : GuestViewContainer(render_frame), | 194 : GuestViewContainer(render_frame), |
138 ready_(false), | 195 ready_(false), |
139 destruction_isolate_(nullptr), | 196 destruction_isolate_(nullptr), |
140 element_resize_isolate_(nullptr), | 197 element_resize_isolate_(nullptr), |
141 weak_ptr_factory_(this) { | 198 weak_ptr_factory_(this) { |
| 199 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 200 switches::kSitePerProcess)) { |
| 201 // There is not BrowserPluginDelegate to wait for. |
| 202 ready_ = true; |
| 203 } |
142 } | 204 } |
143 | 205 |
144 ExtensionsGuestViewContainer::~ExtensionsGuestViewContainer() { | 206 ExtensionsGuestViewContainer::~ExtensionsGuestViewContainer() { |
145 if (element_instance_id() != guestview::kInstanceIDNone) | 207 if (element_instance_id() != guestview::kInstanceIDNone) |
146 g_guest_view_container_map.Get().erase(element_instance_id()); | 208 g_guest_view_container_map.Get().erase(element_instance_id()); |
147 | 209 |
148 if (pending_response_.get()) | 210 if (pending_response_.get()) |
149 pending_response_->ExecuteCallbackIfAvailable(0 /* argc */, nullptr); | 211 pending_response_->ExecuteCallbackIfAvailable(0 /* argc */, nullptr); |
150 | 212 |
151 while (pending_requests_.size() > 0) { | 213 while (pending_requests_.size() > 0) { |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 } | 341 } |
280 | 342 |
281 void ExtensionsGuestViewContainer::HandlePendingResponseCallback( | 343 void ExtensionsGuestViewContainer::HandlePendingResponseCallback( |
282 const IPC::Message& message) { | 344 const IPC::Message& message) { |
283 CHECK(pending_response_.get()); | 345 CHECK(pending_response_.get()); |
284 linked_ptr<Request> pending_response(pending_response_.release()); | 346 linked_ptr<Request> pending_response(pending_response_.release()); |
285 pending_response->HandleResponse(message); | 347 pending_response->HandleResponse(message); |
286 } | 348 } |
287 | 349 |
288 } // namespace extensions | 350 } // namespace extensions |
OLD | NEW |