|
1 /* |
|
2 * Copyright (c) 2006 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 //INCLUDES |
|
19 #include "../../bidi.h" |
|
20 #include "PlatformString.h" |
|
21 #include <centralrepository.h> |
|
22 #include <BrowserUiSDKCRKeys.h> |
|
23 #include "PluginSkin.h" |
|
24 #include "PluginWin.h" |
|
25 #include "PluginHandler.h" |
|
26 #include "PluginStreamLoaderClient.h" |
|
27 #include "PluginStream.h" |
|
28 #include "WebFrame.h" |
|
29 #include "WebFrameView.h" |
|
30 #include "WebView.h" |
|
31 #include "WebPageFullScreenHandler.h" |
|
32 #include "BrCtl.h" |
|
33 #include "WebCoreGraphicsContext.h" |
|
34 #include "StaticObjectsContainer.h" |
|
35 #include "BrCtlDefs.h" |
|
36 #include "SettingsContainer.h" |
|
37 #include <Uri8.h> |
|
38 #include <StringLoader.h> |
|
39 #include <Webkit.rsg> |
|
40 #include "Frame.h" |
|
41 #include "FrameLoader.h" |
|
42 #include "DocumentLoader.h" |
|
43 #include "ResourceRequest.h" |
|
44 #include "Widget.h" |
|
45 #include "PlatformScrollBar.h" |
|
46 |
|
47 #include <ApEngineConsts.h> |
|
48 #include <Uri8.h> |
|
49 #include <InternetConnectionManager.h> |
|
50 #include <es_enum.h> |
|
51 |
|
52 // CONSTANTS |
|
53 using namespace WebCore; |
|
54 // scheme for RTSP url |
|
55 _LIT8(KRtsp, "rtsp"); |
|
56 _LIT(KAccessPtId, "accesspointid"); |
|
57 _LIT(KContentType, "contenttype"); |
|
58 _LIT(KContentTypeFlash, "flash"); |
|
59 _LIT(KContentTypeUnknown, "application/octet-stream"); |
|
60 _LIT(KRequestContentType, "Content-Type:"); |
|
61 _LIT(KRequestEOF, "\r\n"); |
|
62 _LIT(KRequestEOH, "\r\n\r\n"); |
|
63 |
|
64 // The default placeholder width, matches the value set in html4.css |
|
65 const TUint KPlaceholderWidth( 100 ); |
|
66 const TUint KPlaceholderHeight( 50 ); |
|
67 |
|
68 // The Padding between object and border, matches the value in html4.css |
|
69 const TUint KHtml4cssPadding( 1 ); |
|
70 |
|
71 // The border is grow/shrink by this much when the focus changes |
|
72 const TUint KBorderWidthUnfocus( 0 ); |
|
73 const TUint KBorderWidthFocus( KHtml4cssPadding ); |
|
74 |
|
75 //MACROS |
|
76 |
|
77 //DATATYPES |
|
78 // LOCAL FUNCTION PROTOTYPES |
|
79 TInt RunScriptCb( TAny* aPtr ); |
|
80 // ---------------------------------------------------------------------------- |
|
81 // makeAbsoluteUrlL() |
|
82 // return an absolute url that results from refUrl being resolved against |
|
83 // baseUrl. |
|
84 // ---------------------------------------------------------------------------- |
|
85 HBufC8* makeAbsoluteUrlL(const TDesC8& baseUrl, const TDesC8& refUrl) |
|
86 { |
|
87 TUriParser8 baseUrlparser; |
|
88 baseUrlparser.Parse(baseUrl); |
|
89 TUriParser8 refUrlparser; |
|
90 refUrlparser.Parse(refUrl); |
|
91 |
|
92 CUri8* absoluteUrl = CUri8::ResolveL(baseUrlparser, refUrlparser); |
|
93 CleanupStack::PushL(absoluteUrl); |
|
94 |
|
95 HBufC8* absoluteUrlBuf = HBufC8::NewL(absoluteUrl->Uri().UriDes().Length()); |
|
96 TPtr8 absoluteUrlDes = absoluteUrlBuf->Des(); |
|
97 absoluteUrlDes.Copy(absoluteUrl->Uri().UriDes()); |
|
98 |
|
99 CleanupStack::PopAndDestroy(absoluteUrl); |
|
100 |
|
101 return absoluteUrlBuf; |
|
102 } |
|
103 |
|
104 // ---------------------------------------------------------------------------- |
|
105 // PluginSkin::NewL() |
|
106 // Two-phased constructor for PluginSkin |
|
107 // ---------------------------------------------------------------------------- |
|
108 PluginSkin* PluginSkin::NewL( WebFrame& frame, |
|
109 const TPtrC8& url, |
|
110 const Vector<WebCore::String>& attributesNames, |
|
111 const Vector<WebCore::String>& attributeValues, |
|
112 const TPtrC8& baseUrl, |
|
113 const WebCore::String& mimeType, |
|
114 TBool canInteract ) |
|
115 { |
|
116 PluginSkin* self = NULL; |
|
117 |
|
118 //Check if the flash plugin is enabled or disabled. |
|
119 self = new (ELeave) PluginSkin( frame ); |
|
120 CleanupStack::PushL( self ); |
|
121 self->ConstructL( mimeType, attributesNames, attributeValues, |
|
122 url, baseUrl, canInteract ); |
|
123 CleanupStack::Pop(); // self |
|
124 return self; |
|
125 } |
|
126 |
|
127 // ---------------------------------------------------------------------------- |
|
128 // PluginSkin::PluginSkin() |
|
129 // Default constructor for PluginSkin |
|
130 // ---------------------------------------------------------------------------- |
|
131 PluginSkin::PluginSkin( WebFrame& frame ) |
|
132 : m_pluginwin(0), |
|
133 m_frame( &frame ), |
|
134 m_visible( EFalse ), |
|
135 m_pluginSupported( EFalse ), |
|
136 m_pluginClosed(false), |
|
137 m_canInteract( EFalse ), |
|
138 m_rect(TRect(0,0,0,0)), |
|
139 m_ref(1), |
|
140 m_handle(-1), |
|
141 m_instance(0), |
|
142 m_pluginfuncs(0), |
|
143 m_resized(false) |
|
144 { |
|
145 } |
|
146 |
|
147 // ---------------------------------------------------------------------------- |
|
148 // PluginSkin::ConstructL() |
|
149 // Second phase constructor for PluginSkin |
|
150 // ---------------------------------------------------------------------------- |
|
151 void PluginSkin::ConstructL( const WebCore::String& mimeType, |
|
152 const Vector<WebCore::String>& attributesNames, |
|
153 const Vector<WebCore::String>& attributeValues, |
|
154 const TPtrC8& url, |
|
155 const TPtrC8& baseUrl, |
|
156 TBool canInteract ) |
|
157 { |
|
158 // Get the canned object images |
|
159 m_cannedimg = WebCore::StaticObjectsContainer::instance()->webCannedImages()->getImage( WebCannedImages::EImageObject ); |
|
160 |
|
161 TInt value( 0 ); |
|
162 CRepository* rep = CRepository::NewL( KCRUidBrowser ); |
|
163 rep->Get( KBrowserUsBuild, value ); |
|
164 delete rep; |
|
165 |
|
166 if ( !value || canInteract ) |
|
167 { |
|
168 m_canInteract = ETrue; |
|
169 } |
|
170 |
|
171 // Create the plugin if supported by platform |
|
172 PluginHandler* pluginHandler = WebCore::StaticObjectsContainer::instance()->pluginHandler(); |
|
173 m_pluginSupported = pluginHandler->isSupported( mimeType.des(), url ); |
|
174 |
|
175 |
|
176 if ( m_pluginSupported ) { |
|
177 |
|
178 m_attributeNames = new (ELeave) CDesCArrayFlat(attributesNames.size()); |
|
179 m_attributeValues = new (ELeave) CDesCArrayFlat(attributeValues.size()); |
|
180 |
|
181 for (TInt i = 0; i < attributesNames.size(); i++) |
|
182 { m_attributeNames->AppendL(attributesNames[i].des());} |
|
183 for (TInt i = 0; i < attributeValues.size(); i++) |
|
184 { m_attributeValues->AppendL(attributeValues[i].des());} |
|
185 |
|
186 m_attributeNames->AppendL( KContentType() ); |
|
187 m_attributeValues->AppendL( mimeType.des()); |
|
188 |
|
189 // Append the browser access point id. |
|
190 // The access point id could be used by plugins to make open up a connection. |
|
191 m_attributeNames->AppendL( KAccessPtId ); |
|
192 // Convert int value to string and append it |
|
193 TBuf16<4> value; |
|
194 value.Format( _L("%d"), m_frame->frameView()->topView()->accessPointId() ); |
|
195 m_attributeValues->AppendL( value ); |
|
196 if(url.Length()) |
|
197 m_url = url.AllocL(); |
|
198 bool loadPluginContent = m_frame->frameView()->topView()->brCtl()->settings()->brctlSetting(TBrCtlDefs::ESettingsAutoLoadImages); |
|
199 if((mimeType.des().Find(KContentTypeFlash) != KErrNotFound)) { |
|
200 loadPluginContent = loadPluginContent && !m_frame->frameView()->topView()->brCtl()->settings()->brctlSetting(TBrCtlDefs::ESettingsDisableFlash); |
|
201 m_flashContent = ETrue; |
|
202 } |
|
203 else { |
|
204 m_flashContent = EFalse; |
|
205 } |
|
206 if (loadPluginContent) { |
|
207 if (isBrowserScheme(url)) { |
|
208 NetscapePlugInStreamLoaderClient* pluginloader = NetscapePlugInStreamLoaderClient::NewL(url, this, core(m_frame)); |
|
209 if (pluginloader) { |
|
210 pluginloader->start(); |
|
211 } |
|
212 } |
|
213 else { |
|
214 TPtrC mimePtr(mimeType.des()); |
|
215 TPtrC8 urlPtr(url); |
|
216 HBufC8* mime = NULL; |
|
217 mime = HBufC8::NewLC(mimePtr.Length()); |
|
218 mime->Des().Copy(mimePtr); |
|
219 createPluginWinL(urlPtr, mimePtr); |
|
220 loadPluginL(*mime); |
|
221 CleanupStack::PopAndDestroy(); // mime |
|
222 } |
|
223 } |
|
224 } // end of if (iIsPluginSupported) |
|
225 else { |
|
226 if(url.Length()) |
|
227 m_url = url.AllocL(); |
|
228 } |
|
229 |
|
230 // register itself |
|
231 MemoryManager::AddCollector(this); |
|
232 iJavascriptTimer = NULL; |
|
233 } |
|
234 |
|
235 void PluginSkin::addPluginStream(PluginStream* stream) |
|
236 { |
|
237 m_streams.add(stream); |
|
238 } |
|
239 |
|
240 void PluginSkin::removePluginStream(PluginStream* stream) |
|
241 { |
|
242 m_streams.remove(stream); |
|
243 } |
|
244 |
|
245 // ---------------------------------------------------------------------------- |
|
246 // PluginSkin::~PluginSkin() |
|
247 // PluginSkin class Destructor |
|
248 // ---------------------------------------------------------------------------- |
|
249 PluginSkin::~PluginSkin() |
|
250 { |
|
251 MemoryManager::RemoveCollector(this); |
|
252 Close(); |
|
253 |
|
254 RFs& rfs = StaticObjectsContainer::instance()->fsSession(); |
|
255 for(TInt i=0; i < m_tempFilesArray.Count(); i++) |
|
256 { |
|
257 rfs.Delete(m_tempFilesArray[i]->Des()); |
|
258 } |
|
259 |
|
260 m_tempFilesArray.ResetAndDestroy(); |
|
261 } |
|
262 |
|
263 void PluginSkin::Close() |
|
264 { |
|
265 // close any pending stream |
|
266 Vector<PluginStream*> streams; |
|
267 for (HashSet<PluginStream*>::iterator it = m_streams.begin(); it != m_streams.end(); ++it) { |
|
268 streams.append(*it); |
|
269 } |
|
270 for (int i=0; i<streams.size(); ++i) { |
|
271 streams[i]->close(); |
|
272 } |
|
273 m_streams.clear(); |
|
274 |
|
275 if (m_instance && m_pluginfuncs && m_pluginfuncs->destroy) { |
|
276 m_pluginfuncs->destroy(m_instance, NULL); |
|
277 } |
|
278 |
|
279 if (m_handle >= 0) { |
|
280 PluginHandler* pluginhandler = WebCore::StaticObjectsContainer::instance()->pluginHandler(); |
|
281 if ( pluginhandler) { |
|
282 pluginhandler->unloadPlugin( m_handle ); |
|
283 } |
|
284 m_handle = -1; |
|
285 } |
|
286 |
|
287 User::Free(m_instance); m_instance = 0; |
|
288 delete m_pluginwin; m_pluginwin = 0; |
|
289 delete m_attributeNames; m_attributeNames = 0; |
|
290 delete m_attributeValues; m_attributeValues = 0; |
|
291 delete m_url; m_url = 0; |
|
292 delete iJavascriptTimer; iJavascriptTimer = 0; |
|
293 m_pluginfuncs = 0; |
|
294 m_pluginSupported = EFalse; |
|
295 m_pluginClosed = true; |
|
296 } |
|
297 |
|
298 |
|
299 // ---------------------------------------------------------------------------- |
|
300 // PluginSkin::pluginFocusChanged() |
|
301 // PluginSkin function to show/hide fullscreen sprite |
|
302 // ---------------------------------------------------------------------------- |
|
303 void PluginSkin::pluginFocusChanged(TBool focus) |
|
304 { |
|
305 //Trigger Webview to notify all plugins about current view set to foreground/background for playing/pausing swf files (resp.) |
|
306 control(m_frame)->webView()->notifyPlugins(focus); |
|
307 if (control(m_frame)->webView()->pageFullScreenHandler() && |
|
308 !control(m_frame)->webView()->pageFullScreenHandler()->isFullScreenMode()) |
|
309 return; |
|
310 |
|
311 if (focus && !m_flashContent) |
|
312 { |
|
313 control(m_frame)->webView()->LeaveFullscreenBrowsingL(); |
|
314 control(m_frame)->webView()->notifyFullscreenModeChangeL( EFalse ); |
|
315 } |
|
316 else if (focus) |
|
317 { |
|
318 control(m_frame)->webView()->pageFullScreenHandler()->showEscBtnL(); |
|
319 } |
|
320 else |
|
321 { |
|
322 control(m_frame)->webView()->pageFullScreenHandler()->hideEscBtnL(); |
|
323 } |
|
324 } |
|
325 |
|
326 |
|
327 // ---------------------------------------------------------------------------- |
|
328 // PluginSkin::Draw |
|
329 // From MWebCoreObjectWidget |
|
330 // |
|
331 // The "focus" border width of this widget is adjusted to show when it has |
|
332 // focus. The border width is grown to KBorderWidthFocus. The default padding |
|
333 // (set in Html4.css) is set up to handle the focus border growing into it. |
|
334 // ---------------------------------------------------------------------------- |
|
335 void PluginSkin::draw( WebCoreGraphicsContext& context, |
|
336 const TRect& /*rect*/ ) |
|
337 { |
|
338 if(!control(m_frame)->webView()->IsVisible()) |
|
339 return; |
|
340 |
|
341 TRect newRect(m_rect); |
|
342 TInt z(context.view().scalingFactor()); |
|
343 if (z != 100 ) |
|
344 { |
|
345 newRect = m_frame->frameView()->toViewCoords(m_rect); |
|
346 } |
|
347 CFbsBitGc* gc = &context.gc(); |
|
348 gc->SetPenStyle( CGraphicsContext::ENullPen ); |
|
349 gc->SetBrushStyle( CGraphicsContext::ENullBrush ); |
|
350 |
|
351 CFbsBitmap* bitmap = m_cannedimg.m_img; |
|
352 TSize bmpSize( bitmap->SizeInPixels() ); |
|
353 if ( !m_pluginwin && newRect.Height() >= bmpSize.iHeight && newRect.Width() >= bmpSize.iWidth ) |
|
354 { |
|
355 // The inner rect is big enough, draw the placeholder image |
|
356 TPoint bitmapStartPoint( newRect.Center() ); |
|
357 bitmapStartPoint -= TPoint(bmpSize.iWidth/2,bmpSize.iHeight/2); |
|
358 gc->BitBltMasked( bitmapStartPoint, m_cannedimg.m_img, |
|
359 bmpSize, m_cannedimg.m_msk, ETrue ); |
|
360 } |
|
361 if(m_pluginwin) |
|
362 { |
|
363 positionChanged(); |
|
364 // Force the control to be redrawn. |
|
365 m_pluginwin->refreshPlugin(*gc); |
|
366 } |
|
367 } |
|
368 |
|
369 // ---------------------------------------------------------------------------- |
|
370 // PluginSkin::IsVisible |
|
371 // From MWebCoreObjectWidget |
|
372 // ---------------------------------------------------------------------------- |
|
373 TBool PluginSkin::isVisible() const |
|
374 { |
|
375 return m_visible; |
|
376 } |
|
377 |
|
378 // ---------------------------------------------------------------------------- |
|
379 // PluginSkin::SizeHint |
|
380 // From MWebCoreObjectWidget |
|
381 // ---------------------------------------------------------------------------- |
|
382 TSize PluginSkin::sizeHint() const |
|
383 { |
|
384 return TSize( KPlaceholderWidth, KPlaceholderHeight ); |
|
385 } |
|
386 |
|
387 // ---------------------------------------------------------------------------- |
|
388 // PluginSkin::MakeVisible |
|
389 // From MWebCoreObjectWidget |
|
390 // ---------------------------------------------------------------------------- |
|
391 void PluginSkin::makeVisible( TBool visible ) |
|
392 { |
|
393 if ( m_pluginwin ) |
|
394 { |
|
395 m_visible = visible; |
|
396 if(m_active) |
|
397 deActivate(); |
|
398 m_pluginwin->makeVisible(visible); |
|
399 } |
|
400 } |
|
401 |
|
402 // ---------------------------------------------------------------------------- |
|
403 // PluginSkin::SetFocus |
|
404 // From MWebCoreObjectWidget |
|
405 // ---------------------------------------------------------------------------- |
|
406 void PluginSkin::setFocus( TBool focus ) |
|
407 { |
|
408 m_focused = focus; |
|
409 } |
|
410 |
|
411 // ---------------------------------------------------------------------------- |
|
412 // PluginSkin::deActivate |
|
413 // Invoked when the user selects the control |
|
414 // ---------------------------------------------------------------------------- |
|
415 void PluginSkin::deActivate() |
|
416 { |
|
417 TBool consumed(EFalse); |
|
418 if (m_pluginwin ) |
|
419 { |
|
420 TRAP_IGNORE( m_pluginwin->processEventL(EEventDeactivate, consumed)); |
|
421 } |
|
422 |
|
423 if (consumed) |
|
424 { |
|
425 m_active = EFalse; |
|
426 m_frame->frameView()->topView()->setFocusedElementType(TBrCtlDefs::EElementObjectBox); |
|
427 // Set right soft key |
|
428 m_frame->frameView()->topView()->brCtl()->updateDefaultSoftkeys(); |
|
429 } |
|
430 } |
|
431 |
|
432 // ---------------------------------------------------------------------------- |
|
433 // PluginSkin::activate |
|
434 // From MWebCoreObjectWidget |
|
435 // Invoked when the user selects the right key (Cancel) |
|
436 // ---------------------------------------------------------------------------- |
|
437 void PluginSkin::activate() |
|
438 { |
|
439 if (m_pluginClosed) |
|
440 return; |
|
441 |
|
442 TBool consumed(EFalse); |
|
443 if(m_pluginwin) |
|
444 { |
|
445 if(m_canInteract) |
|
446 { |
|
447 TRAP_IGNORE( m_pluginwin->processEventL(EEventActivate, consumed)); |
|
448 if (consumed) |
|
449 { |
|
450 m_active = ETrue; |
|
451 m_frame->frameView()->topView()->setFocusedElementType(TBrCtlDefs::EElementActivatedObjectBox); |
|
452 // Set right soft key |
|
453 m_frame->frameView()->topView()->brCtl()->updateDefaultSoftkeys(); |
|
454 } |
|
455 } |
|
456 else |
|
457 { |
|
458 m_active = ETrue; |
|
459 m_frame->frameView()->topView()->openPluginPlayer(m_pluginwin); |
|
460 consumed = ETrue; |
|
461 m_active = EFalse; |
|
462 } |
|
463 } else { |
|
464 if ( m_pluginSupported ) { |
|
465 NetscapePlugInStreamLoaderClient* pluginloader = NetscapePlugInStreamLoaderClient::NewL(*m_url, this, core(m_frame)); |
|
466 if (pluginloader) { |
|
467 pluginloader->start(); |
|
468 } |
|
469 } |
|
470 else { |
|
471 if (m_url) { |
|
472 // let the download manager handle this. non-native top level load |
|
473 mainFrame(m_frame)->loadURL(*m_url, TBrCtlDefs::ECacheModeNoCache, String()); |
|
474 } |
|
475 } |
|
476 } |
|
477 } |
|
478 |
|
479 // ---------------------------------------------------------------------------- |
|
480 // PluginSkin::Rect |
|
481 // From MWebCoreObjectWidget |
|
482 // ---------------------------------------------------------------------------- |
|
483 TRect PluginSkin::rect() const |
|
484 { |
|
485 return m_rect; |
|
486 } |
|
487 |
|
488 // ---------------------------------------------------------------------------- |
|
489 // PluginSkin::SetRect |
|
490 // From MWebCoreObjectWidget |
|
491 // ---------------------------------------------------------------------------- |
|
492 void PluginSkin::setRect(const TRect& rect) |
|
493 { |
|
494 m_rect = rect; |
|
495 } |
|
496 |
|
497 // ---------------------------------------------------------------------------- |
|
498 // PluginSkin::SetFont |
|
499 // From MWebCoreObjectWidget |
|
500 // ---------------------------------------------------------------------------- |
|
501 void PluginSkin::setFont(CFont* font) |
|
502 { |
|
503 // Use the font set by our widget, when graphicsContext.UseFont() is called |
|
504 // the previous font is cleaned up. |
|
505 m_font = font; |
|
506 } |
|
507 |
|
508 |
|
509 // ----------------------------------------------------------------------------- |
|
510 // PluginSkin::IsFocusable |
|
511 // |
|
512 // ----------------------------------------------------------------------------- |
|
513 // |
|
514 TBool PluginSkin::isFocusable() const |
|
515 { |
|
516 return ETrue; |
|
517 } |
|
518 |
|
519 // ----------------------------------------------------------------------------- |
|
520 // PluginSkin::loadPlugin |
|
521 // |
|
522 // Load the plugin. |
|
523 // ----------------------------------------------------------------------------- |
|
524 void PluginSkin::loadPluginL( const TDesC8& mimetype ) |
|
525 { |
|
526 |
|
527 if (!m_instance) { |
|
528 |
|
529 NPError error( NPERR_NO_ERROR ); |
|
530 |
|
531 m_instance = (NPP) User::AllocL(sizeof(NPP_t)); |
|
532 m_instance->ndata = pluginWin(); |
|
533 m_instance->pdata = NULL; |
|
534 |
|
535 if (m_instance) { |
|
536 |
|
537 PluginHandler* pluginhandler = WebCore::StaticObjectsContainer::instance()->pluginHandler(); |
|
538 if ( pluginhandler ) { |
|
539 pluginhandler->loadPluginL( m_handle, &m_pluginfuncs ); |
|
540 |
|
541 if (m_pluginfuncs && m_pluginfuncs->newp) { |
|
542 |
|
543 error = m_pluginfuncs->newp( TPtrC8(mimetype), |
|
544 m_instance, |
|
545 NP_EMBED, |
|
546 m_attributeNames, |
|
547 m_attributeValues, |
|
548 NULL ); |
|
549 |
|
550 } |
|
551 if (m_pluginwin) { |
|
552 m_pluginwin->ConstructL(*(control(m_frame)->webView())); |
|
553 } |
|
554 } |
|
555 } |
|
556 |
|
557 switch ( error ) { |
|
558 case NPERR_OUT_OF_MEMORY_ERROR: { |
|
559 User::Leave( KErrNoMemory ); |
|
560 break; |
|
561 } |
|
562 case NPERR_GENERIC_ERROR: { |
|
563 User::Leave( KErrNotSupported ); |
|
564 break; |
|
565 } |
|
566 } |
|
567 |
|
568 if (m_pluginwin) |
|
569 m_pluginwin->SetExtent( TPoint(0,0), TSize(0,0) ); |
|
570 |
|
571 } |
|
572 |
|
573 } |
|
574 |
|
575 // ----------------------------------------------------------------------------- |
|
576 // PluginSkin::CreatePluginWinL |
|
577 // |
|
578 // Initializes a new PluginWin |
|
579 // ----------------------------------------------------------------------------- |
|
580 // |
|
581 void PluginSkin::createPluginWinL(TDesC8& url, TDesC& mimetype) |
|
582 { |
|
583 if (m_pluginwin) |
|
584 return; |
|
585 // The aLoadMode is not currently used. It would be used for checking the |
|
586 // load mode and determining if the plugin should be deleted and recreated. |
|
587 // Get plugin handler, so we can find a plugin handle for a plugin that |
|
588 // supports the incoming content (by mimetype or extension) |
|
589 PluginHandler* pluginHandler = WebCore::StaticObjectsContainer::instance()->pluginHandler(); |
|
590 m_handle = pluginHandler->findPlugin( mimetype ); |
|
591 if ( m_handle == KErrNotFound ) { |
|
592 TUriParser8 parser; |
|
593 if ( parser.Parse(url) == KErrNone ) { |
|
594 m_handle = pluginHandler->findPluginByExtension( parser.Extract(EUriPath ) ); |
|
595 } |
|
596 } |
|
597 if (m_handle == KErrNotFound) |
|
598 User::Leave(KErrNotSupported); |
|
599 //Set the cliprect to plugwin |
|
600 TRect clipRect = TRect(m_rect.iTl, m_frame->frameView()->toDocCoords(m_rect.Size())); |
|
601 clipRect.Intersection(m_rect); |
|
602 setClipRect(clipRect); |
|
603 // Create the PluginWin, if it doesn't exist, |
|
604 m_pluginSupported = true; |
|
605 m_pluginwin = PluginWin::NewL(this, *m_frame->frameView()->topView()); |
|
606 m_frame->frameView()->invalidateRect(m_rect, EFalse); |
|
607 } |
|
608 |
|
609 |
|
610 // ----------------------------------------------------------------------------- |
|
611 // PluginSkin::ViewFocusChanged |
|
612 // From MViewFocusObserver |
|
613 // Callback from the view when the focus changes |
|
614 // ----------------------------------------------------------------------------- |
|
615 void PluginSkin::viewFocusChanged(TBool focused) |
|
616 { |
|
617 if (m_pluginwin) |
|
618 { |
|
619 m_pluginwin->viewFocusChanged(focused); |
|
620 } |
|
621 } |
|
622 |
|
623 // ----------------------------------------------------------------------------- |
|
624 // PluginSkin::PositionChanged |
|
625 // From MViewFocusObserver |
|
626 // Callback from the view when the position changes |
|
627 // ----------------------------------------------------------------------------- |
|
628 void PluginSkin::positionChanged() |
|
629 { |
|
630 // If the plugin content hasnt arrived yet or plugin is invalid, then return immediately |
|
631 if ( !m_pluginwin ) { |
|
632 return; |
|
633 } |
|
634 TRect rect = m_rect; |
|
635 TRect clipRect(frameVisibleRect()); |
|
636 clipRect.Intersection(rect); |
|
637 setClipRect(clipRect); |
|
638 setPluginWinClipedRect(); |
|
639 |
|
640 } |
|
641 |
|
642 //------------------------------------------------------------------------------- |
|
643 // RunScriptCb |
|
644 // C-style TCallback function |
|
645 //------------------------------------------------------------------------------- |
|
646 TInt RunScriptCb(TAny* aPtr ) |
|
647 { |
|
648 static_cast<PluginSkin*>(aPtr)->RunScript(); |
|
649 return EFalse; |
|
650 } |
|
651 |
|
652 |
|
653 // ----------------------------------------------------------------------------- |
|
654 // PluginSkin::forceRedraw |
|
655 // |
|
656 // |
|
657 // ----------------------------------------------------------------------------- |
|
658 void PluginSkin::forceRedraw(bool drawNow) |
|
659 { |
|
660 if (m_frame && m_frame->frameView()) |
|
661 m_frame->frameView()->invalidateRect(m_rect, drawNow); |
|
662 } |
|
663 |
|
664 // ----------------------------------------------------------------------------- |
|
665 // PluginSkin::RunScript |
|
666 // |
|
667 // Runs java script, possibly asynchronously |
|
668 // ----------------------------------------------------------------------------- |
|
669 // |
|
670 TBool PluginSkin::RunScript() |
|
671 { |
|
672 _LIT8(KJs, "javascript:"); |
|
673 |
|
674 for(int i=0;i<m_JSUrls.Count();i++) { |
|
675 TPtr16 temp = ((HBufC*)m_JSUrls[i])->Des(); |
|
676 core(mainFrame(m_frame))->loader()->executeScript(String(temp.Mid(KJs().Length()))); |
|
677 } |
|
678 m_JSUrls.ResetAndDestroy(); |
|
679 return EFalse; |
|
680 } |
|
681 |
|
682 //callbacks from NpnImplementation |
|
683 int PluginSkin::getRequestL(const TDesC8& url, bool notify, void* notifydata,const TDesC* aWindowType) |
|
684 { |
|
685 TPluginLoadMode loadmode = GetLoadMode(aWindowType); |
|
686 |
|
687 if (url.Ptr() == NULL ) { |
|
688 return KErrArgument; |
|
689 } |
|
690 |
|
691 _LIT8(KJs, "javascript:"); |
|
692 if ((url.Length() > KJs().Length() ) &&(url.Left(KJs().Length()).FindF(KJs) == 0)) { |
|
693 HBufC* pBuffer = HBufC::NewL(url.Length()); |
|
694 TPtr16 temp = pBuffer->Des(); |
|
695 temp.Copy(url); |
|
696 m_JSUrls.Append(pBuffer); |
|
697 if(!iJavascriptTimer){ |
|
698 iJavascriptTimer = CIdle::NewL(CActive::EPriorityLow); |
|
699 } |
|
700 if( iJavascriptTimer && !iJavascriptTimer->IsActive() ){ |
|
701 iJavascriptTimer->Start(TCallBack(&RunScriptCb, this)); |
|
702 } |
|
703 return KErrNone; |
|
704 } |
|
705 |
|
706 // make sure it is an absolute URL |
|
707 HBufC8* absoluteUrl = makeAbsoluteUrlL(*m_url, url); |
|
708 CleanupStack::PushL(absoluteUrl); |
|
709 |
|
710 if (loadmode == ELoadModePlugin ) { |
|
711 |
|
712 if (m_instance && m_pluginfuncs) { |
|
713 |
|
714 NetscapePlugInStreamLoaderClient* pluginloader = NetscapePlugInStreamLoaderClient::NewL(url, this, core(m_frame), notifydata); |
|
715 if (pluginloader) { |
|
716 pluginloader->start(); |
|
717 |
|
718 if ( notify ) { |
|
719 HBufC* url16 = HBufC::NewLC( url.Length() ); |
|
720 url16->Des().Copy( url ); |
|
721 m_pluginfuncs->urlnotify( m_instance, *url16, NPRES_DONE, notifydata ); |
|
722 CleanupStack::PopAndDestroy(url16); |
|
723 } |
|
724 |
|
725 } |
|
726 } |
|
727 } |
|
728 else { |
|
729 HBufC* windowType = HBufC::NewLC(aWindowType->Length()); |
|
730 windowType->Des().Copy(*aWindowType); |
|
731 frame()->loadURL(*absoluteUrl,TBrCtlDefs::ECacheModeNormal,String(),&String(*windowType)); |
|
732 CleanupStack::PopAndDestroy(windowType); |
|
733 } |
|
734 |
|
735 CleanupStack::PopAndDestroy(absoluteUrl); |
|
736 |
|
737 return KErrNone; |
|
738 } |
|
739 |
|
740 int PluginSkin::postRequestL(const TDesC8& url,const TDesC& buffer, bool fromfile, bool notify, void* notifydata,const TDesC* aWindowType) |
|
741 { |
|
742 // make sure it is an absolute URL |
|
743 HBufC8* absoluteUrl = makeAbsoluteUrlL(*m_url, url); |
|
744 CleanupStack::PushL(absoluteUrl); |
|
745 TPluginLoadMode loadmode = GetLoadMode(aWindowType); |
|
746 |
|
747 ResourceRequest request = (KURL(*absoluteUrl)); |
|
748 |
|
749 request.setMainLoad(true); |
|
750 request.setCachePolicy(UseProtocolCachePolicy); |
|
751 request.setHTTPMethod("POST"); |
|
752 |
|
753 int contenttype_pos = buffer.Find(KRequestContentType()); |
|
754 if (contenttype_pos != KErrNotFound) { |
|
755 contenttype_pos += KRequestContentType().Length(); |
|
756 int contenttype_length = buffer.Mid(contenttype_pos).Find(KRequestEOF()); |
|
757 |
|
758 if (contenttype_length != KErrNotFound) { |
|
759 request.setHTTPContentType(buffer.Mid(contenttype_pos,contenttype_length)); |
|
760 } else { |
|
761 request.setHTTPContentType(KContentTypeUnknown()); |
|
762 } |
|
763 |
|
764 } else { |
|
765 request.setHTTPContentType(KContentTypeUnknown()); |
|
766 } |
|
767 |
|
768 |
|
769 if ( fromfile ) { |
|
770 |
|
771 RFs& rfs = StaticObjectsContainer::instance()->fsSession(); |
|
772 RFile file; |
|
773 |
|
774 User::LeaveIfError(file.Open( rfs, buffer, EFileRead)); |
|
775 CleanupClosePushL(file); |
|
776 |
|
777 // Get the file size and allocate a buffer |
|
778 TInt size(0); |
|
779 User::LeaveIfError( file.Size(size) ); |
|
780 HBufC8* body = HBufC8::NewLC(size); |
|
781 TPtr8 tptr8(body->Des()); |
|
782 |
|
783 User::LeaveIfError(file.Read(tptr8)); |
|
784 FormData* fd = new (ELeave) FormData(body->Ptr(),body->Length()); |
|
785 request.setHTTPBody(fd); |
|
786 CleanupStack::PopAndDestroy(2); // file, body |
|
787 } |
|
788 else{ |
|
789 |
|
790 int start_content = buffer.Find(KRequestEOH()); |
|
791 start_content = (start_content != KErrNotFound) ? start_content+ KRequestEOH().Length() : 0; |
|
792 |
|
793 HBufC8* body = HBufC8::NewLC(buffer.Mid(start_content).Length()); |
|
794 body->Des().Copy(buffer.Mid(start_content)); |
|
795 FormData* fd = new (ELeave) FormData(body->Ptr(),body->Length()); |
|
796 request.setHTTPBody(fd); |
|
797 CleanupStack::PopAndDestroy(); // body |
|
798 } |
|
799 |
|
800 |
|
801 if (loadmode == ELoadModePlugin ) { |
|
802 |
|
803 if (m_instance && m_pluginfuncs) { |
|
804 NetscapePlugInStreamLoaderClient* pluginloader = NetscapePlugInStreamLoaderClient::NewL(request, this, core(m_frame), notifydata); |
|
805 if (pluginloader) { |
|
806 pluginloader->start(); |
|
807 |
|
808 if ( notify ) { |
|
809 HBufC* url16 = HBufC::NewLC( url.Length() ); |
|
810 url16->Des().Copy( url ); |
|
811 m_pluginfuncs->urlnotify( m_instance, *url16, NPRES_DONE, notifydata ); |
|
812 CleanupStack::PopAndDestroy(url16); |
|
813 } |
|
814 |
|
815 } |
|
816 } |
|
817 } |
|
818 else { |
|
819 HBufC* windowType = HBufC::NewLC(aWindowType->Length()); |
|
820 windowType->Des().Copy(*aWindowType); |
|
821 frame()->loadRequest(request,&String(*windowType)); |
|
822 CleanupStack::PopAndDestroy(windowType); |
|
823 } |
|
824 |
|
825 |
|
826 CleanupStack::PopAndDestroy(absoluteUrl); |
|
827 |
|
828 return KErrNone; |
|
829 } |
|
830 |
|
831 |
|
832 bool PluginSkin::isInteractive() |
|
833 { |
|
834 |
|
835 if (m_instance && m_pluginfuncs) { |
|
836 |
|
837 bool isNotInteractive = false; |
|
838 NPError err = m_pluginfuncs->getvalue(m_instance, NPPVpluginInteractiveBool, &isNotInteractive); |
|
839 if( err == NPERR_NO_ERROR) { |
|
840 return !isNotInteractive; |
|
841 } |
|
842 |
|
843 } |
|
844 |
|
845 return false; |
|
846 } |
|
847 |
|
848 void PluginSkin::openInViewerL() |
|
849 { |
|
850 if(m_pluginwin) |
|
851 { |
|
852 m_frame->frameView()->topView()->mainFrame()->loadURL(*m_url, TBrCtlDefs::ECacheModeNormal, String()); |
|
853 } |
|
854 } |
|
855 |
|
856 /* |
|
857 // ----------------------------------------------------------------------------- |
|
858 // PluginSkin::HandlePluginError |
|
859 // |
|
860 // handles error conditions |
|
861 // ----------------------------------------------------------------------------- |
|
862 // |
|
863 void PluginSkin::handlePluginError( TInt error ) |
|
864 { |
|
865 if ( error != KErrNone ) |
|
866 { |
|
867 m_pluginSupported = EFalse; |
|
868 delete m_pluginwin; |
|
869 m_pluginwin = 0; |
|
870 } |
|
871 } |
|
872 |
|
873 */ |
|
874 |
|
875 void* PluginSkin::pluginScriptableObject() |
|
876 { |
|
877 // |
|
878 if (m_pluginfuncs && m_pluginfuncs->getvalue) { |
|
879 void *value = 0; |
|
880 NPError npErr = m_pluginfuncs->getvalue( m_instance, NPPVpluginScriptableNPObject, (void *)&value); |
|
881 if (npErr == NPERR_NO_ERROR) { |
|
882 return value; |
|
883 } |
|
884 } |
|
885 return (void *)0; |
|
886 } |
|
887 |
|
888 TBool PluginSkin::isBrowserScheme(const TPtrC8& url) |
|
889 { |
|
890 TBool supported(EFalse); |
|
891 TUriParser8 parser; |
|
892 if( parser.Parse( url ) == KErrNone ) { |
|
893 TPtrC8 scheme = parser.Extract( EUriScheme ); |
|
894 if (scheme.CompareF( _L8("http" ) ) == 0 || scheme.CompareF( _L8("https" ) ) == 0 |
|
895 || scheme.Length() == 1 || scheme.CompareF( _L8("file") ) == 0 || scheme.CompareF( _L8("data") ) == 0) { |
|
896 supported = ETrue; |
|
897 } |
|
898 } |
|
899 return supported; |
|
900 } |
|
901 |
|
902 void PluginSkin::resized() |
|
903 { |
|
904 m_resized = true; |
|
905 m_frame->frameView()->topView()->forceLayoutAndResize(m_frame); |
|
906 } |
|
907 |
|
908 void PluginSkin::setClipRect(TRect rect) |
|
909 { |
|
910 m_pluginWinClipRect = rect; |
|
911 } |
|
912 |
|
913 void PluginSkin::setPluginWinClipedRect() |
|
914 { |
|
915 TRect fullRect(getPluginWinRect()); |
|
916 TRect clipRect(getClipRect()); |
|
917 m_pluginwin->makeVisible((m_frame->frameView()->isVisible()) |
|
918 && (m_frame->frameView()->rect().Intersects(fullRect)) |
|
919 && (control(m_frame)->webView()->inPageViewMode() == EFalse)); |
|
920 clipRect.Intersection(fullRect); |
|
921 if (m_pluginwin && !m_pluginwin->isPluginInFullscreen() && |
|
922 (m_pluginwin->Rect() != clipRect || m_pluginwin->isForceScroll())) { |
|
923 m_pluginwin->SetRect(clipRect); |
|
924 } |
|
925 } |
|
926 |
|
927 TRect PluginSkin::getClipRect() const |
|
928 { |
|
929 TPoint pt = m_frame->frameView()->convertContentToView(m_pluginWinClipRect.iTl); |
|
930 TRect clipRect(pt, m_frame->frameView()->toViewCoords(m_pluginWinClipRect.Size())); |
|
931 clipRect.Intersection(control(m_frame)->webView()->Rect()); |
|
932 return clipRect; |
|
933 } |
|
934 |
|
935 TRect PluginSkin::getPluginWinRect() const |
|
936 { |
|
937 TPoint pt = m_frame->frameView()->convertContentToView(m_rect.iTl); |
|
938 TRect rect(pt, m_frame->frameView()->toViewCoords(m_rect.Size())); |
|
939 return rect; |
|
940 } |
|
941 |
|
942 TRect PluginSkin::frameVisibleRect() const |
|
943 { |
|
944 TRect rect = m_frame->frameView()->visibleRect(); |
|
945 if (m_frame->isIframe()) { |
|
946 if (m_frame->frameView()->vScrollbar() && m_frame->frameView()->vScrollbar()->isEnabled()) { |
|
947 rect.SetWidth(rect.Width() - m_frame->frameView()->vScrollbar()->width()); |
|
948 } |
|
949 if (m_frame->frameView()->hScrollbar() && m_frame->frameView()->hScrollbar()->isEnabled()) { |
|
950 rect.SetHeight(rect.Height() - m_frame->frameView()->hScrollbar()->height()); |
|
951 } |
|
952 } |
|
953 return rect; |
|
954 } |
|
955 |
|
956 |
|
957 TUint PluginSkin::Collect(TUint aRequired) |
|
958 { |
|
959 // out of memory, we need to remove the plugin win and all streams associating with it. |
|
960 Close(); |
|
961 return 0; |
|
962 } |
|
963 |
|
964 TInt PluginSkin::handleNetworkAccess() const |
|
965 { |
|
966 TInt conn = 0,sockHandle = 0; |
|
967 TBool connNeeded; |
|
968 TApBearerType type; |
|
969 TInt apId = -1; |
|
970 |
|
971 TRAP_IGNORE(m_frame->frameView()->topView()->brCtl()->brCtlSpecialLoadObserver()->NetworkConnectionNeededL(&conn,&sockHandle,&connNeeded,&type)); |
|
972 |
|
973 if ( conn ) |
|
974 { |
|
975 RConnection* connPtr = REINTERPRET_CAST( RConnection*, conn ); |
|
976 TConnectionInfoBuf connInfoBuf; |
|
977 TUint conns( 0 ); |
|
978 connPtr->EnumerateConnections( conns ); |
|
979 if ( conns > 0 && connPtr->GetConnectionInfo(1, connInfoBuf) == KErrNone ) |
|
980 { |
|
981 // set the access point id |
|
982 apId = connInfoBuf().iIapId; |
|
983 } |
|
984 } |
|
985 |
|
986 return apId; |
|
987 } |
|
988 void PluginSkin::handlePluginForeground(TBool focus) |
|
989 { |
|
990 // Send Plugin Visible/Invisible event |
|
991 if (m_pluginwin) |
|
992 { |
|
993 m_pluginwin->NotifyPluginVisible(focus); |
|
994 } |
|
995 } |
|
996 |
|
997 |
|
998 TPluginLoadMode PluginSkin::GetLoadMode(const TDesC* aWindowType) |
|
999 { |
|
1000 TWindowType windowType = GetWindowType(aWindowType); |
|
1001 |
|
1002 switch (windowType) { |
|
1003 |
|
1004 case EWindowTypePlugin: // Return the load response to the plugin |
|
1005 return ELoadModePlugin; |
|
1006 |
|
1007 case EWindowTypeBlank: // New window is opened. |
|
1008 case EWindowTypeNew: |
|
1009 return ELoadModeNew; |
|
1010 |
|
1011 case EWindowTypeCurrent: // Replace the plugin with a new document |
|
1012 case EWindowTypeSelf: |
|
1013 return ELoadModeSelf; |
|
1014 |
|
1015 case EWindowTypeParent: // Replace the page with a new top level document |
|
1016 return ELoadModeParent; |
|
1017 |
|
1018 case EWindowTypeTop: |
|
1019 return ELoadModeTop; |
|
1020 |
|
1021 default: |
|
1022 return ELoadModeNone; |
|
1023 } |
|
1024 } |
|
1025 |
|
1026 |
|
1027 TWindowType PluginSkin::GetWindowType(const TDesC* aWindowType) |
|
1028 { |
|
1029 |
|
1030 if ((aWindowType == NULL) || |
|
1031 (aWindowType->Ptr() == NULL) || |
|
1032 (aWindowType->Length() == 0)) { |
|
1033 |
|
1034 return EWindowTypePlugin; |
|
1035 } |
|
1036 |
|
1037 TPtrC windowTypePtr(*aWindowType); |
|
1038 |
|
1039 if (windowTypePtr.FindF(KBlank) == 0) { |
|
1040 return EWindowTypeBlank; |
|
1041 } |
|
1042 |
|
1043 if (windowTypePtr.FindF(KNew) == 0) { |
|
1044 return EWindowTypeNew; |
|
1045 } |
|
1046 |
|
1047 if (windowTypePtr.FindF(KSelf) == 0) { |
|
1048 return EWindowTypeSelf; |
|
1049 } |
|
1050 |
|
1051 if (windowTypePtr.FindF(KCurrent) == 0) { |
|
1052 return EWindowTypeCurrent; |
|
1053 } |
|
1054 |
|
1055 if (windowTypePtr.FindF(KParent) == 0) { |
|
1056 return EWindowTypeParent; |
|
1057 } |
|
1058 |
|
1059 if (windowTypePtr.FindF(KTop) == 0) { |
|
1060 return EWindowTypeTop; |
|
1061 } |
|
1062 |
|
1063 return EWindowTypeUnknown; |
|
1064 } |