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 #ifndef CHROME_BROWSER_ANDROID_WEBAPPS_SINGLE_TAB_MODE_TAB_HELPER_H_ | 5 #ifndef CHROME_BROWSER_ANDROID_WEBAPPS_SINGLE_TAB_MODE_TAB_HELPER_H_ |
6 #define CHROME_BROWSER_ANDROID_WEBAPPS_SINGLE_TAB_MODE_TAB_HELPER_H_ | 6 #define CHROME_BROWSER_ANDROID_WEBAPPS_SINGLE_TAB_MODE_TAB_HELPER_H_ |
7 | 7 |
8 #include <stdint.h> | |
9 | |
10 #include <set> | |
11 | |
12 #include "base/compiler_specific.h" | |
13 #include "base/macros.h" | 8 #include "base/macros.h" |
14 #include "chrome/browser/ui/blocked_content/blocked_window_params.h" | 9 #include "chrome/browser/ui/blocked_content/blocked_window_params.h" |
15 #include "content/public/browser/web_contents_observer.h" | |
16 #include "content/public/browser/web_contents_user_data.h" | 10 #include "content/public/browser/web_contents_user_data.h" |
17 | 11 |
18 // Registers and unregisters the IDs of renderers in single tab mode, which | 12 namespace content { |
19 // are disallowed from opening new windows via | 13 class WebContents; |
20 // ChromeContentBrowserClient::CanCreateWindow(). | 14 } |
| 15 |
| 16 // Tracks tabs in single tab mode, which are disallowed from opening new windows |
| 17 // via ChromeContentBrowserClient::CanCreateWindow(). |
21 class SingleTabModeTabHelper | 18 class SingleTabModeTabHelper |
22 : public content::WebContentsObserver, | 19 : public content::WebContentsUserData<SingleTabModeTabHelper> { |
23 public content::WebContentsUserData<SingleTabModeTabHelper> { | |
24 public: | 20 public: |
25 // Checks if the ID pair is blocked from creating new windows. IO-thread only. | 21 ~SingleTabModeTabHelper() override; |
26 static bool IsRegistered(int32_t process_id, int32_t routing_id); | |
27 | 22 |
28 ~SingleTabModeTabHelper() override; | 23 bool block_all_new_windows() const { return block_all_new_windows_; } |
29 | 24 |
30 // Handles opening the given URL through the TabModel. | 25 // Handles opening the given URL through the TabModel. |
31 void HandleOpenUrl(const BlockedWindowParams& params); | 26 void HandleOpenUrl(const BlockedWindowParams& params); |
32 | 27 |
33 // Permanently block this WebContents from creating new windows -- there is no | 28 // Permanently block this WebContents from creating new windows -- there is no |
34 // current need to allow toggling this flag on or off. | 29 // current need to allow toggling this flag on or off. |
35 void PermanentlyBlockAllNewWindows(); | 30 void PermanentlyBlockAllNewWindows(); |
36 | 31 |
37 // content::WebContentsObserver | |
38 void RenderFrameCreated(content::RenderFrameHost* render_frame_host) override; | |
39 void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override; | |
40 | |
41 private: | 32 private: |
42 explicit SingleTabModeTabHelper(content::WebContents* web_contents); | 33 explicit SingleTabModeTabHelper(content::WebContents* web_contents); |
43 friend class content::WebContentsUserData<SingleTabModeTabHelper>; | 34 friend class content::WebContentsUserData<SingleTabModeTabHelper>; |
44 | 35 |
45 bool block_all_new_windows_; | 36 content::WebContents* web_contents_; |
| 37 bool block_all_new_windows_ = false; |
46 | 38 |
47 DISALLOW_COPY_AND_ASSIGN(SingleTabModeTabHelper); | 39 DISALLOW_COPY_AND_ASSIGN(SingleTabModeTabHelper); |
48 }; | 40 }; |
49 | 41 |
50 #endif // CHROME_BROWSER_ANDROID_WEBAPPS_SINGLE_TAB_MODE_TAB_HELPER_H_ | 42 #endif // CHROME_BROWSER_ANDROID_WEBAPPS_SINGLE_TAB_MODE_TAB_HELPER_H_ |
OLD | NEW |