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

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

Issue 684143002: Invalidate the previous frame when the window object is cleared. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use RenderViewObserver::WillReleaseScriptContext Created 6 years, 1 month 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
« no previous file with comments | « content/renderer/render_frame_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/script_injection_manager.h" 5 #include "extensions/renderer/script_injection_manager.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/weak_ptr.h" 8 #include "base/memory/weak_ptr.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "content/public/renderer/render_view.h" 10 #include "content/public/renderer/render_view.h"
(...skipping 23 matching lines...) Expand all
34 } // namespace 34 } // namespace
35 35
36 class ScriptInjectionManager::RVOHelper : public content::RenderViewObserver { 36 class ScriptInjectionManager::RVOHelper : public content::RenderViewObserver {
37 public: 37 public:
38 RVOHelper(content::RenderView* render_view, ScriptInjectionManager* manager); 38 RVOHelper(content::RenderView* render_view, ScriptInjectionManager* manager);
39 ~RVOHelper() override; 39 ~RVOHelper() override;
40 40
41 private: 41 private:
42 // RenderViewObserver implementation. 42 // RenderViewObserver implementation.
43 bool OnMessageReceived(const IPC::Message& message) override; 43 bool OnMessageReceived(const IPC::Message& message) override;
44 void WillReleaseScriptContext(blink::WebLocalFrame* frame,
45 v8::Handle<v8::Context> context,
46 int world_id) override;
44 void DidCreateDocumentElement(blink::WebLocalFrame* frame) override; 47 void DidCreateDocumentElement(blink::WebLocalFrame* frame) override;
45 void DidFinishDocumentLoad(blink::WebLocalFrame* frame) override; 48 void DidFinishDocumentLoad(blink::WebLocalFrame* frame) override;
46 void DidFinishLoad(blink::WebLocalFrame* frame) override; 49 void DidFinishLoad(blink::WebLocalFrame* frame) override;
47 void DidStartProvisionalLoad(blink::WebLocalFrame* frame) override; 50 void DidStartProvisionalLoad(blink::WebLocalFrame* frame) override;
48 void FrameDetached(blink::WebFrame* frame) override; 51 void FrameDetached(blink::WebFrame* frame) override;
49 void OnDestruct() override; 52 void OnDestruct() override;
50 53
51 virtual void OnExecuteCode(const ExtensionMsg_ExecuteCode_Params& params); 54 virtual void OnExecuteCode(const ExtensionMsg_ExecuteCode_Params& params);
52 virtual void OnExecuteDeclarativeScript(int tab_id, 55 virtual void OnExecuteDeclarativeScript(int tab_id,
53 const ExtensionId& extension_id, 56 const ExtensionId& extension_id,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 IPC_MESSAGE_HANDLER(ExtensionMsg_ExecuteCode, OnExecuteCode) 95 IPC_MESSAGE_HANDLER(ExtensionMsg_ExecuteCode, OnExecuteCode)
93 IPC_MESSAGE_HANDLER(ExtensionMsg_PermitScriptInjection, 96 IPC_MESSAGE_HANDLER(ExtensionMsg_PermitScriptInjection,
94 OnPermitScriptInjection) 97 OnPermitScriptInjection)
95 IPC_MESSAGE_HANDLER(ExtensionMsg_ExecuteDeclarativeScript, 98 IPC_MESSAGE_HANDLER(ExtensionMsg_ExecuteDeclarativeScript,
96 OnExecuteDeclarativeScript) 99 OnExecuteDeclarativeScript)
97 IPC_MESSAGE_UNHANDLED(handled = false) 100 IPC_MESSAGE_UNHANDLED(handled = false)
98 IPC_END_MESSAGE_MAP() 101 IPC_END_MESSAGE_MAP()
99 return handled; 102 return handled;
100 } 103 }
101 104
105 void ScriptInjectionManager::RVOHelper::WillReleaseScriptContext(
106 blink::WebLocalFrame* frame,
107 v8::Handle<v8::Context> context,
108 int world_id) {
109 // javascript:'...' frames are loaded in two steps:
110 // 1. Load an empty document and execute the JavaScript code.
111 // 2. If the JavaScript code returns a non-void value, replace the current
112 // document with the return value.
113 // The second step is not implemented as a usual navigation, so we cannot use
114 // the DidStartProvisionalLoad or FrameDetached notifications to detect them.
115 // When a page unloads, the main world's script context is released. The main
116 // world for a blank document with a javascript:-URL always exists, because
117 // the javascript:-URL is evaluated in the main world.
118 if (world_id == 0) {
dcheng 2014/11/04 22:40:45 0 should be a named constant somewhere. It's not c
119 InvalidateFrame(frame);
120 }
121 }
122
102 void ScriptInjectionManager::RVOHelper::DidCreateDocumentElement( 123 void ScriptInjectionManager::RVOHelper::DidCreateDocumentElement(
103 blink::WebLocalFrame* frame) { 124 blink::WebLocalFrame* frame) {
104 manager_->InjectScripts(frame, UserScript::DOCUMENT_START); 125 manager_->InjectScripts(frame, UserScript::DOCUMENT_START);
105 } 126 }
106 127
107 void ScriptInjectionManager::RVOHelper::DidFinishDocumentLoad( 128 void ScriptInjectionManager::RVOHelper::DidFinishDocumentLoad(
108 blink::WebLocalFrame* frame) { 129 blink::WebLocalFrame* frame) {
109 manager_->InjectScripts(frame, UserScript::DOCUMENT_END); 130 manager_->InjectScripts(frame, UserScript::DOCUMENT_END);
110 pending_idle_frames_.insert(frame); 131 pending_idle_frames_.insert(frame);
111 // We try to run idle in two places: here and DidFinishLoad. 132 // We try to run idle in two places: here and DidFinishLoad.
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 421
401 ScriptsRunInfo scripts_run_info; 422 ScriptsRunInfo scripts_run_info;
402 if (injection->OnPermissionGranted(extensions_->GetByID( 423 if (injection->OnPermissionGranted(extensions_->GetByID(
403 injection->extension_id()), 424 injection->extension_id()),
404 &scripts_run_info)) { 425 &scripts_run_info)) {
405 scripts_run_info.LogRun(injection->web_frame(), UserScript::RUN_DEFERRED); 426 scripts_run_info.LogRun(injection->web_frame(), UserScript::RUN_DEFERRED);
406 } 427 }
407 } 428 }
408 429
409 } // namespace extensions 430 } // namespace extensions
OLDNEW
« no previous file with comments | « content/renderer/render_frame_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698