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

Unified Diff: extensions/renderer/extension_frame_helper.h

Issue 1642283002: Deal with frame removal by content scripts (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Push down WeakPtr Created 4 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: extensions/renderer/extension_frame_helper.h
diff --git a/extensions/renderer/extension_frame_helper.h b/extensions/renderer/extension_frame_helper.h
index a710d4f970517610fe40be239176e685b9cf89ab..147401e850b483233a6b9651f085f82427032eda 100644
--- a/extensions/renderer/extension_frame_helper.h
+++ b/extensions/renderer/extension_frame_helper.h
@@ -8,6 +8,7 @@
#include <vector>
#include "base/macros.h"
+#include "base/memory/weak_ptr.h"
#include "content/public/common/console_message_level.h"
#include "content/public/renderer/render_frame_observer.h"
#include "content/public/renderer/render_frame_observer_tracker.h"
@@ -29,7 +30,8 @@ class ScriptContext;
// RenderFrame-level plumbing for extension features.
class ExtensionFrameHelper
: public content::RenderFrameObserver,
- public content::RenderFrameObserverTracker<ExtensionFrameHelper> {
+ public content::RenderFrameObserverTracker<ExtensionFrameHelper>,
+ public base::SupportsWeakPtr<ExtensionFrameHelper> {
public:
ExtensionFrameHelper(content::RenderFrame* render_frame,
Dispatcher* extension_dispatcher);
@@ -61,6 +63,18 @@ class ExtensionFrameHelper
return did_create_current_document_element_;
}
+ // Called when the document element has been inserted in this frame. This
+ // method may invoke untrusted JavaScript code that invalidate the frame and
+ // this ExtensionFrameHelper.
+ void AfterDidCreateDocumentElement();
+
+ // Schedule a callback, to be run at the next AfterDidCreateDocumentElement
+ // notification. Only call this when you are certain that there will be such a
+ // notification, e.g. from RenderFrameObserver::DidCreateDocumentElement.
+ // Otherwise the callback is never invoked, or invoked for a document that you
+ // were not expecting.
+ void ScheduleAfterDidCreateDocumentElement(const base::Closure& callback);
+
private:
// RenderFrameObserver implementation.
void DidCreateDocumentElement() override;
@@ -113,6 +127,9 @@ class ExtensionFrameHelper
// Whether or not the current document element has been created.
bool did_create_current_document_element_;
+ // Callbacks to be run at the next AfterDidCreateDocumentElement notification.
+ std::vector<base::Closure> document_element_created_callbacks_;
+
DISALLOW_COPY_AND_ASSIGN(ExtensionFrameHelper);
};

Powered by Google App Engine
This is Rietveld 408576698