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

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

Issue 12583016: Reserve an isolated world ID for Chrome Translate (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rename Created 7 years, 8 months 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
« no previous file with comments | « chrome/chrome_renderer.gypi ('k') | chrome/renderer/isolated_world_ids.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/extensions/user_script_slave.h" 5 #include "chrome/renderer/extensions/user_script_slave.h"
6 6
7 #include <map> 7 #include <map>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/metrics/histogram.h" 11 #include "base/metrics/histogram.h"
12 #include "base/perftimer.h" 12 #include "base/perftimer.h"
13 #include "base/pickle.h" 13 #include "base/pickle.h"
14 #include "base/shared_memory.h" 14 #include "base/shared_memory.h"
15 #include "base/stringprintf.h" 15 #include "base/stringprintf.h"
16 #include "chrome/common/extensions/csp_handler.h" 16 #include "chrome/common/extensions/csp_handler.h"
17 #include "chrome/common/extensions/extension.h" 17 #include "chrome/common/extensions/extension.h"
18 #include "chrome/common/extensions/extension_messages.h" 18 #include "chrome/common/extensions/extension_messages.h"
19 #include "chrome/common/extensions/extension_set.h" 19 #include "chrome/common/extensions/extension_set.h"
20 #include "chrome/common/url_constants.h" 20 #include "chrome/common/url_constants.h"
21 #include "chrome/renderer/chrome_render_process_observer.h" 21 #include "chrome/renderer/chrome_render_process_observer.h"
22 #include "chrome/renderer/extensions/dom_activity_logger.h" 22 #include "chrome/renderer/extensions/dom_activity_logger.h"
23 #include "chrome/renderer/extensions/extension_groups.h" 23 #include "chrome/renderer/extensions/extension_groups.h"
24 #include "chrome/renderer/isolated_world_ids.h"
24 #include "content/public/renderer/render_thread.h" 25 #include "content/public/renderer/render_thread.h"
25 #include "content/public/renderer/render_view.h" 26 #include "content/public/renderer/render_view.h"
26 #include "googleurl/src/gurl.h" 27 #include "googleurl/src/gurl.h"
27 #include "grit/renderer_resources.h" 28 #include "grit/renderer_resources.h"
28 #include "third_party/WebKit/Source/Platform/chromium/public/WebURLRequest.h" 29 #include "third_party/WebKit/Source/Platform/chromium/public/WebURLRequest.h"
29 #include "third_party/WebKit/Source/Platform/chromium/public/WebVector.h" 30 #include "third_party/WebKit/Source/Platform/chromium/public/WebVector.h"
30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h" 31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h"
31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" 32 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
32 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 33 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
33 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" 34 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
(...skipping 11 matching lines...) Expand all
45 46
46 namespace extensions { 47 namespace extensions {
47 48
48 // These two strings are injected before and after the Greasemonkey API and 49 // These two strings are injected before and after the Greasemonkey API and
49 // user script to wrap it in an anonymous scope. 50 // user script to wrap it in an anonymous scope.
50 static const char kUserScriptHead[] = "(function (unsafeWindow) {\n"; 51 static const char kUserScriptHead[] = "(function (unsafeWindow) {\n";
51 static const char kUserScriptTail[] = "\n})(window);"; 52 static const char kUserScriptTail[] = "\n})(window);";
52 53
53 int UserScriptSlave::GetIsolatedWorldIdForExtension(const Extension* extension, 54 int UserScriptSlave::GetIsolatedWorldIdForExtension(const Extension* extension,
54 WebFrame* frame) { 55 WebFrame* frame) {
55 static int g_next_isolated_world_id = 1; 56 static int g_next_isolated_world_id = chrome::ISOLATED_WORLD_ID_EXTENSIONS;
56 57
57 IsolatedWorldMap::iterator iter = isolated_world_ids_.find(extension->id()); 58 IsolatedWorldMap::iterator iter = isolated_world_ids_.find(extension->id());
58 if (iter != isolated_world_ids_.end()) { 59 if (iter != isolated_world_ids_.end()) {
59 // We need to set the isolated world origin and CSP even if it's not a new 60 // We need to set the isolated world origin and CSP even if it's not a new
60 // world since these are stored per frame, and we might not have used this 61 // world since these are stored per frame, and we might not have used this
61 // isolated world in this frame before. 62 // isolated world in this frame before.
62 frame->setIsolatedWorldSecurityOrigin( 63 frame->setIsolatedWorldSecurityOrigin(
63 iter->second, 64 iter->second,
64 WebSecurityOrigin::create(extension->url())); 65 WebSecurityOrigin::create(extension->url()));
65 frame->setIsolatedWorldContentSecurityPolicy( 66 frame->setIsolatedWorldContentSecurityPolicy(
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 } else if (location == UserScript::DOCUMENT_IDLE) { 378 } else if (location == UserScript::DOCUMENT_IDLE) {
378 UMA_HISTOGRAM_COUNTS_100("Extensions.InjectIdle_ScriptCount", num_scripts); 379 UMA_HISTOGRAM_COUNTS_100("Extensions.InjectIdle_ScriptCount", num_scripts);
379 if (num_scripts) 380 if (num_scripts)
380 UMA_HISTOGRAM_TIMES("Extensions.InjectIdle_Time", timer.Elapsed()); 381 UMA_HISTOGRAM_TIMES("Extensions.InjectIdle_Time", timer.Elapsed());
381 } else { 382 } else {
382 NOTREACHED(); 383 NOTREACHED();
383 } 384 }
384 } 385 }
385 386
386 } // namespace extensions 387 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/chrome_renderer.gypi ('k') | chrome/renderer/isolated_world_ids.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698