| 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" | |
| 9 #include "base/histogram.h" | 8 #include "base/histogram.h" |
| 10 #include "base/logging.h" | 9 #include "base/logging.h" |
| 11 #include "base/perftimer.h" | 10 #include "base/perftimer.h" |
| 12 #include "base/pickle.h" | 11 #include "base/pickle.h" |
| 13 #include "base/shared_memory.h" | 12 #include "base/shared_memory.h" |
| 14 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 15 #include "chrome/common/child_process_logging.h" | |
| 16 #include "chrome/common/chrome_switches.h" | |
| 17 #include "chrome/common/extensions/extension.h" | 14 #include "chrome/common/extensions/extension.h" |
| 18 #include "chrome/common/extensions/extension_constants.h" | 15 #include "chrome/common/extensions/extension_constants.h" |
| 19 #include "chrome/renderer/extension_groups.h" | 16 #include "chrome/renderer/extension_groups.h" |
| 20 #include "googleurl/src/gurl.h" | 17 #include "googleurl/src/gurl.h" |
| 21 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" | 18 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" |
| 22 | 19 |
| 23 #include "grit/renderer_resources.h" | 20 #include "grit/renderer_resources.h" |
| 24 | 21 |
| 25 using WebKit::WebFrame; | 22 using WebKit::WebFrame; |
| 26 using WebKit::WebString; | 23 using WebKit::WebString; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 } | 104 } |
| 108 for (size_t j = 0; j < script->css_scripts().size(); ++j) { | 105 for (size_t j = 0; j < script->css_scripts().size(); ++j) { |
| 109 const char* body = NULL; | 106 const char* body = NULL; |
| 110 int body_length = 0; | 107 int body_length = 0; |
| 111 CHECK(pickle.ReadData(&iter, &body, &body_length)); | 108 CHECK(pickle.ReadData(&iter, &body, &body_length)); |
| 112 script->css_scripts()[j].set_external_content( | 109 script->css_scripts()[j].set_external_content( |
| 113 base::StringPiece(body, body_length)); | 110 base::StringPiece(body, body_length)); |
| 114 } | 111 } |
| 115 } | 112 } |
| 116 | 113 |
| 117 // Update the crash reporter with all loaded extensions. In single process, | |
| 118 // this has already been done in the browser code. | |
| 119 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess)) { | |
| 120 std::vector<std::string> extension_ids; | |
| 121 for (size_t i = 0; i < num_scripts; ++i) { | |
| 122 DCHECK(!scripts_[i]->extension_id().empty()); | |
| 123 | |
| 124 // We must check this because there can be multiple scripts from a single | |
| 125 // extension. n^2, but meh, it's a small list. | |
| 126 if (std::find(extension_ids.begin(), extension_ids.end(), | |
| 127 scripts_[i]->extension_id()) == extension_ids.end()) { | |
| 128 extension_ids.push_back(scripts_[i]->extension_id()); | |
| 129 } | |
| 130 } | |
| 131 | |
| 132 child_process_logging::SetActiveExtensions(extension_ids); | |
| 133 } | |
| 134 | |
| 135 return true; | 114 return true; |
| 136 } | 115 } |
| 137 | 116 |
| 138 // static | 117 // static |
| 139 void UserScriptSlave::InsertInitExtensionCode( | 118 void UserScriptSlave::InsertInitExtensionCode( |
| 140 std::vector<WebScriptSource>* sources, const std::string& extension_id) { | 119 std::vector<WebScriptSource>* sources, const std::string& extension_id) { |
| 141 DCHECK(sources); | 120 DCHECK(sources); |
| 142 sources->insert(sources->begin(), | 121 sources->insert(sources->begin(), |
| 143 WebScriptSource(WebString::fromUTF8( | 122 WebScriptSource(WebString::fromUTF8( |
| 144 StringPrintf(kInitExtension, extension_id.c_str())))); | 123 StringPrintf(kInitExtension, extension_id.c_str())))); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 if (num_scripts) | 213 if (num_scripts) |
| 235 UMA_HISTOGRAM_TIMES("Extensions.InjectIdle_Time", timer.Elapsed()); | 214 UMA_HISTOGRAM_TIMES("Extensions.InjectIdle_Time", timer.Elapsed()); |
| 236 } else { | 215 } else { |
| 237 NOTREACHED(); | 216 NOTREACHED(); |
| 238 } | 217 } |
| 239 | 218 |
| 240 LOG(INFO) << "Injected " << num_scripts << " scripts and " << num_css << | 219 LOG(INFO) << "Injected " << num_scripts << " scripts and " << num_css << |
| 241 "css files into " << frame->url().spec().data(); | 220 "css files into " << frame->url().spec().data(); |
| 242 return true; | 221 return true; |
| 243 } | 222 } |
| OLD | NEW |