sbOriginPageImagePropertyInfo.cpp
Go to the documentation of this file.
1 /*
2 //
3 // BEGIN SONGBIRD GPL
4 //
5 // This file is part of the Songbird web player.
6 //
7 // Copyright(c) 2005-2008 POTI, Inc.
8 // http://songbirdnest.com
9 //
10 // This file may be licensed under the terms of of the
11 // GNU General Public License Version 2 (the "GPL").
12 //
13 // Software distributed under the License is distributed
14 // on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
15 // express or implied. See the GPL for the specific language
16 // governing rights and limitations.
17 //
18 // You should have received a copy of the GPL along with this
19 // program. If not, go to http://www.gnu.org/licenses/gpl.html
20 // or write to the Free Software Foundation, Inc.,
21 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 //
23 // END SONGBIRD GPL
24 //
25 */
26 
28 #include "sbStandardOperators.h"
29 
30 #include <sbIPropertyArray.h>
31 #include <sbIPropertyManager.h>
32 #include <nsITreeView.h>
33 
34 #include <nsIURI.h>
35 #include <nsNetUtil.h>
36 #include <nsServiceManagerUtils.h>
37 #include <nsUnicharUtils.h>
38 #include "sbStandardProperties.h"
39 
41  const nsAString& aDisplayName,
42  const nsAString& aLocalizationKey,
43  const PRBool aRemoteReadable,
44  const PRBool aRemoteWritable,
45  const PRBool aUserViewable,
46  const PRBool aUserEditable) :
47  sbImageLinkPropertyInfo(aPropertyID,
48  aDisplayName,
49  aLocalizationKey,
50  aRemoteReadable,
51  aRemoteWritable,
52  aUserViewable,
53  aUserEditable,
54  NS_LITERAL_STRING(SB_PROPERTY_ORIGINPAGE))
55 {
56 }
57 
58 nsresult
60 {
61  nsresult rv;
62 
64  NS_ENSURE_SUCCESS(rv, rv);
65 
66  nsCOMPtr<nsIFaviconService> faviconService =
67  do_GetService("@mozilla.org/browser/favicon-service;1", &rv);
68  NS_ENSURE_SUCCESS(rv, rv);
69 
70  mFaviconService = faviconService;
71 
73  NS_ENSURE_SUCCESS(rv, rv);
74 
75  return NS_OK;
76 }
77 
78 // sbITreeViewPropertyInfo
79 
80 NS_IMETHODIMP
82  nsAString& _retval)
83 {
84  if(aValue.IsEmpty() ||
85  aValue.IsVoid() ||
86  aValue.EqualsLiteral("unknownOrigin") ||
87  aValue.EqualsLiteral("webOrigin")) {
88  _retval.Truncate();
89  return NS_OK;
90  }
91 
92  nsCOMPtr<nsIURI> uri;
93  nsresult rv = NS_NewURI(getter_AddRefs(uri), aValue);
94  NS_ENSURE_SUCCESS(rv, rv);
95 
96  nsCOMPtr<nsIURI> imageUri;
97  rv = mFaviconService->GetFaviconForPage(uri, getter_AddRefs(imageUri));
98 
99  if(rv == NS_ERROR_NOT_AVAILABLE) {
100  _retval.Truncate();
101  return NS_OK;
102  }
103 
104  NS_ENSURE_SUCCESS(rv, rv);
105 
106  nsCAutoString spec;
107  rv = imageUri->GetSpec(spec);
108  NS_ENSURE_SUCCESS(rv, rv);
109 
110  NS_NAMED_LITERAL_CSTRING(mozAnnoFavicon, "moz-anno:favicon:");
111  if(!StringBeginsWith(spec, mozAnnoFavicon)) {
112  _retval = NS_ConvertUTF8toUTF16(spec);
113  return NS_OK;
114  }
115 
116  spec.Cut(0, mozAnnoFavicon.Length());
117  NS_WARNING(spec.get());
118  _retval = NS_ConvertUTF8toUTF16(spec);
119 
120  return NS_OK;
121 }
122 
123 NS_IMETHODIMP
125  nsAString& _retval)
126 {
127  if(aValue.EqualsLiteral("unknownOrigin") ||
128  aValue.IsEmpty() ||
129  aValue.IsVoid()) {
130  _retval.AssignLiteral("image unknownOrigin");
131  return NS_OK;
132  }
133 
134  if(aValue.EqualsLiteral("webOrigin") ||
135  StringBeginsWith(aValue, NS_LITERAL_STRING("http://"), CaseInsensitiveCompare) ||
136  StringBeginsWith(aValue, NS_LITERAL_STRING("https://"), CaseInsensitiveCompare) ||
137  StringBeginsWith(aValue, NS_LITERAL_STRING("ftp://"), CaseInsensitiveCompare)) {
138 
139  _retval.AssignLiteral("image webOrigin");
140  return NS_OK;
141  }
142 
143  _retval.AssignLiteral("image");
144 
145  return NS_OK;
146 }
147 
148 NS_IMETHODIMP
150  const nsAString& aUrlValue,
151  PRBool *_retval)
152 {
153  NS_ENSURE_ARG_POINTER(_retval);
154 
155  *_retval = aImageValue.LowerCaseEqualsLiteral("unknownOrigin") ||
156  aImageValue.IsEmpty() ||
157  aUrlValue.IsEmpty();
158 
159  return NS_OK;
160 }
161 
NS_IMETHOD GetImageSrc(const nsAString &aValue, nsAString &_retval)
return NS_OK
onPageChanged aValue
Definition: FeedWriter.js:1395
#define SB_PROPERTY_ORIGINPAGE
nsCOMPtr< nsIFaviconService > mFaviconService
NS_IMETHOD GetPreventNavigation(const nsAString &aImageValue, const nsAString &aUrlValue, PRBool *_retval)
var uri
Definition: FeedWriter.js:1135
NS_IMETHOD GetCellProperties(const nsAString &aValue, nsAString &_retval)
sbOriginPageImagePropertyInfo(const nsAString &aPropertyID, const nsAString &aDisplayName, const nsAString &aLocalizationKey, const PRBool aRemoteReadable, const PRBool aRemoteWritable, const PRBool aUserViewable, const PRBool aUserEditable)