| 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 "content/public/browser/browser_thread.h" | 5 #include "content/public/browser/browser_thread.h" |
| 6 #include "extensions/browser/guest_view/web_view/web_view_renderer_state.h" | 6 #include "extensions/browser/guest_view/web_view/web_view_renderer_state.h" |
| 7 | 7 |
| 8 using content::BrowserThread; | 8 using content::BrowserThread; |
| 9 | 9 |
| 10 namespace extensions { | 10 namespace extensions { |
| 11 | 11 |
| 12 // static | 12 // static |
| 13 WebViewRendererState* WebViewRendererState::GetInstance() { | 13 WebViewRendererState* WebViewRendererState::GetInstance() { |
| 14 return Singleton<WebViewRendererState>::get(); | 14 return Singleton<WebViewRendererState>::get(); |
| 15 } | 15 } |
| 16 | 16 |
| 17 WebViewRendererState::WebViewRendererState() { | 17 WebViewRendererState::WebViewRendererState() { |
| 18 } | 18 } |
| 19 | 19 |
| 20 WebViewRendererState::~WebViewRendererState() { | 20 WebViewRendererState::~WebViewRendererState() { |
| 21 } | 21 } |
| 22 | 22 |
| 23 bool WebViewRendererState::IsGuest(int render_process_id) { | 23 bool WebViewRendererState::IsGuest(int render_process_id) { |
| 24 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 24 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 25 return webview_partition_id_map_.find(render_process_id) != | 25 return web_view_partition_id_map_.find(render_process_id) != |
| 26 webview_partition_id_map_.end(); | 26 web_view_partition_id_map_.end(); |
| 27 } | 27 } |
| 28 | 28 |
| 29 void WebViewRendererState::AddGuest(int guest_process_id, | 29 void WebViewRendererState::AddGuest(int guest_process_id, |
| 30 int guest_routing_id, | 30 int guest_routing_id, |
| 31 const WebViewInfo& webview_info) { | 31 const WebViewInfo& web_view_info) { |
| 32 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 32 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 33 RenderId render_id(guest_process_id, guest_routing_id); | 33 RenderId render_id(guest_process_id, guest_routing_id); |
| 34 bool updating = webview_info_map_.find(render_id) != webview_info_map_.end(); | 34 bool updating = |
| 35 webview_info_map_[render_id] = webview_info; | 35 web_view_info_map_.find(render_id) != web_view_info_map_.end(); |
| 36 web_view_info_map_[render_id] = web_view_info; |
| 36 if (updating) | 37 if (updating) |
| 37 return; | 38 return; |
| 38 | 39 |
| 39 WebViewPartitionIDMap::iterator iter = | 40 auto iter = web_view_partition_id_map_.find(guest_process_id); |
| 40 webview_partition_id_map_.find(guest_process_id); | 41 if (iter != web_view_partition_id_map_.end()) { |
| 41 if (iter != webview_partition_id_map_.end()) { | |
| 42 ++iter->second.web_view_count; | 42 ++iter->second.web_view_count; |
| 43 return; | 43 return; |
| 44 } | 44 } |
| 45 WebViewPartitionInfo partition_info(1, webview_info.partition_id); | 45 WebViewPartitionInfo partition_info(1, web_view_info.partition_id); |
| 46 webview_partition_id_map_[guest_process_id] = partition_info; | 46 web_view_partition_id_map_[guest_process_id] = partition_info; |
| 47 } | 47 } |
| 48 | 48 |
| 49 void WebViewRendererState::RemoveGuest(int guest_process_id, | 49 void WebViewRendererState::RemoveGuest(int guest_process_id, |
| 50 int guest_routing_id) { | 50 int guest_routing_id) { |
| 51 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 51 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 52 RenderId render_id(guest_process_id, guest_routing_id); | 52 RenderId render_id(guest_process_id, guest_routing_id); |
| 53 webview_info_map_.erase(render_id); | 53 web_view_info_map_.erase(render_id); |
| 54 WebViewPartitionIDMap::iterator iter = | 54 auto iter = web_view_partition_id_map_.find(guest_process_id); |
| 55 webview_partition_id_map_.find(guest_process_id); | 55 if (iter != web_view_partition_id_map_.end() && |
| 56 if (iter != webview_partition_id_map_.end() && | |
| 57 iter->second.web_view_count > 1) { | 56 iter->second.web_view_count > 1) { |
| 58 --iter->second.web_view_count; | 57 --iter->second.web_view_count; |
| 59 return; | 58 return; |
| 60 } | 59 } |
| 61 webview_partition_id_map_.erase(guest_process_id); | 60 web_view_partition_id_map_.erase(guest_process_id); |
| 62 } | 61 } |
| 63 | 62 |
| 64 bool WebViewRendererState::GetInfo(int guest_process_id, | 63 bool WebViewRendererState::GetInfo(int guest_process_id, |
| 65 int guest_routing_id, | 64 int guest_routing_id, |
| 66 WebViewInfo* webview_info) { | 65 WebViewInfo* web_view_info) { |
| 67 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 66 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 68 RenderId render_id(guest_process_id, guest_routing_id); | 67 RenderId render_id(guest_process_id, guest_routing_id); |
| 69 WebViewInfoMap::iterator iter = webview_info_map_.find(render_id); | 68 auto iter = web_view_info_map_.find(render_id); |
| 70 if (iter != webview_info_map_.end()) { | 69 if (iter != web_view_info_map_.end()) { |
| 71 *webview_info = iter->second; | 70 *web_view_info = iter->second; |
| 72 return true; | 71 return true; |
| 73 } | 72 } |
| 74 return false; | 73 return false; |
| 75 } | 74 } |
| 76 | 75 |
| 77 bool WebViewRendererState::GetOwnerInfo(int guest_process_id, | 76 bool WebViewRendererState::GetOwnerInfo(int guest_process_id, |
| 78 int* owner_process_id, | 77 int* owner_process_id, |
| 79 std::string* owner_extension_id) const { | 78 std::string* owner_extension_id) const { |
| 80 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 79 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 81 // TODO(fsamuel): Store per-process info in WebViewPartitionInfo instead of in | 80 // TODO(fsamuel): Store per-process info in WebViewPartitionInfo instead of in |
| 82 // WebViewInfo. | 81 // WebViewInfo. |
| 83 for (const auto& info : webview_info_map_) { | 82 for (const auto& info : web_view_info_map_) { |
| 84 if (info.first.first == guest_process_id) { | 83 if (info.first.first == guest_process_id) { |
| 85 if (owner_process_id) | 84 if (owner_process_id) |
| 86 *owner_process_id = info.second.embedder_process_id; | 85 *owner_process_id = info.second.embedder_process_id; |
| 87 if (owner_extension_id) | 86 if (owner_extension_id) |
| 88 *owner_extension_id = info.second.owner_extension_id; | 87 *owner_extension_id = info.second.owner_extension_id; |
| 89 return true; | 88 return true; |
| 90 } | 89 } |
| 91 } | 90 } |
| 92 return false; | 91 return false; |
| 93 } | 92 } |
| 94 | 93 |
| 95 bool WebViewRendererState::GetPartitionID(int guest_process_id, | 94 bool WebViewRendererState::GetPartitionID(int guest_process_id, |
| 96 std::string* partition_id) { | 95 std::string* partition_id) { |
| 97 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 96 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 98 WebViewPartitionIDMap::iterator iter = | 97 |
| 99 webview_partition_id_map_.find(guest_process_id); | 98 auto iter = web_view_partition_id_map_.find(guest_process_id); |
| 100 if (iter != webview_partition_id_map_.end()) { | 99 if (iter != web_view_partition_id_map_.end()){ |
| 101 *partition_id = iter->second.partition_id; | 100 *partition_id = iter->second.partition_id; |
| 102 return true; | 101 return true; |
| 103 } | 102 } |
| 104 return false; | 103 return false; |
| 105 } | 104 } |
| 106 | 105 |
| 107 } // namespace extensions | 106 } // namespace extensions |
| OLD | NEW |