OLD | NEW |
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/extension.h" | 16 #include "chrome/common/extensions/extension.h" |
17 #include "chrome/common/extensions/extension_messages.h" | 17 #include "chrome/common/extensions/extension_messages.h" |
18 #include "chrome/common/extensions/extension_set.h" | 18 #include "chrome/common/extensions/extension_set.h" |
19 #include "chrome/common/url_constants.h" | 19 #include "chrome/common/url_constants.h" |
20 #include "chrome/renderer/chrome_render_process_observer.h" | 20 #include "chrome/renderer/chrome_render_process_observer.h" |
21 #include "chrome/renderer/extensions/extension_dispatcher.h" | |
22 #include "chrome/renderer/extensions/extension_groups.h" | 21 #include "chrome/renderer/extensions/extension_groups.h" |
23 #include "content/public/renderer/render_thread.h" | 22 #include "content/public/renderer/render_thread.h" |
24 #include "content/public/renderer/render_view.h" | 23 #include "content/public/renderer/render_view.h" |
25 #include "googleurl/src/gurl.h" | 24 #include "googleurl/src/gurl.h" |
26 #include "grit/renderer_resources.h" | 25 #include "grit/renderer_resources.h" |
27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h" | 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h" |
28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" | 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" |
31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h" | 30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h" |
(...skipping 11 matching lines...) Expand all Loading... |
43 using WebKit::WebView; | 42 using WebKit::WebView; |
44 using content::RenderThread; | 43 using content::RenderThread; |
45 | 44 |
46 namespace extensions { | 45 namespace extensions { |
47 | 46 |
48 // These two strings are injected before and after the Greasemonkey API and | 47 // These two strings are injected before and after the Greasemonkey API and |
49 // user script to wrap it in an anonymous scope. | 48 // user script to wrap it in an anonymous scope. |
50 static const char kUserScriptHead[] = "(function (unsafeWindow) {\n"; | 49 static const char kUserScriptHead[] = "(function (unsafeWindow) {\n"; |
51 static const char kUserScriptTail[] = "\n})(window);"; | 50 static const char kUserScriptTail[] = "\n})(window);"; |
52 | 51 |
53 int UserScriptSlave::GetIsolatedWorldIdForExtension( | 52 int UserScriptSlave::GetIsolatedWorldIdForExtension(const Extension* extension, |
54 const Extension* extension, WebFrame* frame) { | 53 WebFrame* frame) { |
55 static int g_next_isolated_world_id = 1; | 54 static int g_next_isolated_world_id = 1; |
56 | 55 |
57 IsolatedWorldMap::iterator iter = isolated_world_ids_.find(extension->id()); | 56 IsolatedWorldMap::iterator iter = isolated_world_ids_.find(extension->id()); |
58 if (iter != isolated_world_ids_.end()) { | 57 if (iter != isolated_world_ids_.end()) { |
59 // We need to set the isolated world origin even if it's not a new world | 58 // We need to set the isolated world origin even if it's not a new world |
60 // since that is stored per frame, and we might not have used this isolated | 59 // since that is stored per frame, and we might not have used this isolated |
61 // world in this frame before. | 60 // world in this frame before. |
62 frame->setIsolatedWorldSecurityOrigin( | 61 frame->setIsolatedWorldSecurityOrigin( |
63 iter->second, | 62 iter->second, |
64 WebSecurityOrigin::create(extension->url())); | 63 WebSecurityOrigin::create(extension->url())); |
(...skipping 17 matching lines...) Expand all Loading... |
82 int isolated_world_id) { | 81 int isolated_world_id) { |
83 for (IsolatedWorldMap::iterator iter = isolated_world_ids_.begin(); | 82 for (IsolatedWorldMap::iterator iter = isolated_world_ids_.begin(); |
84 iter != isolated_world_ids_.end(); ++iter) { | 83 iter != isolated_world_ids_.end(); ++iter) { |
85 if (iter->second == isolated_world_id) | 84 if (iter->second == isolated_world_id) |
86 return iter->first; | 85 return iter->first; |
87 } | 86 } |
88 return ""; | 87 return ""; |
89 } | 88 } |
90 | 89 |
91 // static | 90 // static |
92 void UserScriptSlave::InitializeIsolatedWorld( | 91 void UserScriptSlave::InitializeIsolatedWorld(int isolated_world_id, |
93 int isolated_world_id, | 92 const Extension* extension) { |
94 const Extension* extension) { | |
95 const URLPatternSet& permissions = | 93 const URLPatternSet& permissions = |
96 extension->GetEffectiveHostPermissions(); | 94 extension->GetEffectiveHostPermissions(); |
97 for (URLPatternSet::const_iterator i = permissions.begin(); | 95 for (URLPatternSet::const_iterator i = permissions.begin(); |
98 i != permissions.end(); ++i) { | 96 i != permissions.end(); ++i) { |
99 const char* schemes[] = { | 97 const char* schemes[] = { |
100 chrome::kHttpScheme, | 98 chrome::kHttpScheme, |
101 chrome::kHttpsScheme, | 99 chrome::kHttpsScheme, |
102 chrome::kFileScheme, | 100 chrome::kFileScheme, |
103 chrome::kChromeUIScheme, | 101 chrome::kChromeUIScheme, |
104 }; | 102 }; |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 } else if (location == UserScript::DOCUMENT_IDLE) { | 360 } else if (location == UserScript::DOCUMENT_IDLE) { |
363 UMA_HISTOGRAM_COUNTS_100("Extensions.InjectIdle_ScriptCount", num_scripts); | 361 UMA_HISTOGRAM_COUNTS_100("Extensions.InjectIdle_ScriptCount", num_scripts); |
364 if (num_scripts) | 362 if (num_scripts) |
365 UMA_HISTOGRAM_TIMES("Extensions.InjectIdle_Time", timer.Elapsed()); | 363 UMA_HISTOGRAM_TIMES("Extensions.InjectIdle_Time", timer.Elapsed()); |
366 } else { | 364 } else { |
367 NOTREACHED(); | 365 NOTREACHED(); |
368 } | 366 } |
369 } | 367 } |
370 | 368 |
371 } // namespace extensions | 369 } // namespace extensions |
OLD | NEW |