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

Side by Side Diff: chrome/browser/external_protocol/external_protocol_handler.cc

Issue 2076253002: Simplify the text in the external protocol confirmation dialog. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix ChromeOS compile Created 4 years, 2 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 (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/external_protocol/external_protocol_handler.h" 5 #include "chrome/browser/external_protocol/external_protocol_handler.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <set> 9 #include <set>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/message_loop/message_loop.h" 14 #include "base/message_loop/message_loop.h"
15 #include "base/metrics/histogram_macros.h"
15 #include "base/strings/string_util.h" 16 #include "base/strings/string_util.h"
16 #include "base/threading/thread.h" 17 #include "base/threading/thread.h"
17 #include "build/build_config.h" 18 #include "build/build_config.h"
18 #include "chrome/browser/browser_process.h" 19 #include "chrome/browser/browser_process.h"
19 #include "chrome/browser/platform_util.h" 20 #include "chrome/browser/platform_util.h"
20 #include "chrome/browser/profiles/profile.h" 21 #include "chrome/browser/profiles/profile.h"
21 #include "chrome/browser/tab_contents/tab_util.h" 22 #include "chrome/browser/tab_contents/tab_util.h"
22 #include "chrome/common/pref_names.h" 23 #include "chrome/common/pref_names.h"
23 #include "components/prefs/pref_registry_simple.h" 24 #include "components/prefs/pref_registry_simple.h"
24 #include "components/prefs/pref_service.h" 25 #include "components/prefs/pref_service.h"
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 return; 125 return;
125 } 126 }
126 127
127 LaunchUrlWithoutSecurityCheckWithDelegate(escaped_url, render_process_host_id, 128 LaunchUrlWithoutSecurityCheckWithDelegate(escaped_url, render_process_host_id,
128 tab_contents_id, delegate); 129 tab_contents_id, delegate);
129 } 130 }
130 131
131 } // namespace 132 } // namespace
132 133
133 // static 134 // static
134 void ExternalProtocolHandler::PrepopulateDictionary(
135 base::DictionaryValue* win_pref) {
136 static bool is_warm = false;
137 if (is_warm)
138 return;
139 is_warm = true;
140
141 static const char* const denied_schemes[] = {
142 "afp",
143 "data",
144 "disk",
145 "disks",
146 // ShellExecuting file:///C:/WINDOWS/system32/notepad.exe will simply
147 // execute the file specified! Hopefully we won't see any "file" schemes
148 // because we think of file:// URLs as handled URLs, but better to be safe
149 // than to let an attacker format the user's hard drive.
150 "file",
151 "hcp",
152 "javascript",
153 "ms-help",
154 "nntp",
155 "shell",
156 "vbscript",
157 // view-source is a special case in chrome. When it comes through an
158 // iframe or a redirect, it looks like an external protocol, but we don't
159 // want to shellexecute it.
160 "view-source",
161 "vnd.ms.radio",
162 };
163
164 static const char* const allowed_schemes[] = {
165 "mailto",
166 "news",
167 "snews",
168 };
169
170 bool should_block;
171 for (size_t i = 0; i < arraysize(denied_schemes); ++i) {
172 if (!win_pref->GetBoolean(denied_schemes[i], &should_block)) {
173 win_pref->SetBoolean(denied_schemes[i], true);
174 }
175 }
176
177 for (size_t i = 0; i < arraysize(allowed_schemes); ++i) {
178 if (!win_pref->GetBoolean(allowed_schemes[i], &should_block)) {
179 win_pref->SetBoolean(allowed_schemes[i], false);
180 }
181 }
182 }
183
184 // static
185 ExternalProtocolHandler::BlockState ExternalProtocolHandler::GetBlockState( 135 ExternalProtocolHandler::BlockState ExternalProtocolHandler::GetBlockState(
186 const std::string& scheme) { 136 const std::string& scheme) {
187 // If we are being carpet bombed, block the request. 137 // If we are being carpet bombed, block the request.
188 if (!g_accept_requests) 138 if (!g_accept_requests)
189 return BLOCK; 139 return BLOCK;
190 140
191 if (scheme.length() == 1) { 141 if (scheme.length() == 1) {
192 // We have a URL that looks something like: 142 // We have a URL that looks something like:
193 // C:/WINDOWS/system32/notepad.exe 143 // C:/WINDOWS/system32/notepad.exe
194 // ShellExecuting this URL will cause the specified program to be executed. 144 // ShellExecuting this URL will cause the specified program to be executed.
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 content::WebContents* web_contents = tab_util::GetWebContentsByID( 227 content::WebContents* web_contents = tab_util::GetWebContentsByID(
278 render_process_host_id, tab_contents_id); 228 render_process_host_id, tab_contents_id);
279 if (!web_contents) 229 if (!web_contents)
280 return; 230 return;
281 231
282 platform_util::OpenExternal( 232 platform_util::OpenExternal(
283 Profile::FromBrowserContext(web_contents->GetBrowserContext()), url); 233 Profile::FromBrowserContext(web_contents->GetBrowserContext()), url);
284 } 234 }
285 235
286 // static 236 // static
287 void ExternalProtocolHandler::RegisterPrefs(PrefRegistrySimple* registry) {
288 registry->RegisterDictionaryPref(prefs::kExcludedSchemes);
289 }
290
291 // static
292 void ExternalProtocolHandler::PermitLaunchUrl() { 237 void ExternalProtocolHandler::PermitLaunchUrl() {
293 DCHECK(base::MessageLoopForUI::IsCurrent()); 238 DCHECK(base::MessageLoopForUI::IsCurrent());
294 g_accept_requests = true; 239 g_accept_requests = true;
295 } 240 }
241
242 // static
243 void ExternalProtocolHandler::PrepopulateDictionary(
244 base::DictionaryValue* win_pref) {
245 static bool is_warm = false;
246 if (is_warm)
247 return;
248 is_warm = true;
249
250 static const char* const denied_schemes[] = {
251 "afp",
252 "data",
253 "disk",
254 "disks",
255 // ShellExecuting file:///C:/WINDOWS/system32/notepad.exe will simply
256 // execute the file specified! Hopefully we won't see any "file" schemes
257 // because we think of file:// URLs as handled URLs, but better to be safe
258 // than to let an attacker format the user's hard drive.
259 "file",
260 "hcp",
261 "javascript",
262 "ms-help",
263 "nntp",
264 "shell",
265 "vbscript",
266 // view-source is a special case in chrome. When it comes through an
267 // iframe or a redirect, it looks like an external protocol, but we don't
268 // want to shellexecute it.
269 "view-source",
270 "vnd.ms.radio",
271 };
272
273 static const char* const allowed_schemes[] = {
274 "mailto",
275 "news",
276 "snews",
277 };
278
279 bool should_block;
280 for (size_t i = 0; i < arraysize(denied_schemes); ++i) {
281 if (!win_pref->GetBoolean(denied_schemes[i], &should_block)) {
282 win_pref->SetBoolean(denied_schemes[i], true);
283 }
284 }
285
286 for (size_t i = 0; i < arraysize(allowed_schemes); ++i) {
287 if (!win_pref->GetBoolean(allowed_schemes[i], &should_block)) {
288 win_pref->SetBoolean(allowed_schemes[i], false);
289 }
290 }
291 }
292
293 // static
294 void ExternalProtocolHandler::RecordMetrics(bool selected) {
295 UMA_HISTOGRAM_BOOLEAN("BrowserDialogs.ExternalProtocol.RememberCheckbox",
296 selected);
297 }
298
299 // static
300 void ExternalProtocolHandler::RegisterPrefs(PrefRegistrySimple* registry) {
301 registry->RegisterDictionaryPref(prefs::kExcludedSchemes);
302 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698