| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 IDR_GREASEMONKEY_API_JS); | 61 IDR_GREASEMONKEY_API_JS); |
| 62 } | 62 } |
| 63 | 63 |
| 64 void UserScriptSlave::GetActiveExtensions(std::set<std::string>* extension_ids)
{ | 64 void UserScriptSlave::GetActiveExtensions(std::set<std::string>* extension_ids)
{ |
| 65 for (size_t i = 0; i < scripts_.size(); ++i) { | 65 for (size_t i = 0; i < scripts_.size(); ++i) { |
| 66 DCHECK(!scripts_[i]->extension_id().empty()); | 66 DCHECK(!scripts_[i]->extension_id().empty()); |
| 67 extension_ids->insert(scripts_[i]->extension_id()); | 67 extension_ids->insert(scripts_[i]->extension_id()); |
| 68 } | 68 } |
| 69 } | 69 } |
| 70 | 70 |
| 71 bool UserScriptSlave::UpdateScripts(base::SharedMemoryHandle shared_memory) { | 71 bool UserScriptSlave::UpdateScripts(base::SharedMemoryHandle shared_memory, |
| 72 bool only_inject_incognito) { |
| 72 scripts_.clear(); | 73 scripts_.clear(); |
| 73 | 74 |
| 74 // Create the shared memory object (read only). | 75 // Create the shared memory object (read only). |
| 75 shared_memory_.reset(new base::SharedMemory(shared_memory, true)); | 76 shared_memory_.reset(new base::SharedMemory(shared_memory, true)); |
| 76 if (!shared_memory_.get()) | 77 if (!shared_memory_.get()) |
| 77 return false; | 78 return false; |
| 78 | 79 |
| 79 // First get the size of the memory block. | 80 // First get the size of the memory block. |
| 80 if (!shared_memory_->Map(sizeof(Pickle::Header))) | 81 if (!shared_memory_->Map(sizeof(Pickle::Header))) |
| 81 return false; | 82 return false; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 94 Pickle pickle(reinterpret_cast<char*>(shared_memory_->memory()), | 95 Pickle pickle(reinterpret_cast<char*>(shared_memory_->memory()), |
| 95 pickle_size); | 96 pickle_size); |
| 96 pickle.ReadSize(&iter, &num_scripts); | 97 pickle.ReadSize(&iter, &num_scripts); |
| 97 | 98 |
| 98 scripts_.reserve(num_scripts); | 99 scripts_.reserve(num_scripts); |
| 99 for (size_t i = 0; i < num_scripts; ++i) { | 100 for (size_t i = 0; i < num_scripts; ++i) { |
| 100 scripts_.push_back(new UserScript()); | 101 scripts_.push_back(new UserScript()); |
| 101 UserScript* script = scripts_.back(); | 102 UserScript* script = scripts_.back(); |
| 102 script->Unpickle(pickle, &iter); | 103 script->Unpickle(pickle, &iter); |
| 103 | 104 |
| 105 if (only_inject_incognito && !script->is_incognito_enabled()) { |
| 106 // This script shouldn't run in an incognito tab. |
| 107 delete script; |
| 108 scripts_.pop_back(); |
| 109 continue; |
| 110 } |
| 111 |
| 104 // Note that this is a pointer into shared memory. We don't own it. It gets | 112 // Note that this is a pointer into shared memory. We don't own it. It gets |
| 105 // cleared up when the last renderer or browser process drops their | 113 // cleared up when the last renderer or browser process drops their |
| 106 // reference to the shared memory. | 114 // reference to the shared memory. |
| 107 for (size_t j = 0; j < script->js_scripts().size(); ++j) { | 115 for (size_t j = 0; j < script->js_scripts().size(); ++j) { |
| 108 const char* body = NULL; | 116 const char* body = NULL; |
| 109 int body_length = 0; | 117 int body_length = 0; |
| 110 CHECK(pickle.ReadData(&iter, &body, &body_length)); | 118 CHECK(pickle.ReadData(&iter, &body, &body_length)); |
| 111 script->js_scripts()[j].set_external_content( | 119 script->js_scripts()[j].set_external_content( |
| 112 base::StringPiece(body, body_length)); | 120 base::StringPiece(body, body_length)); |
| 113 } | 121 } |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 if (num_scripts) | 234 if (num_scripts) |
| 227 UMA_HISTOGRAM_TIMES("Extensions.InjectIdle_Time", timer.Elapsed()); | 235 UMA_HISTOGRAM_TIMES("Extensions.InjectIdle_Time", timer.Elapsed()); |
| 228 } else { | 236 } else { |
| 229 NOTREACHED(); | 237 NOTREACHED(); |
| 230 } | 238 } |
| 231 | 239 |
| 232 LOG(INFO) << "Injected " << num_scripts << " scripts and " << num_css << | 240 LOG(INFO) << "Injected " << num_scripts << " scripts and " << num_css << |
| 233 "css files into " << frame->url().spec().data(); | 241 "css files into " << frame->url().spec().data(); |
| 234 return true; | 242 return true; |
| 235 } | 243 } |
| OLD | NEW |