 Chromium Code Reviews
 Chromium Code Reviews Issue 2821473002:
  Service CreateNewWindow on the UI thread with a new mojo interface  (Closed)
    
  
    Issue 2821473002:
  Service CreateNewWindow on the UI thread with a new mojo interface  (Closed) 
  | OLD | NEW | 
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/android/webapps/single_tab_mode_tab_helper.h" | 5 #include "chrome/browser/android/webapps/single_tab_mode_tab_helper.h" | 
| 6 | 6 | 
| 7 #include "base/lazy_instance.h" | |
| 8 #include "chrome/browser/android/tab_android.h" | 7 #include "chrome/browser/android/tab_android.h" | 
| 9 #include "content/public/browser/browser_thread.h" | |
| 10 #include "content/public/browser/render_frame_host.h" | |
| 11 #include "content/public/browser/render_process_host.h" | |
| 12 #include "content/public/browser/web_contents.h" | 8 #include "content/public/browser/web_contents.h" | 
| 13 | 9 | 
| 14 DEFINE_WEB_CONTENTS_USER_DATA_KEY(SingleTabModeTabHelper); | 10 DEFINE_WEB_CONTENTS_USER_DATA_KEY(SingleTabModeTabHelper); | 
| 15 | 11 | 
| 16 namespace { | |
| 17 | |
| 18 typedef std::pair<int32_t, int32_t> RenderFrameHostID; | |
| 19 typedef std::set<RenderFrameHostID> SingleTabIDSet; | |
| 20 base::LazyInstance<SingleTabIDSet>::DestructorAtExit g_blocked_ids = | |
| 21 LAZY_INSTANCE_INITIALIZER; | |
| 22 | |
| 23 void AddPairOnIOThread(int32_t process_id, int32_t frame_routing_id) { | |
| 24 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | |
| 25 RenderFrameHostID single_tab_pair(process_id, frame_routing_id); | |
| 26 g_blocked_ids.Get().insert(single_tab_pair); | |
| 27 } | |
| 28 | |
| 29 void RemovePairOnIOThread(int32_t process_id, int32_t frame_routing_id) { | |
| 30 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | |
| 31 RenderFrameHostID single_tab_pair(process_id, frame_routing_id); | |
| 32 SingleTabIDSet::iterator itr = g_blocked_ids.Get().find(single_tab_pair); | |
| 33 DCHECK(itr != g_blocked_ids.Get().end()); | |
| 34 g_blocked_ids.Get().erase(itr); | |
| 35 } | |
| 36 | |
| 37 void AddPair(content::RenderFrameHost* render_frame_host) { | |
| 38 if (!render_frame_host) | |
| 39 return; | |
| 40 | |
| 41 int32_t process_id = render_frame_host->GetProcess()->GetID(); | |
| 42 int32_t frame_routing_id = render_frame_host->GetRoutingID(); | |
| 43 content::BrowserThread::PostTask( | |
| 44 content::BrowserThread::IO, FROM_HERE, | |
| 45 base::Bind(&AddPairOnIOThread, process_id, frame_routing_id)); | |
| 46 } | |
| 47 | |
| 48 void RemovePair(content::RenderFrameHost* render_frame_host) { | |
| 49 if (!render_frame_host) | |
| 50 return; | |
| 51 | |
| 52 int32_t process_id = render_frame_host->GetProcess()->GetID(); | |
| 53 int32_t frame_routing_id = render_frame_host->GetRoutingID(); | |
| 54 content::BrowserThread::PostTask( | |
| 55 content::BrowserThread::IO, FROM_HERE, | |
| 56 base::Bind(&RemovePairOnIOThread, process_id, frame_routing_id)); | |
| 57 } | |
| 58 | |
| 59 } // namespace | |
| 60 | |
| 61 SingleTabModeTabHelper::SingleTabModeTabHelper( | 12 SingleTabModeTabHelper::SingleTabModeTabHelper( | 
| 62 content::WebContents* web_contents) | 13 content::WebContents* web_contents) | 
| 63 : content::WebContentsObserver(web_contents), | 14 : web_contents_(web_contents) {} | 
| 64 block_all_new_windows_(false) { | |
| 65 } | |
| 66 | 15 | 
| 67 SingleTabModeTabHelper::~SingleTabModeTabHelper() { | 16 SingleTabModeTabHelper::~SingleTabModeTabHelper() {} | 
| 68 } | |
| 69 | |
| 70 void SingleTabModeTabHelper::RenderFrameCreated( | |
| 71 content::RenderFrameHost* render_frame_host) { | |
| 72 if (!block_all_new_windows_) | |
| 73 return; | |
| 74 AddPair(render_frame_host); | |
| 75 } | |
| 76 | |
| 77 void SingleTabModeTabHelper::RenderFrameDeleted( | |
| 78 content::RenderFrameHost* render_frame_host) { | |
| 79 if (!block_all_new_windows_) | |
| 80 return; | |
| 81 RemovePair(render_frame_host); | |
| 82 } | |
| 83 | 17 | 
| 84 void SingleTabModeTabHelper::PermanentlyBlockAllNewWindows() { | 18 void SingleTabModeTabHelper::PermanentlyBlockAllNewWindows() { | 
| 85 block_all_new_windows_ = true; | 19 block_all_new_windows_ = true; | 
| 86 for (content::RenderFrameHost* frame : web_contents()->GetAllFrames()) | |
| 87 AddPair(frame); | |
| 88 } | |
| 89 | |
| 90 bool SingleTabModeTabHelper::IsRegistered(int32_t process_id, | |
| 91 int32_t frame_routing_id) { | |
| 92 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | |
| 93 RenderFrameHostID single_tab_pair(process_id, frame_routing_id); | |
| 94 SingleTabIDSet::iterator itr = g_blocked_ids.Get().find(single_tab_pair); | |
| 95 return itr != g_blocked_ids.Get().end(); | |
| 96 } | 20 } | 
| 97 | 21 | 
| 98 void SingleTabModeTabHelper::HandleOpenUrl(const BlockedWindowParams& params) { | 22 void SingleTabModeTabHelper::HandleOpenUrl(const BlockedWindowParams& params) { | 
| 
Bernhard Bauer
2017/04/24 13:05:30
It looks like that was already the case, but this
 
Charlie Harrison
2017/04/24 14:04:03
Done, mostly because this removes the web_contents
 
Bernhard Bauer
2017/04/24 14:31:35
Exactly :) Sadly, it doesn't look like base::Suppo
 | |
| 99 TabAndroid* tab = TabAndroid::FromWebContents(web_contents()); | 23 TabAndroid* tab = TabAndroid::FromWebContents(web_contents_); | 
| 100 if (!tab) | 24 if (!tab) | 
| 101 return; | 25 return; | 
| 102 | 26 | 
| 103 chrome::NavigateParams nav_params = | 27 chrome::NavigateParams nav_params = | 
| 104 params.CreateNavigateParams(web_contents()); | 28 params.CreateNavigateParams(web_contents_); | 
| 105 tab->HandlePopupNavigation(&nav_params); | 29 tab->HandlePopupNavigation(&nav_params); | 
| 106 } | 30 } | 
| OLD | NEW |