OLD | NEW |
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/platform_util.h" | 5 #include "chrome/browser/platform_util.h" |
6 | 6 |
7 #include "base/bind.h" | |
8 #include "chrome/browser/chromeos/file_manager/open_util.h" | 7 #include "chrome/browser/chromeos/file_manager/open_util.h" |
9 #include "chrome/browser/profiles/profile_manager.h" | |
10 #include "chrome/browser/ui/browser_navigator.h" | 8 #include "chrome/browser/ui/browser_navigator.h" |
11 #include "chrome/browser/ui/host_desktop.h" | |
12 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
13 #include "content/public/browser/browser_thread.h" | 9 #include "content/public/browser/browser_thread.h" |
14 #include "url/gurl.h" | 10 #include "url/gurl.h" |
15 | 11 |
16 using content::BrowserThread; | 12 using content::BrowserThread; |
17 | 13 |
18 namespace { | 14 namespace { |
19 | 15 |
20 const char kGmailComposeUrl[] = | 16 const char kGmailComposeUrl[] = |
21 "https://mail.google.com/mail/?extsrc=mailto&url="; | 17 "https://mail.google.com/mail/?extsrc=mailto&url="; |
22 | 18 |
23 void OpenURL(const std::string& url) { | |
24 // TODO(beng): improve this to locate context from call stack. | |
25 chrome::NavigateParams params( | |
26 ProfileManager::GetDefaultProfileOrOffTheRecord(), | |
27 GURL(url), | |
28 content::PAGE_TRANSITION_LINK); | |
29 params.disposition = NEW_FOREGROUND_TAB; | |
30 params.host_desktop_type = chrome::HOST_DESKTOP_TYPE_ASH; | |
31 chrome::Navigate(¶ms); | |
32 } | |
33 | |
34 } // namespace | 19 } // namespace |
35 | 20 |
36 namespace platform_util { | 21 namespace platform_util { |
37 | 22 |
38 void ShowItemInFolder(const base::FilePath& full_path) { | 23 void ShowItemInFolder(const base::FilePath& full_path) { |
39 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 24 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
40 file_manager::util::ShowItemInFolder(full_path); | 25 file_manager::util::ShowItemInFolder(full_path); |
41 } | 26 } |
42 | 27 |
43 void OpenItem(const base::FilePath& full_path) { | 28 void OpenItem(const base::FilePath& full_path) { |
44 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 29 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
45 file_manager::util::OpenItem(full_path); | 30 file_manager::util::OpenItem(full_path); |
46 } | 31 } |
47 | 32 |
48 void OpenExternal(const GURL& url) { | 33 void OpenExternal(Profile* profile, const GURL& url) { |
| 34 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 35 |
49 // This code should be obsolete since we have default handlers in ChromeOS | 36 // This code should be obsolete since we have default handlers in ChromeOS |
50 // which should handle this. However - there are two things which make it | 37 // which should handle this. However - there are two things which make it |
51 // necessary to keep it in: | 38 // necessary to keep it in: |
52 // a.) The user might have deleted the default handler in this session. | 39 // a.) The user might have deleted the default handler in this session. |
53 // In this case we would need to have this in place. | 40 // In this case we would need to have this in place. |
54 // b.) There are several code paths which are not clear if they would call | 41 // b.) There are several code paths which are not clear if they would call |
55 // this function directly and which would therefore break (e.g. | 42 // this function directly and which would therefore break (e.g. |
56 // "Browser::EmailPageLocation" (to name only one). | 43 // "Browser::EmailPageLocation" (to name only one). |
57 // As such we should keep this code here. | 44 // As such we should keep this code here. |
| 45 chrome::NavigateParams params(profile, url, content::PAGE_TRANSITION_LINK); |
| 46 params.disposition = NEW_FOREGROUND_TAB; |
| 47 params.host_desktop_type = chrome::HOST_DESKTOP_TYPE_ASH; |
| 48 |
58 if (url.SchemeIs("mailto")) { | 49 if (url.SchemeIs("mailto")) { |
59 std::string string_url = kGmailComposeUrl; | 50 std::string string_url = kGmailComposeUrl; |
60 string_url.append(url.spec()); | 51 string_url.append(url.spec()); |
61 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 52 params.url = GURL(url); |
62 base::Bind(OpenURL, string_url)); | |
63 } else if (url.is_valid()) { | |
64 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
65 base::Bind(OpenURL, url.spec())); | |
66 } | 53 } |
| 54 |
| 55 chrome::Navigate(¶ms); |
67 } | 56 } |
68 | 57 |
69 } // namespace platform_util | 58 } // namespace platform_util |
OLD | NEW |