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

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

Issue 404613006: Declarative content scripts: Renderer-side: per-extension shared memory regions (lazily loaded) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixes for last round of comments Created 6 years, 4 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
« no previous file with comments | « extensions/renderer/user_script_set.h ('k') | extensions/renderer/user_script_set_manager.h » ('j') | 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/user_script_set.h" 5 #include "extensions/renderer/user_script_set.h"
6 6
7 #include "content/public/common/url_constants.h" 7 #include "content/public/common/url_constants.h"
8 #include "content/public/renderer/render_thread.h" 8 #include "content/public/renderer/render_thread.h"
9 #include "extensions/common/extension.h" 9 #include "extensions/common/extension.h"
10 #include "extensions/common/extension_messages.h" 10 #include "extensions/common/extension_messages.h"
(...skipping 18 matching lines...) Expand all
29 data_source_url.spec()); 29 data_source_url.spec());
30 } 30 }
31 31
32 return data_source_url; 32 return data_source_url;
33 } 33 }
34 34
35 } // namespace 35 } // namespace
36 36
37 UserScriptSet::UserScriptSet(const ExtensionSet* extensions) 37 UserScriptSet::UserScriptSet(const ExtensionSet* extensions)
38 : extensions_(extensions) { 38 : extensions_(extensions) {
39 content::RenderThread::Get()->AddObserver(this);
40 } 39 }
41 40
42 UserScriptSet::~UserScriptSet() { 41 UserScriptSet::~UserScriptSet() {
43 } 42 }
44 43
45 void UserScriptSet::AddObserver(Observer* observer) { 44 void UserScriptSet::AddObserver(Observer* observer) {
46 observers_.AddObserver(observer); 45 observers_.AddObserver(observer);
47 } 46 }
48 47
49 void UserScriptSet::RemoveObserver(Observer* observer) { 48 void UserScriptSet::RemoveObserver(Observer* observer) {
(...skipping 22 matching lines...) Expand all
72 const Extension* extension = extensions_->GetByID((*iter)->extension_id()); 71 const Extension* extension = extensions_->GetByID((*iter)->extension_id());
73 if (!extension) 72 if (!extension)
74 continue; 73 continue;
75 scoped_ptr<ScriptInjection> injection = GetInjectionForScript( 74 scoped_ptr<ScriptInjection> injection = GetInjectionForScript(
76 *iter, web_frame, tab_id, run_location, document_url, extension); 75 *iter, web_frame, tab_id, run_location, document_url, extension);
77 if (injection.get()) 76 if (injection.get())
78 injections->push_back(injection.release()); 77 injections->push_back(injection.release());
79 } 78 }
80 } 79 }
81 80
82 bool UserScriptSet::OnControlMessageReceived( 81 bool UserScriptSet::UpdateUserScripts(
83 const IPC::Message& message) {
84 bool handled = true;
85 IPC_BEGIN_MESSAGE_MAP(UserScriptSet, message)
86 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdateUserScripts, OnUpdateUserScripts)
87 IPC_MESSAGE_UNHANDLED(handled = false)
88 IPC_END_MESSAGE_MAP()
89 return handled;
90 }
91
92 void UserScriptSet::OnUpdateUserScripts(
93 base::SharedMemoryHandle shared_memory, 82 base::SharedMemoryHandle shared_memory,
94 const std::set<std::string>& changed_extensions) { 83 const std::set<std::string>& changed_extensions) {
95 if (!base::SharedMemory::IsHandleValid(shared_memory)) {
96 NOTREACHED() << "Bad scripts handle";
97 return;
98 }
99
100 for (std::set<std::string>::const_iterator iter = changed_extensions.begin();
101 iter != changed_extensions.end();
102 ++iter) {
103 if (!Extension::IdIsValid(*iter)) {
104 NOTREACHED() << "Invalid extension id: " << *iter;
105 return;
106 }
107 }
108
109 if (UpdateScripts(shared_memory)) {
110 FOR_EACH_OBSERVER(Observer,
111 observers_,
112 OnUserScriptsUpdated(changed_extensions, scripts_.get()));
113 }
114 }
115
116 bool UserScriptSet::UpdateScripts(
117 base::SharedMemoryHandle shared_memory) {
118 bool only_inject_incognito = 84 bool only_inject_incognito =
119 ExtensionsRendererClient::Get()->IsIncognitoProcess(); 85 ExtensionsRendererClient::Get()->IsIncognitoProcess();
120 86
121 // Create the shared memory object (read only). 87 // Create the shared memory object (read only).
122 shared_memory_.reset(new base::SharedMemory(shared_memory, true)); 88 shared_memory_.reset(new base::SharedMemory(shared_memory, true));
123 if (!shared_memory_.get()) 89 if (!shared_memory_.get())
124 return false; 90 return false;
125 91
126 // First get the size of the memory block. 92 // First get the size of the memory block.
127 if (!shared_memory_->Map(sizeof(Pickle::Header))) 93 if (!shared_memory_->Map(sizeof(Pickle::Header)))
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 script->css_scripts()[j].set_external_content( 130 script->css_scripts()[j].set_external_content(
165 base::StringPiece(body, body_length)); 131 base::StringPiece(body, body_length));
166 } 132 }
167 133
168 if (only_inject_incognito && !script->is_incognito_enabled()) 134 if (only_inject_incognito && !script->is_incognito_enabled())
169 continue; // This script shouldn't run in an incognito tab. 135 continue; // This script shouldn't run in an incognito tab.
170 136
171 scripts_.push_back(script.release()); 137 scripts_.push_back(script.release());
172 } 138 }
173 139
140 FOR_EACH_OBSERVER(Observer,
141 observers_,
142 OnUserScriptsUpdated(changed_extensions, scripts_.get()));
174 return true; 143 return true;
175 } 144 }
176 145
177 scoped_ptr<ScriptInjection> UserScriptSet::GetInjectionForScript( 146 scoped_ptr<ScriptInjection> UserScriptSet::GetInjectionForScript(
178 UserScript* script, 147 UserScript* script,
179 blink::WebFrame* web_frame, 148 blink::WebFrame* web_frame,
180 int tab_id, 149 int tab_id,
181 UserScript::RunLocation run_location, 150 UserScript::RunLocation run_location,
182 const GURL& document_url, 151 const GURL& document_url,
183 const Extension* extension) { 152 const Extension* extension) {
(...skipping 26 matching lines...) Expand all
210 scoped_ptr<ScriptInjector>(new UserScriptInjector(script, this)), 179 scoped_ptr<ScriptInjector>(new UserScriptInjector(script, this)),
211 web_frame, 180 web_frame,
212 extension->id(), 181 extension->id(),
213 run_location, 182 run_location,
214 tab_id)); 183 tab_id));
215 } 184 }
216 return injection.Pass(); 185 return injection.Pass();
217 } 186 }
218 187
219 } // namespace extensions 188 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/renderer/user_script_set.h ('k') | extensions/renderer/user_script_set_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698