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

Side by Side Diff: chrome/browser/chromeos/extensions/file_handler_util.cc

Issue 9700011: Convert file url to lowercase to make it match a file handler pattern. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 8 years, 9 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/chromeos/extensions/file_browser_private_api.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/extensions/file_handler_util.h" 5 #include "chrome/browser/chromeos/extensions/file_handler_util.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/i18n/case_conversion.h"
9 #include "base/json/json_writer.h" 10 #include "base/json/json_writer.h"
10 #include "base/string_util.h" 11 #include "base/string_util.h"
11 #include "base/stringprintf.h" 12 #include "base/stringprintf.h"
13 #include "base/utf_string_conversions.h"
12 #include "chrome/browser/chromeos/extensions/file_manager_util.h" 14 #include "chrome/browser/chromeos/extensions/file_manager_util.h"
13 #include "chrome/browser/extensions/extension_event_router.h" 15 #include "chrome/browser/extensions/extension_event_router.h"
14 #include "chrome/browser/extensions/extension_service.h" 16 #include "chrome/browser/extensions/extension_service.h"
15 #include "chrome/browser/extensions/extension_tab_util.h" 17 #include "chrome/browser/extensions/extension_tab_util.h"
16 #include "chrome/browser/prefs/scoped_user_pref_update.h" 18 #include "chrome/browser/prefs/scoped_user_pref_update.h"
17 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/ui/browser.h" 20 #include "chrome/browser/ui/browser.h"
19 #include "chrome/common/extensions/file_browser_handler.h" 21 #include "chrome/common/extensions/file_browser_handler.h"
20 #include "chrome/common/pref_names.h" 22 #include "chrome/common/pref_names.h"
21 #include "content/public/browser/browser_thread.h" 23 #include "content/public/browser/browser_thread.h"
22 #include "content/public/browser/child_process_security_policy.h" 24 #include "content/public/browser/child_process_security_policy.h"
23 #include "content/public/browser/render_process_host.h" 25 #include "content/public/browser/render_process_host.h"
24 #include "content/public/browser/site_instance.h" 26 #include "content/public/browser/site_instance.h"
25 #include "content/public/browser/web_contents.h" 27 #include "content/public/browser/web_contents.h"
28 #include "net/base/escape.h"
26 #include "webkit/fileapi/file_system_context.h" 29 #include "webkit/fileapi/file_system_context.h"
27 #include "webkit/fileapi/file_system_mount_point_provider.h" 30 #include "webkit/fileapi/file_system_mount_point_provider.h"
28 #include "webkit/fileapi/file_system_util.h" 31 #include "webkit/fileapi/file_system_util.h"
29 32
30 using content::BrowserContext; 33 using content::BrowserContext;
31 using content::BrowserThread; 34 using content::BrowserThread;
32 using content::ChildProcessSecurityPolicy; 35 using content::ChildProcessSecurityPolicy;
33 using content::SiteInstance; 36 using content::SiteInstance;
34 using content::WebContents; 37 using content::WebContents;
35 38
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 break; 92 break;
90 } 93 }
91 } 94 }
92 } 95 }
93 96
94 return matching_patterns; 97 return matching_patterns;
95 } 98 }
96 99
97 typedef std::set<const FileBrowserHandler*> ActionSet; 100 typedef std::set<const FileBrowserHandler*> ActionSet;
98 101
102 std::string EscapedUtf8ToLower(const std::string& str) {
103 string16 utf16 = UTF8ToUTF16(
104 net::UnescapeURLComponent(str, net::UnescapeRule::NORMAL));
105 return net::EscapeUrlEncodedData(
106 UTF16ToUTF8(base::i18n::ToLower(utf16)),
107 false /* do not replace space with plus */);
108 }
109
99 bool GetFileBrowserHandlers(Profile* profile, 110 bool GetFileBrowserHandlers(Profile* profile,
100 const GURL& selected_file_url, 111 const GURL& selected_file_url,
101 ActionSet* results) { 112 ActionSet* results) {
102 ExtensionService* service = profile->GetExtensionService(); 113 ExtensionService* service = profile->GetExtensionService();
103 if (!service) 114 if (!service)
104 return false; // In unit-tests, we may not have an ExtensionService. 115 return false; // In unit-tests, we may not have an ExtensionService.
105 116
117 // We need case-insensitive matching, and pattern in the handler is already
118 // in lower case.
119 const GURL lowercase_url(EscapedUtf8ToLower(selected_file_url.spec()));
120
106 for (ExtensionSet::const_iterator iter = service->extensions()->begin(); 121 for (ExtensionSet::const_iterator iter = service->extensions()->begin();
107 iter != service->extensions()->end(); 122 iter != service->extensions()->end();
108 ++iter) { 123 ++iter) {
109 const Extension* extension = *iter; 124 const Extension* extension = *iter;
110 if (profile->IsOffTheRecord() && 125 if (profile->IsOffTheRecord() &&
111 !service->IsIncognitoEnabled(extension->id())) 126 !service->IsIncognitoEnabled(extension->id()))
112 continue; 127 continue;
113 if (!extension->file_browser_handlers()) 128 if (!extension->file_browser_handlers())
114 continue; 129 continue;
115 130
116 for (Extension::FileBrowserHandlerList::const_iterator action_iter = 131 for (Extension::FileBrowserHandlerList::const_iterator action_iter =
117 extension->file_browser_handlers()->begin(); 132 extension->file_browser_handlers()->begin();
118 action_iter != extension->file_browser_handlers()->end(); 133 action_iter != extension->file_browser_handlers()->end();
119 ++action_iter) { 134 ++action_iter) {
120 const FileBrowserHandler* action = action_iter->get(); 135 const FileBrowserHandler* action = action_iter->get();
121 if (!action->MatchesURL(selected_file_url)) 136 if (!action->MatchesURL(lowercase_url))
122 continue; 137 continue;
123 138
124 results->insert(action_iter->get()); 139 results->insert(action_iter->get());
125 } 140 }
126 } 141 }
127 return true; 142 return true;
128 } 143 }
129 144
130 bool SortByLastUsedTimestampDesc(const LastUsedHandler& a, 145 bool SortByLastUsedTimestampDesc(const LastUsedHandler& a,
131 const LastUsedHandler& b) { 146 const LastUsedHandler& b) {
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 base::JSONWriter::Write(event_args.get(), false, &json_args); 560 base::JSONWriter::Write(event_args.get(), false, &json_args);
546 event_router->DispatchEventToExtension( 561 event_router->DispatchEventToExtension(
547 extension_id_, std::string("fileBrowserHandler.onExecute"), 562 extension_id_, std::string("fileBrowserHandler.onExecute"),
548 json_args, profile_, 563 json_args, profile_,
549 GURL()); 564 GURL());
550 Done(true); 565 Done(true);
551 } 566 }
552 567
553 } // namespace file_handler_util 568 } // namespace file_handler_util
554 569
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/extensions/file_browser_private_api.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698