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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 52 | 52 |
| 53 using base::UserMetricsAction; | 53 using base::UserMetricsAction; |
| 54 using content::RenderFrameHost; | 54 using content::RenderFrameHost; |
| 55 using content::ResourceType; | 55 using content::ResourceType; |
| 56 using content::WebContents; | 56 using content::WebContents; |
| 57 | 57 |
| 58 namespace extensions { | 58 namespace extensions { |
| 59 | 59 |
| 60 namespace { | 60 namespace { |
| 61 | 61 |
| 62 using WebViewKey = std::pair<int, int>; | |
| 63 using WebViewKeyToIDMap = std::map<WebViewKey, int>; | |
| 64 base::LazyInstance<WebViewKeyToIDMap> web_view_key_to_id_map = | |
| 65 LAZY_INSTANCE_INITIALIZER; | |
| 66 | |
| 62 std::string WindowOpenDispositionToString( | 67 std::string WindowOpenDispositionToString( |
| 63 WindowOpenDisposition window_open_disposition) { | 68 WindowOpenDisposition window_open_disposition) { |
| 64 switch (window_open_disposition) { | 69 switch (window_open_disposition) { |
| 65 case IGNORE_ACTION: | 70 case IGNORE_ACTION: |
| 66 return "ignore"; | 71 return "ignore"; |
| 67 case SAVE_TO_DISK: | 72 case SAVE_TO_DISK: |
| 68 return "save_to_disk"; | 73 return "save_to_disk"; |
| 69 case CURRENT_TAB: | 74 case CURRENT_TAB: |
| 70 return "current_tab"; | 75 return "current_tab"; |
| 71 case NEW_BACKGROUND_TAB: | 76 case NEW_BACKGROUND_TAB: |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 174 // The partition name is user supplied value, which we have encoded when the | 179 // The partition name is user supplied value, which we have encoded when the |
| 175 // URL was created, so it needs to be decoded. | 180 // URL was created, so it needs to be decoded. |
| 176 *partition_name = | 181 *partition_name = |
| 177 net::UnescapeURLComponent(site.query(), net::UnescapeRule::NORMAL); | 182 net::UnescapeURLComponent(site.query(), net::UnescapeRule::NORMAL); |
| 178 return true; | 183 return true; |
| 179 } | 184 } |
| 180 | 185 |
| 181 // static | 186 // static |
| 182 const char WebViewGuest::Type[] = "webview"; | 187 const char WebViewGuest::Type[] = "webview"; |
| 183 | 188 |
| 184 using WebViewKey = std::pair<int, int>; | |
| 185 using WebViewKeyToIDMap = std::map<WebViewKey, int>; | |
| 186 static base::LazyInstance<WebViewKeyToIDMap> web_view_key_to_id_map = | |
|
Devlin
2015/02/13 18:27:08
Since we're not really adding anything to these fi
Xi Han
2015/02/13 19:11:28
Ok, revert all the changes.
| |
| 187 LAZY_INSTANCE_INITIALIZER; | |
| 188 | |
| 189 // static | 189 // static |
| 190 int WebViewGuest::GetOrGenerateRulesRegistryID( | 190 int WebViewGuest::GetOrGenerateRulesRegistryID( |
| 191 int embedder_process_id, | 191 int embedder_process_id, |
| 192 int webview_instance_id) { | 192 int web_view_instance_id) { |
| 193 bool is_web_view = embedder_process_id && webview_instance_id; | 193 if (!embedder_process_id || !web_view_instance_id) |
| 194 if (!is_web_view) | |
| 195 return RulesRegistryService::kDefaultRulesRegistryID; | 194 return RulesRegistryService::kDefaultRulesRegistryID; |
| 196 | 195 |
| 197 WebViewKey key = std::make_pair(embedder_process_id, webview_instance_id); | 196 WebViewKey key(embedder_process_id, web_view_instance_id); |
| 198 auto it = web_view_key_to_id_map.Get().find(key); | 197 WebViewKeyToIDMap& map = web_view_key_to_id_map.Get(); |
| 199 if (it != web_view_key_to_id_map.Get().end()) | 198 auto it = map.find(key); |
| 199 if (it != map.end()) | |
| 200 return it->second; | 200 return it->second; |
| 201 | 201 |
| 202 auto rph = content::RenderProcessHost::FromID(embedder_process_id); | 202 auto rph = content::RenderProcessHost::FromID(embedder_process_id); |
| 203 int rules_registry_id = | 203 int id = RulesRegistryService::Get(rph->GetBrowserContext())-> |
| 204 RulesRegistryService::Get(rph->GetBrowserContext())-> | 204 GetNextRulesRegistryID(); |
| 205 GetNextRulesRegistryID(); | 205 map[key] = id; |
| 206 web_view_key_to_id_map.Get()[key] = rules_registry_id; | 206 return id; |
| 207 return rules_registry_id; | |
| 208 } | 207 } |
| 209 | 208 |
| 210 // static | 209 // static |
| 211 int WebViewGuest::GetViewInstanceId(WebContents* contents) { | 210 int WebViewGuest::GetViewInstanceId(WebContents* contents) { |
| 212 auto guest = FromWebContents(contents); | 211 auto guest = FromWebContents(contents); |
| 213 if (!guest) | 212 if (!guest) |
| 214 return guestview::kInstanceIDNone; | 213 return guestview::kInstanceIDNone; |
| 215 | 214 |
| 216 return guest->view_instance_id(); | 215 return guest->view_instance_id(); |
| 217 } | 216 } |
| (...skipping 1000 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1218 WebViewGuest::From(owner_web_contents()->GetRenderProcessHost()->GetID(), | 1217 WebViewGuest::From(owner_web_contents()->GetRenderProcessHost()->GetID(), |
| 1219 new_window_instance_id); | 1218 new_window_instance_id); |
| 1220 if (!guest) | 1219 if (!guest) |
| 1221 return; | 1220 return; |
| 1222 | 1221 |
| 1223 if (!allow) | 1222 if (!allow) |
| 1224 guest->Destroy(); | 1223 guest->Destroy(); |
| 1225 } | 1224 } |
| 1226 | 1225 |
| 1227 } // namespace extensions | 1226 } // namespace extensions |
| OLD | NEW |