Stop using GetDefaultProfile() in Chrome OS implementation of platform_util::OpenExternal()
Add Profile* as an argument of OpenExternal().
Disallow calling OpenExternal() from threads other than UI thread.
Changes for the implementations:
Chrome OS implementation: Use the argument Profile and stop posting tasks to UI thread.
Win implementation: Post tasks to FILE thread. (for the reason noted in external_protocol_handler.cc)
Other implementations: Just add Profile* argument and add thread check.
Changes for user code:
1. first_run_dialog.cc: Just pass Profile*.
2. browser_commands.cc: Pass Profile* acquired from Browser.
3. chrome_shell_window_delegate.cc: Pass Profile* acquired from WebContents.
4. external_protocol_handler.cc: Pass Profile* acquired with a pair of render_process_host_id and tab_contents_id.
BUG=322682
TEST=git cl try
Review URL: https://codereview.chromium.org/107033003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@240346 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/external_protocol/external_protocol_handler.cc b/chrome/browser/external_protocol/external_protocol_handler.cc
index 2f9b4d9f..291652d5 100644
--- a/chrome/browser/external_protocol/external_protocol_handler.cc
+++ b/chrome/browser/external_protocol/external_protocol_handler.cc
@@ -17,8 +17,11 @@
#include "build/build_config.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/platform_util.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/tab_contents/tab_util.h"
#include "chrome/common/pref_names.h"
#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/web_contents.h"
#include "net/base/escape.h"
#include "url/gurl.h"
@@ -70,11 +73,15 @@
void LaunchUrlWithoutSecurityCheckWithDelegate(
const GURL& url,
+ int render_process_host_id,
+ int tab_contents_id,
ExternalProtocolHandler::Delegate* delegate) {
- if (!delegate)
- ExternalProtocolHandler::LaunchUrlWithoutSecurityCheck(url);
- else
+ if (!delegate) {
+ ExternalProtocolHandler::LaunchUrlWithoutSecurityCheck(
+ url, render_process_host_id, tab_contents_id);
+ } else {
delegate->LaunchUrlWithoutSecurityCheck(url);
+ }
}
// When we are about to launch a URL with the default OS level application,
@@ -124,7 +131,8 @@
return;
}
- LaunchUrlWithoutSecurityCheckWithDelegate(escaped_url_, delegate_);
+ LaunchUrlWithoutSecurityCheckWithDelegate(
+ escaped_url_, render_process_host_id_, tab_contents_id_, delegate_);
}
virtual bool IsOwnedByWorker() OVERRIDE { return true; }
@@ -282,18 +290,17 @@
}
// static
-void ExternalProtocolHandler::LaunchUrlWithoutSecurityCheck(const GURL& url) {
-#if defined(OS_MACOSX)
- // This must run on the UI thread on OS X.
- platform_util::OpenExternal(url);
-#else
- // Otherwise put this work on the file thread. On Windows ShellExecute may
- // block for a significant amount of time, and it shouldn't hurt on Linux.
- BrowserThread::PostTask(
- BrowserThread::FILE,
- FROM_HERE,
- base::Bind(&platform_util::OpenExternal, url));
-#endif
+void ExternalProtocolHandler::LaunchUrlWithoutSecurityCheck(
+ const GURL& url,
+ int render_process_host_id,
+ int tab_contents_id) {
+ content::WebContents* web_contents = tab_util::GetWebContentsByID(
+ render_process_host_id, tab_contents_id);
+ if (!web_contents)
+ return;
+
+ platform_util::OpenExternal(
+ Profile::FromBrowserContext(web_contents->GetBrowserContext()), url);
}
// static