| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 13 #include "base/threading/thread.h" | 13 #include "base/threading/thread.h" |
| 14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
| 15 #include "chrome/browser/browser_process_impl.h" | 15 #include "chrome/browser/browser_process_impl.h" |
| 16 #include "chrome/browser/platform_util.h" | 16 #include "chrome/browser/platform_util.h" |
| 17 #include "chrome/browser/prefs/pref_service.h" | 17 #include "chrome/browser/prefs/pref_service.h" |
| 18 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 18 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 19 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
| 20 #include "content/public/browser/browser_thread.h" |
| 20 #include "googleurl/src/gurl.h" | 21 #include "googleurl/src/gurl.h" |
| 21 #include "net/base/escape.h" | 22 #include "net/base/escape.h" |
| 22 | 23 |
| 24 using content::BrowserThread; |
| 25 |
| 23 // Whether we accept requests for launching external protocols. This is set to | 26 // Whether we accept requests for launching external protocols. This is set to |
| 24 // false every time an external protocol is requested, and set back to true on | 27 // false every time an external protocol is requested, and set back to true on |
| 25 // each user gesture. This variable should only be accessed from the UI thread. | 28 // each user gesture. This variable should only be accessed from the UI thread. |
| 26 static bool g_accept_requests = true; | 29 static bool g_accept_requests = true; |
| 27 | 30 |
| 28 namespace { | 31 namespace { |
| 29 | 32 |
| 30 // Functions enabling unit testing. Using a NULL delegate will use the default | 33 // Functions enabling unit testing. Using a NULL delegate will use the default |
| 31 // behavior; if a delegate is provided it will be used instead. | 34 // behavior; if a delegate is provided it will be used instead. |
| 32 ShellIntegration::DefaultProtocolClientWorker* CreateShellWorker( | 35 ShellIntegration::DefaultProtocolClientWorker* CreateShellWorker( |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 } | 279 } |
| 277 | 280 |
| 278 // static | 281 // static |
| 279 void ExternalProtocolHandler::LaunchUrlWithoutSecurityCheck(const GURL& url) { | 282 void ExternalProtocolHandler::LaunchUrlWithoutSecurityCheck(const GURL& url) { |
| 280 #if defined(OS_MACOSX) | 283 #if defined(OS_MACOSX) |
| 281 // This must run on the UI thread on OS X. | 284 // This must run on the UI thread on OS X. |
| 282 platform_util::OpenExternal(url); | 285 platform_util::OpenExternal(url); |
| 283 #else | 286 #else |
| 284 // Otherwise put this work on the file thread. On Windows ShellExecute may | 287 // Otherwise put this work on the file thread. On Windows ShellExecute may |
| 285 // block for a significant amount of time, and it shouldn't hurt on Linux. | 288 // block for a significant amount of time, and it shouldn't hurt on Linux. |
| 286 MessageLoop* loop = g_browser_process->file_thread()->message_loop(); | 289 BrowserThread::PostTask( |
| 287 if (loop == NULL) { | 290 BrowserThread::FILE, |
| 288 return; | 291 FROM_HERE, |
| 289 } | 292 base::Bind(&platform_util::OpenExternal, url)); |
| 290 | |
| 291 loop->PostTask(FROM_HERE, base::Bind(&platform_util::OpenExternal, url)); | |
| 292 #endif | 293 #endif |
| 293 } | 294 } |
| 294 | 295 |
| 295 // static | 296 // static |
| 296 void ExternalProtocolHandler::RegisterPrefs(PrefService* prefs) { | 297 void ExternalProtocolHandler::RegisterPrefs(PrefService* prefs) { |
| 297 prefs->RegisterDictionaryPref(prefs::kExcludedSchemes); | 298 prefs->RegisterDictionaryPref(prefs::kExcludedSchemes); |
| 298 } | 299 } |
| 299 | 300 |
| 300 // static | 301 // static |
| 301 void ExternalProtocolHandler::PermitLaunchUrl() { | 302 void ExternalProtocolHandler::PermitLaunchUrl() { |
| 302 DCHECK_EQ(MessageLoop::TYPE_UI, MessageLoop::current()->type()); | 303 DCHECK_EQ(MessageLoop::TYPE_UI, MessageLoop::current()->type()); |
| 303 g_accept_requests = true; | 304 g_accept_requests = true; |
| 304 } | 305 } |
| OLD | NEW |