OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/renderer/extensions/user_script_slave.h" | 5 #include "chrome/renderer/extensions/user_script_slave.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/perftimer.h" | 11 #include "base/perftimer.h" |
12 #include "base/pickle.h" | 12 #include "base/pickle.h" |
13 #include "base/shared_memory.h" | 13 #include "base/shared_memory.h" |
14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
15 #include "base/string_util.h" | 15 #include "base/string_util.h" |
16 #include "chrome/common/extensions/extension.h" | 16 #include "chrome/common/extensions/extension.h" |
17 #include "chrome/common/extensions/extension_set.h" | 17 #include "chrome/common/extensions/extension_set.h" |
18 #include "chrome/common/url_constants.h" | 18 #include "chrome/common/url_constants.h" |
| 19 #include "chrome/renderer/chrome_render_process_observer.h" |
19 #include "chrome/renderer/extension_groups.h" | 20 #include "chrome/renderer/extension_groups.h" |
20 #include "content/renderer/render_thread.h" | |
21 #include "googleurl/src/gurl.h" | 21 #include "googleurl/src/gurl.h" |
22 #include "grit/renderer_resources.h" | 22 #include "grit/renderer_resources.h" |
23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebVector.h" | 24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebVector.h" |
25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
26 #include "ui/base/resource/resource_bundle.h" | 26 #include "ui/base/resource/resource_bundle.h" |
27 | 27 |
28 using WebKit::WebFrame; | 28 using WebKit::WebFrame; |
29 using WebKit::WebString; | 29 using WebKit::WebString; |
30 using WebKit::WebVector; | 30 using WebKit::WebVector; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 std::set<std::string>* extension_ids) { | 74 std::set<std::string>* extension_ids) { |
75 for (size_t i = 0; i < scripts_.size(); ++i) { | 75 for (size_t i = 0; i < scripts_.size(); ++i) { |
76 DCHECK(!scripts_[i]->extension_id().empty()); | 76 DCHECK(!scripts_[i]->extension_id().empty()); |
77 extension_ids->insert(scripts_[i]->extension_id()); | 77 extension_ids->insert(scripts_[i]->extension_id()); |
78 } | 78 } |
79 } | 79 } |
80 | 80 |
81 bool UserScriptSlave::UpdateScripts(base::SharedMemoryHandle shared_memory) { | 81 bool UserScriptSlave::UpdateScripts(base::SharedMemoryHandle shared_memory) { |
82 scripts_.clear(); | 82 scripts_.clear(); |
83 | 83 |
84 bool only_inject_incognito = RenderThread::current()->IsIncognitoProcess(); | 84 bool only_inject_incognito = |
| 85 ChromeRenderProcessObserver::is_incognito_process(); |
85 | 86 |
86 // Create the shared memory object (read only). | 87 // Create the shared memory object (read only). |
87 shared_memory_.reset(new base::SharedMemory(shared_memory, true)); | 88 shared_memory_.reset(new base::SharedMemory(shared_memory, true)); |
88 if (!shared_memory_.get()) | 89 if (!shared_memory_.get()) |
89 return false; | 90 return false; |
90 | 91 |
91 // First get the size of the memory block. | 92 // First get the size of the memory block. |
92 if (!shared_memory_->Map(sizeof(Pickle::Header))) | 93 if (!shared_memory_->Map(sizeof(Pickle::Header))) |
93 return false; | 94 return false; |
94 Pickle::Header* pickle_header = | 95 Pickle::Header* pickle_header = |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 } | 171 } |
171 } | 172 } |
172 | 173 |
173 return true; | 174 return true; |
174 } | 175 } |
175 | 176 |
176 // static | 177 // static |
177 void UserScriptSlave::InsertInitExtensionCode( | 178 void UserScriptSlave::InsertInitExtensionCode( |
178 std::vector<WebScriptSource>* sources, const std::string& extension_id) { | 179 std::vector<WebScriptSource>* sources, const std::string& extension_id) { |
179 DCHECK(sources); | 180 DCHECK(sources); |
180 bool incognito = RenderThread::current()->IsIncognitoProcess(); | 181 bool incognito = ChromeRenderProcessObserver::is_incognito_process(); |
181 sources->insert(sources->begin(), WebScriptSource(WebString::fromUTF8( | 182 sources->insert(sources->begin(), WebScriptSource(WebString::fromUTF8( |
182 StringPrintf(kInitExtension, extension_id.c_str(), | 183 StringPrintf(kInitExtension, extension_id.c_str(), |
183 incognito ? "true" : "false")))); | 184 incognito ? "true" : "false")))); |
184 } | 185 } |
185 | 186 |
186 void UserScriptSlave::InjectScripts(WebFrame* frame, | 187 void UserScriptSlave::InjectScripts(WebFrame* frame, |
187 UserScript::RunLocation location) { | 188 UserScript::RunLocation location) { |
188 GURL frame_url = GURL(frame->url()); | 189 GURL frame_url = GURL(frame->url()); |
189 if (frame_url.is_empty()) | 190 if (frame_url.is_empty()) |
190 return; | 191 return; |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 if (num_scripts) | 269 if (num_scripts) |
269 UMA_HISTOGRAM_TIMES("Extensions.InjectEnd_Time", timer.Elapsed()); | 270 UMA_HISTOGRAM_TIMES("Extensions.InjectEnd_Time", timer.Elapsed()); |
270 } else if (location == UserScript::DOCUMENT_IDLE) { | 271 } else if (location == UserScript::DOCUMENT_IDLE) { |
271 UMA_HISTOGRAM_COUNTS_100("Extensions.InjectIdle_ScriptCount", num_scripts); | 272 UMA_HISTOGRAM_COUNTS_100("Extensions.InjectIdle_ScriptCount", num_scripts); |
272 if (num_scripts) | 273 if (num_scripts) |
273 UMA_HISTOGRAM_TIMES("Extensions.InjectIdle_Time", timer.Elapsed()); | 274 UMA_HISTOGRAM_TIMES("Extensions.InjectIdle_Time", timer.Elapsed()); |
274 } else { | 275 } else { |
275 NOTREACHED(); | 276 NOTREACHED(); |
276 } | 277 } |
277 } | 278 } |
OLD | NEW |