Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(438)

Side by Side Diff: components/guest_view/renderer/guest_view_container.cc

Issue 972313002: Make <webview> use out-of-process iframe architecture. (Closed) Base URL: ssh://saopaulo.wat/mnt/dev/shared/src@testoopif2z-better-chrome
Patch Set: sync Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "components/guest_view/common/guest_view_constants.h" 7 #include "components/guest_view/common/guest_view_constants.h"
8 #include "components/guest_view/common/guest_view_messages.h" 8 #include "components/guest_view/common/guest_view_messages.h"
9 #include "components/guest_view/renderer/guest_view_request.h" 9 #include "components/guest_view/renderer/guest_view_request.h"
10 #include "content/public/renderer/render_frame.h" 10 #include "content/public/renderer/render_frame.h"
11 #include "content/public/renderer/render_frame_observer.h" 11 #include "content/public/renderer/render_frame_observer.h"
12 #include "content/public/renderer/render_view.h" 12 #include "content/public/renderer/render_view.h"
13 #include "third_party/WebKit/public/web/WebScopedMicrotaskSuppression.h"
13 14
14 namespace { 15 namespace {
15 16
16 using GuestViewContainerMap = std::map<int, guest_view::GuestViewContainer*>; 17 using GuestViewContainerMap = std::map<int, guest_view::GuestViewContainer*>;
17 static base::LazyInstance<GuestViewContainerMap> g_guest_view_container_map = 18 static base::LazyInstance<GuestViewContainerMap> g_guest_view_container_map =
18 LAZY_INSTANCE_INITIALIZER; 19 LAZY_INSTANCE_INITIALIZER;
19 20
20 } // namespace 21 } // namespace
21 22
22 namespace guest_view { 23 namespace guest_view {
(...skipping 17 matching lines...) Expand all
40 GuestViewContainer* container, 41 GuestViewContainer* container,
41 content::RenderFrame* render_frame) 42 content::RenderFrame* render_frame)
42 : content::RenderFrameObserver(render_frame), 43 : content::RenderFrameObserver(render_frame),
43 container_(container) {} 44 container_(container) {}
44 45
45 void GuestViewContainer::RenderFrameLifetimeObserver::OnDestruct() { 46 void GuestViewContainer::RenderFrameLifetimeObserver::OnDestruct() {
46 container_->RenderFrameDestroyed(); 47 container_->RenderFrameDestroyed();
47 } 48 }
48 49
49 GuestViewContainer::GuestViewContainer(content::RenderFrame* render_frame) 50 GuestViewContainer::GuestViewContainer(content::RenderFrame* render_frame)
50 : element_instance_id_(guest_view::kInstanceIDNone), 51 : ready_(false),
52 element_instance_id_(guest_view::kInstanceIDNone),
51 render_frame_(render_frame), 53 render_frame_(render_frame),
52 ready_(false),
53 in_destruction_(false), 54 in_destruction_(false),
55 destruction_isolate_(nullptr),
54 weak_ptr_factory_(this) { 56 weak_ptr_factory_(this) {
55 render_frame_lifetime_observer_.reset( 57 render_frame_lifetime_observer_.reset(
56 new RenderFrameLifetimeObserver(this, render_frame_)); 58 new RenderFrameLifetimeObserver(this, render_frame_));
57 } 59 }
58 60
59 GuestViewContainer::~GuestViewContainer() { 61 GuestViewContainer::~GuestViewContainer() {
60 // Note: Cleanups should be done in GuestViewContainer::Destroy(), not here. 62 // Note: Cleanups should be done in GuestViewContainer::Destroy(), not here.
61 } 63 }
62 64
63 // static. 65 // static.
(...skipping 16 matching lines...) Expand all
80 void GuestViewContainer::Destroy(bool embedder_frame_destroyed) { 82 void GuestViewContainer::Destroy(bool embedder_frame_destroyed) {
81 if (in_destruction_) 83 if (in_destruction_)
82 return; 84 return;
83 85
84 in_destruction_ = true; 86 in_destruction_ = true;
85 87
86 // Give our derived class an opportunity to perform some cleanup prior to 88 // Give our derived class an opportunity to perform some cleanup prior to
87 // destruction. 89 // destruction.
88 OnDestroy(embedder_frame_destroyed); 90 OnDestroy(embedder_frame_destroyed);
89 91
92 RunDestructionCallback(embedder_frame_destroyed);
93
90 // Invalidate weak references to us to avoid late arriving tasks from running 94 // Invalidate weak references to us to avoid late arriving tasks from running
91 // during destruction 95 // during destruction
92 weak_ptr_factory_.InvalidateWeakPtrs(); 96 weak_ptr_factory_.InvalidateWeakPtrs();
93 97
94 if (element_instance_id() != guest_view::kInstanceIDNone) 98 if (element_instance_id() != guest_view::kInstanceIDNone)
95 g_guest_view_container_map.Get().erase(element_instance_id()); 99 g_guest_view_container_map.Get().erase(element_instance_id());
96 100
97 if (pending_response_.get()) 101 if (pending_response_.get())
98 pending_response_->ExecuteCallbackIfAvailable(0 /* argc */, nullptr); 102 pending_response_->ExecuteCallbackIfAvailable(0 /* argc */, nullptr);
99 103
100 while (pending_requests_.size() > 0) { 104 while (pending_requests_.size() > 0) {
101 linked_ptr<GuestViewRequest> pending_request = pending_requests_.front(); 105 linked_ptr<GuestViewRequest> pending_request = pending_requests_.front();
102 pending_requests_.pop_front(); 106 pending_requests_.pop_front();
103 // Call the JavaScript callbacks with no arguments which implies an error. 107 // Call the JavaScript callbacks with no arguments which implies an error.
104 pending_request->ExecuteCallbackIfAvailable(0 /* argc */, nullptr); 108 pending_request->ExecuteCallbackIfAvailable(0 /* argc */, nullptr);
105 } 109 }
106 110
107 delete this; 111 delete this;
108 } 112 }
109 113
114 void GuestViewContainer::RegisterDestructionCallback(
115 v8::Local<v8::Function> callback,
116 v8::Isolate* isolate) {
117 destruction_callback_.Reset(isolate, callback);
118 destruction_isolate_ = isolate;
119 }
120
110 void GuestViewContainer::RenderFrameDestroyed() { 121 void GuestViewContainer::RenderFrameDestroyed() {
111 OnRenderFrameDestroyed(); 122 OnRenderFrameDestroyed();
112 render_frame_ = nullptr; 123 render_frame_ = nullptr;
113 Destroy(true /* embedder_frame_destroyed */); 124 Destroy(true /* embedder_frame_destroyed */);
114 } 125 }
115 126
116 void GuestViewContainer::IssueRequest(linked_ptr<GuestViewRequest> request) { 127 void GuestViewContainer::IssueRequest(linked_ptr<GuestViewRequest> request) {
117 EnqueueRequest(request); 128 EnqueueRequest(request);
118 PerformPendingRequest(); 129 PerformPendingRequest();
119 } 130 }
(...skipping 12 matching lines...) Expand all
132 pending_response_ = pending_request; 143 pending_response_ = pending_request;
133 } 144 }
134 145
135 void GuestViewContainer::HandlePendingResponseCallback( 146 void GuestViewContainer::HandlePendingResponseCallback(
136 const IPC::Message& message) { 147 const IPC::Message& message) {
137 CHECK(pending_response_.get()); 148 CHECK(pending_response_.get());
138 linked_ptr<GuestViewRequest> pending_response(pending_response_.release()); 149 linked_ptr<GuestViewRequest> pending_response(pending_response_.release());
139 pending_response->HandleResponse(message); 150 pending_response->HandleResponse(message);
140 } 151 }
141 152
153 void GuestViewContainer::RunDestructionCallback(bool embedder_frame_destroyed) {
154 // Do not attempt to run |destruction_callback_| if the embedder frame was
155 // destroyed. Trying to invoke callback on RenderFrame destruction results in
156 // assertion failure when calling WebScopedMicrotaskSuppression.
157 if (embedder_frame_destroyed)
158 return;
159
160 // Call the destruction callback, if one is registered.
161 if (!destruction_callback_.IsEmpty()) {
162 v8::HandleScope handle_scope(destruction_isolate_);
163 v8::Local<v8::Function> callback = v8::Local<v8::Function>::New(
164 destruction_isolate_, destruction_callback_);
165 v8::Local<v8::Context> context = callback->CreationContext();
166 if (context.IsEmpty())
167 return;
168
169 v8::Context::Scope context_scope(context);
170 blink::WebScopedMicrotaskSuppression suppression;
171
172 callback->Call(context->Global(), 0 /* argc */, nullptr);
173 }
174 }
175
142 void GuestViewContainer::OnHandleCallback(const IPC::Message& message) { 176 void GuestViewContainer::OnHandleCallback(const IPC::Message& message) {
143 // Handle the callback for the current request with a pending response. 177 // Handle the callback for the current request with a pending response.
144 HandlePendingResponseCallback(message); 178 HandlePendingResponseCallback(message);
145 // Perform the subsequent request if one exists. 179 // Perform the subsequent request if one exists.
146 PerformPendingRequest(); 180 PerformPendingRequest();
147 } 181 }
148 182
149 bool GuestViewContainer::OnMessage(const IPC::Message& message) { 183 bool GuestViewContainer::OnMessage(const IPC::Message& message) {
150 return false; 184 return false;
151 } 185 }
(...skipping 27 matching lines...) Expand all
179 213
180 void GuestViewContainer::DidDestroyElement() { 214 void GuestViewContainer::DidDestroyElement() {
181 Destroy(false); 215 Destroy(false);
182 } 216 }
183 217
184 base::WeakPtr<content::BrowserPluginDelegate> GuestViewContainer::GetWeakPtr() { 218 base::WeakPtr<content::BrowserPluginDelegate> GuestViewContainer::GetWeakPtr() {
185 return weak_ptr_factory_.GetWeakPtr(); 219 return weak_ptr_factory_.GetWeakPtr();
186 } 220 }
187 221
188 } // namespace guest_view 222 } // namespace guest_view
OLDNEW
« no previous file with comments | « components/guest_view/renderer/guest_view_container.h ('k') | components/guest_view/renderer/iframe_guest_view_container.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698