| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/extensions/extension_tab_id_map.h" | 5 #include "chrome/browser/extensions/extension_tab_id_map.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "chrome/browser/sessions/restore_tab_helper.h" | 9 #include "chrome/browser/sessions/session_tab_helper.h" |
| 10 #include "chrome/browser/tab_contents/retargeting_details.h" | 10 #include "chrome/browser/tab_contents/retargeting_details.h" |
| 11 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 11 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 12 #include "chrome/common/chrome_notification_types.h" | 12 #include "chrome/common/chrome_notification_types.h" |
| 13 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
| 14 #include "content/public/browser/navigation_details.h" | 14 #include "content/public/browser/navigation_details.h" |
| 15 #include "content/public/browser/notification_observer.h" | 15 #include "content/public/browser/notification_observer.h" |
| 16 #include "content/public/browser/notification_registrar.h" | 16 #include "content/public/browser/notification_registrar.h" |
| 17 #include "content/public/browser/notification_service.h" | 17 #include "content/public/browser/notification_service.h" |
| 18 #include "content/public/browser/notification_types.h" | 18 #include "content/public/browser/notification_types.h" |
| 19 #include "content/public/browser/render_process_host.h" | 19 #include "content/public/browser/render_process_host.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 break; | 73 break; |
| 74 RenderViewHost* host = content::Details<RenderViewHost>(details).ptr(); | 74 RenderViewHost* host = content::Details<RenderViewHost>(details).ptr(); |
| 75 // TODO(mpcmoplete): How can we tell if window_id is bogus? It may not | 75 // TODO(mpcmoplete): How can we tell if window_id is bogus? It may not |
| 76 // have been set yet. | 76 // have been set yet. |
| 77 BrowserThread::PostTask( | 77 BrowserThread::PostTask( |
| 78 BrowserThread::IO, FROM_HERE, | 78 BrowserThread::IO, FROM_HERE, |
| 79 base::Bind( | 79 base::Bind( |
| 80 &ExtensionTabIdMap::SetTabAndWindowId, | 80 &ExtensionTabIdMap::SetTabAndWindowId, |
| 81 base::Unretained(ExtensionTabIdMap::GetInstance()), | 81 base::Unretained(ExtensionTabIdMap::GetInstance()), |
| 82 host->GetProcess()->GetID(), host->GetRoutingID(), | 82 host->GetProcess()->GetID(), host->GetRoutingID(), |
| 83 tab->restore_tab_helper()->session_id().id(), | 83 tab->session_tab_helper()->session_id().id(), |
| 84 tab->restore_tab_helper()->window_id().id())); | 84 tab->session_tab_helper()->window_id().id())); |
| 85 break; | 85 break; |
| 86 } | 86 } |
| 87 case chrome::NOTIFICATION_TAB_PARENTED: { | 87 case chrome::NOTIFICATION_TAB_PARENTED: { |
| 88 TabContents* tab = | 88 TabContents* tab = |
| 89 content::Source<TabContents>(source).ptr(); | 89 content::Source<TabContents>(source).ptr(); |
| 90 RenderViewHost* host = tab->web_contents()->GetRenderViewHost(); | 90 RenderViewHost* host = tab->web_contents()->GetRenderViewHost(); |
| 91 BrowserThread::PostTask( | 91 BrowserThread::PostTask( |
| 92 BrowserThread::IO, FROM_HERE, | 92 BrowserThread::IO, FROM_HERE, |
| 93 base::Bind( | 93 base::Bind( |
| 94 &ExtensionTabIdMap::SetTabAndWindowId, | 94 &ExtensionTabIdMap::SetTabAndWindowId, |
| 95 base::Unretained(ExtensionTabIdMap::GetInstance()), | 95 base::Unretained(ExtensionTabIdMap::GetInstance()), |
| 96 host->GetProcess()->GetID(), host->GetRoutingID(), | 96 host->GetProcess()->GetID(), host->GetRoutingID(), |
| 97 tab->restore_tab_helper()->session_id().id(), | 97 tab->session_tab_helper()->session_id().id(), |
| 98 tab->restore_tab_helper()->window_id().id())); | 98 tab->session_tab_helper()->window_id().id())); |
| 99 break; | 99 break; |
| 100 } | 100 } |
| 101 case chrome::NOTIFICATION_RETARGETING: { | 101 case chrome::NOTIFICATION_RETARGETING: { |
| 102 RetargetingDetails* retargeting_details = | 102 RetargetingDetails* retargeting_details = |
| 103 content::Details<RetargetingDetails>(details).ptr(); | 103 content::Details<RetargetingDetails>(details).ptr(); |
| 104 WebContents* contents = retargeting_details->target_web_contents; | 104 WebContents* contents = retargeting_details->target_web_contents; |
| 105 TabContents* tab = TabContents::FromWebContents(contents); | 105 TabContents* tab = TabContents::FromWebContents(contents); |
| 106 if (!tab) | 106 if (!tab) |
| 107 break; | 107 break; |
| 108 RenderViewHost* host = contents->GetRenderViewHost(); | 108 RenderViewHost* host = contents->GetRenderViewHost(); |
| 109 BrowserThread::PostTask( | 109 BrowserThread::PostTask( |
| 110 BrowserThread::IO, FROM_HERE, | 110 BrowserThread::IO, FROM_HERE, |
| 111 base::Bind( | 111 base::Bind( |
| 112 &ExtensionTabIdMap::SetTabAndWindowId, | 112 &ExtensionTabIdMap::SetTabAndWindowId, |
| 113 base::Unretained(ExtensionTabIdMap::GetInstance()), | 113 base::Unretained(ExtensionTabIdMap::GetInstance()), |
| 114 host->GetProcess()->GetID(), host->GetRoutingID(), | 114 host->GetProcess()->GetID(), host->GetRoutingID(), |
| 115 tab->restore_tab_helper()->session_id().id(), | 115 tab->session_tab_helper()->session_id().id(), |
| 116 tab->restore_tab_helper()->window_id().id())); | 116 tab->session_tab_helper()->window_id().id())); |
| 117 break; | 117 break; |
| 118 } | 118 } |
| 119 case content::NOTIFICATION_RENDER_VIEW_HOST_DELETED: { | 119 case content::NOTIFICATION_RENDER_VIEW_HOST_DELETED: { |
| 120 RenderViewHost* host = content::Source<RenderViewHost>(source).ptr(); | 120 RenderViewHost* host = content::Source<RenderViewHost>(source).ptr(); |
| 121 BrowserThread::PostTask( | 121 BrowserThread::PostTask( |
| 122 BrowserThread::IO, FROM_HERE, | 122 BrowserThread::IO, FROM_HERE, |
| 123 base::Bind( | 123 base::Bind( |
| 124 &ExtensionTabIdMap::ClearTabAndWindowId, | 124 &ExtensionTabIdMap::ClearTabAndWindowId, |
| 125 base::Unretained(ExtensionTabIdMap::GetInstance()), | 125 base::Unretained(ExtensionTabIdMap::GetInstance()), |
| 126 host->GetProcess()->GetID(), host->GetRoutingID())); | 126 host->GetProcess()->GetID(), host->GetRoutingID())); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 174 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 175 RenderId render_id(render_process_host_id, routing_id); | 175 RenderId render_id(render_process_host_id, routing_id); |
| 176 TabAndWindowIdMap::iterator iter = map_.find(render_id); | 176 TabAndWindowIdMap::iterator iter = map_.find(render_id); |
| 177 if (iter != map_.end()) { | 177 if (iter != map_.end()) { |
| 178 *tab_id = iter->second.first; | 178 *tab_id = iter->second.first; |
| 179 *window_id = iter->second.second; | 179 *window_id = iter->second.second; |
| 180 return true; | 180 return true; |
| 181 } | 181 } |
| 182 return false; | 182 return false; |
| 183 } | 183 } |
| OLD | NEW |