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/histogram.h" | 9 #include "base/histogram.h" |
9 #include "base/logging.h" | 10 #include "base/logging.h" |
10 #include "base/perftimer.h" | 11 #include "base/perftimer.h" |
11 #include "base/pickle.h" | 12 #include "base/pickle.h" |
12 #include "base/shared_memory.h" | 13 #include "base/shared_memory.h" |
13 #include "base/string_util.h" | 14 #include "base/string_util.h" |
| 15 #include "chrome/common/child_process_logging.h" |
| 16 #include "chrome/common/chrome_switches.h" |
14 #include "chrome/common/extensions/extension.h" | 17 #include "chrome/common/extensions/extension.h" |
15 #include "chrome/common/extensions/extension_constants.h" | 18 #include "chrome/common/extensions/extension_constants.h" |
16 #include "chrome/renderer/extension_groups.h" | 19 #include "chrome/renderer/extension_groups.h" |
17 #include "googleurl/src/gurl.h" | 20 #include "googleurl/src/gurl.h" |
18 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" | 21 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" |
19 | 22 |
20 #include "grit/renderer_resources.h" | 23 #include "grit/renderer_resources.h" |
21 | 24 |
22 using WebKit::WebFrame; | 25 using WebKit::WebFrame; |
23 using WebKit::WebString; | 26 using WebKit::WebString; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 } | 107 } |
105 for (size_t j = 0; j < script->css_scripts().size(); ++j) { | 108 for (size_t j = 0; j < script->css_scripts().size(); ++j) { |
106 const char* body = NULL; | 109 const char* body = NULL; |
107 int body_length = 0; | 110 int body_length = 0; |
108 CHECK(pickle.ReadData(&iter, &body, &body_length)); | 111 CHECK(pickle.ReadData(&iter, &body, &body_length)); |
109 script->css_scripts()[j].set_external_content( | 112 script->css_scripts()[j].set_external_content( |
110 base::StringPiece(body, body_length)); | 113 base::StringPiece(body, body_length)); |
111 } | 114 } |
112 } | 115 } |
113 | 116 |
| 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 |
114 return true; | 135 return true; |
115 } | 136 } |
116 | 137 |
117 // static | 138 // static |
118 void UserScriptSlave::InsertInitExtensionCode( | 139 void UserScriptSlave::InsertInitExtensionCode( |
119 std::vector<WebScriptSource>* sources, const std::string& extension_id) { | 140 std::vector<WebScriptSource>* sources, const std::string& extension_id) { |
120 DCHECK(sources); | 141 DCHECK(sources); |
121 sources->insert(sources->begin(), | 142 sources->insert(sources->begin(), |
122 WebScriptSource(WebString::fromUTF8( | 143 WebScriptSource(WebString::fromUTF8( |
123 StringPrintf(kInitExtension, extension_id.c_str())))); | 144 StringPrintf(kInitExtension, extension_id.c_str())))); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 if (num_scripts) | 238 if (num_scripts) |
218 UMA_HISTOGRAM_TIMES("Extensions.InjectIdle_Time", timer.Elapsed()); | 239 UMA_HISTOGRAM_TIMES("Extensions.InjectIdle_Time", timer.Elapsed()); |
219 } else { | 240 } else { |
220 NOTREACHED(); | 241 NOTREACHED(); |
221 } | 242 } |
222 | 243 |
223 LOG(INFO) << "Injected " << num_scripts << " scripts and " << num_css << | 244 LOG(INFO) << "Injected " << num_scripts << " scripts and " << num_css << |
224 "css files into " << frame->url().spec().data(); | 245 "css files into " << frame->url().spec().data(); |
225 return true; | 246 return true; |
226 } | 247 } |
OLD | NEW |