Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(243)

Side by Side Diff: chrome/renderer/user_script_slave.cc

Issue 366024: Add stub functions for chrome.* APIs in content scripts. ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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 }
OLDNEW
« no previous file with comments | « chrome/renderer/resources/renderer_extension_bindings.js ('k') | chrome/test/data/extensions/api_test/stubs/background.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698