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 "components/guest_view/renderer/guest_view_container.h" | 5 #include "components/guest_view/renderer/guest_view_container.h" |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "components/guest_view/common/guest_view_constants.h" | 8 #include "components/guest_view/common/guest_view_constants.h" |
9 #include "components/guest_view/common/guest_view_messages.h" | 9 #include "components/guest_view/common/guest_view_messages.h" |
10 #include "components/guest_view/renderer/guest_view_request.h" | 10 #include "components/guest_view/renderer/guest_view_request.h" |
11 #include "content/public/renderer/render_frame.h" | 11 #include "content/public/renderer/render_frame.h" |
12 #include "content/public/renderer/render_frame_observer.h" | 12 #include "content/public/renderer/render_frame_observer.h" |
13 #include "content/public/renderer/render_view.h" | 13 #include "content/public/renderer/render_view.h" |
| 14 #include "third_party/WebKit/public/web/WebScopedMicrotaskSuppression.h" |
14 | 15 |
15 namespace { | 16 namespace { |
16 | 17 |
17 using GuestViewContainerMap = std::map<int, guest_view::GuestViewContainer*>; | 18 using GuestViewContainerMap = std::map<int, guest_view::GuestViewContainer*>; |
18 static base::LazyInstance<GuestViewContainerMap> g_guest_view_container_map = | 19 static base::LazyInstance<GuestViewContainerMap> g_guest_view_container_map = |
19 LAZY_INSTANCE_INITIALIZER; | 20 LAZY_INSTANCE_INITIALIZER; |
20 | 21 |
21 } // namespace | 22 } // namespace |
22 | 23 |
23 namespace guest_view { | 24 namespace guest_view { |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 void GuestViewContainer::HandlePendingResponseCallback( | 147 void GuestViewContainer::HandlePendingResponseCallback( |
147 const IPC::Message& message) { | 148 const IPC::Message& message) { |
148 CHECK(pending_response_.get()); | 149 CHECK(pending_response_.get()); |
149 linked_ptr<GuestViewRequest> pending_response(pending_response_.release()); | 150 linked_ptr<GuestViewRequest> pending_response(pending_response_.release()); |
150 pending_response->HandleResponse(message); | 151 pending_response->HandleResponse(message); |
151 } | 152 } |
152 | 153 |
153 void GuestViewContainer::RunDestructionCallback(bool embedder_frame_destroyed) { | 154 void GuestViewContainer::RunDestructionCallback(bool embedder_frame_destroyed) { |
154 // Do not attempt to run |destruction_callback_| if the embedder frame was | 155 // Do not attempt to run |destruction_callback_| if the embedder frame was |
155 // destroyed. Trying to invoke callback on RenderFrame destruction results in | 156 // destroyed. Trying to invoke callback on RenderFrame destruction results in |
156 // assertion failure when calling v8::MicrotasksScope. | 157 // assertion failure when calling WebScopedMicrotaskSuppression. |
157 if (embedder_frame_destroyed) | 158 if (embedder_frame_destroyed) |
158 return; | 159 return; |
159 | 160 |
160 // Call the destruction callback, if one is registered. | 161 // Call the destruction callback, if one is registered. |
161 if (!destruction_callback_.IsEmpty()) { | 162 if (!destruction_callback_.IsEmpty()) { |
162 v8::HandleScope handle_scope(destruction_isolate_); | 163 v8::HandleScope handle_scope(destruction_isolate_); |
163 v8::Local<v8::Function> callback = v8::Local<v8::Function>::New( | 164 v8::Local<v8::Function> callback = v8::Local<v8::Function>::New( |
164 destruction_isolate_, destruction_callback_); | 165 destruction_isolate_, destruction_callback_); |
165 v8::Local<v8::Context> context = callback->CreationContext(); | 166 v8::Local<v8::Context> context = callback->CreationContext(); |
166 if (context.IsEmpty()) | 167 if (context.IsEmpty()) |
167 return; | 168 return; |
168 | 169 |
169 v8::Context::Scope context_scope(context); | 170 v8::Context::Scope context_scope(context); |
170 v8::MicrotasksScope microtasks( | 171 blink::WebScopedMicrotaskSuppression suppression; |
171 destruction_isolate_, v8::MicrotasksScope::kDoNotRunMicrotasks); | |
172 | 172 |
173 callback->Call(context->Global(), 0 /* argc */, nullptr); | 173 callback->Call(context->Global(), 0 /* argc */, nullptr); |
174 } | 174 } |
175 } | 175 } |
176 | 176 |
177 void GuestViewContainer::OnHandleCallback(const IPC::Message& message) { | 177 void GuestViewContainer::OnHandleCallback(const IPC::Message& message) { |
178 // Handle the callback for the current request with a pending response. | 178 // Handle the callback for the current request with a pending response. |
179 HandlePendingResponseCallback(message); | 179 HandlePendingResponseCallback(message); |
180 // Perform the subsequent request if one exists. | 180 // Perform the subsequent request if one exists. |
181 PerformPendingRequest(); | 181 PerformPendingRequest(); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 | 214 |
215 void GuestViewContainer::DidDestroyElement() { | 215 void GuestViewContainer::DidDestroyElement() { |
216 Destroy(false); | 216 Destroy(false); |
217 } | 217 } |
218 | 218 |
219 base::WeakPtr<content::BrowserPluginDelegate> GuestViewContainer::GetWeakPtr() { | 219 base::WeakPtr<content::BrowserPluginDelegate> GuestViewContainer::GetWeakPtr() { |
220 return weak_ptr_factory_.GetWeakPtr(); | 220 return weak_ptr_factory_.GetWeakPtr(); |
221 } | 221 } |
222 | 222 |
223 } // namespace guest_view | 223 } // namespace guest_view |
OLD | NEW |