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/ui/browser_navigator.h" | 5 #include "chrome/browser/ui/browser_navigator.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 // Returns true if the specified Browser can open tabs. Not all Browsers support | 74 // Returns true if the specified Browser can open tabs. Not all Browsers support |
75 // multiple tabs, such as app frames and popups. This function returns false for | 75 // multiple tabs, such as app frames and popups. This function returns false for |
76 // those types of Browser. | 76 // those types of Browser. |
77 bool WindowCanOpenTabs(Browser* browser) { | 77 bool WindowCanOpenTabs(Browser* browser) { |
78 return browser->CanSupportWindowFeature(Browser::FEATURE_TABSTRIP) || | 78 return browser->CanSupportWindowFeature(Browser::FEATURE_TABSTRIP) || |
79 browser->tab_strip_model()->empty(); | 79 browser->tab_strip_model()->empty(); |
80 } | 80 } |
81 | 81 |
82 // Finds an existing Browser compatible with |profile|, making a new one if no | 82 // Finds an existing Browser compatible with |profile|, making a new one if no |
83 // such Browser is located. | 83 // such Browser is located. |
84 Browser* GetOrCreateBrowser(Profile* profile) { | 84 Browser* GetOrCreateBrowser(Profile* profile, bool user_gesture) { |
85 Browser* browser = chrome::FindTabbedBrowser(profile, false); | 85 Browser* browser = chrome::FindTabbedBrowser(profile, false); |
86 return browser ? browser : new Browser(Browser::CreateParams(profile)); | 86 return browser ? browser |
| 87 : new Browser(Browser::CreateParams(profile, user_gesture)); |
87 } | 88 } |
88 | 89 |
89 // Change some of the navigation parameters based on the particular URL. | 90 // Change some of the navigation parameters based on the particular URL. |
90 // Currently this applies to some chrome:// pages which we always want to open | 91 // Currently this applies to some chrome:// pages which we always want to open |
91 // in a non-incognito window. Note that even though a ChromeOS guest session is | 92 // in a non-incognito window. Note that even though a ChromeOS guest session is |
92 // technically an incognito window, these URLs are allowed. | 93 // technically an incognito window, these URLs are allowed. |
93 // Returns true on success. Otherwise, if changing params leads the browser into | 94 // Returns true on success. Otherwise, if changing params leads the browser into |
94 // an erroneous state, returns false. | 95 // an erroneous state, returns false. |
95 bool AdjustNavigateParamsForURL(chrome::NavigateParams* params) { | 96 bool AdjustNavigateParamsForURL(chrome::NavigateParams* params) { |
96 if (params->target_contents != NULL || | 97 if (params->target_contents != NULL || |
(...skipping 10 matching lines...) Expand all Loading... |
107 profile = profile->GetOriginalProfile(); | 108 profile = profile->GetOriginalProfile(); |
108 | 109 |
109 // If incognito is forced, we punt. | 110 // If incognito is forced, we punt. |
110 PrefService* prefs = profile->GetPrefs(); | 111 PrefService* prefs = profile->GetPrefs(); |
111 if (prefs && IncognitoModePrefs::GetAvailability(prefs) == | 112 if (prefs && IncognitoModePrefs::GetAvailability(prefs) == |
112 IncognitoModePrefs::FORCED) { | 113 IncognitoModePrefs::FORCED) { |
113 return false; | 114 return false; |
114 } | 115 } |
115 | 116 |
116 params->disposition = WindowOpenDisposition::SINGLETON_TAB; | 117 params->disposition = WindowOpenDisposition::SINGLETON_TAB; |
117 params->browser = GetOrCreateBrowser(profile); | 118 params->browser = GetOrCreateBrowser(profile, params->user_gesture); |
118 params->window_action = chrome::NavigateParams::SHOW_WINDOW; | 119 params->window_action = chrome::NavigateParams::SHOW_WINDOW; |
119 } | 120 } |
120 | 121 |
121 return true; | 122 return true; |
122 } | 123 } |
123 | 124 |
124 // Returns a Browser that can host the navigation or tab addition specified in | 125 // Returns a Browser that can host the navigation or tab addition specified in |
125 // |params|. This might just return the same Browser specified in |params|, or | 126 // |params|. This might just return the same Browser specified in |params|, or |
126 // some other if that Browser is deemed incompatible. | 127 // some other if that Browser is deemed incompatible. |
127 Browser* GetBrowserForDisposition(chrome::NavigateParams* params) { | 128 Browser* GetBrowserForDisposition(chrome::NavigateParams* params) { |
128 // If no source WebContents was specified, we use the selected one from | 129 // If no source WebContents was specified, we use the selected one from |
129 // the target browser. This must happen first, before | 130 // the target browser. This must happen first, before |
130 // GetBrowserForDisposition() has a chance to replace |params->browser| with | 131 // GetBrowserForDisposition() has a chance to replace |params->browser| with |
131 // another one. | 132 // another one. |
132 if (!params->source_contents && params->browser) { | 133 if (!params->source_contents && params->browser) { |
133 params->source_contents = | 134 params->source_contents = |
134 params->browser->tab_strip_model()->GetActiveWebContents(); | 135 params->browser->tab_strip_model()->GetActiveWebContents(); |
135 } | 136 } |
136 | 137 |
137 Profile* profile = params->initiating_profile; | 138 Profile* profile = params->initiating_profile; |
138 | 139 |
139 switch (params->disposition) { | 140 switch (params->disposition) { |
140 case WindowOpenDisposition::CURRENT_TAB: | 141 case WindowOpenDisposition::CURRENT_TAB: |
141 if (params->browser) | 142 if (params->browser) |
142 return params->browser; | 143 return params->browser; |
143 // Find a compatible window and re-execute this command in it. Otherwise | 144 // Find a compatible window and re-execute this command in it. Otherwise |
144 // re-run with NEW_WINDOW. | 145 // re-run with NEW_WINDOW. |
145 return GetOrCreateBrowser(profile); | 146 return GetOrCreateBrowser(profile, params->user_gesture); |
146 case WindowOpenDisposition::SINGLETON_TAB: | 147 case WindowOpenDisposition::SINGLETON_TAB: |
147 case WindowOpenDisposition::NEW_FOREGROUND_TAB: | 148 case WindowOpenDisposition::NEW_FOREGROUND_TAB: |
148 case WindowOpenDisposition::NEW_BACKGROUND_TAB: | 149 case WindowOpenDisposition::NEW_BACKGROUND_TAB: |
149 // See if we can open the tab in the window this navigator is bound to. | 150 // See if we can open the tab in the window this navigator is bound to. |
150 if (params->browser && WindowCanOpenTabs(params->browser)) | 151 if (params->browser && WindowCanOpenTabs(params->browser)) |
151 return params->browser; | 152 return params->browser; |
152 // Find a compatible window and re-execute this command in it. Otherwise | 153 // Find a compatible window and re-execute this command in it. Otherwise |
153 // re-run with NEW_WINDOW. | 154 // re-run with NEW_WINDOW. |
154 return GetOrCreateBrowser(profile); | 155 return GetOrCreateBrowser(profile, params->user_gesture); |
155 case WindowOpenDisposition::NEW_POPUP: { | 156 case WindowOpenDisposition::NEW_POPUP: { |
156 // Make a new popup window. | 157 // Make a new popup window. |
157 // Coerce app-style if |source| represents an app. | 158 // Coerce app-style if |source| represents an app. |
158 std::string app_name; | 159 std::string app_name; |
159 #if BUILDFLAG(ENABLE_EXTENSIONS) | 160 #if BUILDFLAG(ENABLE_EXTENSIONS) |
160 if (!params->extension_app_id.empty()) { | 161 if (!params->extension_app_id.empty()) { |
161 app_name = web_app::GenerateApplicationNameFromExtensionId( | 162 app_name = web_app::GenerateApplicationNameFromExtensionId( |
162 params->extension_app_id); | 163 params->extension_app_id); |
163 } else if (params->browser && !params->browser->app_name().empty()) { | 164 } else if (params->browser && !params->browser->app_name().empty()) { |
164 app_name = params->browser->app_name(); | 165 app_name = params->browser->app_name(); |
165 } else if (params->source_contents) { | 166 } else if (params->source_contents) { |
166 extensions::TabHelper* extensions_tab_helper = | 167 extensions::TabHelper* extensions_tab_helper = |
167 extensions::TabHelper::FromWebContents(params->source_contents); | 168 extensions::TabHelper::FromWebContents(params->source_contents); |
168 if (extensions_tab_helper && extensions_tab_helper->is_app()) { | 169 if (extensions_tab_helper && extensions_tab_helper->is_app()) { |
169 app_name = web_app::GenerateApplicationNameFromExtensionId( | 170 app_name = web_app::GenerateApplicationNameFromExtensionId( |
170 extensions_tab_helper->extension_app()->id()); | 171 extensions_tab_helper->extension_app()->id()); |
171 } | 172 } |
172 } | 173 } |
173 #endif | 174 #endif |
174 if (app_name.empty()) { | 175 if (app_name.empty()) { |
175 Browser::CreateParams browser_params(Browser::TYPE_POPUP, profile); | 176 Browser::CreateParams browser_params(Browser::TYPE_POPUP, profile, |
| 177 params->user_gesture); |
176 browser_params.trusted_source = params->trusted_source; | 178 browser_params.trusted_source = params->trusted_source; |
177 browser_params.initial_bounds = params->window_bounds; | 179 browser_params.initial_bounds = params->window_bounds; |
178 return new Browser(browser_params); | 180 return new Browser(browser_params); |
179 } | 181 } |
180 | 182 |
181 return new Browser(Browser::CreateParams::CreateForApp( | 183 return new Browser(Browser::CreateParams::CreateForApp( |
182 app_name, params->trusted_source, params->window_bounds, profile)); | 184 app_name, params->trusted_source, params->window_bounds, profile, |
| 185 params->user_gesture)); |
183 } | 186 } |
184 case WindowOpenDisposition::NEW_WINDOW: { | 187 case WindowOpenDisposition::NEW_WINDOW: { |
185 // Make a new normal browser window. | 188 // Make a new normal browser window. |
186 return new Browser(Browser::CreateParams(profile)); | 189 return new Browser(Browser::CreateParams(profile, params->user_gesture)); |
187 } | 190 } |
188 case WindowOpenDisposition::OFF_THE_RECORD: | 191 case WindowOpenDisposition::OFF_THE_RECORD: |
189 // Make or find an incognito window. | 192 // Make or find an incognito window. |
190 return GetOrCreateBrowser(profile->GetOffTheRecordProfile()); | 193 return GetOrCreateBrowser(profile->GetOffTheRecordProfile(), |
| 194 params->user_gesture); |
191 // The following types result in no navigation. | 195 // The following types result in no navigation. |
192 case WindowOpenDisposition::SAVE_TO_DISK: | 196 case WindowOpenDisposition::SAVE_TO_DISK: |
193 case WindowOpenDisposition::IGNORE_ACTION: | 197 case WindowOpenDisposition::IGNORE_ACTION: |
194 return NULL; | 198 return NULL; |
195 default: | 199 default: |
196 NOTREACHED(); | 200 NOTREACHED(); |
197 } | 201 } |
198 return NULL; | 202 return NULL; |
199 } | 203 } |
200 | 204 |
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
667 bool reverse_on_redirect = false; | 671 bool reverse_on_redirect = false; |
668 content::BrowserURLHandler::GetInstance()->RewriteURLIfNecessary( | 672 content::BrowserURLHandler::GetInstance()->RewriteURLIfNecessary( |
669 &rewritten_url, browser_context, &reverse_on_redirect); | 673 &rewritten_url, browser_context, &reverse_on_redirect); |
670 | 674 |
671 // Some URLs are mapped to uber subpages. Do not allow them in incognito. | 675 // Some URLs are mapped to uber subpages. Do not allow them in incognito. |
672 return !(rewritten_url.scheme_piece() == content::kChromeUIScheme && | 676 return !(rewritten_url.scheme_piece() == content::kChromeUIScheme && |
673 rewritten_url.host_piece() == chrome::kChromeUIUberHost); | 677 rewritten_url.host_piece() == chrome::kChromeUIUberHost); |
674 } | 678 } |
675 | 679 |
676 } // namespace chrome | 680 } // namespace chrome |
OLD | NEW |