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 #include "chrome/browser/chromeos/extensions/file_manager_util.h" | 4 #include "chrome/browser/chromeos/extensions/file_manager_util.h" |
5 | 5 |
6 #include "base/bind.h" | 6 #include "base/bind.h" |
7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 return true; | 115 return true; |
116 } | 116 } |
117 } | 117 } |
118 return false; | 118 return false; |
119 } | 119 } |
120 | 120 |
121 bool IsCRXFile(const char* file_extension) { | 121 bool IsCRXFile(const char* file_extension) { |
122 return base::strcasecmp(file_extension, kCRXExtension) == 0; | 122 return base::strcasecmp(file_extension, kCRXExtension) == 0; |
123 } | 123 } |
124 | 124 |
125 // If pdf plugin is enabled, we should open pdf files in a tab. | |
126 bool ShouldBeOpenedWithPdfPlugin(const char* file_extension) { | |
127 if (base::strcasecmp(file_extension, kPdfExtension) != 0) | |
128 return false; | |
129 | |
130 Browser* browser = BrowserList::GetLastActive(); | |
131 if (!browser) | |
132 return false; | |
133 | |
134 FilePath pdf_path; | |
135 PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_path); | |
136 | |
137 webkit::WebPluginInfo plugin; | |
138 if (!PluginService::GetInstance()->GetPluginInfoByPath(pdf_path, &plugin)) | |
139 return false; | |
140 | |
141 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(browser->profile()); | |
142 if (!plugin_prefs) | |
143 return false; | |
144 | |
145 return plugin_prefs->IsPluginEnabled(plugin); | |
146 } | |
147 | |
148 // Returns index |ext| has in the |array|. If there is no |ext| in |array|, last | 125 // Returns index |ext| has in the |array|. If there is no |ext| in |array|, last |
149 // element's index is return (last element should have irrelevant value). | 126 // element's index is return (last element should have irrelevant value). |
150 int UMAExtensionIndex(const char *file_extension, | 127 int UMAExtensionIndex(const char *file_extension, |
151 const char** array, | 128 const char** array, |
152 size_t array_size) { | 129 size_t array_size) { |
153 for (size_t i = 0; i < array_size; i++) { | 130 for (size_t i = 0; i < array_size; i++) { |
154 if (base::strcasecmp(file_extension, array[i]) == 0) { | 131 if (base::strcasecmp(file_extension, array[i]) == 0) { |
155 return i; | 132 return i; |
156 } | 133 } |
157 } | 134 } |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
461 if (!service) | 438 if (!service) |
462 return; | 439 return; |
463 | 440 |
464 scoped_refptr<CrxInstaller> installer(CrxInstaller::Create(service, | 441 scoped_refptr<CrxInstaller> installer(CrxInstaller::Create(service, |
465 new ExtensionInstallUI(profile))); | 442 new ExtensionInstallUI(profile))); |
466 installer->set_is_gallery_install(false); | 443 installer->set_is_gallery_install(false); |
467 installer->set_allow_silent_install(false); | 444 installer->set_allow_silent_install(false); |
468 installer->InstallCrx(full_path); | 445 installer->InstallCrx(full_path); |
469 } | 446 } |
470 | 447 |
| 448 // If pdf plugin is enabled, we should open pdf files in a tab. |
| 449 bool ShouldBeOpenedWithPdfPlugin(const char* file_extension) { |
| 450 if (base::strcasecmp(file_extension, kPdfExtension) != 0) |
| 451 return false; |
| 452 |
| 453 Browser* browser = BrowserList::GetLastActive(); |
| 454 if (!browser) |
| 455 return false; |
| 456 |
| 457 FilePath pdf_path; |
| 458 PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_path); |
| 459 |
| 460 webkit::WebPluginInfo plugin; |
| 461 if (!PluginService::GetInstance()->GetPluginInfoByPath(pdf_path, &plugin)) |
| 462 return false; |
| 463 |
| 464 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(browser->profile()); |
| 465 if (!plugin_prefs) |
| 466 return false; |
| 467 |
| 468 return plugin_prefs->IsPluginEnabled(plugin); |
| 469 } |
| 470 |
471 } // namespace file_manager_util | 471 } // namespace file_manager_util |
OLD | NEW |