|
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: Implemetation of WebFrameBridge |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "config.h" |
|
19 #include "../../bidi.h" |
|
20 #include "Document.h" |
|
21 #include "WebFrameBridge.h" |
|
22 #include "WebView.h" |
|
23 #include "WebFrame.h" |
|
24 #include "WebFrameView.h" |
|
25 #include "Frame.h" |
|
26 #include "FrameLoader.h" |
|
27 #include "FrameLoaderClient.h" |
|
28 #include "WebFrameLoaderClient.h" |
|
29 #include "FrameTree.h" |
|
30 #include "HTMLFrameOwnerElement.h" |
|
31 #include "Page.h" |
|
32 #include "WebKitLogger.h" |
|
33 #include "PluginSkin.h" |
|
34 #include "BrCtl.h" |
|
35 #include "HistoryInterface.h" |
|
36 #include "Element.h" |
|
37 |
|
38 using namespace WebCore; |
|
39 |
|
40 WebFrameBridge::WebFrameBridge() : |
|
41 m_refCount(1) |
|
42 { |
|
43 } |
|
44 |
|
45 WebFrameBridge::~WebFrameBridge() |
|
46 { |
|
47 m_webFrame.release(); |
|
48 } |
|
49 |
|
50 WebView* WebFrameBridge::webView() const |
|
51 { |
|
52 if (!m_frame) |
|
53 return NULL; |
|
54 |
|
55 return kit(m_frame->page()); |
|
56 } |
|
57 |
|
58 WebFrame* WebFrameBridge::webFrame() const |
|
59 { |
|
60 return m_webFrame.get(); |
|
61 } |
|
62 |
|
63 WebCoreFrameBridge* WebFrameBridge::mainFrame() const |
|
64 { |
|
65 ASSERT(m_webFrame != NULL); |
|
66 return webView()->mainFrame()->bridge(); |
|
67 } |
|
68 |
|
69 MScrollView* WebFrameBridge::documentView() const |
|
70 { |
|
71 ASSERT(m_webFrame != NULL); |
|
72 return m_webFrame->frameView(); |
|
73 } |
|
74 |
|
75 void WebFrameBridge::finishInitializingWithPage(Page* page, const String& frameName, |
|
76 WebFrameView* frameView, HTMLFrameOwnerElement* ownerElement) |
|
77 { |
|
78 WebView* webView = kit(page); |
|
79 |
|
80 m_webFrame = new WebFrame(); |
|
81 m_webFrame->initWithWebFrameView(frameView, webView, this); |
|
82 |
|
83 m_frame = new Frame(page, ownerElement, new WebFrameLoaderClient(m_webFrame.get())); |
|
84 m_frame->setBridge(this); |
|
85 m_frame->tree()->setName(frameName); |
|
86 m_frame->init(); |
|
87 } |
|
88 |
|
89 void WebFrameBridge::initMainFrameWithPage(Page* page, const String& frameName, WebFrameView* frameView) |
|
90 { |
|
91 init(); |
|
92 finishInitializingWithPage(page, frameName, frameView, NULL); |
|
93 } |
|
94 |
|
95 void WebFrameBridge::initSubframeWithOwnerElement(HTMLFrameOwnerElement* ownerElement, const String& frameName, WebFrameView* frameView) |
|
96 { |
|
97 init(); |
|
98 finishInitializingWithPage(ownerElement->document()->frame()->page(), frameName, frameView, ownerElement); |
|
99 } |
|
100 |
|
101 void WebFrameBridge::close() |
|
102 { |
|
103 WebCoreFrameBridge::close(); |
|
104 m_webFrame.release(); |
|
105 m_webFrame = NULL; |
|
106 } |
|
107 |
|
108 Frame* WebFrameBridge::createChildFrameNamed(const String* frameName, const TPtrC8 withURL, const TPtrC referrer, |
|
109 HTMLFrameOwnerElement* ownerElement, bool allowsScrolling, int marginWidth, int marginHeight) |
|
110 { |
|
111 ASSERT(m_webFrame); |
|
112 |
|
113 WebFrameView* childView = new WebFrameView(); |
|
114 childView->initWithFrame(TRect(0,0,0,0)); |
|
115 childView->setAllowsScrolling(allowsScrolling); |
|
116 childView->setMarginWidth(marginWidth); |
|
117 childView->setMarginHeight(marginHeight); |
|
118 |
|
119 WebFrameBridge* newBridge = new WebFrameBridge(); |
|
120 newBridge->initSubframeWithOwnerElement(ownerElement, *frameName, childView); |
|
121 childView->deref(); |
|
122 |
|
123 m_webFrame->addChild(newBridge->webFrame()); |
|
124 newBridge->deref(); |
|
125 |
|
126 RefPtr<Frame> newFrame = newBridge->frame(); |
|
127 |
|
128 #if USE(LOW_BANDWIDTH_DISPLAY) |
|
129 newFrame->loader()->setUseLowBandwidthDisplay(webView()->widgetExtension() != NULL); |
|
130 #endif |
|
131 |
|
132 m_webFrame->loadURL(withURL, referrer, kit(newFrame.get())); |
|
133 |
|
134 // The frame's onload handler may have removed it from the document. |
|
135 if (!newFrame->tree()->parent()) |
|
136 return NULL; |
|
137 |
|
138 return newFrame.get(); |
|
139 } |
|
140 |
|
141 ObjectElementType WebFrameBridge::determineObjectFromMIMEType(const String& MIMEType, const TPtrC8 URL) |
|
142 { |
|
143 if (MIMEType.length() == 0) { |
|
144 // Try to guess the MIME type based off the extension. |
|
145 int index = MIMEType.des().LocateReverse('.'); |
|
146 if (index != KErrNotFound) { |
|
147 TPtrC extPtr = MIMEType.des().Mid(++index); |
|
148 if (extPtr.Length() > 0 && webView()->pluginForExtension(String(extPtr))) |
|
149 // If no MIME type is specified, use a plug-in if we have one that can handle the extension. |
|
150 return ObjectElementPlugin; |
|
151 } |
|
152 } |
|
153 |
|
154 if (MIMEType.length() == 0) |
|
155 return ObjectElementFrame; // Go ahead and hope that we can display the content. |
|
156 |
|
157 //if (MimeTypeRegistry::isSupportedImageMIMEType(MIMEType)) |
|
158 // return ObjectElementImage; |
|
159 |
|
160 if (webView()->isMIMETypeRegisteredAsPlugin(MIMEType)) |
|
161 return ObjectElementPlugin; |
|
162 |
|
163 if (WebFrameView::viewClassForMIMEType(MIMEType)) |
|
164 return ObjectElementFrame; |
|
165 |
|
166 return ObjectElementNone; |
|
167 } |
|
168 |
|
169 void WebFrameBridge::notifyMetaData(String& name, String& value) |
|
170 { |
|
171 webView()->notifyMetaData(name, value); |
|
172 } |
|
173 |
|
174 unsigned WebFrameBridge::getHistoryLength() |
|
175 { |
|
176 return (unsigned)webView()->brCtl()->historyHandler()->historyController()->historyLength(); |
|
177 } |
|
178 |
|
179 void WebFrameBridge::scheduleHistoryNavigation(int distance) |
|
180 { |
|
181 webView()->brCtl()->historyHandler()->historyController()->goBackOrForward(distance); |
|
182 } |
|
183 |
|
184 MWebCoreWidget* WebFrameBridge::viewForPluginWithURL( const TPtrC8& url, const Vector<String>& paramNames, const Vector<String>& paramValues, |
|
185 const TPtrC8& baseUrl, const String& mimeType, TBool loadContent, Element* pluginElement ) |
|
186 { |
|
187 /*tot:fixme TBool hideReferrer; |
|
188 if (!CanLoadUrl(aUrl,iWebCoreBridge->Referrer(),hideReferrer)) |
|
189 { |
|
190 return 0; |
|
191 }*/ |
|
192 PluginSkin* pluginSkin = NULL; |
|
193 //tot: need to fix url convert |
|
194 TRAP_IGNORE( pluginSkin = PluginSkin::NewL( *m_webFrame, |
|
195 url, paramNames, paramValues, baseUrl, mimeType, loadContent ) ); |
|
196 pluginSkin->setElement(pluginElement); |
|
197 return pluginSkin; |
|
198 } |
|
199 |
|
200 // end of file |