OLD | NEW |
---|---|
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/extensions/extension_event_router.h" | 14 #include "chrome/browser/extensions/extension_event_router.h" |
13 #include "chrome/browser/extensions/extension_service.h" | 15 #include "chrome/browser/extensions/extension_service.h" |
14 #include "chrome/browser/extensions/extension_tab_util.h" | 16 #include "chrome/browser/extensions/extension_tab_util.h" |
15 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 17 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
16 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/browser/ui/browser.h" | 19 #include "chrome/browser/ui/browser.h" |
18 #include "chrome/common/extensions/file_browser_handler.h" | 20 #include "chrome/common/extensions/file_browser_handler.h" |
19 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
20 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
21 #include "content/public/browser/child_process_security_policy.h" | 23 #include "content/public/browser/child_process_security_policy.h" |
22 #include "content/public/browser/render_process_host.h" | 24 #include "content/public/browser/render_process_host.h" |
23 #include "content/public/browser/site_instance.h" | 25 #include "content/public/browser/site_instance.h" |
24 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
27 #include "net/base/escape.h" | |
25 #include "webkit/fileapi/file_system_context.h" | 28 #include "webkit/fileapi/file_system_context.h" |
26 #include "webkit/fileapi/file_system_mount_point_provider.h" | 29 #include "webkit/fileapi/file_system_mount_point_provider.h" |
27 #include "webkit/fileapi/file_system_util.h" | 30 #include "webkit/fileapi/file_system_util.h" |
28 | 31 |
29 using content::BrowserContext; | 32 using content::BrowserContext; |
30 using content::BrowserThread; | 33 using content::BrowserThread; |
31 using content::ChildProcessSecurityPolicy; | 34 using content::ChildProcessSecurityPolicy; |
32 using content::SiteInstance; | 35 using content::SiteInstance; |
33 using content::WebContents; | 36 using content::WebContents; |
34 | 37 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
88 break; | 91 break; |
89 } | 92 } |
90 } | 93 } |
91 } | 94 } |
92 | 95 |
93 return matching_patterns; | 96 return matching_patterns; |
94 } | 97 } |
95 | 98 |
96 typedef std::set<const FileBrowserHandler*> ActionSet; | 99 typedef std::set<const FileBrowserHandler*> ActionSet; |
97 | 100 |
101 std::string EscapedUtf8ToLower(const std::string& str) { | |
102 string16 utf16 = UTF8ToUTF16( | |
103 net::UnescapeURLComponent(str, net::UnescapeRule::NORMAL)); | |
SeRya
2012/03/14 11:35:04
Looks suspicious. You are unescaping whole URL wit
Vladislav Kaznacheev
2012/03/14 12:24:43
Actually there is no net::UnescapeURL. The second
| |
104 return net::EscapeUrlEncodedData( | |
105 UTF16ToUTF8(base::i18n::ToLower(utf16)), | |
106 false /* do not replace space with plus */); | |
107 } | |
108 | |
98 bool GetFileBrowserHandlers(Profile* profile, | 109 bool GetFileBrowserHandlers(Profile* profile, |
99 const GURL& selected_file_url, | 110 const GURL& selected_file_url, |
100 ActionSet* results) { | 111 ActionSet* results) { |
101 ExtensionService* service = profile->GetExtensionService(); | 112 ExtensionService* service = profile->GetExtensionService(); |
102 if (!service) | 113 if (!service) |
103 return false; // In unit-tests, we may not have an ExtensionService. | 114 return false; // In unit-tests, we may not have an ExtensionService. |
104 | 115 |
116 // We need case-insensitive matching, and pattern in the handler is already | |
117 // in lower case. | |
118 const GURL lowercase_url(EscapedUtf8ToLower(selected_file_url.spec())); | |
119 LOG(ERROR) << lowercase_url.spec(); | |
120 | |
105 for (ExtensionSet::const_iterator iter = service->extensions()->begin(); | 121 for (ExtensionSet::const_iterator iter = service->extensions()->begin(); |
106 iter != service->extensions()->end(); | 122 iter != service->extensions()->end(); |
107 ++iter) { | 123 ++iter) { |
108 const Extension* extension = *iter; | 124 const Extension* extension = *iter; |
109 if (profile->IsOffTheRecord() && | 125 if (profile->IsOffTheRecord() && |
110 !service->IsIncognitoEnabled(extension->id())) | 126 !service->IsIncognitoEnabled(extension->id())) |
111 continue; | 127 continue; |
112 if (!extension->file_browser_handlers()) | 128 if (!extension->file_browser_handlers()) |
113 continue; | 129 continue; |
114 | 130 |
115 for (Extension::FileBrowserHandlerList::const_iterator action_iter = | 131 for (Extension::FileBrowserHandlerList::const_iterator action_iter = |
116 extension->file_browser_handlers()->begin(); | 132 extension->file_browser_handlers()->begin(); |
117 action_iter != extension->file_browser_handlers()->end(); | 133 action_iter != extension->file_browser_handlers()->end(); |
118 ++action_iter) { | 134 ++action_iter) { |
119 const FileBrowserHandler* action = action_iter->get(); | 135 const FileBrowserHandler* action = action_iter->get(); |
120 if (!action->MatchesURL(selected_file_url)) | 136 if (!action->MatchesURL(lowercase_url)) |
121 continue; | 137 continue; |
122 | 138 |
123 results->insert(action_iter->get()); | 139 results->insert(action_iter->get()); |
124 } | 140 } |
125 } | 141 } |
126 return true; | 142 return true; |
127 } | 143 } |
128 | 144 |
129 bool SortByLastUsedTimestampDesc(const LastUsedHandler& a, | 145 bool SortByLastUsedTimestampDesc(const LastUsedHandler& a, |
130 const LastUsedHandler& b) { | 146 const LastUsedHandler& b) { |
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
538 base::JSONWriter::Write(event_args.get(), false, &json_args); | 554 base::JSONWriter::Write(event_args.get(), false, &json_args); |
539 event_router->DispatchEventToExtension( | 555 event_router->DispatchEventToExtension( |
540 extension_id_, std::string("fileBrowserHandler.onExecute"), | 556 extension_id_, std::string("fileBrowserHandler.onExecute"), |
541 json_args, profile_, | 557 json_args, profile_, |
542 GURL()); | 558 GURL()); |
543 Done(true); | 559 Done(true); |
544 } | 560 } |
545 | 561 |
546 } // namespace file_handler_util | 562 } // namespace file_handler_util |
547 | 563 |
OLD | NEW |