2 * Copyright (C) 2003, 2004, 2005, 2006 Apple Computer, Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #import "BrowserExtensionMac.h"
29 #import "BlockExceptions.h"
35 #import "WebCoreFrameBridge.h"
36 #import "WebCorePageBridge.h"
40 BrowserExtensionMac::BrowserExtensionMac(Frame *frame)
45 void BrowserExtensionMac::createNewWindow(const ResourceRequest& request)
47 createNewWindow(request, WindowArgs(), NULL);
50 void BrowserExtensionMac::createNewWindow(const ResourceRequest& request,
51 const WindowArgs& winArgs,
54 createNewWindow(request, winArgs, &part);
57 void BrowserExtensionMac::createNewWindow(const ResourceRequest& request,
58 const WindowArgs& winArgs,
61 BEGIN_BLOCK_OBJC_EXCEPTIONS;
63 ASSERT(!winArgs.dialog || request.frameName.isEmpty());
68 const KURL& url = request.url();
70 NSString *frameName = request.frameName.isEmpty() ? nil : (NSString*)request.frameName;
72 // FIXME: Can't we just use m_frame->findFrame?
73 if (WebCoreFrameBridge *frameBridge = [m_frame->bridge() findFrameNamed:frameName]) {
75 String argsReferrer = request.referrer();
77 if (!argsReferrer.isEmpty())
78 referrer = argsReferrer;
80 referrer = [frameBridge referrer];
82 [frameBridge loadURL:url.getNSURL()
92 [frameBridge activateWindow];
95 *partResult = [frameBridge impl];
101 WebCorePageBridge *pageBridge;
103 pageBridge = [m_frame->bridge() createModalDialogWithURL:url.getNSURL()];
105 pageBridge = [m_frame->bridge() createWindowWithURL:url.getNSURL()];
109 WebCoreFrameBridge *frameBridge = [pageBridge mainFrame];
110 if ([frameBridge impl])
111 [frameBridge impl]->tree()->setName(AtomicString(request.frameName));
114 *partResult = [frameBridge impl];
116 [frameBridge setToolbarsVisible:winArgs.toolBarVisible || winArgs.locationBarVisible];
117 [frameBridge setStatusbarVisible:winArgs.statusBarVisible];
118 [frameBridge setScrollbarsVisible:winArgs.scrollbarsVisible];
119 [frameBridge setWindowIsResizable:winArgs.resizable];
121 NSRect windowRect = [pageBridge impl]->windowRect();
123 windowRect.origin.x = winArgs.x;
125 windowRect.origin.y = winArgs.y;
127 // 'width' and 'height' specify the dimensions of the WebView, but we can only resize the window,
128 // so we compute a WebView delta and apply it to the window.
129 NSRect webViewRect = [[pageBridge outerView] frame];
130 if (winArgs.widthSet)
131 windowRect.size.width += winArgs.width - webViewRect.size.width;
132 if (winArgs.heightSet)
133 windowRect.size.height += winArgs.height - webViewRect.size.height;
135 [pageBridge impl]->setWindowRect(windowRect);
137 [frameBridge showWindow];
139 END_BLOCK_OBJC_EXCEPTIONS;
142 int BrowserExtensionMac::getHistoryLength()
144 return [m_frame->bridge() historyLength];
147 void BrowserExtensionMac::goBackOrForward(int distance)
149 BEGIN_BLOCK_OBJC_EXCEPTIONS;
150 [m_frame->bridge() goBackOrForward:distance];
151 END_BLOCK_OBJC_EXCEPTIONS;
154 KURL BrowserExtensionMac::historyURL(int distance)
156 BEGIN_BLOCK_OBJC_EXCEPTIONS;
157 return KURL([m_frame->bridge() historyURL:distance]);
158 END_BLOCK_OBJC_EXCEPTIONS;
162 bool BrowserExtensionMac::canRunModal()
164 BEGIN_BLOCK_OBJC_EXCEPTIONS;
165 return [m_frame->bridge() canRunModal];
166 END_BLOCK_OBJC_EXCEPTIONS;
170 bool BrowserExtensionMac::canRunModalNow()
172 BEGIN_BLOCK_OBJC_EXCEPTIONS;
173 return [m_frame->bridge() canRunModalNow];
174 END_BLOCK_OBJC_EXCEPTIONS;
178 void BrowserExtensionMac::runModal()
180 BEGIN_BLOCK_OBJC_EXCEPTIONS;
181 [m_frame->bridge() runModal];
182 END_BLOCK_OBJC_EXCEPTIONS;