diff options
author | zelidrag@chromium.org <zelidrag@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-18 23:31:00 +0000 |
---|---|---|
committer | zelidrag@chromium.org <zelidrag@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-18 23:31:00 +0000 |
commit | 94bda20ef8a54236851e0240094da166afa47724 (patch) | |
tree | 040578877bb9b95d829507e5b963cc728373c3aa /chrome/browser | |
parent | 4e70191dc2dd52cf2f85617e916592d638203c92 (diff) | |
download | chromium_src-94bda20ef8a54236851e0240094da166afa47724.zip chromium_src-94bda20ef8a54236851e0240094da166afa47724.tar.gz chromium_src-94bda20ef8a54236851e0240094da166afa47724.tar.bz2 |
Wired existing media player code with the new file browser. Added a new private method to view selected files:
chrome.fileBrowserPrivate.viewFiles(file_urls);
BUG=chromium-os:14223
TEST=none
Review URL: http://codereview.chromium.org/6874033
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@82029 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
23 files changed, 266 insertions, 1447 deletions
diff --git a/chrome/browser/about_flags.cc b/chrome/browser/about_flags.cc index dbdaa7b..a21b966 100644 --- a/chrome/browser/about_flags.cc +++ b/chrome/browser/about_flags.cc @@ -86,18 +86,6 @@ const Experiment kExperiments[] = { #endif }, { - kMediaPlayerExperimentName, - IDS_FLAGS_MEDIA_PLAYER_NAME, - IDS_FLAGS_MEDIA_PLAYER_DESCRIPTION, - kOsCrOS, -#if defined(OS_CHROMEOS) - // The switch exists only on Chrome OS. - SINGLE_VALUE_TYPE(switches::kEnableMediaPlayer) -#else - SINGLE_VALUE_TYPE("") -#endif - }, - { kAdvancedFileSystemExperimentName, IDS_FLAGS_ADVANCED_FS_NAME, IDS_FLAGS_ADVANCED_FS_DESCRIPTION, diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc index ae3b320..c319fa5 100644 --- a/chrome/browser/automation/testing_automation_provider.cc +++ b/chrome/browser/automation/testing_automation_provider.cc @@ -1069,7 +1069,7 @@ void TestingAutomationProvider::GetShelfVisibility(int handle, bool* visible) { (*it)->GetTabContentsAt((*it)->active_index())->GetURL(); if (url.SchemeIs(chrome::kChromeUIScheme) && - url.host() == chrome::kChromeUIFileBrowseHost) { + url.host() == chrome::kChromeUIActiveDownloadsHost) { *visible = true; break; } diff --git a/chrome/browser/browser_resources.grd b/chrome/browser/browser_resources.grd index 4ad61a8a..9371ac2 100644 --- a/chrome/browser/browser_resources.grd +++ b/chrome/browser/browser_resources.grd @@ -92,7 +92,6 @@ <include name="IDR_CHOOSE_MOBILE_NETWORK_HTML" file="resources\chromeos\choose_mobile_network.html" flattenhtml="true" type="BINDATA" /> <include name="IDR_COLLECTED_COOKIES_HTML" file="resources\collected_cookies.html" flattenhtml="true" type="BINDATA" /> <include name="IDR_GUEST_SESSION_TAB_HTML" file="resources\guest_session_tab.html" flattenhtml="true" type="BINDATA" /> - <include name="IDR_FILEBROWSE_HTML" file="resources\filebrowse.html" flattenhtml="true" type="BINDATA" /> <include name="IDR_ACTIVE_DOWNLOADS_HTML" file="resources\active_downloads.html" flattenhtml="true" type="BINDATA" /> <include name="IDR_HOST_REGISTRATION_PAGE_HTML" file="resources\host_registration_page.html" flattenhtml="true" type="BINDATA" /> <include name="IDR_HTTP_AUTH_HTML" file="resources\http_auth.html" flattenhtml="true" type="BINDATA" /> diff --git a/chrome/browser/chromeos/usb_mount_observer_browsertest.cc b/chrome/browser/chromeos/usb_mount_observer_browsertest.cc deleted file mode 100644 index 4c594bd..0000000 --- a/chrome/browser/chromeos/usb_mount_observer_browsertest.cc +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "base/memory/ref_counted.h" -#include "base/utf_string_conversions.h" -#include "chrome/browser/chromeos/cros/mock_mount_library.h" -#include "chrome/browser/chromeos/usb_mount_observer.h" -#include "chrome/browser/ui/browser.h" -#include "chrome/browser/ui/browser_list.h" -#include "chrome/browser/ui/webui/mediaplayer_ui.h" -#include "chrome/common/url_constants.h" -#include "chrome/test/automation/dom_element_proxy.h" -#include "chrome/test/in_process_browser_test.h" -#include "chrome/test/ui_test_utils.h" -#include "content/browser/tab_contents/tab_contents.h" - -namespace { - -class USBMountObserverBrowserTest : public InProcessBrowserTest { - public: - USBMountObserverBrowserTest() {} - - bool IsFilebrowserVisible() { - for (BrowserList::const_iterator it = BrowserList::begin(); - it != BrowserList::end(); ++it) { - if ((*it)->type() == Browser::TYPE_POPUP) { - const GURL& url = - (*it)->GetTabContentsAt((*it)->active_index())->GetURL(); - if (url.SchemeIs(chrome::kChromeUIScheme) && - url.host() == chrome::kChromeUIFileBrowseHost) { - return true; - } - } - } - return false; - } -}; - -IN_PROC_BROWSER_TEST_F(USBMountObserverBrowserTest, PopupOnEvent) { - StartHTTPServer(); - // Doing this so we have a valid profile - ui_test_utils::NavigateToURL(browser(), - GURL(chrome::kChromeUIDownloadsURL)); - chromeos::USBMountObserver* observe = chromeos::USBMountObserver::GetInstance(); - observe->set_profile(browser()->profile()); - scoped_ptr<chromeos::MockMountLibrary> lib(new chromeos::MockMountLibrary()); - lib->AddObserver(observe); - // Check that its not currently visible - EXPECT_FALSE(IsFilebrowserVisible()); - - lib->FireDeviceInsertEvents(); - - EXPECT_TRUE(IsFilebrowserVisible()); -} - -} diff --git a/chrome/browser/extensions/extension_file_browser_private_api.cc b/chrome/browser/extensions/extension_file_browser_private_api.cc index ecf88e8..4aa7791 100644 --- a/chrome/browser/extensions/extension_file_browser_private_api.cc +++ b/chrome/browser/extensions/extension_file_browser_private_api.cc @@ -18,6 +18,7 @@ #include "chrome/browser/extensions/extension_function_dispatcher.h" #include "chrome/browser/extensions/extension_process_manager.h" #include "chrome/browser/extensions/extension_service.h" +#include "chrome/browser/platform_util.h" #include "chrome/browser/ui/webui/extension_icon_source.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/extensions/extension.h" @@ -454,7 +455,6 @@ class ExecuteTasksFileSystemCallbackDispatcher GURL file_origin_url; FilePath virtual_path; fileapi::FileSystemType type; - if (!CrackFileSystemURL(origin_file_url, &file_origin_url, &type, &virtual_path)) { return false; @@ -726,9 +726,9 @@ const FileDialogFunction::Callback& FileDialogFunction::GetCallback() const { // so here we are. This function takes a vector of virtual paths, converts // them to local paths and calls GetLocalPathsResponseOnUIThread with the // result vector, on the UI thread. -void FileDialogFunction::GetLocalPathsOnFileThread() { +void FileDialogFunction::GetLocalPathsOnFileThread(const UrlList& file_urls) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); - DCHECK(selected_files_.empty()); + FilePathList selected_files; // FilePath(virtual_path) doesn't work on win, so limit this to ChromeOS. #if defined(OS_CHROMEOS) @@ -736,61 +736,123 @@ void FileDialogFunction::GetLocalPathsOnFileThread() { fileapi::FileSystemPathManager* path_manager = profile()->GetFileSystemContext()->path_manager(); - size_t len = virtual_paths_.size(); - selected_files_.reserve(len); + size_t len = file_urls.size(); + selected_files.reserve(len); for (size_t i = 0; i < len; ++i) { - std::string virtual_path = virtual_paths_[i]; + const GURL& file_url = file_urls[i]; + GURL file_origin_url; + FilePath virtual_path; + fileapi::FileSystemType type; + if (!CrackFileSystemURL(file_url, &file_origin_url, &type, + &virtual_path)) { + continue; + } + if (type != fileapi::kFileSystemTypeExternal) { + NOTREACHED(); + continue; + } FilePath root = path_manager->GetFileSystemRootPathOnFileThread( origin_url, fileapi::kFileSystemTypeExternal, FilePath(virtual_path), false); if (!root.empty()) { - selected_files_.push_back(root.Append(virtual_path)); + selected_files.push_back(root.Append(virtual_path)); } else { - LOG(WARNING) << "GetLocalPathsOnFileThread failed " << virtual_path; + LOG(WARNING) << "GetLocalPathsOnFileThread failed " + << file_url.spec(); } } #endif - if (!selected_files_.empty()) { + if (!selected_files.empty()) { BrowserThread::PostTask( BrowserThread::UI, FROM_HERE, NewRunnableMethod(this, - &FileDialogFunction::GetLocalPathsResponseOnUIThread)); + &FileDialogFunction::GetLocalPathsResponseOnUIThread, + selected_files)); } } bool SelectFileFunction::RunImpl() { - DCHECK_EQ(static_cast<size_t>(2), args_->GetSize()); - - std::string virtual_path; - args_->GetString(0, &virtual_path); - virtual_paths_.push_back(virtual_path); + if (args_->GetSize() != 2) { + return false; + } + std::string file_url; + args_->GetString(0, &file_url); + UrlList file_paths; + file_paths.push_back(GURL(file_url)); BrowserThread::PostTask( BrowserThread::FILE, FROM_HERE, NewRunnableMethod(this, - &SelectFileFunction::GetLocalPathsOnFileThread)); + &SelectFileFunction::GetLocalPathsOnFileThread, + file_paths)); return true; } -void SelectFileFunction::GetLocalPathsResponseOnUIThread() { +void SelectFileFunction::GetLocalPathsResponseOnUIThread( + const FilePathList& files) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - DCHECK_EQ(selected_files_.size(), static_cast<size_t>(1)); - + if (files.size() != 1) { + return; + } int index; args_->GetInteger(1, &index); const Callback& callback = GetCallback(); DCHECK(!callback.IsNull()); if (!callback.IsNull()) { - callback.listener()->FileSelected(selected_files_[0], + callback.listener()->FileSelected(files[0], index, callback.params()); } } + +ViewFilesFunction::ViewFilesFunction() { +} + +ViewFilesFunction::~ViewFilesFunction() { +} + +bool ViewFilesFunction::RunImpl() { + if (args_->GetSize() != 1) { + return false; + } + + ListValue* path_list = NULL; + args_->GetList(0, &path_list); + DCHECK(path_list); + + std::string virtual_path; + size_t len = path_list->GetSize(); + UrlList file_urls; + file_urls.reserve(len); + for (size_t i = 0; i < len; ++i) { + path_list->GetString(i, &virtual_path); + file_urls.push_back(GURL(virtual_path)); + } + + BrowserThread::PostTask( + BrowserThread::FILE, FROM_HERE, + NewRunnableMethod(this, + &ViewFilesFunction::GetLocalPathsOnFileThread, + file_urls)); + + return true; +} + +void ViewFilesFunction::GetLocalPathsResponseOnUIThread( + const FilePathList& files) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + for (FilePathList::const_iterator iter = files.begin(); + iter != files.end(); + ++iter) { + platform_util::OpenItem(*iter); + } +} + SelectFilesFunction::SelectFilesFunction() { } @@ -798,7 +860,9 @@ SelectFilesFunction::~SelectFilesFunction() { } bool SelectFilesFunction::RunImpl() { - DCHECK_EQ(static_cast<size_t>(1), args_->GetSize()); + if (args_->GetSize() != 1) { + return false; + } ListValue* path_list = NULL; args_->GetList(0, &path_list); @@ -806,27 +870,30 @@ bool SelectFilesFunction::RunImpl() { std::string virtual_path; size_t len = path_list->GetSize(); - virtual_paths_.reserve(len); + UrlList file_urls; + file_urls.reserve(len); for (size_t i = 0; i < len; ++i) { path_list->GetString(i, &virtual_path); - virtual_paths_.push_back(virtual_path); + file_urls.push_back(GURL(virtual_path)); } BrowserThread::PostTask( BrowserThread::FILE, FROM_HERE, NewRunnableMethod(this, - &SelectFilesFunction::GetLocalPathsOnFileThread)); + &SelectFilesFunction::GetLocalPathsOnFileThread, + file_urls)); return true; } -void SelectFilesFunction::GetLocalPathsResponseOnUIThread() { +void SelectFilesFunction::GetLocalPathsResponseOnUIThread( + const FilePathList& files) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); const Callback& callback = GetCallback(); DCHECK(!callback.IsNull()); if (!callback.IsNull()) { - callback.listener()->MultiFilesSelected(selected_files_, callback.params()); + callback.listener()->MultiFilesSelected(files, callback.params()); } } diff --git a/chrome/browser/extensions/extension_file_browser_private_api.h b/chrome/browser/extensions/extension_file_browser_private_api.h index 684e8e1..3765a9d 100644 --- a/chrome/browser/extensions/extension_file_browser_private_api.h +++ b/chrome/browser/extensions/extension_file_browser_private_api.h @@ -75,9 +75,6 @@ class ExecuteTasksFileBrowserFunction : public AsyncExtensionFunction { class FileDialogFunction : public AsyncExtensionFunction { public: - typedef std::vector<std::string> VirtualPathVec; - typedef std::vector<FilePath> FilePathVec; - FileDialogFunction(); // Register/unregister callbacks. @@ -112,20 +109,20 @@ class FileDialogFunction }; protected: + typedef std::vector<GURL> UrlList; + typedef std::vector<FilePath> FilePathList; + virtual ~FileDialogFunction(); // Convert virtual paths to local paths on the file thread. - void GetLocalPathsOnFileThread(); + void GetLocalPathsOnFileThread(const UrlList& file_urls); // Callback with converted local paths. - virtual void GetLocalPathsResponseOnUIThread() {} + virtual void GetLocalPathsResponseOnUIThread(const FilePathList& files) {} // Get the callback for the hosting tab. const Callback& GetCallback() const; - VirtualPathVec virtual_paths_; - FilePathVec selected_files_; - private: // Figure out the tab_id of the hosting tab. int32 GetTabId() const; @@ -144,12 +141,33 @@ class SelectFileFunction virtual bool RunImpl() OVERRIDE; // FileDialogFunction overrides. - virtual void GetLocalPathsResponseOnUIThread() OVERRIDE; + virtual void GetLocalPathsResponseOnUIThread( + const FilePathList& files) OVERRIDE; private: DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.selectFile"); }; +// Views multiple selected file. +class ViewFilesFunction + : public FileDialogFunction { + public: + ViewFilesFunction(); + + protected: + virtual ~ViewFilesFunction(); + + // AsyncExtensionFunction overrides. + virtual bool RunImpl() OVERRIDE; + + // FileDialogFunction overrides. + virtual void GetLocalPathsResponseOnUIThread( + const FilePathList& files) OVERRIDE; + + private: + DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.viewFiles"); +}; + // Select multiple files. class SelectFilesFunction : public FileDialogFunction { @@ -163,7 +181,8 @@ class SelectFilesFunction virtual bool RunImpl() OVERRIDE; // FileDialogFunction overrides. - virtual void GetLocalPathsResponseOnUIThread() OVERRIDE; + virtual void GetLocalPathsResponseOnUIThread( + const FilePathList& files) OVERRIDE; private: DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.selectFiles"); diff --git a/chrome/browser/extensions/extension_function_dispatcher.cc b/chrome/browser/extensions/extension_function_dispatcher.cc index 1fd1ccf..1949e68 100644 --- a/chrome/browser/extensions/extension_function_dispatcher.cc +++ b/chrome/browser/extensions/extension_function_dispatcher.cc @@ -315,13 +315,14 @@ void FactoryRegistry::ResetFunctions() { RegisterFunction<GetChromeosInfoFunction>(); // FileBrowserPrivate functions. + RegisterFunction<CancelFileDialogFunction>(); RegisterFunction<ExecuteTasksFileBrowserFunction>(); + RegisterFunction<FileDialogStringsFunction>(); RegisterFunction<GetFileTasksFileBrowserFunction>(); RegisterFunction<RequestLocalFileSystemFunction>(); RegisterFunction<SelectFileFunction>(); RegisterFunction<SelectFilesFunction>(); - RegisterFunction<CancelFileDialogFunction>(); - RegisterFunction<FileDialogStringsFunction>(); + RegisterFunction<ViewFilesFunction>(); #endif // Debugger diff --git a/chrome/browser/extensions/file_manager_util.cc b/chrome/browser/extensions/file_manager_util.cc index 8fc1d9c..2f6bb64 100644 --- a/chrome/browser/extensions/file_manager_util.cc +++ b/chrome/browser/extensions/file_manager_util.cc @@ -8,9 +8,13 @@ #include "base/utf_string_conversions.h" #include "base/values.h" #include "chrome/browser/metrics/user_metrics.h" +#include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_list.h" #include "third_party/libjingle/source/talk/base/urlencode.h" +#include "webkit/fileapi/file_system_context.h" +#include "webkit/fileapi/file_system_mount_point_provider.h" +#include "webkit/fileapi/file_system_util.h" // This is the "well known" url for the file manager extension from // browser/resources/file_manager. In the future we may provide a way to swap @@ -24,6 +28,34 @@ GURL FileManagerUtil::GetFileBrowserUrl() { } // static +bool FileManagerUtil::ConvertFileToFileSystemUrl( + Profile* profile, const FilePath& full_file_path, const GURL& origin_url, + GURL* url) { + fileapi::FileSystemPathManager* path_manager = + profile->GetFileSystemContext()->path_manager(); + fileapi::ExternalFileSystemMountPointProvider* provider = + path_manager->external_provider(); + if (!provider) + return false; + + // Find if this file path is managed by the external provider. + std::vector<FilePath> root_dirs = provider->GetRootDirectories(); + for (std::vector<FilePath>::iterator iter = root_dirs.begin(); + iter != root_dirs.end(); + ++iter) { + FilePath path; + const FilePath& root_path = *iter; + if (root_path.AppendRelativePath(full_file_path, &path)) { + GURL base_url = fileapi::GetFileSystemRootURI(origin_url, + fileapi::kFileSystemTypeExternal); + *url = GURL(base_url.spec() + root_path.Append(path).value().substr(1)); + return true; + } + } + return false; +} + +// static GURL FileManagerUtil::GetFileBrowserUrlWithParams( SelectFileDialog::Type type, const string16& title, diff --git a/chrome/browser/extensions/file_manager_util.h b/chrome/browser/extensions/file_manager_util.h index b4524d9..2553ef5 100644 --- a/chrome/browser/extensions/file_manager_util.h +++ b/chrome/browser/extensions/file_manager_util.h @@ -15,6 +15,10 @@ class Profile; // Helper class for wiring file browser component extension with the rest of UI. class FileManagerUtil { public: + // Converts |full_file_path| into external filesystem: url. Returns false + // if |full_file_path| is not managed by the external filesystem provider. + static bool ConvertFileToFileSystemUrl(Profile* profile, + const FilePath& full_file_path, const GURL& origin_url, GURL* url); // Gets base file browser url for. static GURL GetFileBrowserUrlWithParams( SelectFileDialog::Type type, diff --git a/chrome/browser/platform_util_chromeos.cc b/chrome/browser/platform_util_chromeos.cc index efa02dd5c..2c6c00e 100644 --- a/chrome/browser/platform_util_chromeos.cc +++ b/chrome/browser/platform_util_chromeos.cc @@ -10,10 +10,11 @@ #include "base/process_util.h" #include "base/task.h" #include "base/utf_string_conversions.h" -#include "chrome/browser/tabs/tab_strip_model.h" +#include "chrome/browser/extensions/file_manager_util.h" +#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_list.h" -#include "chrome/browser/ui/webui/filebrowse_ui.h" #include "chrome/browser/ui/webui/mediaplayer_ui.h" +#include "chrome/browser/tabs/tab_strip_model.h" #include "content/browser/browser_thread.h" #include "content/common/process_watcher.h" #include "googleurl/src/gurl.h" @@ -31,18 +32,15 @@ static const std::string kGmailComposeUrl = void OpenFileBrowserOnUIThread(const FilePath& dir) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - Profile* profile; - profile = BrowserList::GetLastActive()->profile(); - - FileBrowseUI::OpenPopup(profile, - dir.value(), - FileBrowseUI::kPopupWidth, - FileBrowseUI::kPopupHeight); + Browser* browser = BrowserList::GetLastActive(); + if (!browser) + return; + GURL url = FileManagerUtil::GetFileBrowserUrlWithParams( + SelectFileDialog::SELECT_NONE, string16(), dir, NULL, 0, + FilePath::StringType()); + browser->ShowSingletonTab(url); } -// TODO(estade): It would be nice to be able to select the file in the file -// manager, but that probably requires extending xdg-open. For now just -// show the folder. void ShowItemInFolder(const FilePath& full_path) { FilePath dir = full_path.DirName(); if (!file_util::DirectoryExists(dir)) @@ -61,13 +59,13 @@ void OpenItem(const FilePath& full_path) { std::string ext = full_path.Extension(); // For things supported natively by the browser, we should open it // in a tab. - if (ext == ".jpg" || - ext == ".jpeg" || - ext == ".png" || - ext == ".gif" || - ext == ".txt" || - ext == ".html" || - ext == ".htm") { + if (base::strcasecmp(ext.data(), ".jpg") == 0 || + base::strcasecmp(ext.data(), ".jpeg") == 0 || + base::strcasecmp(ext.data(), ".png") == 0 || + base::strcasecmp(ext.data(), ".gif") == 0 || + base::strcasecmp(ext.data(), ".txt") == 0 || + base::strcasecmp(ext.data(), ".html") == 0 || + base::strcasecmp(ext.data(), ".htm") == 0) { std::string path; path = "file://"; path.append(full_path.value()); @@ -82,17 +80,17 @@ void OpenItem(const FilePath& full_path) { browser->AddSelectedTabWithURL(GURL(path), PageTransition::LINK); return; } - if (ext == ".avi" || - ext == ".wav" || - ext == ".mp4" || - ext == ".mp3" || - ext == ".mkv" || - ext == ".ogg") { + if (base::strcasecmp(ext.data(), ".avi") == 0 || + base::strcasecmp(ext.data(), ".wav") == 0 || + base::strcasecmp(ext.data(), ".mp4") == 0 || + base::strcasecmp(ext.data(), ".mp3") == 0 || + base::strcasecmp(ext.data(), ".mkv") == 0 || + base::strcasecmp(ext.data(), ".ogg") == 0) { + Browser* browser = BrowserList::GetLastActive(); + if (!browser) + return; MediaPlayer* mediaplayer = MediaPlayer::GetInstance(); - std::string url = "file://"; - url += full_path.value(); - GURL gurl(url); - mediaplayer->EnqueueMediaURL(gurl, NULL); + mediaplayer->EnqueueMediaFile(browser->profile(), full_path, NULL); return; } diff --git a/chrome/browser/resources/active_downloads.html b/chrome/browser/resources/active_downloads.html index fdec63b..153b8a6 100644 --- a/chrome/browser/resources/active_downloads.html +++ b/chrome/browser/resources/active_downloads.html @@ -1327,13 +1327,11 @@ function clearPreviewPane() { } function playMediaFile(path) { - var newPath = 'file://' + path; - chrome.send('playMediaFile', [newPath]); + chrome.send('playMediaFile', [path]); } function enqueueMediaFile(path) { - var newPath = 'file://' + path; - chrome.send('enqueueMediaFile', [newPath]); + chrome.send('enqueueMediaFile', [path]); } function showImage(path) { diff --git a/chrome/browser/resources/file_manager/js/file_manager.js b/chrome/browser/resources/file_manager/js/file_manager.js index 03bc6c0..47a1c91 100644 --- a/chrome/browser/resources/file_manager/js/file_manager.js +++ b/chrome/browser/resources/file_manager/js/file_manager.js @@ -713,7 +713,7 @@ FileManager.prototype = { var entry = this.table.dataModel.item(selectedIndexes[i]); selection.entries.push(entry); - selection.uris.push(entry.toURI()); + selection.uris.push(entry.toURL()); if (selection.iconType == null) { selection.iconType = getIconType(entry); @@ -997,7 +997,7 @@ FileManager.prototype = { selectable = !!this.filenameInput_.value; } else if (this.dialogType_ == FileManager.DialogType.FULL_PAGE) { // No "select" buttons on the full page UI. - selectable = false; + selectable = true; } else { throw new Error('Unknown dialog type'); } @@ -1218,10 +1218,11 @@ FileManager.prototype = { * @param {Event} event The click event. */ FileManager.prototype.onOk_ = function(event) { - var currentPath = this.currentDirEntry_.fullPath.substr(1); + console.log("dialogType = " + this.dialogType_); + var currentDirUrl = this.currentDirEntry_.toURL(); - if (currentPath) - currentPath += '/'; + if (currentDirUrl.charAt(currentDirUrl.length - 1) != '/') + currentDirUrl += '/'; if (this.dialogType_ == FileManager.DialogType.SELECT_SAVEAS_FILE) { // Save-as doesn't require a valid selection from the list, since @@ -1230,7 +1231,8 @@ FileManager.prototype = { if (!filename) throw new Error('Missing filename!'); - chrome.fileBrowserPrivate.selectFile(currentPath + filename, 0); + chrome.fileBrowserPrivate.selectFile(currentDirUrl + encodeURI(filename), + 0); window.close(); return; } @@ -1251,7 +1253,7 @@ FileManager.prototype = { continue; } - ary.push(currentPath + entry.name); + ary.push(currentDirUrl + encodeURI(entry.name)); } // Multi-file selection has no other restrictions. @@ -1261,6 +1263,12 @@ FileManager.prototype = { return; } + // In full screen mode, open all files for vieweing. + if (this.dialogType_ == FileManager.DialogType.FULL_PAGE) { + chrome.fileBrowserPrivate.viewFiles(ary); + return; + } + // Everything else must have exactly one. if (ary.length > 1) throw new Error('Too many files selected!'); diff --git a/chrome/browser/resources/file_manager/js/mock_chrome.js b/chrome/browser/resources/file_manager/js/mock_chrome.js index 5b0a9c4..7a2b399 100644 --- a/chrome/browser/resources/file_manager/js/mock_chrome.js +++ b/chrome/browser/resources/file_manager/js/mock_chrome.js @@ -21,6 +21,14 @@ chrome.fileBrowserPrivate = { }, /** + * View multiple files. + */ + viewFiles: function(selectedFiles) { + console.log('viewFiles called: ' + selectedFiles.length + + ' files selected'); + }, + + /** * Select multiple files. */ selectFiles: function(selectedFiles) { diff --git a/chrome/browser/resources/mediaplayer.html b/chrome/browser/resources/mediaplayer.html index 094a263..f9ce076 100644 --- a/chrome/browser/resources/mediaplayer.html +++ b/chrome/browser/resources/mediaplayer.html @@ -329,7 +329,8 @@ function onLoadedProgress(e) { } function onMediaError(e) { - console.log('Got new error' + e); + console.log('Got new error'); + console.log(e); chrome.send('playbackError', ['Error playing back', currentPlaylist[currentItem].path]); if (currentPlaylist.length == 1) { diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc index 04ee11f..eb30372 100644 --- a/chrome/browser/ui/browser.cc +++ b/chrome/browser/ui/browser.cc @@ -91,7 +91,6 @@ #include "chrome/browser/ui/web_applications/web_app_ui.h" #include "chrome/browser/ui/webui/active_downloads_ui.h" #include "chrome/browser/ui/webui/bug_report_ui.h" -#include "chrome/browser/ui/webui/filebrowse_ui.h" #include "chrome/browser/ui/webui/options/content_settings_handler.h" #include "chrome/browser/ui/window_sizer.h" #include "chrome/browser/upgrade_detector.h" diff --git a/chrome/browser/ui/webui/active_downloads_ui.cc b/chrome/browser/ui/webui/active_downloads_ui.cc index 3d7cc0c..580193b 100644 --- a/chrome/browser/ui/webui/active_downloads_ui.cc +++ b/chrome/browser/ui/webui/active_downloads_ui.cc @@ -414,25 +414,23 @@ void ActiveDownloadsHandler::HandleGetRoots(const ListValue* args) { void ActiveDownloadsHandler::PlayMediaFile(const ListValue* args) { #if defined(OS_CHROMEOS) - std::string url = UTF16ToUTF8(ExtractStringValue(args)); - GURL gurl(url); + FilePath file_path(UTF16ToUTF8(ExtractStringValue(args))); Browser* browser = Browser::GetBrowserForController( &tab_contents_->controller(), NULL); MediaPlayer* mediaplayer = MediaPlayer::GetInstance(); - mediaplayer->ForcePlayMediaURL(gurl, browser); + mediaplayer->ForcePlayMediaFile(profile_, file_path, browser); #endif } void ActiveDownloadsHandler::EnqueueMediaFile(const ListValue* args) { #if defined(OS_CHROMEOS) - std::string url = UTF16ToUTF8(ExtractStringValue(args)); - GURL gurl(url); + FilePath file_path(UTF16ToUTF8(ExtractStringValue(args))); Browser* browser = Browser::GetBrowserForController( &tab_contents_->controller(), NULL); MediaPlayer* mediaplayer = MediaPlayer::GetInstance(); - mediaplayer->EnqueueMediaURL(gurl, browser); + mediaplayer->EnqueueMediaFile(profile_, file_path, browser); #endif } @@ -440,11 +438,9 @@ void ActiveDownloadsHandler::HandleIsAdvancedEnabled(const ListValue* args) { #if defined(OS_CHROMEOS) bool is_enabled = CommandLine::ForCurrentProcess()->HasSwitch( switches::kEnableAdvancedFileSystem); - bool mp_enabled = CommandLine::ForCurrentProcess()->HasSwitch( - switches::kEnableMediaPlayer); DictionaryValue info_value; info_value.SetBoolean("enabled", is_enabled); - info_value.SetBoolean("mpEnabled", mp_enabled); + info_value.SetBoolean("mpEnabled", true); web_ui_->CallJavascriptFunction("enabledResult", info_value); #endif diff --git a/chrome/browser/ui/webui/chrome_web_ui_factory.cc b/chrome/browser/ui/webui/chrome_web_ui_factory.cc index 02db80c..a06142f 100644 --- a/chrome/browser/ui/webui/chrome_web_ui_factory.cc +++ b/chrome/browser/ui/webui/chrome_web_ui_factory.cc @@ -48,7 +48,6 @@ #include "chrome/browser/ui/webui/chromeos/sim_unlock_ui.h" #include "chrome/browser/ui/webui/chromeos/system_info_ui.h" #include "chrome/browser/ui/webui/active_downloads_ui.h" -#include "chrome/browser/ui/webui/filebrowse_ui.h" #include "chrome/browser/ui/webui/mediaplayer_ui.h" #endif @@ -187,8 +186,6 @@ static WebUIFactoryFunction GetWebUIFactoryFunction(Profile* profile, url.host() == chrome::kChromeUIHttpAuthHost) { return &NewWebUI<ConstrainedHtmlUI>; } - if (url.host() == chrome::kChromeUIFileBrowseHost) - return &NewWebUI<FileBrowseUI>; if (url.host() == chrome::kChromeUIActiveDownloadsHost) return &NewWebUI<ActiveDownloadsUI>; if (url.host() == chrome::kChromeUIImageBurnerHost) diff --git a/chrome/browser/ui/webui/file_browse_browsertest.cc b/chrome/browser/ui/webui/file_browse_browsertest.cc deleted file mode 100644 index 8a127cd..0000000 --- a/chrome/browser/ui/webui/file_browse_browsertest.cc +++ /dev/null @@ -1,131 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "base/path_service.h" -#include "base/task.h" -#include "chrome/browser/ui/views/html_dialog_view.h" -#include "chrome/common/chrome_paths.h" -#include "chrome/common/url_constants.h" -#include "chrome/test/in_process_browser_test.h" -#include "chrome/test/ui_test_utils.h" -#include "content/browser/tab_contents/navigation_controller.h" -#include "content/browser/tab_contents/tab_contents.h" -#include "content/browser/webui/web_ui.h" -#include "content/common/notification_registrar.h" -#include "net/test/test_server.h" - -namespace { - -typedef DOMElementProxy::By By; - -class FileBrowseBrowserTest : public InProcessBrowserTest { - public: - FileBrowseBrowserTest() { - EnableDOMAutomation(); - } -}; - -class FileBrowseUiObserver : public NotificationObserver { - public: - FileBrowseUiObserver() : file_browse_tab_(NULL), is_waiting_(false) { - registrar_.Add(this, NotificationType::LOAD_STOP, - NotificationService::AllSources()); - registrar_.Add(this, NotificationType::TAB_CONTENTS_DESTROYED, - NotificationService::AllSources()); - } - - void WaitForFileBrowseLoad() { - if (file_browse_tab_ == NULL) { - is_waiting_ = true; - ui_test_utils::RunMessageLoop(); - } - } - - // File browse tab deletion is a non-nestable task and BrowserTest would - // not get related notification because test body runs in a task already. - // Uses a periodical check of the dialog window to implement the wait. - void WaitForFileBrowseClose() { - if (file_browse_tab_ != NULL) { - is_waiting_ = true; - ui_test_utils::RunMessageLoop(); - } - } - - virtual void Observe(NotificationType type, - const NotificationSource& source, - const NotificationDetails& details) { - if (type == NotificationType::LOAD_STOP) { - NavigationController* controller = - Source<NavigationController>(source).ptr(); - - if (controller) { - TabContents* tab_contents = controller->tab_contents(); - if (tab_contents && - tab_contents->GetURL().SchemeIs(chrome::kChromeUIScheme) && - tab_contents->GetURL().host() == chrome::kChromeUIFileBrowseHost) { - file_browse_tab_ = tab_contents; - - if (is_waiting_) { - is_waiting_ = false; - MessageLoopForUI::current()->Quit(); - } - } - } - } else if (type == NotificationType::TAB_CONTENTS_DESTROYED) { - TabContents* tab_contents = Source<TabContents>(source).ptr(); - if (file_browse_tab_ == tab_contents) { - file_browse_tab_ = NULL; - - if (is_waiting_) { - is_waiting_ = false; - MessageLoopForUI::current()->Quit(); - } - } - } - } - - TabContents* file_browse_tab() { - return file_browse_tab_; - } - - WebUI* file_browse_ui() { - return file_browse_tab_ ? file_browse_tab_->render_manager()->web_ui() : - NULL; - } - - private: - NotificationRegistrar registrar_; - TabContents* file_browse_tab_; - bool is_waiting_; - - DISALLOW_COPY_AND_ASSIGN(FileBrowseUiObserver); -}; - -IN_PROC_BROWSER_TEST_F(FileBrowseBrowserTest, - DISABLED_InputFileTriggerFileBrowse) { - ASSERT_TRUE(test_server()->Start()); - ui_test_utils::NavigateToURL(browser(), - test_server()->GetURL("files/input_file.html")); - - DOMElementProxyRef doc = ui_test_utils::GetActiveDOMDocument(browser()); - - DOMElementProxyRef input_file = doc->FindElement(By::Selectors(".single")); - ASSERT_TRUE(input_file); - - // Creates FileBrowseUiObserver before we click. - FileBrowseUiObserver observer; - - // Click on the input control. This should bring up the FileBrowseUI. - input_file->Click(); - - observer.WaitForFileBrowseLoad(); - WebUI* file_browser_ui = observer.file_browse_ui(); - ASSERT_TRUE(file_browser_ui); - - file_browser_ui->CallJavascriptFunction("dialogCancelClick"); - - observer.WaitForFileBrowseClose(); -} - -} // namespace diff --git a/chrome/browser/ui/webui/filebrowse_ui.cc b/chrome/browser/ui/webui/filebrowse_ui.cc deleted file mode 100644 index 9204401..0000000 --- a/chrome/browser/ui/webui/filebrowse_ui.cc +++ /dev/null @@ -1,1082 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/ui/webui/filebrowse_ui.h" - -#include <algorithm> -#include <vector> - -#include "base/callback.h" -#include "base/command_line.h" -#include "base/file_util.h" -#include "base/logging.h" -#include "base/memory/singleton.h" -#include "base/memory/weak_ptr.h" -#include "base/message_loop.h" -#include "base/path_service.h" -#include "base/string_piece.h" -#include "base/string_util.h" -#include "base/threading/thread.h" -#include "base/time.h" -#include "base/utf_string_conversions.h" -#include "base/values.h" -#include "chrome/browser/bookmarks/bookmark_model.h" -#include "chrome/browser/download/download_item.h" -#include "chrome/browser/download/download_manager.h" -#include "chrome/browser/download/download_util.h" -#include "chrome/browser/history/history_types.h" -#include "chrome/browser/metrics/user_metrics.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/tabs/tab_strip_model.h" -#include "chrome/browser/ui/browser.h" -#include "chrome/browser/ui/browser_list.h" -#include "chrome/browser/ui/browser_navigator.h" -#include "chrome/browser/ui/browser_window.h" -#include "chrome/browser/ui/webui/favicon_source.h" -#include "chrome/browser/ui/webui/mediaplayer_ui.h" -#include "chrome/common/chrome_paths.h" -#include "chrome/common/chrome_switches.h" -#include "chrome/common/jstemplate_builder.h" -#include "chrome/common/net/url_fetcher.h" -#include "chrome/common/time_format.h" -#include "chrome/common/url_constants.h" -#include "content/browser/browser_thread.h" -#include "content/browser/tab_contents/tab_contents.h" -#include "grit/browser_resources.h" -#include "grit/chromium_strings.h" -#include "grit/generated_resources.h" -#include "grit/locale_settings.h" -#include "net/base/escape.h" -#include "net/url_request/url_request_file_job.h" -#include "ui/base/l10n/l10n_util.h" -#include "ui/base/resource/resource_bundle.h" - -#if defined(OS_CHROMEOS) -#include "chrome/browser/chromeos/cros/cros_library.h" -#include "chrome/browser/chromeos/cros/mount_library.h" -#include "chrome/browser/chromeos/login/user_manager.h" -#endif - -// Maximum number of search results to return in a given search. We should -// eventually remove this. -static const int kMaxSearchResults = 100; -static const char kPropertyPath[] = "path"; -static const char kPropertyTitle[] = "title"; -static const char kPropertyDirectory[] = "isDirectory"; -static const char kMediaPath[] = "/media"; -static const char kFilebrowseURLHash[] = "chrome://filebrowse#"; -static const int kPopupLeft = 0; -static const int kPopupTop = 0; - -class FileBrowseUIHTMLSource : public ChromeURLDataManager::DataSource { - public: - FileBrowseUIHTMLSource(); - - // Called when the network layer has requested a resource underneath - // the path we registered. - virtual void StartDataRequest(const std::string& path, - bool is_incognito, - int request_id); - virtual std::string GetMimeType(const std::string&) const { - return "text/html"; - } - - private: - ~FileBrowseUIHTMLSource() {} - - DISALLOW_COPY_AND_ASSIGN(FileBrowseUIHTMLSource); -}; - -class TaskProxy; - -// The handler for Javascript messages related to the "filebrowse" view. -class FilebrowseHandler : public net::DirectoryLister::DirectoryListerDelegate, - public WebUIMessageHandler, -#if defined(OS_CHROMEOS) - public chromeos::MountLibrary::Observer, -#endif - public base::SupportsWeakPtr<FilebrowseHandler>, - public DownloadManager::Observer, - public DownloadItem::Observer { - public: - FilebrowseHandler(); - virtual ~FilebrowseHandler(); - - // Init work after Attach. - void Init(); - - // DirectoryLister::DirectoryListerDelegate methods: - virtual void OnListFile( - const net::DirectoryLister::DirectoryListerData& data); - virtual void OnListDone(int error); - - // WebUIMessageHandler implementation. - virtual WebUIMessageHandler* Attach(WebUI* web_ui); - virtual void RegisterMessages(); - -#if defined(OS_CHROMEOS) - // chromeos::MountLibrary::Observer interface - virtual void DiskChanged(chromeos::MountLibraryEventType event, - const chromeos::MountLibrary::Disk* disk); - virtual void DeviceChanged(chromeos::MountLibraryEventType event, - const std::string& device_path); -#endif - - // DownloadItem::Observer interface - virtual void OnDownloadUpdated(DownloadItem* download); - virtual void OnDownloadFileCompleted(DownloadItem* download); - virtual void OnDownloadOpened(DownloadItem* download) { } - - // DownloadManager::Observer interface - virtual void ModelChanged(); - - // Callback for the "getRoots" message. - void HandleGetRoots(const ListValue* args); - - void GetChildrenForPath(const FilePath& path, bool is_refresh); - - // Callback for the "getChildren" message. - void HandleGetChildren(const ListValue* args); - // Callback for the "refreshDirectory" message. - void HandleRefreshDirectory(const ListValue* args); - void HandleIsAdvancedEnabled(const ListValue* args); - - // Callback for the "getMetadata" message. - void HandleGetMetadata(const ListValue* args); - - // Callback for the "openNewWindow" message. - void OpenNewFullWindow(const ListValue* args); - void OpenNewPopupWindow(const ListValue* args); - - // Callback for the "getDownloads" message. - void HandleGetDownloads(const ListValue* args); - - void HandleCreateNewFolder(const ListValue* args); - - void PlayMediaFile(const ListValue* args); - void EnqueueMediaFile(const ListValue* args); - - void HandleDeleteFile(const ListValue* args); - void HandleCopyFile(const ListValue* value); - void CopyFile(const FilePath& src, const FilePath& dest, TaskProxy* task); - void DeleteFile(const FilePath& path, TaskProxy* task); - void FireDeleteComplete(const FilePath& path); - void FireCopyComplete(const FilePath& src, const FilePath& dest); - - void HandlePauseToggleDownload(const ListValue* args); - - void HandleCancelDownload(const ListValue* args); - void HandleAllowDownload(const ListValue* args); - - void CreateNewFolder(const FilePath& path) const; - - // Callback for the "validateSavePath" message. - void HandleValidateSavePath(const ListValue* args); - - // Validate a save path on file thread. - void ValidateSavePathOnFileThread(const FilePath& save_path, TaskProxy* task); - - // Fire save path validation result to JS onValidatedSavePath. - void FireOnValidatedSavePathOnUIThread(bool valid, const FilePath& save_path); - - private: - - // Retrieves downloads from the DownloadManager and updates the page. - void UpdateDownloadList(); - - void OpenNewWindow(const ListValue* args, bool popup); - - // Clear all download items and their observers. - void ClearDownloadItems(); - - // Send the current list of downloads to the page. - void SendCurrentDownloads(); - - void SendNewDownload(DownloadItem* download); - - bool ValidateSaveDir(const FilePath& save_dir, bool exists) const; - bool AccessDisabled(const FilePath& path) const; - - scoped_ptr<ListValue> filelist_value_; - FilePath currentpath_; - Profile* profile_; - TabContents* tab_contents_; - std::string current_file_contents_; - TaskProxy* current_task_; - scoped_refptr<net::DirectoryLister> lister_; - bool is_refresh_; - - DownloadManager* download_manager_; - typedef std::vector<DownloadItem*> DownloadList; - DownloadList active_download_items_; - DownloadList download_items_; - bool got_first_download_list_; - DISALLOW_COPY_AND_ASSIGN(FilebrowseHandler); -}; - -class TaskProxy : public base::RefCountedThreadSafe<TaskProxy> { - public: - TaskProxy(const base::WeakPtr<FilebrowseHandler>& handler, - const FilePath& path, const FilePath& dest) - : handler_(handler), - src_(path), - dest_(dest) {} - TaskProxy(const base::WeakPtr<FilebrowseHandler>& handler, - const FilePath& path) - : handler_(handler), - src_(path) {} - - // TaskProxy is created on the UI thread, so in some cases, - // we need to post back to the UI thread for destruction. - void DeleteOnUIThread() { - BrowserThread::PostTask( - BrowserThread::UI, FROM_HERE, - NewRunnableMethod(this, &TaskProxy::DoNothing)); - } - - void DoNothing() {} - - void DeleteFileProxy() { - if (handler_) - handler_->DeleteFile(src_, this); - } - - void CopyFileProxy() { - if (handler_) - handler_->CopyFile(src_, dest_, this); - } - - void CreateNewFolderProxy() { - if (handler_) - handler_->CreateNewFolder(src_); - DeleteOnUIThread(); - } - - void FireDeleteCompleteProxy() { - if (handler_) - handler_->FireDeleteComplete(src_); - } - void FireCopyCompleteProxy() { - if (handler_) - handler_->FireCopyComplete(src_, dest_); - } - - void ValidateSavePathOnFileThread() { - if (handler_) - handler_->ValidateSavePathOnFileThread(src_, this); - } - - void FireOnValidatedSavePathOnUIThread(bool valid) { - if (handler_) - handler_->FireOnValidatedSavePathOnUIThread(valid, src_); - } - - private: - base::WeakPtr<FilebrowseHandler> handler_; - FilePath src_; - FilePath dest_; - friend class base::RefCountedThreadSafe<TaskProxy>; - DISALLOW_COPY_AND_ASSIGN(TaskProxy); -}; - - -//////////////////////////////////////////////////////////////////////////////// -// -// FileBrowseHTMLSource -// -//////////////////////////////////////////////////////////////////////////////// - -FileBrowseUIHTMLSource::FileBrowseUIHTMLSource() - : DataSource(chrome::kChromeUIFileBrowseHost, MessageLoop::current()) { -} - -void FileBrowseUIHTMLSource::StartDataRequest(const std::string& path, - bool is_incognito, - int request_id) { - DictionaryValue localized_strings; - // TODO(dhg): Add stirings to localized strings, also add more strings - // that are currently hardcoded. - localized_strings.SetString("title", - l10n_util::GetStringUTF16(IDS_FILEBROWSER_TITLE)); - localized_strings.SetString("pause", - l10n_util::GetStringUTF16(IDS_FILEBROWSER_PAUSE)); - localized_strings.SetString("resume", - l10n_util::GetStringUTF16(IDS_FILEBROWSER_RESUME)); - localized_strings.SetString("scanning", - l10n_util::GetStringUTF16(IDS_FILEBROWSER_SCANNING)); - localized_strings.SetString("confirmdelete", - l10n_util::GetStringUTF16(IDS_FILEBROWSER_CONFIRM_DELETE)); - localized_strings.SetString("confirmyes", - l10n_util::GetStringUTF16(IDS_FILEBROWSER_CONFIRM_YES)); - localized_strings.SetString("confirmcancel", - l10n_util::GetStringUTF16(IDS_FILEBROWSER_CONFIRM_CANCEL)); - localized_strings.SetString("allowdownload", - l10n_util::GetStringUTF16(IDS_FILEBROWSER_CONFIRM_DOWNLOAD)); - localized_strings.SetString("filenameprompt", - l10n_util::GetStringUTF16(IDS_FILEBROWSER_PROMPT_FILENAME)); - localized_strings.SetString("save", - l10n_util::GetStringUTF16(IDS_FILEBROWSER_SAVE)); - localized_strings.SetString("newfolder", - l10n_util::GetStringUTF16(IDS_FILEBROWSER_NEW_FOLDER)); - localized_strings.SetString("open", - l10n_util::GetStringUTF16(IDS_FILEBROWSER_OPEN)); - localized_strings.SetString("delete", - l10n_util::GetStringUTF16(IDS_FILEBROWSER_DELETE)); - localized_strings.SetString("enqueue", - l10n_util::GetStringUTF16(IDS_FILEBROWSER_ENQUEUE)); - localized_strings.SetString("mediapath", kMediaPath); - localized_strings.SetString("downloadtitle", - l10n_util::GetStringUTF16(IDS_DOWNLOAD_TITLE)); - FilePath default_download_path; - if (!PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS, - &default_download_path)) { - NOTREACHED(); - } - // TODO(viettrungluu): this is wrong -- FilePath's need not be Unicode. - localized_strings.SetString("downloadpath", default_download_path.value()); - localized_strings.SetString("error_unknown_file_type", - l10n_util::GetStringUTF16(IDS_FILEBROWSER_ERROR_UNKNOWN_FILE_TYPE)); - SetFontAndTextDirection(&localized_strings); - - static const base::StringPiece filebrowse_html( - ResourceBundle::GetSharedInstance().GetRawDataResource( - IDR_FILEBROWSE_HTML)); - const std::string full_html = jstemplate_builder::GetI18nTemplateHtml( - filebrowse_html, &localized_strings); - - scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); - html_bytes->data.resize(full_html.size()); - std::copy(full_html.begin(), full_html.end(), html_bytes->data.begin()); - - SendResponse(request_id, html_bytes); -} - -//////////////////////////////////////////////////////////////////////////////// -// -// FilebrowseHandler -// -//////////////////////////////////////////////////////////////////////////////// -FilebrowseHandler::FilebrowseHandler() - : profile_(NULL), - tab_contents_(NULL), - is_refresh_(false), - download_manager_(NULL), - got_first_download_list_(false) { - lister_ = NULL; -#if defined(OS_CHROMEOS) - chromeos::MountLibrary* lib = - chromeos::CrosLibrary::Get()->GetMountLibrary(); - lib->AddObserver(this); -#endif -} - -FilebrowseHandler::~FilebrowseHandler() { -#if defined(OS_CHROMEOS) - chromeos::MountLibrary* lib = - chromeos::CrosLibrary::Get()->GetMountLibrary(); - lib->RemoveObserver(this); -#endif - if (lister_.get()) { - lister_->Cancel(); - lister_->set_delegate(NULL); - } - - ClearDownloadItems(); - download_manager_->RemoveObserver(this); -} - -WebUIMessageHandler* FilebrowseHandler::Attach(WebUI* web_ui) { - // Create our favicon data source. - profile_ = web_ui->GetProfile(); - profile_->GetChromeURLDataManager()->AddDataSource( - new FaviconSource(profile_)); - tab_contents_ = web_ui->tab_contents(); - return WebUIMessageHandler::Attach(web_ui); -} - -void FilebrowseHandler::Init() { - download_manager_ = profile_->GetDownloadManager(); - download_manager_->AddObserver(this); -} - -void FilebrowseHandler::RegisterMessages() { - web_ui_->RegisterMessageCallback("getRoots", - NewCallback(this, &FilebrowseHandler::HandleGetRoots)); - web_ui_->RegisterMessageCallback("getChildren", - NewCallback(this, &FilebrowseHandler::HandleGetChildren)); - web_ui_->RegisterMessageCallback("getMetadata", - NewCallback(this, &FilebrowseHandler::HandleGetMetadata)); - web_ui_->RegisterMessageCallback("openNewPopupWindow", - NewCallback(this, &FilebrowseHandler::OpenNewPopupWindow)); - web_ui_->RegisterMessageCallback("openNewFullWindow", - NewCallback(this, &FilebrowseHandler::OpenNewFullWindow)); - web_ui_->RegisterMessageCallback("getDownloads", - NewCallback(this, &FilebrowseHandler::HandleGetDownloads)); - web_ui_->RegisterMessageCallback("createNewFolder", - NewCallback(this, &FilebrowseHandler::HandleCreateNewFolder)); - web_ui_->RegisterMessageCallback("playMediaFile", - NewCallback(this, &FilebrowseHandler::PlayMediaFile)); - web_ui_->RegisterMessageCallback("enqueueMediaFile", - NewCallback(this, &FilebrowseHandler::EnqueueMediaFile)); - web_ui_->RegisterMessageCallback("pauseToggleDownload", - NewCallback(this, &FilebrowseHandler::HandlePauseToggleDownload)); - web_ui_->RegisterMessageCallback("deleteFile", - NewCallback(this, &FilebrowseHandler::HandleDeleteFile)); - web_ui_->RegisterMessageCallback("copyFile", - NewCallback(this, &FilebrowseHandler::HandleCopyFile)); - web_ui_->RegisterMessageCallback("cancelDownload", - NewCallback(this, &FilebrowseHandler::HandleCancelDownload)); - web_ui_->RegisterMessageCallback("allowDownload", - NewCallback(this, &FilebrowseHandler::HandleAllowDownload)); - web_ui_->RegisterMessageCallback("refreshDirectory", - NewCallback(this, &FilebrowseHandler::HandleRefreshDirectory)); - web_ui_->RegisterMessageCallback("isAdvancedEnabled", - NewCallback(this, &FilebrowseHandler::HandleIsAdvancedEnabled)); - web_ui_->RegisterMessageCallback("validateSavePath", - NewCallback(this, &FilebrowseHandler::HandleValidateSavePath)); -} - - -void FilebrowseHandler::FireDeleteComplete(const FilePath& path) { - // We notify the UI by telling it to refresh its contents. - FilePath dir_path = path.DirName(); - GetChildrenForPath(dir_path, true); -}; - -void FilebrowseHandler::FireCopyComplete(const FilePath& src, - const FilePath& dest) { - // Notify the UI somehow. - FilePath dir_path = dest.DirName(); - GetChildrenForPath(dir_path, true); -}; - -#if defined(OS_CHROMEOS) -void FilebrowseHandler::DiskChanged(chromeos::MountLibraryEventType event, - const chromeos::MountLibrary::Disk* disk) { - if (event == chromeos::MOUNT_DISK_REMOVED || - event == chromeos::MOUNT_DISK_CHANGED) { - web_ui_->CallJavascriptFunction("rootsChanged"); - } -} - -void FilebrowseHandler::DeviceChanged(chromeos::MountLibraryEventType event, - const std::string& device_path) { -} -#endif - -void FilebrowseHandler::HandleGetRoots(const ListValue* args) { - ListValue results_value; - DictionaryValue info_value; - // TODO(dhg): add other entries, make this more general -#if defined(OS_CHROMEOS) - chromeos::MountLibrary* lib = chromeos::CrosLibrary::Get()->GetMountLibrary(); - for (chromeos::MountLibrary::DiskMap::const_iterator iter = - lib->disks().begin(); - iter != lib->disks().end(); - ++iter) { - const chromeos::MountLibrary::Disk* disk = iter->second; - if (!disk->mount_path().empty()) { - DictionaryValue* page_value = new DictionaryValue(); - page_value->SetString(kPropertyPath, disk->mount_path()); - FilePath currentpath(disk->mount_path()); - std::string filename; - filename = currentpath.BaseName().value(); - page_value->SetString(kPropertyTitle, filename); - page_value->SetBoolean(kPropertyDirectory, true); - results_value.Append(page_value); - } - } -#else - DictionaryValue* page_value = new DictionaryValue(); - page_value->SetString(kPropertyPath, "/media"); - page_value->SetString(kPropertyTitle, "Removeable"); - page_value->SetBoolean(kPropertyDirectory, true); - results_value.Append(page_value); -#endif - FilePath default_download_path; - if (!PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS, - &default_download_path)) { - NOTREACHED(); - } - - DictionaryValue* download_value = new DictionaryValue(); - download_value->SetString(kPropertyPath, default_download_path.value()); - download_value->SetString(kPropertyTitle, "File Shelf"); - download_value->SetBoolean(kPropertyDirectory, true); - - results_value.Append(download_value); - - info_value.SetString("functionCall", "getRoots"); - info_value.SetString(kPropertyPath, ""); - web_ui_->CallJavascriptFunction("browseFileResult", - info_value, results_value); -} - -void FilebrowseHandler::HandleCreateNewFolder(const ListValue* args) { -#if defined(OS_CHROMEOS) - std::string path = UTF16ToUTF8(ExtractStringValue(args)); - FilePath currentpath(path); - - scoped_refptr<TaskProxy> task = new TaskProxy(AsWeakPtr(), currentpath); - BrowserThread::PostTask( - BrowserThread::FILE, FROM_HERE, - NewRunnableMethod( - task.get(), &TaskProxy::CreateNewFolderProxy)); -#endif -} - -void FilebrowseHandler::CreateNewFolder(const FilePath& currentpath) const { - if (!ValidateSaveDir(currentpath, false) || - !file_util::CreateDirectory(currentpath)) - LOG(ERROR) << "Unable to create directory " << currentpath.value(); -} - -void FilebrowseHandler::PlayMediaFile(const ListValue* args) { -#if defined(OS_CHROMEOS) - std::string url = UTF16ToUTF8(ExtractStringValue(args)); - GURL gurl(url); - - Browser* browser = Browser::GetBrowserForController( - &tab_contents_->controller(), NULL); - MediaPlayer* mediaplayer = MediaPlayer::GetInstance(); - mediaplayer->ForcePlayMediaURL(gurl, browser); -#endif -} - -void FilebrowseHandler::EnqueueMediaFile(const ListValue* args) { -#if defined(OS_CHROMEOS) - std::string url = UTF16ToUTF8(ExtractStringValue(args)); - GURL gurl(url); - - Browser* browser = Browser::GetBrowserForController( - &tab_contents_->controller(), NULL); - MediaPlayer* mediaplayer = MediaPlayer::GetInstance(); - mediaplayer->EnqueueMediaURL(gurl, browser); -#endif -} - -void FilebrowseHandler::HandleIsAdvancedEnabled(const ListValue* args) { -#if defined(OS_CHROMEOS) - bool is_enabled = CommandLine::ForCurrentProcess()->HasSwitch( - switches::kEnableAdvancedFileSystem); - bool mp_enabled = CommandLine::ForCurrentProcess()->HasSwitch( - switches::kEnableMediaPlayer); - DictionaryValue info_value; - info_value.SetBoolean("enabled", is_enabled); - info_value.SetBoolean("mpEnabled", mp_enabled); - web_ui_->CallJavascriptFunction("enabledResult", - info_value); - -#endif -} - -void FilebrowseHandler::HandleRefreshDirectory(const ListValue* args) { -#if defined(OS_CHROMEOS) - std::string path = UTF16ToUTF8(ExtractStringValue(args)); - FilePath currentpath(path); - GetChildrenForPath(currentpath, true); -#endif -} - -void FilebrowseHandler::HandlePauseToggleDownload(const ListValue* args) { -#if defined(OS_CHROMEOS) - int id; - ExtractIntegerValue(args, &id); - if ((id - 1) >= static_cast<int>(active_download_items_.size())) { - return; - } - DownloadItem* item = active_download_items_[id]; - item->TogglePause(); -#endif -} - -void FilebrowseHandler::HandleAllowDownload(const ListValue* args) { -#if defined(OS_CHROMEOS) - int id; - ExtractIntegerValue(args, &id); - if ((id - 1) >= static_cast<int>(active_download_items_.size())) { - return; - } - - DownloadItem* item = active_download_items_[id]; - download_manager_->DangerousDownloadValidated(item); -#endif -} - -void FilebrowseHandler::HandleCancelDownload(const ListValue* args) { -#if defined(OS_CHROMEOS) - int id; - ExtractIntegerValue(args, &id); - if ((id - 1) >= static_cast<int>(active_download_items_.size())) { - return; - } - DownloadItem* item = active_download_items_[id]; - FilePath path = item->full_path(); - item->Cancel(true); - FilePath dir_path = path.DirName(); - item->Remove(true); - GetChildrenForPath(dir_path, true); -#endif -} - -void FilebrowseHandler::OpenNewFullWindow(const ListValue* args) { - OpenNewWindow(args, false); -} - -void FilebrowseHandler::OpenNewPopupWindow(const ListValue* args) { - OpenNewWindow(args, true); -} - -void FilebrowseHandler::OpenNewWindow(const ListValue* args, bool popup) { - std::string url = UTF16ToUTF8(ExtractStringValue(args)); - Browser* browser = popup ? - Browser::CreateForType(Browser::TYPE_APP_PANEL, profile_) : - BrowserList::GetLastActive(); - browser::NavigateParams params(browser, GURL(url), PageTransition::LINK); - params.disposition = NEW_FOREGROUND_TAB; - browser::Navigate(¶ms); - // TODO(beng): The following two calls should be automatic by Navigate(). - if (popup) { - // TODO(dhg): Remove these from being hardcoded. Allow javascript - // to specify. - params.browser->window()->SetBounds(gfx::Rect(0, 0, 400, 300)); - } - params.browser->window()->Show(); -} - - -void FilebrowseHandler::GetChildrenForPath(const FilePath& path, - bool is_refresh) { - if (path.empty()) - return; - - filelist_value_.reset(new ListValue()); - currentpath_ = path; - - if (lister_.get()) { - lister_->Cancel(); - lister_->set_delegate(NULL); - lister_ = NULL; - } - - is_refresh_ = is_refresh; - -#if defined(OS_CHROMEOS) - // Don't allow listing files in inaccessible dirs. - if (AccessDisabled(path)) - return; -#endif - - FilePath default_download_path; - if (!PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS, - &default_download_path)) { - NOTREACHED(); - } - - if (currentpath_ == default_download_path) { - lister_ = new net::DirectoryLister(currentpath_, - false, - net::DirectoryLister::DATE, - this); - } else { - lister_ = new net::DirectoryLister(currentpath_, this); - } - lister_->Start(); -} - -void FilebrowseHandler::HandleGetChildren(const ListValue* args) { -#if defined(OS_CHROMEOS) - std::string path = UTF16ToUTF8(ExtractStringValue(args)); - FilePath currentpath(path); - filelist_value_.reset(new ListValue()); - - GetChildrenForPath(currentpath, false); -#endif -} - -void FilebrowseHandler::OnListFile( - const net::DirectoryLister::DirectoryListerData& data) { -#if defined(OS_WIN) - if (data.info.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) { - return; - } -#elif defined(OS_POSIX) - if (data.info.filename[0] == '.') { - return; - } - - // Suppress .crdownload files. - static const char crdownload[] = (".crdownload"); - static const size_t crdownload_size = arraysize(crdownload); - const std::string& filename = data.info.filename; - if ((filename.size() > crdownload_size) && - (filename.rfind(crdownload) == (filename.size() - crdownload_size))) - return; -#endif - - DictionaryValue* file_value = new DictionaryValue(); - -#if defined(OS_WIN) - int64 size = (static_cast<int64>(data.info.nFileSizeHigh) << 32) | - data.info.nFileSizeLow; - file_value->SetString(kPropertyTitle, data.info.cFileName); - file_value->SetString(kPropertyPath, - currentpath_.Append(data.info.cFileName).value()); - file_value->SetBoolean(kPropertyDirectory, - (data.info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? true : false); -#elif defined(OS_POSIX) - file_value->SetString(kPropertyTitle, data.info.filename); - file_value->SetString(kPropertyPath, - currentpath_.Append(data.info.filename).value()); - file_value->SetBoolean(kPropertyDirectory, S_ISDIR(data.info.stat.st_mode)); -#endif - filelist_value_->Append(file_value); -} - -void FilebrowseHandler::OnListDone(int error) { - DictionaryValue info_value; - if (is_refresh_) { - info_value.SetString("functionCall", "refresh"); - } else { - info_value.SetString("functionCall", "getChildren"); - } - info_value.SetString(kPropertyPath, currentpath_.value()); - web_ui_->CallJavascriptFunction("browseFileResult", - info_value, *(filelist_value_.get())); -} - -void FilebrowseHandler::HandleGetMetadata(const ListValue* args) { -} - -void FilebrowseHandler::HandleGetDownloads(const ListValue* args) { - UpdateDownloadList(); -} - -void FilebrowseHandler::ModelChanged() { - if (!currentpath_.empty()) - GetChildrenForPath(currentpath_, true); - else - UpdateDownloadList(); -} - -void FilebrowseHandler::UpdateDownloadList() { - ClearDownloadItems(); - - std::vector<DownloadItem*> downloads; - download_manager_->GetAllDownloads(FilePath(), &downloads); - - std::vector<DownloadItem*> new_downloads; - // Scan for any in progress downloads and add ourself to them as an observer. - for (DownloadList::iterator it = downloads.begin(); - it != downloads.end(); ++it) { - DownloadItem* download = *it; - // We want to know what happens as the download progresses and be notified - // when the user validates the dangerous download. - if (download->IsInProgress() || - download->safety_state() == DownloadItem::DANGEROUS) { - download->AddObserver(this); - active_download_items_.push_back(download); - } - DownloadList::iterator item = find(download_items_.begin(), - download_items_.end(), - download); - if (item == download_items_.end() && got_first_download_list_) { - SendNewDownload(download); - } - new_downloads.push_back(download); - } - download_items_.swap(new_downloads); - got_first_download_list_ = true; - SendCurrentDownloads(); -} - -void FilebrowseHandler::SendNewDownload(DownloadItem* download) { - ListValue results_value; - results_value.Append(download_util::CreateDownloadItemValue(download, -1)); - web_ui_->CallJavascriptFunction("newDownload", results_value); -} - -void FilebrowseHandler::DeleteFile(const FilePath& path, TaskProxy* task) { - if (!file_util::Delete(path, true)) { - LOG(ERROR) << "unable to delete directory"; - } - BrowserThread::PostTask( - BrowserThread::UI, FROM_HERE, - NewRunnableMethod(task, &TaskProxy::FireDeleteCompleteProxy)); -} - -void FilebrowseHandler::CopyFile(const FilePath& src, - const FilePath& dest, - TaskProxy* task) { - if (file_util::DirectoryExists(src)) { - if (!file_util::CopyDirectory(src, dest, true)) { - LOG(ERROR) << "unable to copy directory:" << src.value(); - } - } else { - if (!file_util::CopyFile(src, dest)) { - LOG(ERROR) << "unable to copy file" << src.value(); - } - } - BrowserThread::PostTask( - BrowserThread::UI, FROM_HERE, - NewRunnableMethod(task, &TaskProxy::FireCopyCompleteProxy)); -} - -void FilebrowseHandler::HandleDeleteFile(const ListValue* args) { -#if defined(OS_CHROMEOS) - std::string path = UTF16ToUTF8(ExtractStringValue(args)); - FilePath currentpath(path); - - // Don't allow file deletion in inaccessible dirs. - if (AccessDisabled(currentpath)) - return; - - for (unsigned int x = 0; x < active_download_items_.size(); x++) { - FilePath item = active_download_items_[x]->full_path(); - if (item == currentpath) { - active_download_items_[x]->Cancel(true); - active_download_items_[x]->Remove(true); - FilePath dir_path = item.DirName(); - GetChildrenForPath(dir_path, true); - return; - } - } - scoped_refptr<TaskProxy> task = new TaskProxy(AsWeakPtr(), currentpath); - BrowserThread::PostTask( - BrowserThread::FILE, FROM_HERE, - NewRunnableMethod( - task.get(), &TaskProxy::DeleteFileProxy)); -#endif -} - -void FilebrowseHandler::HandleCopyFile(const ListValue* value) { -#if defined(OS_CHROMEOS) - if (value && value->GetType() == Value::TYPE_LIST) { - const ListValue* list_value = static_cast<const ListValue*>(value); - std::string src; - std::string dest; - - // Get path string. - if (list_value->GetString(0, &src) && - list_value->GetString(1, &dest)) { - FilePath SrcPath = FilePath(src); - FilePath DestPath = FilePath(dest); - - // Don't allow file copy to inaccessible dirs. - if (AccessDisabled(DestPath)) - return; - - scoped_refptr<TaskProxy> task = new TaskProxy(AsWeakPtr(), - SrcPath, DestPath); - BrowserThread::PostTask( - BrowserThread::FILE, FROM_HERE, - NewRunnableMethod( - task.get(), &TaskProxy::CopyFileProxy)); - } else { - LOG(ERROR) << "Unable to get string"; - return; - } - } -#endif -} - -void FilebrowseHandler::HandleValidateSavePath(const ListValue* args) { - std::string string_path; - if (!args || !args->GetString(0, &string_path)) { - FireOnValidatedSavePathOnUIThread(false, FilePath()); // Invalid save path. - return; - } - - FilePath save_path(string_path); - -#if defined(OS_CHROMEOS) - scoped_refptr<TaskProxy> task = new TaskProxy(AsWeakPtr(), save_path); - BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, - NewRunnableMethod(task.get(), &TaskProxy::ValidateSavePathOnFileThread)); -#else - // No save path checking for non-ChromeOS platforms. - FireOnValidatedSavePathOnUIThread(true, save_path); -#endif -} - -void FilebrowseHandler::ValidateSavePathOnFileThread( - const FilePath& save_path, TaskProxy* task) { -#if defined(OS_CHROMEOS) - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); - - const bool valid = ValidateSaveDir(save_path.DirName(), true); - - BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, - NewRunnableMethod(task, - &TaskProxy::FireOnValidatedSavePathOnUIThread, - valid)); -#endif -} - -bool FilebrowseHandler::ValidateSaveDir(const FilePath& save_dir, - bool exists) const { -#if defined(OS_CHROMEOS) - FilePath default_download_path; - if (!PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS, - &default_download_path)) { - NOTREACHED(); - } - - // Valid save dir must be inside default download dir. - if (default_download_path == save_dir) - return true; - if (exists) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); - return file_util::ContainsPath(default_download_path, save_dir); - } else { - return default_download_path.IsParent(save_dir); - } -#endif - return false; -} - -void FilebrowseHandler::FireOnValidatedSavePathOnUIThread(bool valid, - const FilePath& save_path) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - - FundamentalValue valid_value(valid); - StringValue path_value(save_path.value()); - web_ui_->CallJavascriptFunction("onValidatedSavePath", - valid_value, path_value); -} - -void FilebrowseHandler::OnDownloadUpdated(DownloadItem* download) { - DownloadList::iterator it = find(active_download_items_.begin(), - active_download_items_.end(), - download); - if (it == active_download_items_.end()) - return; - const int id = static_cast<int>(it - active_download_items_.begin()); - - scoped_ptr<DictionaryValue> download_item( - download_util::CreateDownloadItemValue(download, id)); - web_ui_->CallJavascriptFunction("downloadUpdated", *download_item.get()); -} - -void FilebrowseHandler::ClearDownloadItems() { - for (DownloadList::iterator it = active_download_items_.begin(); - it != active_download_items_.end(); ++it) { - (*it)->RemoveObserver(this); - } - active_download_items_.clear(); -} - -void FilebrowseHandler::SendCurrentDownloads() { - ListValue results_value; - for (DownloadList::iterator it = active_download_items_.begin(); - it != active_download_items_.end(); ++it) { - int index = static_cast<int>(it - active_download_items_.begin()); - results_value.Append(download_util::CreateDownloadItemValue(*it, index)); - } - - web_ui_->CallJavascriptFunction("downloadsList", results_value); -} - -void FilebrowseHandler::OnDownloadFileCompleted(DownloadItem* download) { - GetChildrenForPath(currentpath_, true); -} - -bool FilebrowseHandler::AccessDisabled(const FilePath& path) const { - return !ValidateSaveDir(path, false) && - net::URLRequestFileJob::AccessDisabled(path); -} - -//////////////////////////////////////////////////////////////////////////////// -// -// FileBrowseUI -// -//////////////////////////////////////////////////////////////////////////////// - -FileBrowseUI::FileBrowseUI(TabContents* contents) : HtmlDialogUI(contents) { - FilebrowseHandler* handler = new FilebrowseHandler(); - AddMessageHandler((handler)->Attach(this)); - handler->Init(); - FileBrowseUIHTMLSource* html_source = new FileBrowseUIHTMLSource(); - - // Set up the chrome://filebrowse/ source. - contents->profile()->GetChromeURLDataManager()->AddDataSource(html_source); -} - -// static -Browser* FileBrowseUI::OpenPopup(Profile* profile, - const std::string& hashArgument, - int width, - int height) { - // Get existing pop up for given hashArgument. - Browser* browser = GetPopupForPath(hashArgument, profile); - - // Create new browser if no matching pop up found. - if (browser == NULL) { - browser = Browser::CreateForType(Browser::TYPE_APP_PANEL, profile); - std::string url; - if (hashArgument.empty()) { - url = chrome::kChromeUIFileBrowseURL; - } else { - url = kFilebrowseURLHash; - url.append(hashArgument); - } - - browser::NavigateParams params(browser, GURL(url), PageTransition::LINK); - params.disposition = NEW_FOREGROUND_TAB; - browser::Navigate(¶ms); - // TODO(beng): The following two calls should be automatic by Navigate(). - params.browser->window()->SetBounds(gfx::Rect(kPopupLeft, - kPopupTop, - width, - height)); - - params.browser->window()->Show(); - } else { - browser->window()->Show(); - } - - return browser; -} - -Browser* FileBrowseUI::GetPopupForPath(const std::string& path, - Profile* profile) { - std::string current_path = path; - if (current_path.empty()) { - bool is_enabled = CommandLine::ForCurrentProcess()->HasSwitch( - switches::kEnableAdvancedFileSystem); - if (!is_enabled) { - FilePath default_download_path; - if (!PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS, - &default_download_path)) { - NOTREACHED(); - } - current_path = default_download_path.value(); - } - } - - for (BrowserList::const_iterator it = BrowserList::begin(); - it != BrowserList::end(); ++it) { - if (((*it)->type() == Browser::TYPE_APP_PANEL)) { - TabContents* tab_contents = (*it)->GetSelectedTabContents(); - DCHECK(tab_contents); - if (!tab_contents) - continue; - const GURL& url = tab_contents->GetURL(); - - if (url.SchemeIs(chrome::kChromeUIScheme) && - url.host() == chrome::kChromeUIFileBrowseHost && - url.ref() == current_path && - (*it)->profile() == profile) { - return (*it); - } - } - } - - return NULL; -} - -const int FileBrowseUI::kPopupWidth = 250; -const int FileBrowseUI::kPopupHeight = 300; -const int FileBrowseUI::kSmallPopupWidth = 250; -const int FileBrowseUI::kSmallPopupHeight = 50; diff --git a/chrome/browser/ui/webui/filebrowse_ui.h b/chrome/browser/ui/webui/filebrowse_ui.h deleted file mode 100644 index 3e3a69c..0000000 --- a/chrome/browser/ui/webui/filebrowse_ui.h +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_UI_WEBUI_FILEBROWSE_UI_H_ -#define CHROME_BROWSER_UI_WEBUI_FILEBROWSE_UI_H_ -#pragma once - -#include <string> - -#include "chrome/browser/history/history.h" -#include "chrome/browser/ui/webui/chrome_url_data_manager.h" -#include "chrome/browser/ui/webui/html_dialog_ui.h" -#include "net/base/directory_lister.h" - -class Browser; -class Profile; - -class FileBrowseUI : public HtmlDialogUI { - public: - static const int kPopupWidth; - static const int kPopupHeight; - static const int kSmallPopupWidth; - static const int kSmallPopupHeight; - - explicit FileBrowseUI(TabContents* contents); - - static Browser* OpenPopup(Profile* profile, - const std::string& hashArgument, - int width, - int height); - static Browser* GetPopupForPath(const std::string& path, - Profile* profile); - - private: - DISALLOW_COPY_AND_ASSIGN(FileBrowseUI); -}; - -#endif // CHROME_BROWSER_UI_WEBUI_FILEBROWSE_UI_H_ diff --git a/chrome/browser/ui/webui/mediaplayer_browsertest.cc b/chrome/browser/ui/webui/mediaplayer_browsertest.cc index 32d0a17..0d5fb19 100644 --- a/chrome/browser/ui/webui/mediaplayer_browsertest.cc +++ b/chrome/browser/ui/webui/mediaplayer_browsertest.cc @@ -21,10 +21,6 @@ class MediaPlayerBrowserTest : public InProcessBrowserTest { public: MediaPlayerBrowserTest() {} - virtual void SetUpCommandLine(CommandLine* command_line) { - command_line->AppendSwitch(switches::kEnableMediaPlayer); - } - GURL GetMusicTestURL() { return GURL("http://localhost:1337/files/plugin/sample_mp3.mp3"); } @@ -73,7 +69,7 @@ IN_PROC_BROWSER_TEST_F(MediaPlayerBrowserTest, Popup) { // Check that its not currently visible ASSERT_FALSE(IsPlayerVisible()); - player->EnqueueMediaURL(GetMusicTestURL(), NULL); + player->EnqueueMediaFileUrl(GetMusicTestURL(), NULL); ASSERT_TRUE(IsPlayerVisible()); } @@ -87,7 +83,7 @@ IN_PROC_BROWSER_TEST_F(MediaPlayerBrowserTest, PopupPlaylist) { MediaPlayer* player = MediaPlayer::GetInstance(); - player->EnqueueMediaURL(GetMusicTestURL(), NULL); + player->EnqueueMediaFileUrl(GetMusicTestURL(), NULL); EXPECT_FALSE(IsPlaylistVisible()); diff --git a/chrome/browser/ui/webui/mediaplayer_ui.cc b/chrome/browser/ui/webui/mediaplayer_ui.cc index 5bb6707..f176d6c 100644 --- a/chrome/browser/ui/webui/mediaplayer_ui.cc +++ b/chrome/browser/ui/webui/mediaplayer_ui.cc @@ -18,6 +18,7 @@ #include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/download/download_manager.h" #include "chrome/browser/download/download_util.h" +#include "chrome/browser/extensions/file_manager_util.h" #include "chrome/browser/history/history_types.h" #include "chrome/browser/metrics/user_metrics.h" #include "chrome/browser/profiles/profile.h" @@ -114,7 +115,7 @@ class MediaplayerHandler : public WebUIMessageHandler, void PlaybackMediaFile(const GURL& url); - void EnqueueMediaFile(const GURL& url); + void EnqueueMediaFileUrl(const GURL& url); void GetPlaylistValue(ListValue& args); @@ -300,7 +301,7 @@ void MediaplayerHandler::SetCurrentPlaylist( FirePlaylistChanged(std::string(), false, current_offset_); } -void MediaplayerHandler::EnqueueMediaFile(const GURL& url) { +void MediaplayerHandler::EnqueueMediaFileUrl(const GURL& url) { current_playlist_.push_back(MediaplayerHandler::MediaUrl(url)); FirePlaylistChanged(url.spec(), false, current_offset_); MediaPlayer::GetInstance()->NotifyPlaylistChanged(); @@ -357,22 +358,37 @@ MediaPlayer* MediaPlayer::GetInstance() { return Singleton<MediaPlayer>::get(); } -void MediaPlayer::EnqueueMediaURL(const GURL& url, Browser* creator) { - if (!Enabled()) { - return; +void MediaPlayer::EnqueueMediaFile(Profile* profile, const FilePath& file_path, + Browser* creator) { + static GURL origin_url(kMediaplayerURL); + GURL url; + if (!FileManagerUtil::ConvertFileToFileSystemUrl(profile, file_path, + origin_url, &url)) { } + EnqueueMediaFileUrl(url, creator); +} + +void MediaPlayer::EnqueueMediaFileUrl(const GURL& url, Browser* creator) { if (handler_ == NULL) { unhandled_urls_.push_back(url); PopupMediaPlayer(creator); } else { - handler_->EnqueueMediaFile(url); + handler_->EnqueueMediaFileUrl(url); } } -void MediaPlayer::ForcePlayMediaURL(const GURL& url, Browser* creator) { - if (!Enabled()) { - return; +void MediaPlayer::ForcePlayMediaFile(Profile* profile, + const FilePath& file_path, + Browser* creator) { + static GURL origin_url(kMediaplayerURL); + GURL url; + if (!FileManagerUtil::ConvertFileToFileSystemUrl(profile, file_path, + origin_url, &url)) { } + ForcePlayMediaURL(url, creator); +} + +void MediaPlayer::ForcePlayMediaURL(const GURL& url, Browser* creator) { if (handler_ == NULL) { unhandled_urls_.push_back(url); PopupMediaPlayer(creator); @@ -381,15 +397,6 @@ void MediaPlayer::ForcePlayMediaURL(const GURL& url, Browser* creator) { } } -bool MediaPlayer::Enabled() { -#if defined(OS_CHROMEOS) - return CommandLine::ForCurrentProcess()->HasSwitch( - switches::kEnableMediaPlayer); -#else - return true; -#endif -} - void MediaPlayer::TogglePlaylistWindowVisible() { if (playlist_browser_) { ClosePlaylistWindow(); @@ -425,7 +432,7 @@ void MediaPlayer::SetNewHandler(MediaplayerHandler* handler, mediaplayer_tab_ = contents; RegisterListeners(); for (size_t x = 0; x < unhandled_urls_.size(); x++) { - handler_->EnqueueMediaFile(unhandled_urls_[x]); + handler_->EnqueueMediaFileUrl(unhandled_urls_[x]); } unhandled_urls_.clear(); } @@ -569,7 +576,7 @@ net::URLRequestJob* MediaPlayer::MaybeInterceptResponse( if (supported_mime_types_.find(mime_type) != supported_mime_types_.end()) { if (request->referrer() != chrome::kChromeUIMediaplayerURL && !request->referrer().empty()) { - EnqueueMediaURL(request->url(), NULL); + EnqueueMediaFileUrl(request->url(), NULL); request->Cancel(); } } diff --git a/chrome/browser/ui/webui/mediaplayer_ui.h b/chrome/browser/ui/webui/mediaplayer_ui.h index 055307b..2cd070e 100644 --- a/chrome/browser/ui/webui/mediaplayer_ui.h +++ b/chrome/browser/ui/webui/mediaplayer_ui.h @@ -19,18 +19,31 @@ #include "net/url_request/url_request.h" template <typename T> struct DefaultSingletonTraits; + +class Browser; class GURL; class MediaplayerHandler; -class Browser; +class Profile; class MediaPlayer : public NotificationObserver, public net::URLRequest::Interceptor { public: ~MediaPlayer(); - // Enqueues this url into the current playlist. If the mediaplayer is + // Enqueues this file into the current playlist. If the mediaplayer is // not currently visible, show it, and play the given url. - void EnqueueMediaURL(const GURL& url, Browser* creator); + void EnqueueMediaFile(Profile* profile, const FilePath& file_path, + Browser* creator); + + // Enqueues this fileschema url into the current playlist. If the mediaplayer + // is not currently visible, show it, and play the given url. + void EnqueueMediaFileUrl(const GURL& url, Browser* creator); + + // Clears out the current playlist, and start playback of the given + // |file_path|. If there is no mediaplayer currently, show it, and play the + // given |file_path|. + void ForcePlayMediaFile(Profile* profile, const FilePath& file_path, + Browser* creator); // Clears out the current playlist, and start playback of the given url. // If there is no mediaplayer currently, show it, and play the given url. @@ -100,9 +113,6 @@ class MediaPlayer : public NotificationObserver, // locations correctly. void PopupMediaPlayer(Browser* creator); - // Checks to see the the mediaplayer is currently enabled - bool Enabled(); - // Popup the playlist. Shows the browser, sets it up to point at // chrome://mediaplayer#playlist void PopupPlaylist(Browser* creator); |