diff options
author | zelidrag@chromium.org <zelidrag@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-16 20:48:51 +0000 |
---|---|---|
committer | zelidrag@chromium.org <zelidrag@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-16 20:48:51 +0000 |
commit | 3d38d8e4427433cc57f62658f09c3480b18b0d92 (patch) | |
tree | 43ae9368d16c03b78986518e6e088b26a4e4b37a | |
parent | a45bda1f74849eb77a4f9140dbeab5ee23b634a8 (diff) | |
download | chromium_src-3d38d8e4427433cc57f62658f09c3480b18b0d92.zip chromium_src-3d38d8e4427433cc57f62658f09c3480b18b0d92.tar.gz chromium_src-3d38d8e4427433cc57f62658f09c3480b18b0d92.tar.bz2 |
Made full tab file browser to open automatically when a new disk device is properly mounted.
BUG=chromium-os:14215
TEST=plug in SD card or USB key, observe file browser opens and navigates to that new device
Review URL: http://codereview.chromium.org/6865033
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@81881 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | build/common.gypi | 15 | ||||
-rw-r--r-- | chrome/app/generated_resources.grd | 4 | ||||
-rw-r--r-- | chrome/browser/chromeos/extensions/file_browser_event_router.cc | 6 | ||||
-rw-r--r-- | chrome/browser/extensions/file_manager_util.cc | 132 | ||||
-rw-r--r-- | chrome/browser/extensions/file_manager_util.h | 50 | ||||
-rw-r--r-- | chrome/browser/ui/views/file_manager_dialogs.cc | 110 | ||||
-rw-r--r-- | chrome/chrome_browser.gypi | 4 |
7 files changed, 203 insertions, 118 deletions
diff --git a/build/common.gypi b/build/common.gypi index 3eab5ac..6333160 100644 --- a/build/common.gypi +++ b/build/common.gypi @@ -23,14 +23,10 @@ # Disable touch support by default. 'touchui%': 0, - - # Disable file manager component extension by default. - 'file_manager_extension%': 0, }, # Copy conditionally-set variables out one scope. 'chromeos%': '<(chromeos)', 'touchui%': '<(touchui)', - 'file_manager_extension%': '<(file_manager_extension)', # To do a shared build on linux we need to be able to choose between # type static_library and shared_library. We default to doing a static @@ -65,7 +61,6 @@ # Copy conditionally-set variables out one scope. 'chromeos%': '<(chromeos)', 'touchui%': '<(touchui)', - 'file_manager_extension%': '<(file_manager_extension)', 'host_arch%': '<(host_arch)', 'library%': '<(library)', 'toolkit_views%': '<(toolkit_views)', @@ -96,6 +91,9 @@ # compilation. 'fastbuild%': 0, + # Disable file manager component extension by default. + 'file_manager_extension%': 0, + # Python version. 'python_ver%': '2.5', @@ -167,6 +165,13 @@ }, { 'enable_flapper_hacks%': 0, }], + + # Enable file manager extension by default on Chrome OS. + ['chromeos==1', { + 'file_manager_extension%': 1, + }, { + 'file_manager_extension%': 0, + }], ], }, diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd index 376e343..d452d17 100644 --- a/chrome/app/generated_resources.grd +++ b/chrome/app/generated_resources.grd @@ -11247,10 +11247,6 @@ Keep your key file in a safe place. You will need it to create new versions of y <message name="IDS_REMOVABLE_DEVICE_SCANNING_MESSAGE" desc="Text of notification message which is shown when user inserts removable device (SD card, USB key...)"> Scanning content... </message> - <!-- TODO(zelidrag): Remove this one once file system is wired --> - <message name="IDS_REMOVABLE_DEVICE_MOUNTED_MESSAGE" desc="Text of notification message which is shown when removable device is ready to be used."> - Removable device is ready to be used, click here to open... - </message> <!-- Network state strings for ChromeOS --> <message name="IDS_CHROMEOS_NETWORK_STATE_UNKNOWN" desc="Network state in about:network: UNKNOWN"> diff --git a/chrome/browser/chromeos/extensions/file_browser_event_router.cc b/chrome/browser/chromeos/extensions/file_browser_event_router.cc index 7cd24479..103e780 100644 --- a/chrome/browser/chromeos/extensions/file_browser_event_router.cc +++ b/chrome/browser/chromeos/extensions/file_browser_event_router.cc @@ -14,6 +14,7 @@ #include "chrome/browser/extensions/extension_event_names.h" #include "chrome/browser/extensions/extension_event_router.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/extensions/file_manager_util.h" #include "grit/generated_resources.h" #include "grit/theme_resources.h" #include "ui/base/l10n/l10n_util.h" @@ -144,9 +145,8 @@ void ExtensionFileBrowserEventRouter::OnDiskChanged( std::pair<std::string, std::string>(disk->device_path(), disk->mount_path())); DispatchEvent(disk->mount_path()); - // TODO(zelidrag): Find better icon here. - ShowDeviceNotification(disk->system_path(), IDR_PAGEINFO_INFO, - l10n_util::GetStringUTF16(IDS_REMOVABLE_DEVICE_MOUNTED_MESSAGE)); + HideDeviceNotification(disk->system_path()); + FileManagerUtil::ShowFullTabUrl(profile_, FilePath(disk->mount_path())); } } } diff --git a/chrome/browser/extensions/file_manager_util.cc b/chrome/browser/extensions/file_manager_util.cc new file mode 100644 index 0000000..8fc1d9c --- /dev/null +++ b/chrome/browser/extensions/file_manager_util.cc @@ -0,0 +1,132 @@ +// 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/extensions/file_manager_util.h" + +#include "base/json/json_writer.h" +#include "base/logging.h" +#include "base/utf_string_conversions.h" +#include "base/values.h" +#include "chrome/browser/metrics/user_metrics.h" +#include "chrome/browser/ui/browser.h" +#include "chrome/browser/ui/browser_list.h" +#include "third_party/libjingle/source/talk/base/urlencode.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 +// out this file manager for an aftermarket part, but not yet. +const char kBaseFileBrowserUrl[] = + "chrome-extension://hhaomjibdihmijegdhdafkllkbggdgoj/main.html"; + +// static +GURL FileManagerUtil::GetFileBrowserUrl() { + return GURL(kBaseFileBrowserUrl); +} + +// static +GURL FileManagerUtil::GetFileBrowserUrlWithParams( + SelectFileDialog::Type type, + const string16& title, + const FilePath& default_path, + const SelectFileDialog::FileTypeInfo* file_types, + int file_type_index, + const FilePath::StringType& default_extension) { + std::string json = GetArgumentsJson(type, title, default_path, file_types, + file_type_index, default_extension); + return GURL(FileManagerUtil::GetFileBrowserUrl().spec() + "?" + + UrlEncodeStringWithoutEncodingSpaceAsPlus(json)); + +} +// static +void FileManagerUtil::ShowFullTabUrl(Profile* profile, + const FilePath& default_path) { + std::string json = GetArgumentsJson(SelectFileDialog::SELECT_NONE, string16(), + default_path, NULL, 0, FilePath::StringType()); + GURL url(std::string(kBaseFileBrowserUrl) + "?" + + UrlEncodeStringWithoutEncodingSpaceAsPlus(json)); + Browser* browser = BrowserList::GetLastActive(); + if (!browser) + return; + + UserMetrics::RecordAction(UserMetricsAction("ShowFileBrowserFullTab"), + profile); + browser->ShowSingletonTab(GURL(url)); +} + +// static +std::string FileManagerUtil::GetArgumentsJson( + SelectFileDialog::Type type, + const string16& title, + const FilePath& default_path, + const 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); + // TODO(zelidrag): Convert local system path into virtual path for File API. + arg_value.SetString("defaultPath", default_path.value()); + arg_value.SetString("defaultExtension", default_extension); + + ListValue* types_list = new ListValue(); + + if (file_types) { + 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->Set( + i, Value::CreateStringValue(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); + } + + dict->SetBoolean("selected", + (static_cast<size_t>(file_type_index) == i)); + + types_list->Set(i, dict); + } + } + + std::string rv; + base::JSONWriter::Write(&arg_value, false, &rv); + + return rv; +} + +// static +std::string FileManagerUtil::GetDialogTypeAsString( + SelectFileDialog::Type dialog_type) { + std::string type_str; + switch (dialog_type) { + case SelectFileDialog::SELECT_NONE: + type_str = "none"; + break; + + case SelectFileDialog::SELECT_FOLDER: + type_str = "folder"; + break; + + case SelectFileDialog::SELECT_SAVEAS_FILE: + type_str = "saveas-file"; + break; + + case SelectFileDialog::SELECT_OPEN_FILE: + type_str = "open-file"; + break; + + case SelectFileDialog::SELECT_OPEN_MULTI_FILE: + type_str = "open-multi-file"; + break; + + default: + NOTREACHED(); + } + + return type_str; +} diff --git a/chrome/browser/extensions/file_manager_util.h b/chrome/browser/extensions/file_manager_util.h new file mode 100644 index 0000000..b4524d9 --- /dev/null +++ b/chrome/browser/extensions/file_manager_util.h @@ -0,0 +1,50 @@ +// 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_EXTENSIONS_FILE_MANAGER_UTIL_H_ +#define CHROME_BROWSER_EXTENSIONS_FILE_MANAGER_UTIL_H_ +#pragma once + +#include "base/file_path.h" +#include "chrome/browser/ui/shell_dialogs.h" +#include "googleurl/src/gurl.h" + +class Profile; + +// Helper class for wiring file browser component extension with the rest of UI. +class FileManagerUtil { + public: + // Gets base file browser url for. + static GURL GetFileBrowserUrlWithParams( + SelectFileDialog::Type type, + const string16& title, + const FilePath& default_path, + const SelectFileDialog::FileTypeInfo* file_types, + int file_type_index, + const FilePath::StringType& default_extension); + + // Opens file browser UI in its own tab on file system location defined with + // |default_path|. + static void ShowFullTabUrl(Profile* profile, + const FilePath& default_path); + + private: + FileManagerUtil() {} + // Helper to convert numeric dialog type to a string. + static std::string GetDialogTypeAsString(SelectFileDialog::Type dialog_type); + // Gets base file browser url. + static GURL GetFileBrowserUrl(); + // Help to convert potential dialog arguments into json. + static std::string GetArgumentsJson( + SelectFileDialog::Type type, + const string16& title, + const FilePath& default_path, + const SelectFileDialog::FileTypeInfo* file_types, + int file_type_index, + const FilePath::StringType& default_extension); + + DISALLOW_COPY_AND_ASSIGN(FileManagerUtil); +}; + +#endif // CHROME_BROWSER_EXTENSIONS_FILE_MANAGER_UTIL_H_ diff --git a/chrome/browser/ui/views/file_manager_dialogs.cc b/chrome/browser/ui/views/file_manager_dialogs.cc index 62214e4..59de0d5 100644 --- a/chrome/browser/ui/views/file_manager_dialogs.cc +++ b/chrome/browser/ui/views/file_manager_dialogs.cc @@ -2,23 +2,19 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "base/json/json_writer.h" #include "base/logging.h" -#include "base/memory/scoped_ptr.h" -#include "base/utf_string_conversions.h" -#include "base/values.h" #include "chrome/browser/extensions/extension_file_browser_private_api.h" +#include "chrome/browser/extensions/file_manager_util.h" +#include "chrome/browser/metrics/user_metrics.h" #include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_dialogs.h" #include "chrome/browser/ui/browser_list.h" -#include "chrome/browser/ui/shell_dialogs.h" #include "chrome/browser/ui/views/html_dialog_view.h" #include "chrome/browser/ui/views/window.h" #include "chrome/browser/ui/webui/html_dialog_ui.h" #include "content/browser/browser_thread.h" #include "content/browser/tab_contents/tab_contents.h" -#include "third_party/libjingle/source/talk/base/urlencode.h" #include "views/window/window.h" #include "ui/gfx/rect.h" #include "ui/gfx/size.h" @@ -31,18 +27,6 @@ class FileManagerDialog public: explicit FileManagerDialog(Listener* listener); - // Helper to convert numeric dialog type to a string. - static std::string GetDialogTypeAsString(Type dialog_type); - - // Help to convert potential dialog arguments into json. - static std::string GetArgumentsJson( - Type type, - const string16& title, - const FilePath& default_path, - const FileTypeInfo* file_types, - int file_type_index, - const FilePath::StringType& default_extension); - void CreateHtmlDialogView(Profile* profile, void* params) { HtmlDialogView* html_view = new HtmlDialogView(profile, this); browser::CreateViewsWindow(owner_window_, gfx::Rect(), html_view); @@ -149,9 +133,6 @@ class FileManagerDialog // Base url plus query string. GURL dialog_url_; - // The base url for the file manager extension. - static std::string s_extension_base_url_; - DISALLOW_COPY_AND_ASSIGN(FileManagerDialog); }; @@ -164,12 +145,6 @@ SelectFileDialog* SelectFileDialog::Create(Listener* listener) { return new FileManagerDialog(listener); } -// 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 -// out this file manager for an aftermarket part, but not yet. -std::string FileManagerDialog::s_extension_base_url_ = - "chrome-extension://hhaomjibdihmijegdhdafkllkbggdgoj/main.html"; - FileManagerDialog::FileManagerDialog(Listener* listener) : SelectFileDialog(listener), tab_id_(0), @@ -195,10 +170,8 @@ void FileManagerDialog::SelectFileImpl( title_ = UTF16ToWide(title); owner_window_ = owner_window; - std::string json = GetArgumentsJson(type, title, default_path, file_types, - file_type_index, default_extension); - dialog_url_ = GURL(s_extension_base_url_ + "?" + - UrlEncodeStringWithoutEncodingSpaceAsPlus(json)); + dialog_url_ = FileManagerUtil::GetFileBrowserUrlWithParams(type, title, + default_path, file_types, file_type_index, default_extension); if (browser_mode_) { Browser* browser = BrowserList::GetLastActive(); @@ -217,78 +190,3 @@ void FileManagerDialog::SelectFileImpl( ProfileManager::GetDefaultProfile(), params)); } -// static -std::string FileManagerDialog::GetDialogTypeAsString(Type dialog_type) { - std::string type_str; - switch (dialog_type) { - case SelectFileDialog::SELECT_NONE: - type_str = "none"; - break; - - case SELECT_FOLDER: - type_str = "folder"; - break; - - case SELECT_SAVEAS_FILE: - type_str = "saveas-file"; - break; - - case SELECT_OPEN_FILE: - type_str = "open-file"; - break; - - case SELECT_OPEN_MULTI_FILE: - type_str = "open-multi-file"; - break; - - default: - NOTREACHED(); - } - - return type_str; -} - -// static -std::string FileManagerDialog::GetArgumentsJson( - Type type, - const string16& title, - const FilePath& default_path, - const 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_path.value()); - arg_value.SetString("defaultExtension", default_extension); - - ListValue* types_list = new ListValue(); - - if (file_types) { - 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->Set( - i, Value::CreateStringValue(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); - } - - dict->SetBoolean("selected", - (static_cast<size_t>(file_type_index) == i)); - - types_list->Set(i, dict); - } - } - - std::string rv; - base::JSONWriter::Write(&arg_value, false, &rv); - - return rv; -} diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 1eaea97..05ff46f 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -1035,6 +1035,8 @@ 'browser/extensions/external_pref_extension_loader.h', 'browser/extensions/external_registry_extension_loader_win.cc', 'browser/extensions/external_registry_extension_loader_win.h', + 'browser/extensions/file_manager_util.h', + 'browser/extensions/file_manager_util.cc', 'browser/extensions/file_reader.cc', 'browser/extensions/file_reader.h', 'browser/extensions/gtk_theme_installed_infobar_delegate.cc', @@ -3422,6 +3424,8 @@ ['exclude', '^browser/ui/webui/chromeos'], ['exclude', '^browser/ui/webui/options/chromeos'], ['exclude', 'browser/extensions/extension_tts_api_chromeos.cc'], + ['exclude', 'browser/extensions/file_manager_util.h'], + ['exclude', 'browser/extensions/file_manager_util.cc'], ['exclude', 'browser/oom_priority_manager.cc'], ['exclude', 'browser/oom_priority_manager.h'], ['exclude', 'browser/policy/device_policy_cache\\.(h|cc)'], |