| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/restore_tab_helper.h" |
| 10 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 10 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 11 #include "content/browser/renderer_host/render_process_host.h" | 11 #include "content/browser/renderer_host/render_process_host.h" |
| 12 #include "content/browser/renderer_host/render_view_host.h" | 12 #include "content/browser/renderer_host/render_view_host.h" |
| 13 #include "content/browser/tab_contents/navigation_details.h" |
| 13 #include "content/browser/tab_contents/tab_contents.h" | 14 #include "content/browser/tab_contents/tab_contents.h" |
| 14 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
| 15 #include "content/public/browser/notification_observer.h" | 16 #include "content/public/browser/notification_observer.h" |
| 16 #include "content/public/browser/notification_registrar.h" | 17 #include "content/public/browser/notification_registrar.h" |
| 17 #include "content/public/browser/notification_service.h" | 18 #include "content/public/browser/notification_service.h" |
| 18 #include "content/public/browser/notification_types.h" | 19 #include "content/public/browser/notification_types.h" |
| 19 | 20 |
| 20 // | 21 // |
| 21 // ExtensionTabIdMap::TabObserver | 22 // ExtensionTabIdMap::TabObserver |
| 22 // | 23 // |
| (...skipping 16 matching lines...) Expand all Loading... |
| 39 }; | 40 }; |
| 40 | 41 |
| 41 ExtensionTabIdMap::TabObserver::TabObserver() { | 42 ExtensionTabIdMap::TabObserver::TabObserver() { |
| 42 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 43 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 43 registrar_.Add(this, content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB, | 44 registrar_.Add(this, content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB, |
| 44 content::NotificationService::AllBrowserContextsAndSources()); | 45 content::NotificationService::AllBrowserContextsAndSources()); |
| 45 registrar_.Add(this, content::NOTIFICATION_RENDER_VIEW_HOST_DELETED, | 46 registrar_.Add(this, content::NOTIFICATION_RENDER_VIEW_HOST_DELETED, |
| 46 content::NotificationService::AllBrowserContextsAndSources()); | 47 content::NotificationService::AllBrowserContextsAndSources()); |
| 47 registrar_.Add(this, content::NOTIFICATION_TAB_PARENTED, | 48 registrar_.Add(this, content::NOTIFICATION_TAB_PARENTED, |
| 48 content::NotificationService::AllBrowserContextsAndSources()); | 49 content::NotificationService::AllBrowserContextsAndSources()); |
| 50 registrar_.Add(this, content::NOTIFICATION_RETARGETING, |
| 51 content::NotificationService::AllBrowserContextsAndSources()); |
| 49 } | 52 } |
| 50 | 53 |
| 51 ExtensionTabIdMap::TabObserver::~TabObserver() { | 54 ExtensionTabIdMap::TabObserver::~TabObserver() { |
| 52 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 55 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 53 } | 56 } |
| 54 | 57 |
| 55 void ExtensionTabIdMap::TabObserver::Observe( | 58 void ExtensionTabIdMap::TabObserver::Observe( |
| 56 int type, const content::NotificationSource& source, | 59 int type, const content::NotificationSource& source, |
| 57 const content::NotificationDetails& details) { | 60 const content::NotificationDetails& details) { |
| 58 switch (type) { | 61 switch (type) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 82 BrowserThread::PostTask( | 85 BrowserThread::PostTask( |
| 83 BrowserThread::IO, FROM_HERE, | 86 BrowserThread::IO, FROM_HERE, |
| 84 base::Bind( | 87 base::Bind( |
| 85 &ExtensionTabIdMap::SetTabAndWindowId, | 88 &ExtensionTabIdMap::SetTabAndWindowId, |
| 86 base::Unretained(ExtensionTabIdMap::GetInstance()), | 89 base::Unretained(ExtensionTabIdMap::GetInstance()), |
| 87 host->process()->id(), host->routing_id(), | 90 host->process()->id(), host->routing_id(), |
| 88 tab->restore_tab_helper()->session_id().id(), | 91 tab->restore_tab_helper()->session_id().id(), |
| 89 tab->restore_tab_helper()->window_id().id())); | 92 tab->restore_tab_helper()->window_id().id())); |
| 90 break; | 93 break; |
| 91 } | 94 } |
| 95 case content::NOTIFICATION_RETARGETING: { |
| 96 content::RetargetingDetails* retargeting_details = |
| 97 content::Details<content::RetargetingDetails>(details).ptr(); |
| 98 TabContents* contents = retargeting_details->target_tab_contents; |
| 99 TabContentsWrapper* tab = |
| 100 TabContentsWrapper::GetCurrentWrapperForContents(contents); |
| 101 if (!tab) |
| 102 break; |
| 103 RenderViewHost* host = tab->render_view_host(); |
| 104 BrowserThread::PostTask( |
| 105 BrowserThread::IO, FROM_HERE, |
| 106 base::Bind( |
| 107 &ExtensionTabIdMap::SetTabAndWindowId, |
| 108 base::Unretained(ExtensionTabIdMap::GetInstance()), |
| 109 host->process()->id(), host->routing_id(), |
| 110 tab->restore_tab_helper()->session_id().id(), |
| 111 tab->restore_tab_helper()->window_id().id())); |
| 112 break; |
| 113 } |
| 92 case content::NOTIFICATION_RENDER_VIEW_HOST_DELETED: { | 114 case content::NOTIFICATION_RENDER_VIEW_HOST_DELETED: { |
| 93 RenderViewHost* host = content::Source<RenderViewHost>(source).ptr(); | 115 RenderViewHost* host = content::Source<RenderViewHost>(source).ptr(); |
| 94 BrowserThread::PostTask( | 116 BrowserThread::PostTask( |
| 95 BrowserThread::IO, FROM_HERE, | 117 BrowserThread::IO, FROM_HERE, |
| 96 base::Bind( | 118 base::Bind( |
| 97 &ExtensionTabIdMap::ClearTabAndWindowId, | 119 &ExtensionTabIdMap::ClearTabAndWindowId, |
| 98 base::Unretained(ExtensionTabIdMap::GetInstance()), | 120 base::Unretained(ExtensionTabIdMap::GetInstance()), |
| 99 host->process()->id(), host->routing_id())); | 121 host->process()->id(), host->routing_id())); |
| 100 break; | 122 break; |
| 101 } | 123 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 169 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 148 RenderId render_id(render_process_host_id, routing_id); | 170 RenderId render_id(render_process_host_id, routing_id); |
| 149 TabAndWindowIdMap::iterator iter = map_.find(render_id); | 171 TabAndWindowIdMap::iterator iter = map_.find(render_id); |
| 150 if (iter != map_.end()) { | 172 if (iter != map_.end()) { |
| 151 *tab_id = iter->second.first; | 173 *tab_id = iter->second.first; |
| 152 *window_id = iter->second.second; | 174 *window_id = iter->second.second; |
| 153 return true; | 175 return true; |
| 154 } | 176 } |
| 155 return false; | 177 return false; |
| 156 } | 178 } |
| OLD | NEW |