| 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/restore_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_wrapper.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" |
| 20 #include "content/public/browser/render_view_host.h" | 20 #include "content/public/browser/render_view_host.h" |
| 21 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 ExtensionTabIdMap::TabObserver::~TabObserver() { | 60 ExtensionTabIdMap::TabObserver::~TabObserver() { |
| 61 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 61 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 62 } | 62 } |
| 63 | 63 |
| 64 void ExtensionTabIdMap::TabObserver::Observe( | 64 void ExtensionTabIdMap::TabObserver::Observe( |
| 65 int type, const content::NotificationSource& source, | 65 int type, const content::NotificationSource& source, |
| 66 const content::NotificationDetails& details) { | 66 const content::NotificationDetails& details) { |
| 67 switch (type) { | 67 switch (type) { |
| 68 case content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB: { | 68 case content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB: { |
| 69 WebContents* contents = content::Source<WebContents>(source).ptr(); | 69 WebContents* contents = content::Source<WebContents>(source).ptr(); |
| 70 TabContentsWrapper* tab = | 70 TabContents* tab = TabContents::FromWebContents(contents); |
| 71 TabContentsWrapper::GetCurrentWrapperForContents(contents); | |
| 72 if (!tab) | 71 if (!tab) |
| 73 break; | 72 break; |
| 74 RenderViewHost* host = content::Details<RenderViewHost>(details).ptr(); | 73 RenderViewHost* host = content::Details<RenderViewHost>(details).ptr(); |
| 75 // TODO(mpcmoplete): How can we tell if window_id is bogus? It may not | 74 // TODO(mpcmoplete): How can we tell if window_id is bogus? It may not |
| 76 // have been set yet. | 75 // have been set yet. |
| 77 BrowserThread::PostTask( | 76 BrowserThread::PostTask( |
| 78 BrowserThread::IO, FROM_HERE, | 77 BrowserThread::IO, FROM_HERE, |
| 79 base::Bind( | 78 base::Bind( |
| 80 &ExtensionTabIdMap::SetTabAndWindowId, | 79 &ExtensionTabIdMap::SetTabAndWindowId, |
| 81 base::Unretained(ExtensionTabIdMap::GetInstance()), | 80 base::Unretained(ExtensionTabIdMap::GetInstance()), |
| 82 host->GetProcess()->GetID(), host->GetRoutingID(), | 81 host->GetProcess()->GetID(), host->GetRoutingID(), |
| 83 tab->restore_tab_helper()->session_id().id(), | 82 tab->restore_tab_helper()->session_id().id(), |
| 84 tab->restore_tab_helper()->window_id().id())); | 83 tab->restore_tab_helper()->window_id().id())); |
| 85 break; | 84 break; |
| 86 } | 85 } |
| 87 case chrome::NOTIFICATION_TAB_PARENTED: { | 86 case chrome::NOTIFICATION_TAB_PARENTED: { |
| 88 TabContentsWrapper* tab = | 87 TabContents* tab = |
| 89 content::Source<TabContentsWrapper>(source).ptr(); | 88 content::Source<TabContents>(source).ptr(); |
| 90 RenderViewHost* host = tab->web_contents()->GetRenderViewHost(); | 89 RenderViewHost* host = tab->web_contents()->GetRenderViewHost(); |
| 91 BrowserThread::PostTask( | 90 BrowserThread::PostTask( |
| 92 BrowserThread::IO, FROM_HERE, | 91 BrowserThread::IO, FROM_HERE, |
| 93 base::Bind( | 92 base::Bind( |
| 94 &ExtensionTabIdMap::SetTabAndWindowId, | 93 &ExtensionTabIdMap::SetTabAndWindowId, |
| 95 base::Unretained(ExtensionTabIdMap::GetInstance()), | 94 base::Unretained(ExtensionTabIdMap::GetInstance()), |
| 96 host->GetProcess()->GetID(), host->GetRoutingID(), | 95 host->GetProcess()->GetID(), host->GetRoutingID(), |
| 97 tab->restore_tab_helper()->session_id().id(), | 96 tab->restore_tab_helper()->session_id().id(), |
| 98 tab->restore_tab_helper()->window_id().id())); | 97 tab->restore_tab_helper()->window_id().id())); |
| 99 break; | 98 break; |
| 100 } | 99 } |
| 101 case chrome::NOTIFICATION_RETARGETING: { | 100 case chrome::NOTIFICATION_RETARGETING: { |
| 102 RetargetingDetails* retargeting_details = | 101 RetargetingDetails* retargeting_details = |
| 103 content::Details<RetargetingDetails>(details).ptr(); | 102 content::Details<RetargetingDetails>(details).ptr(); |
| 104 WebContents* contents = retargeting_details->target_web_contents; | 103 WebContents* contents = retargeting_details->target_web_contents; |
| 105 TabContentsWrapper* tab = | 104 TabContents* tab = TabContents::FromWebContents(contents); |
| 106 TabContentsWrapper::GetCurrentWrapperForContents(contents); | |
| 107 if (!tab) | 105 if (!tab) |
| 108 break; | 106 break; |
| 109 RenderViewHost* host = contents->GetRenderViewHost(); | 107 RenderViewHost* host = contents->GetRenderViewHost(); |
| 110 BrowserThread::PostTask( | 108 BrowserThread::PostTask( |
| 111 BrowserThread::IO, FROM_HERE, | 109 BrowserThread::IO, FROM_HERE, |
| 112 base::Bind( | 110 base::Bind( |
| 113 &ExtensionTabIdMap::SetTabAndWindowId, | 111 &ExtensionTabIdMap::SetTabAndWindowId, |
| 114 base::Unretained(ExtensionTabIdMap::GetInstance()), | 112 base::Unretained(ExtensionTabIdMap::GetInstance()), |
| 115 host->GetProcess()->GetID(), host->GetRoutingID(), | 113 host->GetProcess()->GetID(), host->GetRoutingID(), |
| 116 tab->restore_tab_helper()->session_id().id(), | 114 tab->restore_tab_helper()->session_id().id(), |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 173 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 176 RenderId render_id(render_process_host_id, routing_id); | 174 RenderId render_id(render_process_host_id, routing_id); |
| 177 TabAndWindowIdMap::iterator iter = map_.find(render_id); | 175 TabAndWindowIdMap::iterator iter = map_.find(render_id); |
| 178 if (iter != map_.end()) { | 176 if (iter != map_.end()) { |
| 179 *tab_id = iter->second.first; | 177 *tab_id = iter->second.first; |
| 180 *window_id = iter->second.second; | 178 *window_id = iter->second.second; |
| 181 return true; | 179 return true; |
| 182 } | 180 } |
| 183 return false; | 181 return false; |
| 184 } | 182 } |
| OLD | NEW |