Chromium Code Reviews| Index: extensions/renderer/user_script_injector.cc |
| diff --git a/extensions/renderer/user_script_injector.cc b/extensions/renderer/user_script_injector.cc |
| index 5a42ffa71b03f1a26c0d1fda54ff0427c341471c..0176374634c840aac307859a622609ab217d7aae 100644 |
| --- a/extensions/renderer/user_script_injector.cc |
| +++ b/extensions/renderer/user_script_injector.cc |
| @@ -10,6 +10,7 @@ |
| #include "content/public/common/url_constants.h" |
| #include "content/public/renderer/render_view.h" |
| #include "extensions/common/extension.h" |
| +#include "extensions/common/guest_view/guest_view_messages.h" |
| #include "extensions/common/permissions/permissions_data.h" |
| #include "extensions/renderer/injection_host.h" |
| #include "extensions/renderer/script_context.h" |
| @@ -25,11 +26,30 @@ namespace extensions { |
| namespace { |
| +struct RoutingInfoKey { |
| + int routing_id; |
| + int script_id; |
| + |
| + bool operator<(const RoutingInfoKey& other) const { |
| + if (routing_id != other.routing_id) |
| + return routing_id < other.routing_id; |
| + |
| + if (script_id != other.script_id) |
| + return script_id < other.script_id; |
| + return false; // keys are equal. |
| + } |
| +}; |
| + |
| +using RoutingInfoMap = std::map<RoutingInfoKey, bool>; |
| + |
| // These two strings are injected before and after the Greasemonkey API and |
| // user script to wrap it in an anonymous scope. |
| const char kUserScriptHead[] = "(function (unsafeWindow) {\n"; |
| const char kUserScriptTail[] = "\n})(window);"; |
| +base::LazyInstance<RoutingInfoMap> g_routing_info_map = |
| + LAZY_INSTANCE_INITIALIZER; |
| + |
| // Greasemonkey API source that is injected with the scripts. |
| struct GreasemonkeyApiJsString { |
| GreasemonkeyApiJsString(); |
| @@ -131,7 +151,6 @@ PermissionsData::AccessType UserScriptInjector::CanExecuteOnFrame( |
| web_frame, web_frame->document().url(), script_->match_about_blank()); |
| PermissionsData::AccessType can_execute = injection_host->CanExecuteOnFrame( |
| effective_document_url, top_url, tab_id, is_declarative_); |
| - |
| if (script_->consumer_instance_type() != |
| UserScript::ConsumerInstanceType::WEBVIEW || |
| can_execute == PermissionsData::ACCESS_DENIED) |
| @@ -139,9 +158,26 @@ PermissionsData::AccessType UserScriptInjector::CanExecuteOnFrame( |
| int routing_id = content::RenderView::FromWebView(web_frame->top()->view()) |
| ->GetRoutingID(); |
| - return script_->routing_info().render_view_id == routing_id |
| - ? PermissionsData::ACCESS_ALLOWED |
| - : PermissionsData::ACCESS_DENIED; |
| + |
| + RoutingInfoKey key; |
|
Fady Samuel
2015/03/27 20:25:36
Give it a constructor:
RoutingInfoKey key(routing
Xi Han
2015/03/30 17:50:49
Done.
|
| + key.routing_id = routing_id; |
| + key.script_id = script_->id(); |
| + |
| + RoutingInfoMap& map = g_routing_info_map.Get(); |
| + RoutingInfoMap::iterator iter = map.find(key); |
|
Fady Samuel
2015/03/27 20:25:36
nit: auto
Xi Han
2015/03/30 17:50:49
Done.
|
| + |
| + bool allowed = false; |
| + if (iter != map.end()) { |
| + allowed = iter->second; |
| + } else { |
| + auto rdv = content::RenderView::FromWebView(web_frame->top()->view()); |
| + rdv->Send(new GuestViewHostMsg_CanExecuteContentScript( |
|
Fady Samuel
2015/03/27 20:25:36
I don't think this is necessary:
content::RenderT
Xi Han
2015/03/30 17:50:49
Done.
|
| + routing_id, script_->id(), &allowed)); |
| + map.insert(std::pair<RoutingInfoKey, bool>(key, allowed)); |
| + } |
| + |
| + return allowed ? PermissionsData::ACCESS_ALLOWED |
| + : PermissionsData::ACCESS_DENIED; |
| } |
| std::vector<blink::WebScriptSource> UserScriptInjector::GetJsSources( |