Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(209)

Unified Diff: chrome/browser/chromeos/extensions/file_manager_util.cc

Issue 10094012: Made File Manager respect the user-selected launch type (tab/pinned tab/window/fullscreen) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 87fceabd69418ce9f82f49d03ab665b83cfd5aeb..5fce9b1ebe1461a7850ed4b5dbd2ccba788e3198 100644
--- a/chrome/browser/chromeos/extensions/file_manager_util.cc
+++ b/chrome/browser/chromeos/extensions/file_manager_util.cc
@@ -22,16 +22,20 @@
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/plugin_prefs.h"
#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/simple_message_box.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_window.h"
+#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
#include "chrome/common/extensions/file_browser_handler.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/url_constants.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/plugin_service.h"
#include "content/public/browser/user_metrics.h"
+#include "content/public/browser/web_contents.h"
#include "grit/generated_resources.h"
#include "net/base/escape.h"
#include "net/base/net_util.h"
@@ -366,51 +370,92 @@ string16 GetTitleFromType(SelectFileDialog::Type dialog_type) {
return title;
}
-void ViewRemovableDrive(const FilePath& dir) {
- Browser* browser = BrowserList::GetLastActive();
- if (!browser)
- return;
-
- FilePath virtual_path;
- if (!ConvertFileToRelativeFileSystemPath(browser->profile(), dir,
- &virtual_path)) {
- return;
- }
-
- DictionaryValue arg_value;
- arg_value.SetBoolean("mountTriggered", true);
+enum TAB_REUSE_MODE {
+ REUSE_ANY_FILE_MANAGER,
+ REUSE_SAME_PATH,
+ REUSE_NEVER
+};
- std::string json_args;
- base::JSONWriter::Write(&arg_value, &json_args);
+bool FileManageTabExists(const FilePath& path, TAB_REUSE_MODE mode) {
+ if (mode == REUSE_NEVER)
+ return false;
- std::string url = chrome::kChromeUIFileManagerURL;
- url += "?" + json_args + "#/" +
- net::EscapeUrlEncodedData(virtual_path.value(), false);
+ const std::string ref = std::string("/") + path.value();
+
+ for (BrowserList::const_iterator browser_iterator = BrowserList::begin();
+ browser_iterator != BrowserList::end(); ++browser_iterator) {
+ Browser* browser = *browser_iterator;
+ TabStripModel* tab_strip = browser->tabstrip_model();
+ for (int idx = 0; idx < tab_strip->count(); idx++) {
+ content::WebContents* web_contents =
+ tab_strip->GetTabContentsAt(idx)->web_contents();
+ const GURL& url = web_contents->GetURL();
+ if (url.GetOrigin().spec() == chrome::kChromeUIFileManagerURL) {
dgozman 2012/04/16 14:48:32 So, this does not work for 'chrome-extension://...
Vladislav Kaznacheev 2012/04/16 15:23:44 I have added a comment. On 2012/04/16 14:48:32, d
+ if (mode == REUSE_ANY_FILE_MANAGER || ref == url.ref()) {
+ if (mode == REUSE_SAME_PATH && tab_strip->active_index() != idx) {
+ browser->window()->Show();
+ tab_strip->ActivateTabAt(idx, false);
+ }
+ return true;
+ }
+ }
+ }
+ }
- content::RecordAction(UserMetricsAction("ShowFileBrowserFullTab"));
- browser->ShowSingletonTabRespectRef(GURL(url));
+ return false;
}
-void OpenFileBrowser(const FilePath& full_path) {
- Browser* browser = BrowserList::GetLastActive();
- if (!browser)
+void OpenFileBrowser(const FilePath& path,
+ TAB_REUSE_MODE mode,
+ const std::string& flag_name) {
+ if (FileManageTabExists(path, mode))
return;
+ Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord();
+
FilePath virtual_path;
- if (!ConvertFileToRelativeFileSystemPath(browser->profile(), full_path,
- &virtual_path)) {
+ if (!ConvertFileToRelativeFileSystemPath(profile, path, &virtual_path))
return;
- }
std::string url = chrome::kChromeUIFileManagerURL;
+ if (flag_name.size()) {
+ DictionaryValue arg_value;
+ arg_value.SetBoolean(flag_name, "true");
+ std::string query;
+ base::JSONWriter::Write(&arg_value, &query);
+ url += "?" + net::EscapeUrlEncodedData(query, false);
+ }
url += "#/" + net::EscapeUrlEncodedData(virtual_path.value(), false);
+ ExtensionService* service = profile->GetExtensionService();
+ if (!service)
+ return;
+
+ const Extension* extension =
+ service->GetExtensionById(kFileBrowserDomain, false);
+ if (!extension)
+ return;
+
+ extension_misc::LaunchContainer launch_container =
+ service->extension_prefs()->
+ GetLaunchContainer(extension, ExtensionPrefs::LAUNCH_DEFAULT);
+
content::RecordAction(UserMetricsAction("ShowFileBrowserFullTab"));
- browser->ShowSingletonTabRespectRef(GURL(url));
+ Browser::OpenApplication(
+ profile, extension, launch_container, GURL(url), NEW_FOREGROUND_TAB);
}
-void ViewFolder(const FilePath& dir) {
- OpenFileBrowser(dir);
+void ViewRemovableDrive(const FilePath& path) {
+ OpenFileBrowser(path, REUSE_ANY_FILE_MANAGER, "mountTriggered");
dgozman 2012/04/16 14:48:32 Why reuse any? Maybe, REUSE_SAME_PATH?
Vladislav Kaznacheev 2012/04/16 15:23:44 This is what we want. I added a comment in the hea
+}
+
+void ShowFileInFolder(const FilePath& path) {
+ // This action changes the selection so we do not reuse existing tabs.
+ OpenFileBrowser(path, REUSE_NEVER, "selectOnly");
+}
+
+void ViewFolder(const FilePath& path) {
+ OpenFileBrowser(path, REUSE_SAME_PATH, "");
}
class StandaloneExecutor : public FileTaskExecutor {
@@ -424,19 +469,15 @@ class StandaloneExecutor : public FileTaskExecutor {
protected :
// FileTaskExecutor overrides.
- virtual Browser* browser() { return BrowserList::GetLastActive(); }
+ virtual Browser* browser() {
+ return Browser::GetOrCreateTabbedBrowser(profile());
+ }
virtual void Done(bool) {}
};
-bool TryOpeningFileBrowser(const FilePath& full_path) {
- Browser* browser = BrowserList::GetLastActive();
- if (!browser)
- return false;
-
- Profile* profile = browser->profile();
-
+bool TryOpeningFileBrowser(Profile* profile, const FilePath& path) {
GURL url;
- if (!ConvertFileToFileSystemUrl(profile, full_path,
+ if (!ConvertFileToFileSystemUrl(profile, path,
GetFileBrowserExtensionUrl().GetOrigin(), &url))
return false;
@@ -451,7 +492,11 @@ bool TryOpeningFileBrowser(const FilePath& full_path) {
// Browser tab. Others just end up calling TryViewingFile.
if (action_id == kFileBrowserGalleryTaskId ||
action_id == kFileBrowserMountArchiveTaskId) {
- OpenFileBrowser(full_path);
+ // Tab reuse currently does not work for these two tasks.
+ // |gallery| tries to put the file url into the tab url but it does not
+ // work on Chrome OS.
+ // |mount-archive| does not even try.
+ OpenFileBrowser(path, REUSE_SAME_PATH, "");
return true;
}
} else {
@@ -476,16 +521,16 @@ bool TryOpeningFileBrowser(const FilePath& full_path) {
return false;
}
-void ViewFile(const FilePath& full_path, bool enqueue) {
- if (!TryOpeningFileBrowser(full_path) && !TryViewingFile(full_path)) {
- Browser* browser = BrowserList::GetLastActive();
- if (!browser)
- return;
+void ViewFile(const FilePath& path) {
+ Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord();
+ if (!TryOpeningFileBrowser(profile, path) &&
+ !TryViewingFile(profile, path)) {
+ Browser* browser = Browser::GetOrCreateTabbedBrowser(profile);
browser::ShowErrorBox(
browser->window()->GetNativeHandle(),
l10n_util::GetStringFUTF16(
IDS_FILE_BROWSER_ERROR_VIEWING_FILE_TITLE,
- UTF8ToUTF16(full_path.BaseName().value())),
+ UTF8ToUTF16(path.BaseName().value())),
l10n_util::GetStringUTF16(
IDS_FILE_BROWSER_ERROR_VIEWING_FILE));
}
@@ -510,9 +555,8 @@ bool ReadSmallFileToString(const FilePath& path, std::string* contents) {
void OpenUrlOnUIThread(const GURL& url) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- Browser* browser = BrowserList::GetLastActive();
- if (!browser)
- return;
+ Browser* browser = Browser::GetOrCreateTabbedBrowser(
+ ProfileManager::GetDefaultProfileOrOffTheRecord());
browser->AddSelectedTabWithURL(url, content::PAGE_TRANSITION_LINK);
}
@@ -542,37 +586,33 @@ void ReadUrlFromGDocOnFileThread(const FilePath& file_path) {
base::Bind(OpenUrlOnUIThread, GURL(edit_url_string)));
}
-bool TryViewingFile(const FilePath& full_path) {
+bool TryViewingFile(Profile* profile, const FilePath& path) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- // There is nothing we can do if the browser is not present.
- Browser* browser = BrowserList::GetLastActive();
- if (!browser)
- return true;
+ Browser* browser = Browser::GetOrCreateTabbedBrowser(profile);
- std::string file_extension = full_path.Extension();
+ std::string file_extension = path.Extension();
// For things supported natively by the browser, we should open it
// in a tab.
if (IsSupportedBrowserExtension(file_extension.data()) ||
- ShouldBeOpenedWithPdfPlugin(file_extension.data())) {
- GURL page_url = net::FilePathToFileURL(full_path);
+ ShouldBeOpenedWithPdfPlugin(profile, file_extension.data())) {
+ GURL page_url = net::FilePathToFileURL(path);
#if defined(OS_CHROMEOS)
// Override gdata resource to point to internal handler instead of file:
// URL.
- // There is nothing we can do if the browser is not present.
- if (gdata::util::GetSpecialRemoteRootPath().IsParent(full_path)) {
+ if (gdata::util::GetSpecialRemoteRootPath().IsParent(path)) {
gdata::GDataSystemService* system_service =
- gdata::GDataSystemServiceFactory::GetForProfile(browser->profile());
+ gdata::GDataSystemServiceFactory::GetForProfile(profile);
if (!system_service)
return false;
GetFilePropertiesDelegate delegate;
system_service->file_system()->FindFileByPathSync(
- gdata::util::ExtractGDataPath(full_path), &delegate);
+ gdata::util::ExtractGDataPath(path), &delegate);
if (delegate.resource_id().empty())
return false;
- page_url = gdata::util::GetFileResourceUrl(delegate.resource_id(),
- delegate.file_name());
+ page_url = gdata::util::GetFileResourceUrl(delegate.resource_id(),
+ delegate.file_name());
}
#endif
browser->AddSelectedTabWithURL(page_url,
@@ -581,16 +621,16 @@ bool TryViewingFile(const FilePath& full_path) {
}
if (IsSupportedGDocsExtension(file_extension.data())) {
- if (gdata::util::GetSpecialRemoteRootPath().IsParent(full_path)) {
+ if (gdata::util::GetSpecialRemoteRootPath().IsParent(path)) {
// The file is on Google Docs. Get the Docs from the GData service.
gdata::GDataSystemService* system_service =
- gdata::GDataSystemServiceFactory::GetForProfile(browser->profile());
+ gdata::GDataSystemServiceFactory::GetForProfile(profile);
if (!system_service)
return false;
GetFilePropertiesDelegate delegate;
system_service->file_system()->FindFileByPathSync(
- gdata::util::ExtractGDataPath(full_path), &delegate);
+ gdata::util::ExtractGDataPath(path), &delegate);
if (delegate.edit_url().spec().empty())
return false;
@@ -600,22 +640,26 @@ bool TryViewingFile(const FilePath& full_path) {
// The file is local (downloaded from an attachment or otherwise copied).
// Parse the file to extract the Docs url and open this url.
BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
- base::Bind(&ReadUrlFromGDocOnFileThread, full_path));
+ base::Bind(&ReadUrlFromGDocOnFileThread, path));
}
return true;
}
#if defined(OS_CHROMEOS)
if (IsSupportedAVExtension(file_extension.data())) {
+ GURL url;
+ if (!ConvertFileToFileSystemUrl(profile, path,
+ GetFileBrowserExtensionUrl().GetOrigin(), &url))
+ return false;
MediaPlayer* mediaplayer = MediaPlayer::GetInstance();
- mediaplayer->PopupMediaPlayer(browser);
- mediaplayer->ForcePlayMediaFile(browser->profile(), full_path);
+ mediaplayer->PopupMediaPlayer();
+ mediaplayer->ForcePlayMediaURL(url);
return true;
}
#endif // OS_CHROMEOS
if (IsCRXFile(file_extension.data())) {
- InstallCRX(browser->profile(), full_path);
+ InstallCRX(profile, path);
return true;
}
@@ -629,7 +673,7 @@ bool TryViewingFile(const FilePath& full_path) {
return false;
}
-void InstallCRX(Profile* profile, const FilePath& full_path) {
+void InstallCRX(Profile* profile, const FilePath& path) {
ExtensionService* service = profile->GetExtensionService();
CHECK(service);
if (!service)
@@ -639,18 +683,14 @@ void InstallCRX(Profile* profile, const FilePath& full_path) {
new ExtensionInstallUI(profile)));
installer->set_is_gallery_install(false);
installer->set_allow_silent_install(false);
- installer->InstallCrx(full_path);
+ installer->InstallCrx(path);
}
// If pdf plugin is enabled, we should open pdf files in a tab.
-bool ShouldBeOpenedWithPdfPlugin(const char* file_extension) {
+bool ShouldBeOpenedWithPdfPlugin(Profile* profile, const char* file_extension) {
if (base::strcasecmp(file_extension, kPdfExtension) != 0)
return false;
- Browser* browser = BrowserList::GetLastActive();
- if (!browser)
- return false;
-
FilePath pdf_path;
PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_path);
@@ -658,7 +698,7 @@ bool ShouldBeOpenedWithPdfPlugin(const char* file_extension) {
if (!PluginService::GetInstance()->GetPluginInfoByPath(pdf_path, &plugin))
return false;
- PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(browser->profile());
+ PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile);
if (!plugin_prefs)
return false;
« no previous file with comments | « chrome/browser/chromeos/extensions/file_manager_util.h ('k') | chrome/browser/chromeos/media/media_player.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698