| 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/histogram.h" | 8 #include "base/histogram.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/perftimer.h" | 10 #include "base/perftimer.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 using WebKit::WebString; | 21 using WebKit::WebString; |
| 22 | 22 |
| 23 // These two strings are injected before and after the Greasemonkey API and | 23 // These two strings are injected before and after the Greasemonkey API and |
| 24 // user script to wrap it in an anonymous scope. | 24 // user script to wrap it in an anonymous scope. |
| 25 static const char kUserScriptHead[] = "(function (unsafeWindow) {\n"; | 25 static const char kUserScriptHead[] = "(function (unsafeWindow) {\n"; |
| 26 static const char kUserScriptTail[] = "\n})(window);"; | 26 static const char kUserScriptTail[] = "\n})(window);"; |
| 27 | 27 |
| 28 // Sets up the chrome.extension module. This may be run multiple times per | 28 // Sets up the chrome.extension module. This may be run multiple times per |
| 29 // context, but the init method deletes itself after the first time. | 29 // context, but the init method deletes itself after the first time. |
| 30 static const char kInitExtension[] = | 30 static const char kInitExtension[] = |
| 31 "if (chrome.initExtension) chrome.initExtension('%s');"; | 31 "if (chrome.initExtension) chrome.initExtension('%s', true);"; |
| 32 |
| 32 | 33 |
| 33 int UserScriptSlave::GetIsolatedWorldId(const std::string& extension_id) { | 34 int UserScriptSlave::GetIsolatedWorldId(const std::string& extension_id) { |
| 34 typedef std::map<std::string, int> IsolatedWorldMap; | 35 typedef std::map<std::string, int> IsolatedWorldMap; |
| 35 | 36 |
| 36 static IsolatedWorldMap g_isolated_world_ids; | 37 static IsolatedWorldMap g_isolated_world_ids; |
| 37 static int g_next_isolated_world_id = 1; | 38 static int g_next_isolated_world_id = 1; |
| 38 | 39 |
| 39 IsolatedWorldMap::iterator iter = g_isolated_world_ids.find(extension_id); | 40 IsolatedWorldMap::iterator iter = g_isolated_world_ids.find(extension_id); |
| 40 if (iter != g_isolated_world_ids.end()) | 41 if (iter != g_isolated_world_ids.end()) |
| 41 return iter->second; | 42 return iter->second; |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 if (num_scripts) | 205 if (num_scripts) |
| 205 UMA_HISTOGRAM_TIMES("Extensions.InjectIdle_Time", timer.Elapsed()); | 206 UMA_HISTOGRAM_TIMES("Extensions.InjectIdle_Time", timer.Elapsed()); |
| 206 } else { | 207 } else { |
| 207 NOTREACHED(); | 208 NOTREACHED(); |
| 208 } | 209 } |
| 209 | 210 |
| 210 LOG(INFO) << "Injected " << num_scripts << " scripts and " << num_css << | 211 LOG(INFO) << "Injected " << num_scripts << " scripts and " << num_css << |
| 211 "css files into " << frame->url().spec().data(); | 212 "css files into " << frame->url().spec().data(); |
| 212 return true; | 213 return true; |
| 213 } | 214 } |
| OLD | NEW |