Chromium Code Reviews| Index: extensions/browser/guest_view/web_view/web_view_guest.cc |
| diff --git a/extensions/browser/guest_view/web_view/web_view_guest.cc b/extensions/browser/guest_view/web_view/web_view_guest.cc |
| index 36418980eadde3a8fa1d9fd78e76eafe7215b33b..73fe4257c7627b301f5bb7f39c0f79482ed6e0d3 100644 |
| --- a/extensions/browser/guest_view/web_view/web_view_guest.cc |
| +++ b/extensions/browser/guest_view/web_view/web_view_guest.cc |
| @@ -59,6 +59,8 @@ namespace extensions { |
| namespace { |
| +int current_script_injection_instance_id = 0; |
| + |
| std::string WindowOpenDispositionToString( |
| WindowOpenDisposition window_open_disposition) { |
| switch (window_open_disposition) { |
| @@ -100,6 +102,10 @@ static std::string TerminationStatusToString(base::TerminationStatus status) { |
| return "unknown"; |
| } |
| +int GetNextScriptInjectionInstanceID() { |
| + return ++current_script_injection_instance_id; |
| +} |
| + |
| std::string GetStoragePartitionIdFromSiteURL(const GURL& site_url) { |
| const std::string& partition_id = site_url.query(); |
| bool persist_storage = site_url.path().find("persist") != std::string::npos; |
| @@ -185,6 +191,8 @@ using WebViewKey = std::pair<int, int>; |
| using WebViewKeyToIDMap = std::map<WebViewKey, int>; |
| static base::LazyInstance<WebViewKeyToIDMap> web_view_key_to_id_map = |
| LAZY_INSTANCE_INITIALIZER; |
| +static base::LazyInstance<WebViewKeyToIDMap> script_injection_instance_id_map = |
|
Devlin
2015/02/06 00:28:41
It bothers me that we have multiple different maps
Xi Han
2015/02/06 17:21:45
We would like to have just one function, but the i
Devlin
2015/02/06 18:48:36
But the RulesRegistry one is going away, right?
Xi Han
2015/02/06 19:45:33
Hmmm, I don't think so, because the declarative we
Devlin
2015/02/09 17:40:24
Ah, right. In that case, can we make GetRulesRegi
Xi Han
2015/02/09 23:28:11
As discussed offline, we will still keeps two maps
|
| + LAZY_INSTANCE_INITIALIZER; |
| // static |
| int WebViewGuest::GetOrGenerateRulesRegistryID( |
| @@ -208,6 +216,25 @@ int WebViewGuest::GetOrGenerateRulesRegistryID( |
| } |
| // static |
| +int WebViewGuest:: GetOrGenerateScriptInjectionInstanceID( |
| + int embedder_process_id, |
| + int guest_instance_id ) { |
| + if (!(embedder_process_id && guest_instance_id)) |
| + return Host::kDefaultInstanceId; |
| + |
| + WebViewKey key = std::make_pair(embedder_process_id, guest_instance_id); |
| + WebViewKeyToIDMap& script_injection_ids = |
| + script_injection_instance_id_map.Get(); |
| + auto it = script_injection_ids.find(key); |
| + if (it != script_injection_ids.end()) |
| + return it->second; |
| + |
| + int script_injection_instance_id = GetNextScriptInjectionInstanceID(); |
| + script_injection_ids[key] = script_injection_instance_id; |
| + return script_injection_instance_id; |
| +} |
| + |
| +// static |
| int WebViewGuest::GetViewInstanceId(WebContents* contents) { |
| auto guest = FromWebContents(contents); |
| if (!guest) |
| @@ -294,6 +321,10 @@ void WebViewGuest::DidInitialize(const base::DictionaryValue& create_params) { |
| owner_web_contents()->GetRenderProcessHost()->GetID(), |
| view_instance_id()); |
| + GetOrGenerateScriptInjectionInstanceID( |
| + owner_web_contents()->GetRenderProcessHost()->GetID(), |
| + guest_instance_id()); |
| + |
| // We must install the mapping from guests to WebViews prior to resuming |
| // suspended resource loads so that the WebRequest API will catch resource |
| // requests. |
| @@ -321,6 +352,7 @@ void WebViewGuest::EmbedderWillBeDestroyed() { |
| WebViewKey key(owner_web_contents()->GetRenderProcessHost()->GetID(), |
| view_instance_id()); |
| web_view_key_to_id_map.Get().erase(key); |
| + script_injection_instance_id_map.Get().erase(key); |
| content::BrowserThread::PostTask( |
| content::BrowserThread::IO, |