Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/guest_view/web_view/web_view_guest.h" | 5 #include "extensions/browser/guest_view/web_view/web_view_guest.h" |
| 6 | 6 |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "content/public/browser/browser_context.h" | 10 #include "content/public/browser/browser_context.h" |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 #include "content/public/browser/site_instance.h" | 23 #include "content/public/browser/site_instance.h" |
| 24 #include "content/public/browser/storage_partition.h" | 24 #include "content/public/browser/storage_partition.h" |
| 25 #include "content/public/browser/user_metrics.h" | 25 #include "content/public/browser/user_metrics.h" |
| 26 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
| 27 #include "content/public/browser/web_contents_delegate.h" | 27 #include "content/public/browser/web_contents_delegate.h" |
| 28 #include "content/public/common/media_stream_request.h" | 28 #include "content/public/common/media_stream_request.h" |
| 29 #include "content/public/common/page_zoom.h" | 29 #include "content/public/common/page_zoom.h" |
| 30 #include "content/public/common/result_codes.h" | 30 #include "content/public/common/result_codes.h" |
| 31 #include "content/public/common/stop_find_action.h" | 31 #include "content/public/common/stop_find_action.h" |
| 32 #include "content/public/common/url_constants.h" | 32 #include "content/public/common/url_constants.h" |
| 33 #include "extensions/browser/api/declarative/rules_registry_service.h" | |
| 33 #include "extensions/browser/api/extensions_api_client.h" | 34 #include "extensions/browser/api/extensions_api_client.h" |
| 34 #include "extensions/browser/api/web_request/web_request_api.h" | 35 #include "extensions/browser/api/web_request/web_request_api.h" |
| 35 #include "extensions/browser/api/web_view/web_view_internal_api.h" | 36 #include "extensions/browser/api/web_view/web_view_internal_api.h" |
| 36 #include "extensions/browser/extension_system.h" | 37 #include "extensions/browser/extension_system.h" |
| 37 #include "extensions/browser/guest_view/guest_view_manager.h" | 38 #include "extensions/browser/guest_view/guest_view_manager.h" |
| 38 #include "extensions/browser/guest_view/web_view/web_view_constants.h" | 39 #include "extensions/browser/guest_view/web_view/web_view_constants.h" |
| 39 #include "extensions/browser/guest_view/web_view/web_view_permission_helper.h" | 40 #include "extensions/browser/guest_view/web_view/web_view_permission_helper.h" |
| 40 #include "extensions/browser/guest_view/web_view/web_view_permission_types.h" | 41 #include "extensions/browser/guest_view/web_view/web_view_permission_types.h" |
| 41 #include "extensions/browser/guest_view/web_view/web_view_renderer_state.h" | 42 #include "extensions/browser/guest_view/web_view/web_view_renderer_state.h" |
| 42 #include "extensions/common/constants.h" | 43 #include "extensions/common/constants.h" |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 173 // The partition name is user supplied value, which we have encoded when the | 174 // The partition name is user supplied value, which we have encoded when the |
| 174 // URL was created, so it needs to be decoded. | 175 // URL was created, so it needs to be decoded. |
| 175 *partition_name = | 176 *partition_name = |
| 176 net::UnescapeURLComponent(site.query(), net::UnescapeRule::NORMAL); | 177 net::UnescapeURLComponent(site.query(), net::UnescapeRule::NORMAL); |
| 177 return true; | 178 return true; |
| 178 } | 179 } |
| 179 | 180 |
| 180 // static | 181 // static |
| 181 const char WebViewGuest::Type[] = "webview"; | 182 const char WebViewGuest::Type[] = "webview"; |
| 182 | 183 |
| 184 typedef std::pair<int, int> WebViewKey; | |
| 185 typedef std::map<WebViewKey, int> WebViewKeyToIDMap; | |
| 186 typedef std::map<int, WebViewKey> IDToWebViewKeyMap; | |
| 187 static base::LazyInstance<WebViewKeyToIDMap> web_view_key_to_id_map = | |
| 188 LAZY_INSTANCE_INITIALIZER; | |
| 189 static base::LazyInstance<IDToWebViewKeyMap> id_to_web_view_key_map = | |
| 190 LAZY_INSTANCE_INITIALIZER; | |
| 191 | |
| 192 // static | |
| 193 void WebViewGuest::GenerateRulesRegistryID( | |
|
Fady Samuel
2014/11/28 11:34:24
GetOrGenerateRulesRegistryID
Xi Han
2014/11/28 16:12:56
Done.
| |
| 194 int embedder_process_id, | |
| 195 int webview_instance_id, | |
| 196 RulesRegistryService* rules_registry_service, | |
|
Fady Samuel
2014/11/26 23:39:41
Pass in a BrowserContext instead.
Xi Han
2014/11/27 23:25:26
Done.
| |
| 197 int* rules_registry_id) { | |
|
Fady Samuel
2014/11/26 23:39:41
return this value instead of making it an output p
Xi Han
2014/11/27 23:25:26
Done.
| |
| 198 WebViewKey key = std::make_pair(embedder_process_id, webview_instance_id); | |
| 199 WebViewKeyToIDMap::iterator it = web_view_key_to_id_map.Get().find(key); | |
| 200 if (it != web_view_key_to_id_map.Get().end()) { | |
| 201 (*rules_registry_id) = it->second; | |
| 202 return; | |
| 203 } | |
| 204 *rules_registry_id = rules_registry_service->GetNextRulesRegistryId(); | |
| 205 web_view_key_to_id_map.Get()[key] = *rules_registry_id; | |
| 206 id_to_web_view_key_map.Get()[*rules_registry_id] = key; | |
| 207 } | |
| 208 | |
| 209 // static | |
| 210 int WebViewGuest::GetEmbedderProcessID(int rules_registry_id) { | |
| 211 return id_to_web_view_key_map.Get().find(rules_registry_id)->first; | |
| 212 } | |
| 213 | |
| 214 // static | |
| 215 void WebViewGuest::RemoveRulesRegistryID(int rules_registry_id) { | |
| 216 IDToWebViewKeyMap::iterator it = | |
| 217 id_to_web_view_key_map.Get().find(rules_registry_id); | |
| 218 web_view_key_to_id_map.Get().erase(it->second); | |
| 219 id_to_web_view_key_map.Get().erase(it); | |
| 220 } | |
| 221 | |
| 183 // static | 222 // static |
| 184 int WebViewGuest::GetViewInstanceId(WebContents* contents) { | 223 int WebViewGuest::GetViewInstanceId(WebContents* contents) { |
| 185 WebViewGuest* guest = FromWebContents(contents); | 224 WebViewGuest* guest = FromWebContents(contents); |
| 186 if (!guest) | 225 if (!guest) |
| 187 return guestview::kInstanceIDNone; | 226 return guestview::kInstanceIDNone; |
| 188 | 227 |
| 189 return guest->view_instance_id(); | 228 return guest->view_instance_id(); |
| 190 } | 229 } |
| 191 | 230 |
| 192 const char* WebViewGuest::GetAPINamespace() const { | 231 const char* WebViewGuest::GetAPINamespace() const { |
| (...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 805 site_url, &partition_domain, &partition_id, &in_memory)) { | 844 site_url, &partition_domain, &partition_id, &in_memory)) { |
| 806 NOTREACHED(); | 845 NOTREACHED(); |
| 807 return; | 846 return; |
| 808 } | 847 } |
| 809 | 848 |
| 810 WebViewRendererState::WebViewInfo web_view_info; | 849 WebViewRendererState::WebViewInfo web_view_info; |
| 811 web_view_info.embedder_process_id = embedder_render_process_id(); | 850 web_view_info.embedder_process_id = embedder_render_process_id(); |
| 812 web_view_info.instance_id = view_instance_id(); | 851 web_view_info.instance_id = view_instance_id(); |
| 813 web_view_info.partition_id = partition_id; | 852 web_view_info.partition_id = partition_id; |
| 814 web_view_info.embedder_extension_id = embedder_extension_id(); | 853 web_view_info.embedder_extension_id = embedder_extension_id(); |
| 854 WebViewKey key(web_view_info.embedder_process_id, web_view_info.instance_id); | |
| 855 web_view_info.rules_registry_id = | |
| 856 web_view_key_to_id_map.Get().find(key)->second; | |
| 815 | 857 |
| 816 content::BrowserThread::PostTask( | 858 content::BrowserThread::PostTask( |
| 817 content::BrowserThread::IO, | 859 content::BrowserThread::IO, |
| 818 FROM_HERE, | 860 FROM_HERE, |
| 819 base::Bind(&WebViewRendererState::AddGuest, | 861 base::Bind(&WebViewRendererState::AddGuest, |
| 820 base::Unretained(WebViewRendererState::GetInstance()), | 862 base::Unretained(WebViewRendererState::GetInstance()), |
| 821 web_contents()->GetRenderProcessHost()->GetID(), | 863 web_contents()->GetRenderProcessHost()->GetID(), |
| 822 web_contents()->GetRoutingID(), | 864 web_contents()->GetRoutingID(), |
| 823 web_view_info)); | 865 web_view_info)); |
| 824 } | 866 } |
| (...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1219 WebViewGuest* guest = | 1261 WebViewGuest* guest = |
| 1220 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); | 1262 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); |
| 1221 if (!guest) | 1263 if (!guest) |
| 1222 return; | 1264 return; |
| 1223 | 1265 |
| 1224 if (!allow) | 1266 if (!allow) |
| 1225 guest->Destroy(); | 1267 guest->Destroy(); |
| 1226 } | 1268 } |
| 1227 | 1269 |
| 1228 } // namespace extensions | 1270 } // namespace extensions |
| OLD | NEW |