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/intents/web_intents_registry.h" | 5 #include "chrome/browser/intents/web_intents_registry.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
42 | 42 |
43 typedef base::Callback<void(const WDTypedResult* result)> ResultsHandler; | 43 typedef base::Callback<void(const WDTypedResult* result)> ResultsHandler; |
44 typedef WebIntentsRegistry::IntentServiceList IntentServiceList; | 44 typedef WebIntentsRegistry::IntentServiceList IntentServiceList; |
45 | 45 |
46 // Compares two mime types for equality. Supports wild cards in both | 46 // Compares two mime types for equality. Supports wild cards in both |
47 // |type1| and |type2|. Wild cards are of the form '<type>/*' or '*'. | 47 // |type1| and |type2|. Wild cards are of the form '<type>/*' or '*'. |
48 bool MimeTypesAreEqual(const string16& type1, const string16& type2) { | 48 bool MimeTypesAreEqual(const string16& type1, const string16& type2) { |
49 // We don't have a MIME matcher that allows patterns on both sides | 49 // We don't have a MIME matcher that allows patterns on both sides |
50 // Instead, we do two comparisons, treating each type in turn as a | 50 // Instead, we do two comparisons, treating each type in turn as a |
51 // pattern. If either one matches, we consider this a MIME match. | 51 // pattern. If either one matches, we consider this a MIME match. |
52 if (net::MatchesMimeType(UTF16ToUTF8(type1), UTF16ToUTF8(type2))) | 52 std::string t1 = UTF16ToUTF8(type1); |
53 std::string t2 = UTF16ToUTF8(type2); | |
54 StringToLowerASCII(&t1); | |
55 StringToLowerASCII(&t2); | |
56 if (net::MatchesMimeType(t1, t2)) | |
53 return true; | 57 return true; |
54 return net::MatchesMimeType(UTF16ToUTF8(type2), UTF16ToUTF8(type1)); | 58 return net::MatchesMimeType(t2, t1); |
55 } | 59 } |
56 | 60 |
57 // Returns true if the passed string is a MIME type. Works by comparing string | 61 // Returns true if the passed string is a MIME type. Works by comparing string |
58 // prefix to the valid MIME top-level types (and the wildcard type */). | 62 // prefix to the valid MIME top-level types (and the wildcard type */). |
59 // "*" is also accepted as a valid MIME type. | 63 // "*" is also accepted as a valid MIME type. |
60 // The passed |type_str| should have no leading or trailing whitespace. | 64 // The passed |type_str| should have no leading or trailing whitespace. |
61 bool IsMimeType(const string16& type_str) { | 65 bool IsMimeType(const string16& type_str) { |
62 return net::IsMimeType(UTF16ToUTF8(type_str)); | 66 return net::IsMimeType(UTF16ToUTF8(type_str)); |
63 } | 67 } |
64 | 68 |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
318 else if (iter->url_pattern < default_service.url_pattern) | 322 else if (iter->url_pattern < default_service.url_pattern) |
319 default_service = *iter; | 323 default_service = *iter; |
320 } | 324 } |
321 | 325 |
322 // TODO(hshi): Temporary workaround for http://crbug.com/134197. | 326 // TODO(hshi): Temporary workaround for http://crbug.com/134197. |
323 // If no user-set default service is found, use built-in QuickOffice Viewer as | 327 // If no user-set default service is found, use built-in QuickOffice Viewer as |
324 // default for MS office files. Remove this once full defaults is in place. | 328 // default for MS office files. Remove this once full defaults is in place. |
325 if (default_service.user_date <= 0) { | 329 if (default_service.user_date <= 0) { |
326 for (size_t i = 0; i < sizeof(kQuickOfficeViewerMimeType) / sizeof(char*); | 330 for (size_t i = 0; i < sizeof(kQuickOfficeViewerMimeType) / sizeof(char*); |
327 ++i) { | 331 ++i) { |
332 LOG(INFO) << "Adding default for QO"; | |
Randy Smith (Not in Mondays)
2012/08/16 20:54:41
Remove before landing.
Greg Billock
2012/08/16 21:06:03
Got rid of this and other logging crap.
| |
328 DefaultWebIntentService qoviewer_service; | 333 DefaultWebIntentService qoviewer_service; |
329 qoviewer_service.action = ASCIIToUTF16(kViewActionURL); | 334 qoviewer_service.action = ASCIIToUTF16(kViewActionURL); |
330 qoviewer_service.type = ASCIIToUTF16(kQuickOfficeViewerMimeType[i]); | 335 qoviewer_service.type = ASCIIToUTF16(kQuickOfficeViewerMimeType[i]); |
331 qoviewer_service.service_url = kQuickOfficeViewerServiceURL; | 336 qoviewer_service.service_url = kQuickOfficeViewerServiceURL; |
332 if (WebIntentsTypesMatch(qoviewer_service.type, params.type_)) { | 337 if (WebIntentsTypesMatch(qoviewer_service.type, params.type_)) { |
333 default_service = qoviewer_service; | 338 default_service = qoviewer_service; |
334 break; | 339 break; |
335 } | 340 } |
336 } | 341 } |
337 } | 342 } |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
516 void WebIntentsRegistry::ReleaseQuery(QueryAdapter* query) { | 521 void WebIntentsRegistry::ReleaseQuery(QueryAdapter* query) { |
517 QueryVector::iterator it = std::find( | 522 QueryVector::iterator it = std::find( |
518 pending_queries_.begin(), pending_queries_.end(), query); | 523 pending_queries_.begin(), pending_queries_.end(), query); |
519 if (it != pending_queries_.end()) { | 524 if (it != pending_queries_.end()) { |
520 pending_queries_.erase(it); | 525 pending_queries_.erase(it); |
521 delete query; | 526 delete query; |
522 } else { | 527 } else { |
523 NOTREACHED(); | 528 NOTREACHED(); |
524 } | 529 } |
525 } | 530 } |
OLD | NEW |