Index: chrome/browser/chromeos/extensions/file_manager_util.cc |
diff --git a/chrome/browser/chromeos/extensions/file_manager_util.cc b/chrome/browser/chromeos/extensions/file_manager_util.cc |
index 55fba96316b14297d01f94065530cd60285e9aaa..42b4d428b0b2e21df7f524088a50e9f9fb659125 100644 |
--- a/chrome/browser/chromeos/extensions/file_manager_util.cc |
+++ b/chrome/browser/chromeos/extensions/file_manager_util.cc |
@@ -263,6 +263,23 @@ void OnDriveFileFound(Profile* profile, |
} |
} |
+void InstallCRX(Browser* browser, const FilePath& path) { |
+ ExtensionService* service = |
+ extensions::ExtensionSystem::Get(browser->profile())->extension_service(); |
+ CHECK(service); |
+ |
+ content::WebContents* web_contents = |
+ browser->tab_strip_model()->GetActiveWebContents(); |
+ scoped_refptr<extensions::CrxInstaller> installer( |
+ extensions::CrxInstaller::Create( |
+ service, |
+ new ExtensionInstallPrompt(web_contents))); |
+ installer->set_error_on_unsupported_requirements(true); |
+ installer->set_is_gallery_install(false); |
+ installer->set_allow_silent_install(false); |
+ installer->InstallCrx(path); |
+} |
+ |
// Called when a crx file on Drive was downloaded. |
void OnCRXDownloadCallback(Browser* browser, |
drive::DriveFileError error, |
@@ -274,158 +291,6 @@ void OnCRXDownloadCallback(Browser* browser, |
InstallCRX(browser, file); |
} |
-} // namespace |
- |
-GURL GetFileBrowserExtensionUrl() { |
- return GURL(kFileBrowserExtensionUrl); |
-} |
- |
-GURL GetFileBrowserUrl() { |
- return GURL(kBaseFileBrowserUrl); |
-} |
- |
-GURL GetMediaPlayerUrl() { |
- return GURL(kMediaPlayerUrl); |
-} |
- |
-GURL GetVideoPlayerUrl(const GURL& source_url) { |
- return GURL(kVideoPlayerUrl + std::string("?") + source_url.spec()); |
-} |
- |
-bool ConvertFileToFileSystemUrl(Profile* profile, |
- const FilePath& full_file_path, |
- const std::string& extension_id, |
- GURL* url) { |
- GURL origin_url = Extension::GetBaseURLFromExtensionId(extension_id); |
- FilePath virtual_path; |
- if (!ConvertFileToRelativeFileSystemPath(profile, extension_id, |
- full_file_path, &virtual_path)) { |
- return false; |
- } |
- |
- GURL base_url = fileapi::GetFileSystemRootURI(origin_url, |
- fileapi::kFileSystemTypeExternal); |
- *url = GURL(base_url.spec() + virtual_path.value()); |
- return true; |
-} |
- |
-bool ConvertFileToRelativeFileSystemPath( |
- Profile* profile, |
- const std::string& extension_id, |
- const FilePath& full_file_path, |
- FilePath* virtual_path) { |
- ExtensionService* service = |
- extensions::ExtensionSystem::Get(profile)->extension_service(); |
- // May be NULL during unit_tests. |
- if (!service) |
- return false; |
- |
- // File browser APIs are ment to be used only from extension context, so the |
- // extension's site is the one in whose file system context the virtual path |
- // should be found. |
- GURL site = service->GetSiteForExtensionId(extension_id); |
- fileapi::ExternalFileSystemMountPointProvider* provider = |
- BrowserContext::GetStoragePartitionForSite(profile, site)-> |
- GetFileSystemContext()->external_provider(); |
- if (!provider) |
- return false; |
- |
- // Find if this file path is managed by the external provider. |
- if (!provider->GetVirtualPath(full_file_path, virtual_path)) |
- return false; |
- |
- return true; |
-} |
- |
-GURL GetFileBrowserUrlWithParams( |
- ui::SelectFileDialog::Type type, |
- const string16& title, |
- const FilePath& default_virtual_path, |
- const ui::SelectFileDialog::FileTypeInfo* file_types, |
- int file_type_index, |
- const FilePath::StringType& default_extension) { |
- DictionaryValue arg_value; |
- arg_value.SetString("type", GetDialogTypeAsString(type)); |
- arg_value.SetString("title", title); |
- arg_value.SetString("defaultPath", default_virtual_path.value()); |
- arg_value.SetString("defaultExtension", default_extension); |
- |
- if (file_types) { |
- ListValue* types_list = new ListValue(); |
- for (size_t i = 0; i < file_types->extensions.size(); ++i) { |
- ListValue* extensions_list = new ListValue(); |
- for (size_t j = 0; j < file_types->extensions[i].size(); ++j) { |
- extensions_list->Append( |
- new base::StringValue(file_types->extensions[i][j])); |
- } |
- |
- DictionaryValue* dict = new DictionaryValue(); |
- dict->Set("extensions", extensions_list); |
- |
- if (i < file_types->extension_description_overrides.size()) { |
- string16 desc = file_types->extension_description_overrides[i]; |
- dict->SetString("description", desc); |
- } |
- |
- // file_type_index is 1-based. 0 means no selection at all. |
- dict->SetBoolean("selected", |
- (static_cast<size_t>(file_type_index) == (i + 1))); |
- |
- types_list->Set(i, dict); |
- } |
- arg_value.Set("typeList", types_list); |
- |
- arg_value.SetBoolean("includeAllFiles", file_types->include_all_files); |
- } |
- |
- // Disable showing GDrive unless it's specifically supported. |
- arg_value.SetBoolean("disableGData", |
- !file_types || !file_types->support_gdata); |
- |
- std::string json_args; |
- base::JSONWriter::Write(&arg_value, &json_args); |
- |
- // kChromeUIFileManagerURL could not be used since query parameters are not |
- // supported for it. |
- std::string url = GetFileBrowserUrl().spec() + |
- '?' + net::EscapeUrlEncodedData(json_args, false); |
- return GURL(url); |
-} |
- |
-string16 GetTitleFromType(ui::SelectFileDialog::Type dialog_type) { |
- string16 title; |
- switch (dialog_type) { |
- case ui::SelectFileDialog::SELECT_NONE: |
- // Full page file manager doesn't need a title. |
- break; |
- |
- case ui::SelectFileDialog::SELECT_FOLDER: |
- title = l10n_util::GetStringUTF16( |
- IDS_FILE_BROWSER_SELECT_FOLDER_TITLE); |
- break; |
- |
- case ui::SelectFileDialog::SELECT_SAVEAS_FILE: |
- title = l10n_util::GetStringUTF16( |
- IDS_FILE_BROWSER_SELECT_SAVEAS_FILE_TITLE); |
- break; |
- |
- case ui::SelectFileDialog::SELECT_OPEN_FILE: |
- title = l10n_util::GetStringUTF16( |
- IDS_FILE_BROWSER_SELECT_OPEN_FILE_TITLE); |
- break; |
- |
- case ui::SelectFileDialog::SELECT_OPEN_MULTI_FILE: |
- title = l10n_util::GetStringUTF16( |
- IDS_FILE_BROWSER_SELECT_OPEN_MULTI_FILE_TITLE); |
- break; |
- |
- default: |
- NOTREACHED(); |
- } |
- |
- return title; |
-} |
- |
enum TAB_REUSE_MODE { |
REUSE_ANY_FILE_MANAGER, |
REUSE_SAME_PATH, |
@@ -565,56 +430,6 @@ Browser* GetBrowserForUrl(GURL target_url) { |
return NULL; |
} |
-void ViewRemovableDrive(const FilePath& path) { |
- OpenFileBrowser(path, REUSE_ANY_FILE_MANAGER, "auto-open"); |
-} |
- |
-void OpenActionChoiceDialog(const FilePath& path) { |
- const int kDialogWidth = 394; |
- // TODO(dgozman): remove 50, which is a title height once popup window |
- // will have no title. |
- const int kDialogHeight = 316 + 50; |
- |
- Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord(); |
- |
- FilePath virtual_path; |
- if (!ConvertFileToRelativeFileSystemPath(profile, kFileBrowserDomain, path, |
- &virtual_path)) |
- return; |
- std::string url = kActionChoiceUrl; |
- url += "#/" + net::EscapeUrlEncodedData(virtual_path.value(), false); |
- GURL dialog_url(url); |
- |
- const gfx::Size screen = ash::Shell::GetScreen()->GetPrimaryDisplay().size(); |
- const gfx::Rect bounds((screen.width() - kDialogWidth) / 2, |
- (screen.height() - kDialogHeight) / 2, |
- kDialogWidth, |
- kDialogHeight); |
- |
- Browser* browser = GetBrowserForUrl(dialog_url); |
- |
- if (!browser) { |
- browser = new Browser( |
- Browser::CreateParams::CreateForApp(Browser::TYPE_POPUP, |
- "action_choice", |
- bounds, |
- profile)); |
- |
- chrome::AddSelectedTabWithURL(browser, dialog_url, |
- content::PAGE_TRANSITION_LINK); |
- } |
- browser->window()->Show(); |
-} |
- |
-void ShowFileInFolder(const FilePath& path) { |
- // This action changes the selection so we do not reuse existing tabs. |
- OpenFileBrowser(path, REUSE_NEVER, "select"); |
-} |
- |
-void ViewFolder(const FilePath& path) { |
- OpenFileBrowser(path, REUSE_SAME_PATH, "open"); |
-} |
- |
bool ExecuteDefaultHandler(Profile* profile, const FilePath& path) { |
GURL url; |
if (!ConvertFileToFileSystemUrl(profile, path, kFileBrowserDomain, &url)) |
@@ -664,12 +479,6 @@ bool ExecuteDefaultHandler(Profile* profile, const FilePath& path) { |
return true; |
} |
-void ViewFile(const FilePath& path) { |
- Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord(); |
- if (!ExecuteDefaultHandler(profile, path)) |
- ShowWarningMessageBox(profile, path); |
-} |
- |
// Reads an entire file into a string. Fails is the file is 4K or longer. |
bool ReadSmallFileToString(const FilePath& path, std::string* contents) { |
FILE* file = file_util::OpenFile(path, "rb"); |
@@ -713,6 +522,214 @@ void ReadUrlFromGDocOnFileThread(const FilePath& file_path) { |
base::Bind(OpenNewTab, GURL(edit_url_string), (Profile*)NULL)); |
} |
+} // namespace |
+ |
+GURL GetFileBrowserExtensionUrl() { |
+ return GURL(kFileBrowserExtensionUrl); |
+} |
+ |
+GURL GetFileBrowserUrl() { |
+ return GURL(kBaseFileBrowserUrl); |
+} |
+ |
+GURL GetMediaPlayerUrl() { |
+ return GURL(kMediaPlayerUrl); |
+} |
+ |
+GURL GetVideoPlayerUrl(const GURL& source_url) { |
+ return GURL(kVideoPlayerUrl + std::string("?") + source_url.spec()); |
+} |
+ |
+bool ConvertFileToFileSystemUrl(Profile* profile, |
+ const FilePath& full_file_path, |
+ const std::string& extension_id, |
+ GURL* url) { |
+ GURL origin_url = Extension::GetBaseURLFromExtensionId(extension_id); |
+ FilePath virtual_path; |
+ if (!ConvertFileToRelativeFileSystemPath(profile, extension_id, |
+ full_file_path, &virtual_path)) { |
+ return false; |
+ } |
+ |
+ GURL base_url = fileapi::GetFileSystemRootURI(origin_url, |
+ fileapi::kFileSystemTypeExternal); |
+ *url = GURL(base_url.spec() + virtual_path.value()); |
+ return true; |
+} |
+ |
+bool ConvertFileToRelativeFileSystemPath( |
+ Profile* profile, |
+ const std::string& extension_id, |
+ const FilePath& full_file_path, |
+ FilePath* virtual_path) { |
+ ExtensionService* service = |
+ extensions::ExtensionSystem::Get(profile)->extension_service(); |
+ // May be NULL during unit_tests. |
+ if (!service) |
+ return false; |
+ |
+ // File browser APIs are ment to be used only from extension context, so the |
+ // extension's site is the one in whose file system context the virtual path |
+ // should be found. |
+ GURL site = service->GetSiteForExtensionId(extension_id); |
+ fileapi::ExternalFileSystemMountPointProvider* provider = |
+ BrowserContext::GetStoragePartitionForSite(profile, site)-> |
+ GetFileSystemContext()->external_provider(); |
+ if (!provider) |
+ return false; |
+ |
+ // Find if this file path is managed by the external provider. |
+ if (!provider->GetVirtualPath(full_file_path, virtual_path)) |
+ return false; |
+ |
+ return true; |
+} |
+ |
+GURL GetFileBrowserUrlWithParams( |
+ ui::SelectFileDialog::Type type, |
+ const string16& title, |
+ const FilePath& default_virtual_path, |
+ const ui::SelectFileDialog::FileTypeInfo* file_types, |
+ int file_type_index, |
+ const FilePath::StringType& default_extension) { |
+ DictionaryValue arg_value; |
+ arg_value.SetString("type", GetDialogTypeAsString(type)); |
+ arg_value.SetString("title", title); |
+ arg_value.SetString("defaultPath", default_virtual_path.value()); |
+ arg_value.SetString("defaultExtension", default_extension); |
+ |
+ if (file_types) { |
+ ListValue* types_list = new ListValue(); |
+ for (size_t i = 0; i < file_types->extensions.size(); ++i) { |
+ ListValue* extensions_list = new ListValue(); |
+ for (size_t j = 0; j < file_types->extensions[i].size(); ++j) { |
+ extensions_list->Append( |
+ new base::StringValue(file_types->extensions[i][j])); |
+ } |
+ |
+ DictionaryValue* dict = new DictionaryValue(); |
+ dict->Set("extensions", extensions_list); |
+ |
+ if (i < file_types->extension_description_overrides.size()) { |
+ string16 desc = file_types->extension_description_overrides[i]; |
+ dict->SetString("description", desc); |
+ } |
+ |
+ // file_type_index is 1-based. 0 means no selection at all. |
+ dict->SetBoolean("selected", |
+ (static_cast<size_t>(file_type_index) == (i + 1))); |
+ |
+ types_list->Set(i, dict); |
+ } |
+ arg_value.Set("typeList", types_list); |
+ |
+ arg_value.SetBoolean("includeAllFiles", file_types->include_all_files); |
+ } |
+ |
+ // Disable showing GDrive unless it's specifically supported. |
+ arg_value.SetBoolean("disableGData", |
+ !file_types || !file_types->support_gdata); |
+ |
+ std::string json_args; |
+ base::JSONWriter::Write(&arg_value, &json_args); |
+ |
+ // kChromeUIFileManagerURL could not be used since query parameters are not |
+ // supported for it. |
+ std::string url = GetFileBrowserUrl().spec() + |
+ '?' + net::EscapeUrlEncodedData(json_args, false); |
+ return GURL(url); |
+} |
+ |
+string16 GetTitleFromType(ui::SelectFileDialog::Type dialog_type) { |
+ string16 title; |
+ switch (dialog_type) { |
+ case ui::SelectFileDialog::SELECT_NONE: |
+ // Full page file manager doesn't need a title. |
+ break; |
+ |
+ case ui::SelectFileDialog::SELECT_FOLDER: |
+ title = l10n_util::GetStringUTF16( |
+ IDS_FILE_BROWSER_SELECT_FOLDER_TITLE); |
+ break; |
+ |
+ case ui::SelectFileDialog::SELECT_SAVEAS_FILE: |
+ title = l10n_util::GetStringUTF16( |
+ IDS_FILE_BROWSER_SELECT_SAVEAS_FILE_TITLE); |
+ break; |
+ |
+ case ui::SelectFileDialog::SELECT_OPEN_FILE: |
+ title = l10n_util::GetStringUTF16( |
+ IDS_FILE_BROWSER_SELECT_OPEN_FILE_TITLE); |
+ break; |
+ |
+ case ui::SelectFileDialog::SELECT_OPEN_MULTI_FILE: |
+ title = l10n_util::GetStringUTF16( |
+ IDS_FILE_BROWSER_SELECT_OPEN_MULTI_FILE_TITLE); |
+ break; |
+ |
+ default: |
+ NOTREACHED(); |
+ } |
+ |
+ return title; |
+} |
+ |
+void ViewRemovableDrive(const FilePath& path) { |
+ OpenFileBrowser(path, REUSE_ANY_FILE_MANAGER, "auto-open"); |
+} |
+ |
+void OpenActionChoiceDialog(const FilePath& path) { |
+ const int kDialogWidth = 394; |
+ // TODO(dgozman): remove 50, which is a title height once popup window |
+ // will have no title. |
+ const int kDialogHeight = 316 + 50; |
+ |
+ Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord(); |
+ |
+ FilePath virtual_path; |
+ if (!ConvertFileToRelativeFileSystemPath(profile, kFileBrowserDomain, path, |
+ &virtual_path)) |
+ return; |
+ std::string url = kActionChoiceUrl; |
+ url += "#/" + net::EscapeUrlEncodedData(virtual_path.value(), false); |
+ GURL dialog_url(url); |
+ |
+ const gfx::Size screen = ash::Shell::GetScreen()->GetPrimaryDisplay().size(); |
+ const gfx::Rect bounds((screen.width() - kDialogWidth) / 2, |
+ (screen.height() - kDialogHeight) / 2, |
+ kDialogWidth, |
+ kDialogHeight); |
+ |
+ Browser* browser = GetBrowserForUrl(dialog_url); |
+ |
+ if (!browser) { |
+ browser = new Browser( |
+ Browser::CreateParams::CreateForApp(Browser::TYPE_POPUP, |
+ "action_choice", |
+ bounds, |
+ profile)); |
+ |
+ chrome::AddSelectedTabWithURL(browser, dialog_url, |
+ content::PAGE_TRANSITION_LINK); |
+ } |
+ browser->window()->Show(); |
+} |
+ |
+void ViewFolder(const FilePath& path) { |
+ OpenFileBrowser(path, REUSE_SAME_PATH, "open"); |
+} |
+ |
+void ViewFile(const FilePath& path) { |
+ Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord(); |
+ if (!ExecuteDefaultHandler(profile, path)) |
+ ShowWarningMessageBox(profile, path); |
+} |
+ |
+void ShowFileInFolder(const FilePath& path) { |
+ // This action changes the selection so we do not reuse existing tabs. |
+ OpenFileBrowser(path, REUSE_NEVER, "select"); |
+} |
+ |
bool ExecuteBuiltinHandler(Browser* browser, const FilePath& path, |
const std::string& internal_task_id) { |
@@ -824,23 +841,6 @@ bool ExecuteBuiltinHandler(Browser* browser, const FilePath& path, |
return false; |
} |
-void InstallCRX(Browser* browser, const FilePath& path) { |
- ExtensionService* service = |
- extensions::ExtensionSystem::Get(browser->profile())->extension_service(); |
- CHECK(service); |
- |
- content::WebContents* web_contents = |
- browser->tab_strip_model()->GetActiveWebContents(); |
- scoped_refptr<extensions::CrxInstaller> installer( |
- extensions::CrxInstaller::Create( |
- service, |
- new ExtensionInstallPrompt(web_contents))); |
- installer->set_error_on_unsupported_requirements(true); |
- installer->set_is_gallery_install(false); |
- installer->set_allow_silent_install(false); |
- installer->InstallCrx(path); |
-} |
- |
// If pdf plugin is enabled, we should open pdf files in a tab. |
bool ShouldBeOpenedWithPdfPlugin(Profile* profile, const char* file_extension) { |
if (base::strcasecmp(file_extension, kPdfExtension) != 0) |