OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/chromeos/extensions/file_manager/open_with_browser.h" | 5 #include "chrome/browser/chromeos/extensions/file_manager/open_with_browser.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 bool IsViewableInBrowser(const base::FilePath& file_path) { | 70 bool IsViewableInBrowser(const base::FilePath& file_path) { |
71 for (size_t i = 0; i < arraysize(kFileExtensionsViewableInBrowser); i++) { | 71 for (size_t i = 0; i < arraysize(kFileExtensionsViewableInBrowser); i++) { |
72 if (file_path.MatchesExtension(kFileExtensionsViewableInBrowser[i])) | 72 if (file_path.MatchesExtension(kFileExtensionsViewableInBrowser[i])) |
73 return true; | 73 return true; |
74 } | 74 } |
75 return false; | 75 return false; |
76 } | 76 } |
77 | 77 |
78 bool IsPepperPluginEnabled(Profile* profile, | 78 bool IsPepperPluginEnabled(Profile* profile, |
79 const base::FilePath& plugin_path) { | 79 const base::FilePath& plugin_path) { |
| 80 DCHECK(profile); |
| 81 |
80 content::PepperPluginInfo* pepper_info = | 82 content::PepperPluginInfo* pepper_info = |
81 PluginService::GetInstance()->GetRegisteredPpapiPluginInfo(plugin_path); | 83 PluginService::GetInstance()->GetRegisteredPpapiPluginInfo(plugin_path); |
82 if (!pepper_info) | 84 if (!pepper_info) |
83 return false; | 85 return false; |
84 | 86 |
85 scoped_refptr<PluginPrefs> plugin_prefs = PluginPrefs::GetForProfile(profile); | 87 scoped_refptr<PluginPrefs> plugin_prefs = PluginPrefs::GetForProfile(profile); |
86 if (!plugin_prefs.get()) | 88 if (!plugin_prefs.get()) |
87 return false; | 89 return false; |
88 | 90 |
89 return plugin_prefs->IsPluginEnabled(pepper_info->ToWebPluginInfo()); | 91 return plugin_prefs->IsPluginEnabled(pepper_info->ToWebPluginInfo()); |
90 } | 92 } |
91 | 93 |
92 bool IsPdfPluginEnabled(Profile* profile) { | 94 bool IsPdfPluginEnabled(Profile* profile) { |
| 95 DCHECK(profile); |
| 96 |
93 base::FilePath plugin_path; | 97 base::FilePath plugin_path; |
94 PathService::Get(chrome::FILE_PDF_PLUGIN, &plugin_path); | 98 PathService::Get(chrome::FILE_PDF_PLUGIN, &plugin_path); |
95 return IsPepperPluginEnabled(profile, plugin_path); | 99 return IsPepperPluginEnabled(profile, plugin_path); |
96 } | 100 } |
97 | 101 |
98 bool IsFlashPluginEnabled(Profile* profile) { | 102 bool IsFlashPluginEnabled(Profile* profile) { |
| 103 DCHECK(profile); |
| 104 |
99 base::FilePath plugin_path( | 105 base::FilePath plugin_path( |
100 CommandLine::ForCurrentProcess()->GetSwitchValueNative( | 106 CommandLine::ForCurrentProcess()->GetSwitchValueNative( |
101 switches::kPpapiFlashPath)); | 107 switches::kPpapiFlashPath)); |
102 if (plugin_path.empty()) | 108 if (plugin_path.empty()) |
103 PathService::Get(chrome::FILE_PEPPER_FLASH_PLUGIN, &plugin_path); | 109 PathService::Get(chrome::FILE_PEPPER_FLASH_PLUGIN, &plugin_path); |
104 return IsPepperPluginEnabled(profile, plugin_path); | 110 return IsPepperPluginEnabled(profile, plugin_path); |
105 } | 111 } |
106 | 112 |
107 void OpenNewTab(Profile* profile, const GURL& url) { | 113 void OpenNewTab(Profile* profile, const GURL& url) { |
| 114 DCHECK(profile); |
| 115 |
108 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 116 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
109 Browser* browser = chrome::FindOrCreateTabbedBrowser( | 117 Browser* browser = chrome::FindOrCreateTabbedBrowser( |
110 profile ? profile : ProfileManager::GetDefaultProfileOrOffTheRecord(), | 118 profile, chrome::HOST_DESKTOP_TYPE_ASH); |
111 chrome::HOST_DESKTOP_TYPE_ASH); | |
112 chrome::AddSelectedTabWithURL(browser, url, content::PAGE_TRANSITION_LINK); | 119 chrome::AddSelectedTabWithURL(browser, url, content::PAGE_TRANSITION_LINK); |
113 // If the current browser is not tabbed then the new tab will be created | 120 // If the current browser is not tabbed then the new tab will be created |
114 // in a different browser. Make sure it is visible. | 121 // in a different browser. Make sure it is visible. |
115 browser->window()->Show(); | 122 browser->window()->Show(); |
116 } | 123 } |
117 | 124 |
118 void InstallCRX(Browser* browser, const base::FilePath& file_path) { | 125 void InstallCRX(Profile* profile, const base::FilePath& file_path) { |
| 126 DCHECK(profile); |
| 127 |
119 ExtensionService* service = | 128 ExtensionService* service = |
120 extensions::ExtensionSystem::Get(browser->profile())->extension_service(); | 129 extensions::ExtensionSystem::Get(profile)->extension_service(); |
121 CHECK(service); | 130 CHECK(service); |
122 | 131 |
123 scoped_refptr<extensions::CrxInstaller> installer( | 132 scoped_refptr<extensions::CrxInstaller> installer( |
124 extensions::CrxInstaller::Create( | 133 extensions::CrxInstaller::Create( |
125 service, | 134 service, |
126 scoped_ptr<ExtensionInstallPrompt>(new ExtensionInstallPrompt( | 135 scoped_ptr<ExtensionInstallPrompt>(new ExtensionInstallPrompt( |
127 browser->profile(), NULL, NULL)))); | 136 profile, NULL, NULL)))); |
128 installer->set_error_on_unsupported_requirements(true); | 137 installer->set_error_on_unsupported_requirements(true); |
129 installer->set_is_gallery_install(false); | 138 installer->set_is_gallery_install(false); |
130 installer->set_allow_silent_install(false); | 139 installer->set_allow_silent_install(false); |
131 installer->InstallCrx(file_path); | 140 installer->InstallCrx(file_path); |
132 } | 141 } |
133 | 142 |
134 // Called when a crx file on Drive was downloaded. | 143 // Called when a crx file on Drive was downloaded. |
135 void OnCRXDownloadCallback(Browser* browser, | 144 void OnCRXDownloadCallback(Profile* profile, |
136 drive::FileError error, | 145 drive::FileError error, |
137 const base::FilePath& file, | 146 const base::FilePath& file, |
138 scoped_ptr<drive::ResourceEntry> entry) { | 147 scoped_ptr<drive::ResourceEntry> entry) { |
| 148 DCHECK(profile); |
| 149 |
139 if (error != drive::FILE_ERROR_OK) | 150 if (error != drive::FILE_ERROR_OK) |
140 return; | 151 return; |
141 InstallCRX(browser, file); | 152 InstallCRX(profile, file); |
142 } | 153 } |
143 | 154 |
144 // Reads the alternate URL from a GDoc file. When it fails, returns a file URL | 155 // Reads the alternate URL from a GDoc file. When it fails, returns a file URL |
145 // for |file_path| as fallback. | 156 // for |file_path| as fallback. |
146 // Note that an alternate url is a URL to open a hosted document. | 157 // Note that an alternate url is a URL to open a hosted document. |
147 GURL ReadUrlFromGDocOnBlockingPool(const base::FilePath& file_path) { | 158 GURL ReadUrlFromGDocOnBlockingPool(const base::FilePath& file_path) { |
148 GURL url = drive::util::ReadUrlFromGDocFile(file_path); | 159 GURL url = drive::util::ReadUrlFromGDocFile(file_path); |
149 if (url.is_empty()) | 160 if (url.is_empty()) |
150 url = net::FilePathToFileURL(file_path); | 161 url = net::FilePathToFileURL(file_path); |
151 return url; | 162 return url; |
152 } | 163 } |
153 | 164 |
154 } // namespace | 165 } // namespace |
155 | 166 |
156 bool OpenFileWithBrowser(Browser* browser, const base::FilePath& file_path) { | 167 bool OpenFileWithBrowser(Profile* profile, const base::FilePath& file_path) { |
157 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 168 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 169 DCHECK(profile); |
158 | 170 |
159 Profile* profile = browser->profile(); | |
160 // For things supported natively by the browser, we should open it | 171 // For things supported natively by the browser, we should open it |
161 // in a tab. | 172 // in a tab. |
162 if (IsViewableInBrowser(file_path) || | 173 if (IsViewableInBrowser(file_path) || |
163 ShouldBeOpenedWithPlugin(profile, file_path.Extension())) { | 174 ShouldBeOpenedWithPlugin(profile, file_path.Extension())) { |
164 GURL page_url = net::FilePathToFileURL(file_path); | 175 GURL page_url = net::FilePathToFileURL(file_path); |
165 // Override drive resource to point to internal handler instead of file URL. | 176 // Override drive resource to point to internal handler instead of file URL. |
166 if (drive::util::IsUnderDriveMountPoint(file_path)) { | 177 if (drive::util::IsUnderDriveMountPoint(file_path)) { |
167 page_url = drive::util::FilePathToDriveURL( | 178 page_url = drive::util::FilePathToDriveURL( |
168 drive::util::ExtractDrivePath(file_path)); | 179 drive::util::ExtractDrivePath(file_path)); |
169 } | 180 } |
(...skipping 20 matching lines...) Expand all Loading... |
190 } | 201 } |
191 | 202 |
192 if (file_path.MatchesExtension(kCRXExtension)) { | 203 if (file_path.MatchesExtension(kCRXExtension)) { |
193 if (drive::util::IsUnderDriveMountPoint(file_path)) { | 204 if (drive::util::IsUnderDriveMountPoint(file_path)) { |
194 drive::DriveIntegrationService* integration_service = | 205 drive::DriveIntegrationService* integration_service = |
195 drive::DriveIntegrationServiceFactory::GetForProfile(profile); | 206 drive::DriveIntegrationServiceFactory::GetForProfile(profile); |
196 if (!integration_service) | 207 if (!integration_service) |
197 return false; | 208 return false; |
198 integration_service->file_system()->GetFileByPath( | 209 integration_service->file_system()->GetFileByPath( |
199 drive::util::ExtractDrivePath(file_path), | 210 drive::util::ExtractDrivePath(file_path), |
200 base::Bind(&OnCRXDownloadCallback, browser)); | 211 base::Bind(&OnCRXDownloadCallback, profile)); |
201 } else { | 212 } else { |
202 InstallCRX(browser, file_path); | 213 InstallCRX(profile, file_path); |
203 } | 214 } |
204 return true; | 215 return true; |
205 } | 216 } |
206 | 217 |
207 // Failed to open the file of unknown type. | 218 // Failed to open the file of unknown type. |
208 LOG(WARNING) << "Unknown file type: " << file_path.value(); | 219 LOG(WARNING) << "Unknown file type: " << file_path.value(); |
209 return false; | 220 return false; |
210 } | 221 } |
211 | 222 |
212 // If a bundled plugin is enabled, we should open pdf/swf files in a tab. | 223 // If a bundled plugin is enabled, we should open pdf/swf files in a tab. |
213 bool ShouldBeOpenedWithPlugin( | 224 bool ShouldBeOpenedWithPlugin( |
214 Profile* profile, | 225 Profile* profile, |
215 const base::FilePath::StringType& file_extension) { | 226 const base::FilePath::StringType& file_extension) { |
| 227 DCHECK(profile); |
| 228 |
216 const base::FilePath file_path = | 229 const base::FilePath file_path = |
217 base::FilePath::FromUTF8Unsafe("dummy").AddExtension(file_extension); | 230 base::FilePath::FromUTF8Unsafe("dummy").AddExtension(file_extension); |
218 if (file_path.MatchesExtension(kPdfExtension)) | 231 if (file_path.MatchesExtension(kPdfExtension)) |
219 return IsPdfPluginEnabled(profile); | 232 return IsPdfPluginEnabled(profile); |
220 if (file_path.MatchesExtension(kSwfExtension)) | 233 if (file_path.MatchesExtension(kSwfExtension)) |
221 return IsFlashPluginEnabled(profile); | 234 return IsFlashPluginEnabled(profile); |
222 return false; | 235 return false; |
223 } | 236 } |
224 | 237 |
225 } // namespace util | 238 } // namespace util |
226 } // namespace file_manager | 239 } // namespace file_manager |
OLD | NEW |