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

Side by Side Diff: chrome/browser/intents/web_intents_util.cc

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

Powered by Google App Engine
This is Rietveld 408576698