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

Side by Side Diff: extensions/renderer/render_frame_observer_natives.cc

Issue 1642283002: Deal with frame removal by content scripts (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Last nits Created 4 years, 9 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 "extensions/renderer/render_frame_observer_natives.h" 5 #include "extensions/renderer/render_frame_observer_natives.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.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 "extensions/renderer/extension_frame_helper.h" 12 #include "extensions/renderer/extension_frame_helper.h"
13 #include "extensions/renderer/script_context.h" 13 #include "extensions/renderer/script_context.h"
14 14
15 namespace extensions { 15 namespace extensions {
16 16
17 namespace { 17 namespace {
18 18
19 // Deletes itself when done. 19 // Deletes itself when done.
20 class LoadWatcher : public content::RenderFrameObserver { 20 class LoadWatcher : public content::RenderFrameObserver {
21 public: 21 public:
22 LoadWatcher(content::RenderFrame* frame, 22 LoadWatcher(content::RenderFrame* frame,
23 const base::Callback<void(bool)>& callback) 23 const base::Callback<void(bool)>& callback)
24 : content::RenderFrameObserver(frame), callback_(callback) {} 24 : content::RenderFrameObserver(frame), callback_(callback) {}
25 25
26 void DidCreateDocumentElement() override { 26 void DidCreateDocumentElement() override {
27 // The callback must be run as soon as the root element is available. 27 // Defer the callback instead of running it now to avoid re-entrancy caused
28 // Running the callback may trigger DidCreateDocumentElement or 28 // by the JavaScript callback.
29 // DidFailProvisionalLoad, so delete this before running the callback. 29 ExtensionFrameHelper::Get(render_frame())
30 base::Callback<void(bool)> callback = callback_; 30 ->ScheduleAtDocumentStart(base::Bind(callback_, true));
31 delete this; 31 delete this;
32 callback.Run(true);
33 } 32 }
34 33
35 void DidFailProvisionalLoad(const blink::WebURLError& error) override { 34 void DidFailProvisionalLoad(const blink::WebURLError& error) override {
36 // Use PostTask to avoid running user scripts while handling this 35 // Use PostTask to avoid running user scripts while handling this
37 // DidFailProvisionalLoad notification. 36 // DidFailProvisionalLoad notification.
38 base::MessageLoop::current()->PostTask(FROM_HERE, 37 base::MessageLoop::current()->PostTask(FROM_HERE,
39 base::Bind(callback_, false)); 38 base::Bind(callback_, false));
40 delete this; 39 delete this;
41 } 40 }
42 41
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 v8::Global<v8::Function> callback, 98 v8::Global<v8::Function> callback,
100 bool succeeded) { 99 bool succeeded) {
101 v8::Isolate* isolate = context()->isolate(); 100 v8::Isolate* isolate = context()->isolate();
102 v8::HandleScope handle_scope(isolate); 101 v8::HandleScope handle_scope(isolate);
103 v8::Local<v8::Value> args[] = {v8::Boolean::New(isolate, succeeded)}; 102 v8::Local<v8::Value> args[] = {v8::Boolean::New(isolate, succeeded)};
104 context()->CallFunction(v8::Local<v8::Function>::New(isolate, callback), 103 context()->CallFunction(v8::Local<v8::Function>::New(isolate, callback),
105 arraysize(args), args); 104 arraysize(args), args);
106 } 105 }
107 106
108 } // namespace extensions 107 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/renderer/extension_frame_helper.cc ('k') | extensions/renderer/script_injection_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698