| 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" |
| 11 #include "base/pickle.h" | 11 #include "base/pickle.h" |
| 12 #include "base/shared_memory.h" | 12 #include "base/shared_memory.h" |
| 13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 14 #include "chrome/renderer/extension_groups.h" | 14 #include "chrome/renderer/extension_groups.h" |
| 15 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
| 16 #include "webkit/api/public/WebFrame.h" | 16 #include "webkit/api/public/WebFrame.h" |
| 17 | 17 |
| 18 #include "grit/renderer_resources.h" | 18 #include "grit/renderer_resources.h" |
| 19 | 19 |
| 20 using WebKit::WebFrame; | 20 using WebKit::WebFrame; |
| 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 // Creates a convenient reference to a content script's parent extension. | 28 // Sets up the chrome.extension module. |
| 29 // TODO(mpcomplete): self.onConnect is deprecated. Remove it at 1.0. | 29 static const char kInitExtension[] = "chrome.initExtension('%s');"; |
| 30 // http://code.google.com/p/chromium/issues/detail?id=16356 | |
| 31 static const char kInitExtension[] = | |
| 32 "chrome.extension = new chrome.Extension('%s');" | |
| 33 "chrome.self.onConnect = chrome.extension.onConnect;"; | |
| 34 | 30 |
| 35 int UserScriptSlave::GetIsolatedWorldId(const std::string& extension_id) { | 31 int UserScriptSlave::GetIsolatedWorldId(const std::string& extension_id) { |
| 36 typedef std::map<std::string, int> IsolatedWorldMap; | 32 typedef std::map<std::string, int> IsolatedWorldMap; |
| 37 | 33 |
| 38 static IsolatedWorldMap g_isolated_world_ids; | 34 static IsolatedWorldMap g_isolated_world_ids; |
| 39 static int g_next_isolated_world_id = 1; | 35 static int g_next_isolated_world_id = 1; |
| 40 | 36 |
| 41 IsolatedWorldMap::iterator iter = g_isolated_world_ids.find(extension_id); | 37 IsolatedWorldMap::iterator iter = g_isolated_world_ids.find(extension_id); |
| 42 if (iter != g_isolated_world_ids.end()) | 38 if (iter != g_isolated_world_ids.end()) |
| 43 return iter->second; | 39 return iter->second; |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 UMA_HISTOGRAM_TIMES("Extensions.InjectStart_Time", timer.Elapsed()); | 200 UMA_HISTOGRAM_TIMES("Extensions.InjectStart_Time", timer.Elapsed()); |
| 205 } else { | 201 } else { |
| 206 UMA_HISTOGRAM_COUNTS_100("Extensions.InjectEnd_ScriptCount", num_scripts); | 202 UMA_HISTOGRAM_COUNTS_100("Extensions.InjectEnd_ScriptCount", num_scripts); |
| 207 UMA_HISTOGRAM_TIMES("Extensions.InjectEnd_Time", timer.Elapsed()); | 203 UMA_HISTOGRAM_TIMES("Extensions.InjectEnd_Time", timer.Elapsed()); |
| 208 } | 204 } |
| 209 | 205 |
| 210 LOG(INFO) << "Injected " << num_scripts << " scripts and " << num_css << | 206 LOG(INFO) << "Injected " << num_scripts << " scripts and " << num_css << |
| 211 "css files into " << frame->url().spec().data(); | 207 "css files into " << frame->url().spec().data(); |
| 212 return true; | 208 return true; |
| 213 } | 209 } |
| OLD | NEW |