Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(211)

Side by Side Diff: chrome/browser/android/webapps/single_tab_mode_tab_helper.cc

Issue 2821473002: Service CreateNewWindow on the UI thread with a new mojo interface (Closed)
Patch Set: MakeShared goodness Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
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"
13
14 DEFINE_WEB_CONTENTS_USER_DATA_KEY(SingleTabModeTabHelper); 7 DEFINE_WEB_CONTENTS_USER_DATA_KEY(SingleTabModeTabHelper);
15 8
16 namespace { 9 SingleTabModeTabHelper::SingleTabModeTabHelper(
10 content::WebContents* web_contents) {}
17 11
18 typedef std::pair<int32_t, int32_t> RenderFrameHostID; 12 SingleTabModeTabHelper::~SingleTabModeTabHelper() {}
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(
62 content::WebContents* web_contents)
63 : content::WebContentsObserver(web_contents),
64 block_all_new_windows_(false) {
65 }
66
67 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 13
84 void SingleTabModeTabHelper::PermanentlyBlockAllNewWindows() { 14 void SingleTabModeTabHelper::PermanentlyBlockAllNewWindows() {
85 block_all_new_windows_ = true; 15 block_all_new_windows_ = true;
86 for (content::RenderFrameHost* frame : web_contents()->GetAllFrames())
87 AddPair(frame);
88 } 16 }
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 }
97
98 void SingleTabModeTabHelper::HandleOpenUrl(const BlockedWindowParams& params) {
99 TabAndroid* tab = TabAndroid::FromWebContents(web_contents());
100 if (!tab)
101 return;
102
103 chrome::NavigateParams nav_params =
104 params.CreateNavigateParams(web_contents());
105 tab->HandlePopupNavigation(&nav_params);
106 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698