| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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_handler.h" | 5 #include "chrome/browser/external_protocol_handler.h" |
| 6 | 6 |
| 7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
| 8 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 | 10 |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
| 13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 14 #include "base/thread.h" | 14 #include "base/thread.h" |
| 15 #include "chrome/browser/browser.h" | 15 #include "chrome/browser/browser.h" |
| 16 #include "chrome/browser/browser_process_impl.h" | 16 #include "chrome/browser/browser_process_impl.h" |
| 17 #include "chrome/common/platform_util.h" | 17 #include "chrome/common/platform_util.h" |
| 18 #include "chrome/common/pref_service.h" | 18 #include "chrome/common/pref_service.h" |
| 19 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
| 20 #include "googleurl/src/gurl.h" | 20 #include "googleurl/src/gurl.h" |
| 21 #include "net/base/escape.h" | 21 #include "net/base/escape.h" |
| 22 | 22 |
| 23 #if defined(OS_WIN) | |
| 24 #include "chrome/browser/views/external_protocol_dialog.h" | |
| 25 #endif | |
| 26 | |
| 27 // static | 23 // static |
| 28 void ExternalProtocolHandler::PrepopulateDictionary(DictionaryValue* win_pref) { | 24 void ExternalProtocolHandler::PrepopulateDictionary(DictionaryValue* win_pref) { |
| 29 static bool is_warm = false; | 25 static bool is_warm = false; |
| 30 if (is_warm) | 26 if (is_warm) |
| 31 return; | 27 return; |
| 32 is_warm = true; | 28 is_warm = true; |
| 33 | 29 |
| 34 static const wchar_t* const denied_schemes[] = { | 30 static const wchar_t* const denied_schemes[] = { |
| 35 L"afp", | 31 L"afp", |
| 36 L"data", | 32 L"data", |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 int render_process_host_id, | 105 int render_process_host_id, |
| 110 int tab_contents_id) { | 106 int tab_contents_id) { |
| 111 // Escape the input scheme to be sure that the command does not | 107 // Escape the input scheme to be sure that the command does not |
| 112 // have parameters unexpected by the external program. | 108 // have parameters unexpected by the external program. |
| 113 std::string escaped_url_string = EscapeExternalHandlerValue(url.spec()); | 109 std::string escaped_url_string = EscapeExternalHandlerValue(url.spec()); |
| 114 GURL escaped_url(escaped_url_string); | 110 GURL escaped_url(escaped_url_string); |
| 115 BlockState block_state = GetBlockState(ASCIIToWide(escaped_url.scheme())); | 111 BlockState block_state = GetBlockState(ASCIIToWide(escaped_url.scheme())); |
| 116 if (block_state == BLOCK) | 112 if (block_state == BLOCK) |
| 117 return; | 113 return; |
| 118 | 114 |
| 119 #if defined(OS_WIN) | |
| 120 if (block_state == UNKNOWN) { | 115 if (block_state == UNKNOWN) { |
| 121 std::wstring command = ExternalProtocolDialog::GetApplicationForProtocol( | 116 #if !defined(OS_MACOSX) |
| 122 escaped_url); | |
| 123 if (command.empty()) { | |
| 124 // ShellExecute won't do anything. Don't bother warning the user. | |
| 125 return; | |
| 126 } | |
| 127 | |
| 128 // Ask the user if they want to allow the protocol. This will call | 117 // Ask the user if they want to allow the protocol. This will call |
| 129 // LaunchUrlWithoutSecurityCheck if the user decides to accept the protocol. | 118 // LaunchUrlWithoutSecurityCheck if the user decides to accept the protocol. |
| 130 ExternalProtocolDialog::RunExternalProtocolDialog(escaped_url, | 119 RunExternalProtocolDialog(escaped_url, |
| 131 command, | 120 render_process_host_id, |
| 132 render_process_host_id, | 121 tab_contents_id); |
| 133 tab_contents_id); | 122 #endif |
| 123 // For now, allow only whitelisted protocols to fire on Mac. |
| 124 // See http://crbug.com/15546. |
| 134 return; | 125 return; |
| 135 } | 126 } |
| 136 #else | |
| 137 // For now, allow only whitelisted protocols to fire. | |
| 138 // TODO(port): implement dialog for Mac/Linux. | |
| 139 // See http://code.google.com/p/chromium/issues/detail?id=20731 | |
| 140 // and http://code.google.com/p/chromium/issues/detail?id=15546. | |
| 141 if (block_state == UNKNOWN) | |
| 142 return; | |
| 143 #endif | |
| 144 | 127 |
| 145 // Otherwise the protocol is white-listed, so go ahead and launch. | 128 LaunchUrlWithoutSecurityCheck(escaped_url); |
| 129 } |
| 130 |
| 131 // static |
| 132 void ExternalProtocolHandler::LaunchUrlWithoutSecurityCheck(const GURL& url) { |
| 146 #if defined(OS_MACOSX) | 133 #if defined(OS_MACOSX) |
| 147 // This must run on the main thread on OS X. | 134 // This must run on the main thread on OS X. |
| 148 LaunchUrlWithoutSecurityCheck(escaped_url); | 135 platform_util::OpenExternal(url); |
| 149 #else | 136 #else |
| 150 // Otherwise put this work on the file thread. On Windows ShellExecute may | 137 // Otherwise put this work on the file thread. On Windows ShellExecute may |
| 151 // block for a significant amount of time, and it shouldn't hurt on Linux. | 138 // block for a significant amount of time, and it shouldn't hurt on Linux. |
| 152 MessageLoop* loop = g_browser_process->file_thread()->message_loop(); | 139 MessageLoop* loop = g_browser_process->file_thread()->message_loop(); |
| 153 if (loop == NULL) { | 140 if (loop == NULL) { |
| 154 return; | 141 return; |
| 155 } | 142 } |
| 156 | 143 |
| 157 loop->PostTask(FROM_HERE, | 144 loop->PostTask(FROM_HERE, |
| 158 NewRunnableFunction( | 145 NewRunnableFunction(&platform_util::OpenExternal, url)); |
| 159 &ExternalProtocolHandler::LaunchUrlWithoutSecurityCheck, | |
| 160 escaped_url)); | |
| 161 #endif | 146 #endif |
| 162 } | 147 } |
| 163 | 148 |
| 164 // static | 149 // static |
| 165 void ExternalProtocolHandler::LaunchUrlWithoutSecurityCheck(const GURL& url) { | |
| 166 platform_util::OpenExternal(url); | |
| 167 } | |
| 168 | |
| 169 // static | |
| 170 void ExternalProtocolHandler::RegisterPrefs(PrefService* prefs) { | 150 void ExternalProtocolHandler::RegisterPrefs(PrefService* prefs) { |
| 171 prefs->RegisterDictionaryPref(prefs::kExcludedSchemes); | 151 prefs->RegisterDictionaryPref(prefs::kExcludedSchemes); |
| 172 } | 152 } |
| OLD | NEW |