|
1 /* |
|
2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Implementation of WebPolicyManager |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "config.h" |
|
19 #include <../bidi.h> |
|
20 #include "WebPolicyManager.h" |
|
21 #include "WebFrameLoaderClient.h" |
|
22 #include "WebFrame.h" |
|
23 #include "WebFrameView.h" |
|
24 #include "WebView.h" |
|
25 #include "Frame.h" |
|
26 #include "FrameLoader.h" |
|
27 #include "DocumentLoader.h" |
|
28 #include "BrCtl.h" |
|
29 #include "WebUtil.h" |
|
30 #include "StaticObjectsContainer.h" |
|
31 #include "PlugInInfoStore.h" |
|
32 #include "MIMETypeRegistry.h" |
|
33 #include <Uri8.h> |
|
34 #include <badesca.h> |
|
35 |
|
36 using namespace WebCore; |
|
37 |
|
38 // CONSTANTS |
|
39 const char* typeTextHtml = "text/html"; |
|
40 const char* typeApplicationXhtml = "application/xhtml+xml"; |
|
41 const char* typeTextPlain = "text/plain"; |
|
42 const char* typeApplicationWapXhtml = "application/vnd.wap.xhtml+xml"; |
|
43 const char* typeMultipartMixed = "multipart/mixed"; |
|
44 const char* typeApplicationOctetStream = "application/octet-stream"; |
|
45 const char* typeImageSlash = "image/"; |
|
46 const char* typeSvg = "svg"; |
|
47 _LIT(KPathBegin,"<!--framePathBegin "); |
|
48 _LIT(KPathEnd," framePathEnd --!>"); |
|
49 |
|
50 WebPolicyManager::WebPolicyManager(WebFrameLoaderClient* webFrameLoaderClient) : |
|
51 m_webFrameLoaderClient(webFrameLoaderClient) |
|
52 { |
|
53 m_newWindowUserGesture = false; |
|
54 m_newWindowTargetName = NULL; |
|
55 } |
|
56 |
|
57 WebPolicyManager::~WebPolicyManager() |
|
58 { |
|
59 delete m_newWindowTargetName; |
|
60 } |
|
61 |
|
62 void WebPolicyManager::dispatchDecidePolicyForMIMEType(WebCore::FramePolicyFunction function, |
|
63 const WebCore::String& MIMEType, |
|
64 const WebCore::ResourceRequest& /*request*/) |
|
65 { |
|
66 if ( m_webFrameLoaderClient->isWMLContent(MIMEType) ) { |
|
67 // check for wml limitations |
|
68 const Vector<CBrCtl*>& ctrls = StaticObjectsContainer::instance()->activeBrowserControls(); |
|
69 for (int i=0; i<ctrls.size(); ++i) { |
|
70 // check non-current BrCtls to see if wml engine is loaded |
|
71 // if it is then we need to ignore this url since only one BrCtl can load the wml engine |
|
72 if (ctrls[i]->wmlEngineInterface() && |
|
73 ctrls[i] != control(m_webFrameLoaderClient->webFrame())) { |
|
74 m_webFrameLoaderClient->ignore(function); |
|
75 return; |
|
76 } |
|
77 } |
|
78 m_webFrameLoaderClient->use(function); |
|
79 } |
|
80 else if ( canShowMIMEType(MIMEType) || |
|
81 ((m_webFrameLoaderClient->webFrame()->parentFrame()) && (PlugInInfoStore::supportsMIMEType(MIMEType)) && |
|
82 !(MIMEType.startsWith("audio/", false)) && !(MIMEType.startsWith("video/", false)))) { |
|
83 m_webFrameLoaderClient->use(function); |
|
84 } |
|
85 else { |
|
86 m_webFrameLoaderClient->download(function); |
|
87 } |
|
88 } |
|
89 |
|
90 void WebPolicyManager::dispatchDecidePolicyForNewWindowAction(WebCore::FramePolicyFunction function, const WebCore::NavigationAction& action, const WebCore::ResourceRequest& request, const WebCore::String& frameName) |
|
91 { |
|
92 switch (action.type()) |
|
93 { |
|
94 case NavigationTypeLinkClicked: |
|
95 case NavigationTypeFormSubmitted: |
|
96 case NavigationTypeBackForward: |
|
97 case NavigationTypeReload: |
|
98 case NavigationTypeFormResubmitted: |
|
99 m_newWindowUserGesture = true; |
|
100 break; |
|
101 case NavigationTypeOther: |
|
102 default: |
|
103 m_newWindowUserGesture = false; |
|
104 break; |
|
105 } |
|
106 delete m_newWindowTargetName; |
|
107 m_newWindowTargetName = NULL; |
|
108 if (frameName.des().Length()) { |
|
109 if (frameName == "_blank" || frameName == "_new") { |
|
110 m_newWindowTargetName = generateFrameName(); |
|
111 } |
|
112 else { // frame has a name |
|
113 m_newWindowTargetName = frameName.des().Alloc(); |
|
114 } |
|
115 } |
|
116 if (m_newWindowTargetName) { |
|
117 m_webFrameLoaderClient->use(function); |
|
118 } |
|
119 else { |
|
120 m_webFrameLoaderClient->ignore(function); |
|
121 } |
|
122 } |
|
123 |
|
124 void WebPolicyManager::dispatchDecidePolicyForNavigationAction(WebCore::FramePolicyFunction function, const WebCore::NavigationAction&, const WebCore::ResourceRequest& request) |
|
125 { |
|
126 // ResourceLoadDelegate does all the checks now. |
|
127 m_webFrameLoaderClient->use(function); |
|
128 } |
|
129 |
|
130 void WebPolicyManager::cancelPolicyCheck() |
|
131 { |
|
132 } |
|
133 |
|
134 void WebPolicyManager::dispatchUnableToImplementPolicy(const WebCore::ResourceError&) |
|
135 { |
|
136 } |
|
137 |
|
138 void WebPolicyManager::dispatchWillSubmitForm(WebCore::FramePolicyFunction function, PassRefPtr<WebCore::FormState>) |
|
139 { |
|
140 m_webFrameLoaderClient->use(function); |
|
141 } |
|
142 |
|
143 WebCore::ResourceError WebPolicyManager::interruptForPolicyChangeError(const WebCore::ResourceRequest& request) |
|
144 { |
|
145 return ResourceError(); |
|
146 } |
|
147 |
|
148 bool WebPolicyManager::canShowMIMEType(const String& MIMEType) const |
|
149 { |
|
150 bool found = false; |
|
151 |
|
152 //RFC 2183: "Content-Disposition: attachment" means downloaded by DM |
|
153 FrameLoader* frameLoader = m_webFrameLoaderClient->webFrame()->frameLoader(); |
|
154 if(frameLoader && frameLoader->activeDocumentLoader()) { |
|
155 ResourceResponse r = frameLoader->activeDocumentLoader()->response(); |
|
156 if (r.isAttachment()) |
|
157 return found; |
|
158 } |
|
159 |
|
160 if (MIMEType == typeTextHtml || |
|
161 MIMEType == typeApplicationXhtml || |
|
162 MIMEType == typeApplicationWapXhtml || |
|
163 MIMEType == typeMultipartMixed) { |
|
164 found = true; |
|
165 } |
|
166 //Check if the image type can be handled by the browser. If not |
|
167 //forward download manager downloads the content |
|
168 else if (MIMETypeRegistry::isSupportedImageMIMEType(MIMEType)){ |
|
169 found = true; |
|
170 } |
|
171 |
|
172 // special case for application/octet-stream. some web servers |
|
173 // are miscofigured and send application/octet-stream even for html |
|
174 // page so we need to pass it to webcore as if it was text/html. however |
|
175 // some binary content also comes as application/octet-stream (such as |
|
176 // sisx files ). so here we che(ha)ck if the response url has .html .htm .asp |
|
177 // extension. though luck for the rest. feel free to extend the list. |
|
178 // some text/plain is actually not (example: cacert.org DER root certificate) |
|
179 else if( MIMEType == typeTextPlain || |
|
180 MIMEType == typeApplicationOctetStream ) { |
|
181 TPtrC8 url = (core(m_webFrameLoaderClient->webFrame()))->loader()->activeDocumentLoader()->responseURL().des(); |
|
182 TUriParser8 parser; |
|
183 if( parser.Parse(url) == KErrNone ) { |
|
184 TPtrC8 path = parser.Extract( EUriPath ); |
|
185 // path == 1 means only / (no filename) |
|
186 if( path.Length() > 1 ) { |
|
187 found = (path.Find(_L8(".html")) != KErrNotFound || |
|
188 path.Find(_L8(".htm")) != KErrNotFound || |
|
189 path.Find(_L8(".asp")) != KErrNotFound || |
|
190 path.Find(_L8(".php")) != KErrNotFound || |
|
191 path.Find(_L8(".jsp")) != KErrNotFound || |
|
192 path.Find(_L8(".txt")) != KErrNotFound); |
|
193 } |
|
194 } |
|
195 } |
|
196 // tot:fixme defaultcontenthandler is only for selfdownloadable, go through the list |
|
197 return found; |
|
198 } |
|
199 |
|
200 |