diff options
author | serya@chromium.org <serya@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-09 08:35:07 +0000 |
---|---|---|
committer | serya@chromium.org <serya@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-09 08:35:07 +0000 |
commit | d1f03e6741c66915b482cf15256a323f4b2ab3b0 (patch) | |
tree | 2593b5a29155ebae9e2754586f97818d76b6bde1 /chrome | |
parent | 41716639b97bc4d36e540c3fd5c7cd22ca823f03 (diff) | |
download | chromium_src-d1f03e6741c66915b482cf15256a323f4b2ab3b0.zip chromium_src-d1f03e6741c66915b482cf15256a323f4b2ab3b0.tar.gz chromium_src-d1f03e6741c66915b482cf15256a323f4b2ab3b0.tar.bz2 |
Escaping file names correctly. Also fixed a crush in chromeos debug build while saving a web page.
BUG=chromium-os:13130
TEST=Save a file with special characters like '#', '&', '"'.
Review URL: http://codereview.chromium.org/7057053
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@88510 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/chromeos/status/network_menu.cc | 2 | ||||
-rw-r--r-- | chrome/browser/extensions/file_manager_util.cc | 13 | ||||
-rw-r--r-- | chrome/browser/resources/file_manager/js/file_manager.js | 36 | ||||
-rw-r--r-- | chrome/browser/sync/engine/net/url_translator.cc | 4 | ||||
-rw-r--r-- | chrome/browser/translate/translate_manager.cc | 2 | ||||
-rw-r--r-- | chrome/common/net/gaia/gaia_auth_fetcher.cc | 14 | ||||
-rw-r--r-- | chrome/common/net/gaia/gaia_authenticator.cc | 18 | ||||
-rw-r--r-- | chrome/common/net/gaia/gaia_oauth_client.cc | 12 |
8 files changed, 66 insertions, 35 deletions
diff --git a/chrome/browser/chromeos/status/network_menu.cc b/chrome/browser/chromeos/status/network_menu.cc index 87d2e8e..89c50573 100644 --- a/chrome/browser/chromeos/status/network_menu.cc +++ b/chrome/browser/chromeos/status/network_menu.cc @@ -1484,7 +1484,7 @@ void NetworkMenu::ShowTabbedNetworkSettings(const Network* network) const { return; std::string page = StringPrintf("%s?servicePath=%s&networkType=%d", chrome::kInternetOptionsSubPage, - EscapeUrlEncodedData(network->service_path()).c_str(), + EscapeUrlEncodedData(network->service_path(), true).c_str(), network->type()); browser->ShowOptionsTab(page); } diff --git a/chrome/browser/extensions/file_manager_util.cc b/chrome/browser/extensions/file_manager_util.cc index 833e817..7beef7c 100644 --- a/chrome/browser/extensions/file_manager_util.cc +++ b/chrome/browser/extensions/file_manager_util.cc @@ -16,7 +16,7 @@ #include "content/browser/browser_thread.h" #include "content/browser/user_metrics.h" #include "grit/generated_resources.h" -#include "third_party/libjingle/source/talk/base/urlencode.h" +#include "net/base/escape.h" #include "ui/base/l10n/l10n_util.h" #include "webkit/fileapi/file_system_context.h" #include "webkit/fileapi/file_system_mount_point_provider.h" @@ -112,16 +112,17 @@ GURL FileManagerUtil::GetFileBrowserUrlWithParams( std::string json = GetArgumentsJson(type, title, default_path, file_types, file_type_index, default_extension); return GURL(FileManagerUtil::GetFileBrowserUrl().spec() + "?" + - UrlEncodeStringWithoutEncodingSpaceAsPlus(json)); + EscapeUrlEncodedData(json, false)); } + // static void FileManagerUtil::ShowFullTabUrl(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)); + EscapeUrlEncodedData(json, false)); Browser* browser = BrowserList::GetLastActive(); if (!browser) return; @@ -130,7 +131,6 @@ void FileManagerUtil::ShowFullTabUrl(Profile*, browser->ShowSingletonTab(GURL(url)); } - void FileManagerUtil::ViewItem(const FilePath& full_path, bool enqueue) { std::string ext = full_path.Extension(); // For things supported natively by the browser, we should open it @@ -138,7 +138,7 @@ void FileManagerUtil::ViewItem(const FilePath& full_path, bool enqueue) { if (IsSupportedBrowserExtension(ext.data())) { std::string path; path = "file://"; - path.append(full_path.value()); + path.append(EscapeUrlEncodedData(full_path.value(), false)); if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { bool result = BrowserThread::PostTask( BrowserThread::UI, FROM_HERE, @@ -190,9 +190,9 @@ std::string FileManagerUtil::GetArgumentsJson( arg_value.SetString("defaultPath", default_path.value()); arg_value.SetString("defaultExtension", default_extension); - ListValue* types_list = new ListValue(); if (file_types) { + ListValue* types_list = new ListValue(); for (size_t i = 0; i < file_types->extensions.size(); ++i) { ListValue* extensions_list = new ListValue(); for (size_t j = 0; j < file_types->extensions[i].size(); ++j) { @@ -213,6 +213,7 @@ std::string FileManagerUtil::GetArgumentsJson( types_list->Set(i, dict); } + arg_value.Set("typeList", types_list); } std::string rv; diff --git a/chrome/browser/resources/file_manager/js/file_manager.js b/chrome/browser/resources/file_manager/js/file_manager.js index 9c4f5bc..29c85f2 100644 --- a/chrome/browser/resources/file_manager/js/file_manager.js +++ b/chrome/browser/resources/file_manager/js/file_manager.js @@ -54,6 +54,9 @@ function FileManager(dialogDom, rootEntries, params) { this.defaultPath_ = this.params_.defaultPath || '/'; + // Optional list of file types. + this.fileTypes_ = this.params_.typeList; + // This is set to just the directory portion of defaultPath in initDialogType. this.defaultFolder_ = '/'; @@ -555,6 +558,29 @@ FileManager.prototype = { }; /** + * "Save a file" dialog is supposed to have a combo box with available + * file types. Selecting an item filters files by extension and specifies how + * file should be saved. + * @return {intener} Index of selected type from this.fileTypes_ + 1. 0 + * means value is not specified. + */ + FileManager.prototype.getSelectedFilterIndex_= function(fileName) { + // TODO(serya): Implement the combo box + // For now try to guess choice by file extension. + if (!this.fileTypes_ || this.fileTypes_.length == 0) return 0; + + var extension = /\.[^\.]+$/.exec(fileName); + extension = extension ? extension[0].substring(1).toLowerCase() : ""; + var result = 0; // Use first type by default. + for (var i = 0; i < this.fileTypes_.length; i++) { + if (this.fileTypes_[i].extensions.indexOf(extension)) { + result = i; + } + } + return result + 1; // 1-based index. + }; + + /** * Force the canExecute events to be dispatched. */ FileManager.prototype.updateCommands_ = function() { @@ -2078,8 +2104,9 @@ FileManager.prototype = { if (!filename) throw new Error('Missing filename!'); - chrome.fileBrowserPrivate.selectFile(currentDirUrl + encodeURI(filename), - 0); + chrome.fileBrowserPrivate.selectFile( + currentDirUrl + encodeURIComponent(filename), + this.getSelectedFilterIndex_(filename)); window.close(); return; } @@ -2100,7 +2127,7 @@ FileManager.prototype = { continue; } - ary.push(currentDirUrl + encodeURI(entry.name)); + ary.push(currentDirUrl + encodeURIComponent(entry.name)); } // Multi-file selection has no other restrictions. @@ -2129,7 +2156,8 @@ FileManager.prototype = { throw new Error('Selected entry is not a file!'); } - chrome.fileBrowserPrivate.selectFile(ary[0], 0); + chrome.fileBrowserPrivate.selectFile( + ary[0], this.getSelectedFilterIndex_(ary[0])); window.close(); }; diff --git a/chrome/browser/sync/engine/net/url_translator.cc b/chrome/browser/sync/engine/net/url_translator.cc index 4b91e54..c96c9d3 100644 --- a/chrome/browser/sync/engine/net/url_translator.cc +++ b/chrome/browser/sync/engine/net/url_translator.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// 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. // @@ -27,7 +27,7 @@ string CgiEscapeString(const char* src) { } string CgiEscapeString(const string& src) { - return EscapeUrlEncodedData(src); + return EscapeUrlEncodedData(src, true); } // This method appends the query string to the sync server path. diff --git a/chrome/browser/translate/translate_manager.cc b/chrome/browser/translate/translate_manager.cc index e3a4f4a..38e8325 100644 --- a/chrome/browser/translate/translate_manager.cc +++ b/chrome/browser/translate/translate_manager.cc @@ -499,7 +499,7 @@ void TranslateManager::ReportLanguageDetectionError(TabContents* tab_contents) { GURL page_url = tab_contents->controller().GetActiveEntry()->url(); std::string report_error_url(kReportLanguageDetectionErrorURL); report_error_url += "?client=cr&action=langidc&u="; - report_error_url += EscapeUrlEncodedData(page_url.spec()); + report_error_url += EscapeUrlEncodedData(page_url.spec(), true); report_error_url += "&sl="; TranslateTabHelper* helper = TabContentsWrapper::GetCurrentWrapperForContents( diff --git a/chrome/common/net/gaia/gaia_auth_fetcher.cc b/chrome/common/net/gaia/gaia_auth_fetcher.cc index c8d5311..9493d0b 100644 --- a/chrome/common/net/gaia/gaia_auth_fetcher.cc +++ b/chrome/common/net/gaia/gaia_auth_fetcher.cc @@ -143,10 +143,10 @@ std::string GaiaAuthFetcher::MakeClientLoginBody( const std::string& login_token, const std::string& login_captcha, HostedAccountsSetting allow_hosted_accounts) { - std::string encoded_username = EscapeUrlEncodedData(username); - std::string encoded_password = EscapeUrlEncodedData(password); - std::string encoded_login_token = EscapeUrlEncodedData(login_token); - std::string encoded_login_captcha = EscapeUrlEncodedData(login_captcha); + std::string encoded_username = EscapeUrlEncodedData(username, true); + std::string encoded_password = EscapeUrlEncodedData(password, true); + std::string encoded_login_token = EscapeUrlEncodedData(login_token, true); + std::string encoded_login_captcha = EscapeUrlEncodedData(login_captcha, true); const char* account_type = allow_hosted_accounts == HostedAccountsAllowed ? kAccountTypeHostedOrGoogle : @@ -179,8 +179,8 @@ std::string GaiaAuthFetcher::MakeIssueAuthTokenBody( const std::string& sid, const std::string& lsid, const char* const service) { - std::string encoded_sid = EscapeUrlEncodedData(sid); - std::string encoded_lsid = EscapeUrlEncodedData(lsid); + std::string encoded_sid = EscapeUrlEncodedData(sid, true); + std::string encoded_lsid = EscapeUrlEncodedData(lsid, true); // All tokens should be session tokens except the gaia auth token. bool session = true; @@ -196,7 +196,7 @@ std::string GaiaAuthFetcher::MakeIssueAuthTokenBody( // static std::string GaiaAuthFetcher::MakeGetUserInfoBody(const std::string& lsid) { - std::string encoded_lsid = EscapeUrlEncodedData(lsid); + std::string encoded_lsid = EscapeUrlEncodedData(lsid, true); return base::StringPrintf(kGetUserInfoFormat, encoded_lsid.c_str()); } diff --git a/chrome/common/net/gaia/gaia_authenticator.cc b/chrome/common/net/gaia/gaia_authenticator.cc index 36d060e..1b4d1c1 100644 --- a/chrome/common/net/gaia/gaia_authenticator.cc +++ b/chrome/common/net/gaia/gaia_authenticator.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// 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. @@ -158,13 +158,15 @@ bool GaiaAuthenticator::PerformGaiaRequest(const AuthParams& params, GURL gaia_auth_url(gaia_url_); string post_body; - post_body += "Email=" + EscapeUrlEncodedData(params.email); - post_body += "&Passwd=" + EscapeUrlEncodedData(params.password); - post_body += "&source=" + EscapeUrlEncodedData(user_agent_); + post_body += "Email=" + EscapeUrlEncodedData(params.email, true); + post_body += "&Passwd=" + EscapeUrlEncodedData(params.password, true); + post_body += "&source=" + EscapeUrlEncodedData(user_agent_, true); post_body += "&service=" + service_id_; if (!params.captcha_token.empty() && !params.captcha_value.empty()) { - post_body += "&logintoken=" + EscapeUrlEncodedData(params.captcha_token); - post_body += "&logincaptcha=" + EscapeUrlEncodedData(params.captcha_value); + post_body += "&logintoken=" + + EscapeUrlEncodedData(params.captcha_token, true); + post_body += "&logincaptcha=" + + EscapeUrlEncodedData(params.captcha_value, true); } post_body += "&PersistentCookie=true"; // We set it to GOOGLE (and not HOSTED or HOSTED_OR_GOOGLE) because we only @@ -215,7 +217,7 @@ bool GaiaAuthenticator::LookupEmail(AuthResults* results) { string post_body; post_body += "LSID="; - post_body += EscapeUrlEncodedData(results->lsid); + post_body += EscapeUrlEncodedData(results->lsid, true); unsigned long server_response_code; string message_text; @@ -265,7 +267,7 @@ bool GaiaAuthenticator::IssueAuthToken(AuthResults* results, string post_body; post_body += "LSID="; - post_body += EscapeUrlEncodedData(results->lsid); + post_body += EscapeUrlEncodedData(results->lsid, true); post_body += "&service=" + service_id; post_body += "&Session=true"; diff --git a/chrome/common/net/gaia/gaia_oauth_client.cc b/chrome/common/net/gaia/gaia_oauth_client.cc index 5ad361b..8cdec59 100644 --- a/chrome/common/net/gaia/gaia_oauth_client.cc +++ b/chrome/common/net/gaia/gaia_oauth_client.cc @@ -76,10 +76,10 @@ void GaiaOAuthClient::Core::GetTokensFromAuthCode( int max_retries, GaiaOAuthClient::Delegate* delegate) { std::string post_body = - "code=" + EscapeUrlEncodedData(auth_code) + - "&client_id=" + EscapeUrlEncodedData(oauth_client_info.client_id) + + "code=" + EscapeUrlEncodedData(auth_code, true) + + "&client_id=" + EscapeUrlEncodedData(oauth_client_info.client_id, true) + "&client_secret=" + - EscapeUrlEncodedData(oauth_client_info.client_secret) + + EscapeUrlEncodedData(oauth_client_info.client_secret, true) + "&redirect_uri=oob&grant_type=authorization_code"; MakeGaiaRequest(post_body, max_retries, delegate); } @@ -90,10 +90,10 @@ void GaiaOAuthClient::Core::RefreshToken( int max_retries, GaiaOAuthClient::Delegate* delegate) { std::string post_body = - "refresh_token=" + EscapeUrlEncodedData(refresh_token) + - "&client_id=" + EscapeUrlEncodedData(oauth_client_info.client_id) + + "refresh_token=" + EscapeUrlEncodedData(refresh_token, true) + + "&client_id=" + EscapeUrlEncodedData(oauth_client_info.client_id, true) + "&client_secret=" + - EscapeUrlEncodedData(oauth_client_info.client_secret) + + EscapeUrlEncodedData(oauth_client_info.client_secret, true) + "&grant_type=refresh_token"; MakeGaiaRequest(post_body, max_retries, delegate); } |