| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/intents/web_intents_util.h" | |
| 6 | |
| 7 #include "base/command_line.h" | |
| 8 #include "base/string_util.h" | |
| 9 #include "base/utf_string_conversions.h" | |
| 10 #include "chrome/browser/prefs/pref_registry_syncable.h" | |
| 11 #include "chrome/browser/prefs/pref_service.h" | |
| 12 #include "chrome/browser/profiles/profile.h" | |
| 13 #include "chrome/browser/ui/browser.h" | |
| 14 #include "chrome/browser/ui/browser_finder.h" | |
| 15 #include "chrome/browser/ui/host_desktop.h" | |
| 16 #include "chrome/common/chrome_switches.h" | |
| 17 #include "chrome/common/pref_names.h" | |
| 18 #include "chrome/common/url_constants.h" | |
| 19 #include "content/public/common/content_switches.h" | |
| 20 #include "net/base/mime_util.h" | |
| 21 | |
| 22 namespace web_intents { | |
| 23 namespace { | |
| 24 | |
| 25 struct ActionMapping { | |
| 26 const char* name; | |
| 27 const ActionId id; | |
| 28 }; | |
| 29 | |
| 30 const ActionMapping kActionMap[] = { | |
| 31 { kActionEdit, ACTION_ID_EDIT }, | |
| 32 { kActionPick, ACTION_ID_PICK }, | |
| 33 { kActionSave, ACTION_ID_SAVE }, | |
| 34 { kActionShare, ACTION_ID_SHARE}, | |
| 35 { kActionSubscribe, ACTION_ID_SUBSCRIBE }, | |
| 36 { kActionView, ACTION_ID_VIEW }, | |
| 37 }; | |
| 38 | |
| 39 // Returns the ActionMapping for |action| if one exists, or NULL. | |
| 40 const ActionMapping* FindActionMapping(const string16& action) { | |
| 41 for (size_t i = 0; i < arraysize(kActionMap); ++i) { | |
| 42 if (EqualsASCII(action, kActionMap[i].name)) { | |
| 43 return &kActionMap[i]; | |
| 44 } | |
| 45 } | |
| 46 return NULL; | |
| 47 } | |
| 48 | |
| 49 } // namespace | |
| 50 | |
| 51 const char kActionEdit[] = "http://webintents.org/edit"; | |
| 52 const char kActionPick[] = "http://webintents.org/pick"; | |
| 53 const char kActionSave[] = "http://webintents.org/save"; | |
| 54 const char kActionShare[] = "http://webintents.org/share"; | |
| 55 const char kActionSubscribe[] = "http://webintents.org/subscribe"; | |
| 56 const char kActionView[] = "http://webintents.org/view"; | |
| 57 const char kActionCrosEcho[] = "https://crosecho.com/startEcho"; | |
| 58 const char kQuickOfficeViewerServiceURL[] = | |
| 59 "chrome-extension://gbkeegbaiigmenfmjfclcdgdpimamgkj/views/appViewer.html"; | |
| 60 const char kQuickOfficeViewerDevServiceURL[] = | |
| 61 "chrome-extension://ionpfmkccalenbmnddpbmocokhaknphg/views/appEditor.html"; | |
| 62 | |
| 63 void RegisterUserPrefs(PrefRegistrySyncable* registry) { | |
| 64 registry->RegisterBooleanPref(prefs::kWebIntentsEnabled, true, | |
| 65 PrefRegistrySyncable::SYNCABLE_PREF); | |
| 66 } | |
| 67 | |
| 68 bool IsWebIntentsEnabled(PrefService* prefs) { | |
| 69 return CommandLine::ForCurrentProcess()->HasSwitch( | |
| 70 switches::kWebIntentsInvocationEnabled); | |
| 71 } | |
| 72 | |
| 73 bool IsWebIntentsEnabledForProfile(Profile* profile) { | |
| 74 return IsWebIntentsEnabled(profile->GetPrefs()); | |
| 75 } | |
| 76 | |
| 77 Browser* GetBrowserForBackgroundWebIntentDelivery(Profile* profile) { | |
| 78 Browser* browser = chrome::FindLastActiveWithHostDesktopType( | |
| 79 chrome::GetActiveDesktop()); | |
| 80 if (browser && profile && browser->profile() != profile) | |
| 81 return NULL; | |
| 82 return browser; | |
| 83 } | |
| 84 | |
| 85 bool IsRecognizedAction(const string16& action) { | |
| 86 const ActionMapping* mapping = FindActionMapping(action); | |
| 87 return mapping != NULL; | |
| 88 } | |
| 89 | |
| 90 ActionId ToActionId(const string16& action) { | |
| 91 const ActionMapping* mapping = FindActionMapping(action); | |
| 92 return mapping != NULL ? mapping->id : ACTION_ID_CUSTOM; | |
| 93 } | |
| 94 | |
| 95 bool MimeTypesMatch(const string16& type1, const string16& type2) { | |
| 96 // We don't have a MIME matcher that allows patterns on both sides | |
| 97 // Instead, we do two comparisons, treating each type in turn as a | |
| 98 // pattern. If either one matches, we consider this a MIME match. | |
| 99 std::string t1 = UTF16ToUTF8(type1); | |
| 100 std::string t2 = UTF16ToUTF8(type2); | |
| 101 | |
| 102 // If either side is _all_ wildcard, it's a match! | |
| 103 if (t1 == "*" || t1 == "*/*" || t2 == "*" || t2 == "*/*") | |
| 104 return true; | |
| 105 | |
| 106 StringToLowerASCII(&t1); | |
| 107 StringToLowerASCII(&t2); | |
| 108 return (net::MatchesMimeType(t1, t2)) || net::MatchesMimeType(t2, t1); | |
| 109 } | |
| 110 | |
| 111 } // namespace web_intents | |
| OLD | NEW |