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

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

Issue 107033003: Stop using GetDefaultProfile() in Chrome OS implementation of platform_util::OpenExternal() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years 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 | Annotate | Revision Log
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 <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/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/prefs/pref_registry_simple.h" 12 #include "base/prefs/pref_registry_simple.h"
13 #include "base/prefs/pref_service.h" 13 #include "base/prefs/pref_service.h"
14 #include "base/prefs/scoped_user_pref_update.h" 14 #include "base/prefs/scoped_user_pref_update.h"
15 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
16 #include "base/threading/thread.h" 16 #include "base/threading/thread.h"
17 #include "build/build_config.h" 17 #include "build/build_config.h"
18 #include "chrome/browser/browser_process.h" 18 #include "chrome/browser/browser_process.h"
19 #include "chrome/browser/platform_util.h" 19 #include "chrome/browser/platform_util.h"
20 #include "chrome/browser/profiles/profile.h"
21 #include "chrome/browser/tab_contents/tab_util.h"
20 #include "chrome/common/pref_names.h" 22 #include "chrome/common/pref_names.h"
21 #include "content/public/browser/browser_thread.h" 23 #include "content/public/browser/browser_thread.h"
24 #include "content/public/browser/web_contents.h"
22 #include "net/base/escape.h" 25 #include "net/base/escape.h"
23 #include "url/gurl.h" 26 #include "url/gurl.h"
24 27
25 using content::BrowserThread; 28 using content::BrowserThread;
26 29
27 // Whether we accept requests for launching external protocols. This is set to 30 // Whether we accept requests for launching external protocols. This is set to
28 // false every time an external protocol is requested, and set back to true on 31 // false every time an external protocol is requested, and set back to true on
29 // each user gesture. This variable should only be accessed from the UI thread. 32 // each user gesture. This variable should only be accessed from the UI thread.
30 static bool g_accept_requests = true; 33 static bool g_accept_requests = true;
31 34
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 render_process_host_id, 66 render_process_host_id,
64 routing_id); 67 routing_id);
65 } else { 68 } else {
66 delegate->RunExternalProtocolDialog(url, render_process_host_id, 69 delegate->RunExternalProtocolDialog(url, render_process_host_id,
67 routing_id); 70 routing_id);
68 } 71 }
69 } 72 }
70 73
71 void LaunchUrlWithoutSecurityCheckWithDelegate( 74 void LaunchUrlWithoutSecurityCheckWithDelegate(
72 const GURL& url, 75 const GURL& url,
76 int render_process_host_id,
77 int tab_contents_id,
73 ExternalProtocolHandler::Delegate* delegate) { 78 ExternalProtocolHandler::Delegate* delegate) {
74 if (!delegate) 79 if (!delegate) {
75 ExternalProtocolHandler::LaunchUrlWithoutSecurityCheck(url); 80 ExternalProtocolHandler::LaunchUrlWithoutSecurityCheck(
76 else 81 url, render_process_host_id, tab_contents_id);
82 } else {
77 delegate->LaunchUrlWithoutSecurityCheck(url); 83 delegate->LaunchUrlWithoutSecurityCheck(url);
84 }
78 } 85 }
79 86
80 // When we are about to launch a URL with the default OS level application, 87 // When we are about to launch a URL with the default OS level application,
81 // we check if that external application will be us. If it is we just ignore 88 // we check if that external application will be us. If it is we just ignore
82 // the request. 89 // the request.
83 class ExternalDefaultProtocolObserver 90 class ExternalDefaultProtocolObserver
84 : public ShellIntegration::DefaultWebClientObserver { 91 : public ShellIntegration::DefaultWebClientObserver {
85 public: 92 public:
86 ExternalDefaultProtocolObserver(const GURL& escaped_url, 93 ExternalDefaultProtocolObserver(const GURL& escaped_url,
87 int render_process_host_id, 94 int render_process_host_id,
(...skipping 29 matching lines...) Expand all
117 // what the default is, so we proceed. 124 // what the default is, so we proceed.
118 if (prompt_user_) { 125 if (prompt_user_) {
119 // Ask the user if they want to allow the protocol. This will call 126 // Ask the user if they want to allow the protocol. This will call
120 // LaunchUrlWithoutSecurityCheck if the user decides to accept the 127 // LaunchUrlWithoutSecurityCheck if the user decides to accept the
121 // protocol. 128 // protocol.
122 RunExternalProtocolDialogWithDelegate(escaped_url_, 129 RunExternalProtocolDialogWithDelegate(escaped_url_,
123 render_process_host_id_, tab_contents_id_, delegate_); 130 render_process_host_id_, tab_contents_id_, delegate_);
124 return; 131 return;
125 } 132 }
126 133
127 LaunchUrlWithoutSecurityCheckWithDelegate(escaped_url_, delegate_); 134 LaunchUrlWithoutSecurityCheckWithDelegate(
135 escaped_url_, render_process_host_id_, tab_contents_id_, delegate_);
128 } 136 }
129 137
130 virtual bool IsOwnedByWorker() OVERRIDE { return true; } 138 virtual bool IsOwnedByWorker() OVERRIDE { return true; }
131 139
132 private: 140 private:
133 ExternalProtocolHandler::Delegate* delegate_; 141 ExternalProtocolHandler::Delegate* delegate_;
134 GURL escaped_url_; 142 GURL escaped_url_;
135 int render_process_host_id_; 143 int render_process_host_id_;
136 int tab_contents_id_; 144 int tab_contents_id_;
137 bool prompt_user_; 145 bool prompt_user_;
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 scoped_refptr<ShellIntegration::DefaultProtocolClientWorker> worker = 283 scoped_refptr<ShellIntegration::DefaultProtocolClientWorker> worker =
276 CreateShellWorker(observer, escaped_url.scheme(), delegate); 284 CreateShellWorker(observer, escaped_url.scheme(), delegate);
277 285
278 // Start the check process running. This will send tasks to the FILE thread 286 // Start the check process running. This will send tasks to the FILE thread
279 // and when the answer is known will send the result back to the observer on 287 // and when the answer is known will send the result back to the observer on
280 // the UI thread. 288 // the UI thread.
281 worker->StartCheckIsDefault(); 289 worker->StartCheckIsDefault();
282 } 290 }
283 291
284 // static 292 // static
285 void ExternalProtocolHandler::LaunchUrlWithoutSecurityCheck(const GURL& url) { 293 void ExternalProtocolHandler::LaunchUrlWithoutSecurityCheck(
286 #if defined(OS_MACOSX) 294 const GURL& url,
287 // This must run on the UI thread on OS X. 295 int render_process_host_id,
288 platform_util::OpenExternal(url); 296 int tab_contents_id) {
289 #else 297 content::WebContents* web_contents = tab_util::GetWebContentsByID(
sky 2013/12/10 17:32:11 Can't this code be passed the Profile?
hashimoto 2013/12/11 08:57:51 I preferred receiving a pair of int to Profile* be
sky 2013/12/11 15:19:25 If this goes through different threads, keep what
290 // Otherwise put this work on the file thread. On Windows ShellExecute may 298 render_process_host_id, tab_contents_id);
291 // block for a significant amount of time, and it shouldn't hurt on Linux. 299 if (!web_contents)
292 BrowserThread::PostTask( 300 return;
293 BrowserThread::FILE, 301
294 FROM_HERE, 302 platform_util::OpenExternal(
295 base::Bind(&platform_util::OpenExternal, url)); 303 Profile::FromBrowserContext(web_contents->GetBrowserContext()), url);
296 #endif
297 } 304 }
298 305
299 // static 306 // static
300 void ExternalProtocolHandler::RegisterPrefs(PrefRegistrySimple* registry) { 307 void ExternalProtocolHandler::RegisterPrefs(PrefRegistrySimple* registry) {
301 registry->RegisterDictionaryPref(prefs::kExcludedSchemes); 308 registry->RegisterDictionaryPref(prefs::kExcludedSchemes);
302 } 309 }
303 310
304 // static 311 // static
305 void ExternalProtocolHandler::PermitLaunchUrl() { 312 void ExternalProtocolHandler::PermitLaunchUrl() {
306 DCHECK_EQ(base::MessageLoop::TYPE_UI, base::MessageLoop::current()->type()); 313 DCHECK_EQ(base::MessageLoop::TYPE_UI, base::MessageLoop::current()->type());
307 g_accept_requests = true; 314 g_accept_requests = true;
308 } 315 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698