Bug 628949 - Update visible region / glass regions after we paint. r=roc a=2.0.
[mozilla-central.git] / netwerk / protocol / viewsource / nsViewSourceHandler.cpp
blobaece5f6eda7a0cfab6f56d4af4deed9d5a6cdb6f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* vim:set ts=4 sw=4 sts=4 et: */
3 /* ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
16 * The Original Code is mozilla.org code.
18 * The Initial Developer of the Original Code is
19 * Netscape Communications Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 1998
21 * the Initial Developer. All Rights Reserved.
23 * Contributor(s):
24 * Chak Nanga <chak@netscape.com>
25 * Darin Fisher <darin@meer.net>
27 * Alternatively, the contents of this file may be used under the terms of
28 * either the GNU General Public License Version 2 or later (the "GPL"), or
29 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30 * in which case the provisions of the GPL or the LGPL are applicable instead
31 * of those above. If you wish to allow use of your version of this file only
32 * under the terms of either the GPL or the LGPL, and not to allow others to
33 * use your version of this file under the terms of the MPL, indicate your
34 * decision by deleting the provisions above and replace them with the notice
35 * and other provisions required by the GPL or the LGPL. If you do not delete
36 * the provisions above, a recipient may use your version of this file under
37 * the terms of any one of the MPL, the GPL or the LGPL.
39 * ***** END LICENSE BLOCK ***** */
41 #include "nsViewSourceHandler.h"
42 #include "nsViewSourceChannel.h"
43 #include "nsNetUtil.h"
44 #include "nsSimpleNestedURI.h"
46 #define VIEW_SOURCE "view-source"
48 ////////////////////////////////////////////////////////////////////////////////
50 NS_IMPL_ISUPPORTS1(nsViewSourceHandler, nsIProtocolHandler)
52 ////////////////////////////////////////////////////////////////////////////////
53 // nsIProtocolHandler methods:
55 NS_IMETHODIMP
56 nsViewSourceHandler::GetScheme(nsACString &result)
58 result.AssignLiteral(VIEW_SOURCE);
59 return NS_OK;
62 NS_IMETHODIMP
63 nsViewSourceHandler::GetDefaultPort(PRInt32 *result)
65 *result = -1;
66 return NS_OK;
69 NS_IMETHODIMP
70 nsViewSourceHandler::GetProtocolFlags(PRUint32 *result)
72 *result = URI_NORELATIVE | URI_NOAUTH | URI_LOADABLE_BY_ANYONE |
73 URI_NON_PERSISTABLE;
74 return NS_OK;
77 NS_IMETHODIMP
78 nsViewSourceHandler::NewURI(const nsACString &aSpec,
79 const char *aCharset,
80 nsIURI *aBaseURI,
81 nsIURI **aResult)
83 *aResult = nsnull;
85 // Extract inner URL and normalize to ASCII. This is done to properly
86 // support IDN in cases like "view-source:http://www.szalagavató.hu/"
88 PRInt32 colon = aSpec.FindChar(':');
89 if (colon == kNotFound)
90 return NS_ERROR_MALFORMED_URI;
92 nsCOMPtr<nsIURI> innerURI;
93 nsresult rv = NS_NewURI(getter_AddRefs(innerURI),
94 Substring(aSpec, colon + 1), aCharset);
95 if (NS_FAILED(rv))
96 return rv;
98 nsCAutoString asciiSpec;
99 rv = innerURI->GetAsciiSpec(asciiSpec);
100 if (NS_FAILED(rv))
101 return rv;
103 // put back our scheme and construct a simple-uri wrapper
105 asciiSpec.Insert(VIEW_SOURCE ":", 0);
107 // We can't swap() from an nsRefPtr<nsSimpleNestedURI> to an nsIURI**,
108 // sadly.
109 nsSimpleNestedURI* ourURI = new nsSimpleNestedURI(innerURI);
110 nsCOMPtr<nsIURI> uri = ourURI;
111 if (!uri)
112 return NS_ERROR_OUT_OF_MEMORY;
114 rv = ourURI->SetSpec(asciiSpec);
115 if (NS_FAILED(rv))
116 return rv;
118 // Make the URI immutable so it's impossible to get it out of sync
119 // with its inner URI.
120 ourURI->SetMutable(PR_FALSE);
122 uri.swap(*aResult);
123 return rv;
126 NS_IMETHODIMP
127 nsViewSourceHandler::NewChannel(nsIURI* uri, nsIChannel* *result)
129 NS_ENSURE_ARG_POINTER(uri);
130 nsViewSourceChannel *channel = new nsViewSourceChannel();
131 if (!channel)
132 return NS_ERROR_OUT_OF_MEMORY;
133 NS_ADDREF(channel);
135 nsresult rv = channel->Init(uri);
136 if (NS_FAILED(rv)) {
137 NS_RELEASE(channel);
138 return rv;
141 *result = static_cast<nsIViewSourceChannel*>(channel);
142 return NS_OK;
145 NS_IMETHODIMP
146 nsViewSourceHandler::AllowPort(PRInt32 port, const char *scheme, PRBool *_retval)
148 // don't override anything.
149 *_retval = PR_FALSE;
150 return NS_OK;