| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/user_script_slave.h" | 5 #include "chrome/renderer/user_script_slave.h" |
| 6 | 6 |
| 7 #include "app/resource_bundle.h" | 7 #include "app/resource_bundle.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/histogram.h" | 9 #include "base/histogram.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 void UserScriptSlave::GetActiveExtensions(std::set<std::string>* extension_ids)
{ | 69 void UserScriptSlave::GetActiveExtensions(std::set<std::string>* extension_ids)
{ |
| 70 for (size_t i = 0; i < scripts_.size(); ++i) { | 70 for (size_t i = 0; i < scripts_.size(); ++i) { |
| 71 DCHECK(!scripts_[i]->extension_id().empty()); | 71 DCHECK(!scripts_[i]->extension_id().empty()); |
| 72 extension_ids->insert(scripts_[i]->extension_id()); | 72 extension_ids->insert(scripts_[i]->extension_id()); |
| 73 } | 73 } |
| 74 } | 74 } |
| 75 | 75 |
| 76 bool UserScriptSlave::UpdateScripts(base::SharedMemoryHandle shared_memory) { | 76 bool UserScriptSlave::UpdateScripts(base::SharedMemoryHandle shared_memory) { |
| 77 scripts_.clear(); | 77 scripts_.clear(); |
| 78 | 78 |
| 79 bool only_inject_incognito = RenderThread::current()->is_incognito_process(); | 79 bool only_inject_incognito = RenderThread::current()->IsIncognitoProcess(); |
| 80 | 80 |
| 81 // Create the shared memory object (read only). | 81 // Create the shared memory object (read only). |
| 82 shared_memory_.reset(new base::SharedMemory(shared_memory, true)); | 82 shared_memory_.reset(new base::SharedMemory(shared_memory, true)); |
| 83 if (!shared_memory_.get()) | 83 if (!shared_memory_.get()) |
| 84 return false; | 84 return false; |
| 85 | 85 |
| 86 // First get the size of the memory block. | 86 // First get the size of the memory block. |
| 87 if (!shared_memory_->Map(sizeof(Pickle::Header))) | 87 if (!shared_memory_->Map(sizeof(Pickle::Header))) |
| 88 return false; | 88 return false; |
| 89 Pickle::Header* pickle_header = | 89 Pickle::Header* pickle_header = |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 } | 169 } |
| 170 } | 170 } |
| 171 | 171 |
| 172 return true; | 172 return true; |
| 173 } | 173 } |
| 174 | 174 |
| 175 // static | 175 // static |
| 176 void UserScriptSlave::InsertInitExtensionCode( | 176 void UserScriptSlave::InsertInitExtensionCode( |
| 177 std::vector<WebScriptSource>* sources, const std::string& extension_id) { | 177 std::vector<WebScriptSource>* sources, const std::string& extension_id) { |
| 178 DCHECK(sources); | 178 DCHECK(sources); |
| 179 bool incognito = RenderThread::current()->is_incognito_process(); | 179 bool incognito = RenderThread::current()->IsIncognitoProcess(); |
| 180 sources->insert(sources->begin(), WebScriptSource(WebString::fromUTF8( | 180 sources->insert(sources->begin(), WebScriptSource(WebString::fromUTF8( |
| 181 StringPrintf(kInitExtension, extension_id.c_str(), | 181 StringPrintf(kInitExtension, extension_id.c_str(), |
| 182 incognito ? "true" : "false")))); | 182 incognito ? "true" : "false")))); |
| 183 } | 183 } |
| 184 | 184 |
| 185 void UserScriptSlave::InjectScripts(WebFrame* frame, | 185 void UserScriptSlave::InjectScripts(WebFrame* frame, |
| 186 UserScript::RunLocation location) { | 186 UserScript::RunLocation location) { |
| 187 GURL frame_url = GURL(frame->url()); | 187 GURL frame_url = GURL(frame->url()); |
| 188 // Don't bother if this is not a URL we inject script into. | 188 // Don't bother if this is not a URL we inject script into. |
| 189 if (!URLPattern(UserScript::kValidUserScriptSchemes).IsValidScheme( | 189 if (!URLPattern(UserScript::kValidUserScriptSchemes).IsValidScheme( |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 if (num_scripts) | 277 if (num_scripts) |
| 278 UMA_HISTOGRAM_TIMES("Extensions.InjectIdle_Time", timer.Elapsed()); | 278 UMA_HISTOGRAM_TIMES("Extensions.InjectIdle_Time", timer.Elapsed()); |
| 279 } else { | 279 } else { |
| 280 NOTREACHED(); | 280 NOTREACHED(); |
| 281 } | 281 } |
| 282 | 282 |
| 283 LOG(INFO) << "Injected " << num_scripts << " scripts and " << num_css << | 283 LOG(INFO) << "Injected " << num_scripts << " scripts and " << num_css << |
| 284 " css files into " << frame->url().spec().data(); | 284 " css files into " << frame->url().spec().data(); |
| 285 return; | 285 return; |
| 286 } | 286 } |
| OLD | NEW |