BrowserExtensionMac.mm 6.1 KB
Newer Older
mjs's avatar
mjs committed
1
/*
darin's avatar
darin committed
2
 * Copyright (C) 2003, 2004, 2005, 2006 Apple Computer, Inc.  All rights reserved.
mjs's avatar
mjs committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
 */

justing's avatar
justing committed
26
#import "config.h"
27
#import "BrowserExtensionMac.h"
mjs's avatar
mjs committed
28

darin's avatar
darin committed
29
#import "BlockExceptions.h"
ggaren's avatar
ggaren committed
30
#import "FloatRect.h"
darin's avatar
darin committed
31
#import "FrameMac.h"
ggaren's avatar
ggaren committed
32 33 34
#import "FrameTree.h"
#import "Page.h"
#import "Screen.h"
darin's avatar
darin committed
35
#import "WebCoreFrameBridge.h"
darin's avatar
darin committed
36
#import "WebCorePageBridge.h"
mjs's avatar
mjs committed
37

darin's avatar
darin committed
38
namespace WebCore {
39 40

BrowserExtensionMac::BrowserExtensionMac(Frame *frame)
41
    : m_frame(Mac(frame))
mjs's avatar
mjs committed
42 43 44
{
}

mjs's avatar
mjs committed
45
void BrowserExtensionMac::createNewWindow(const ResourceRequest& request) 
darin's avatar
darin committed
46
{
mjs's avatar
mjs committed
47
    createNewWindow(request, WindowArgs(), NULL);
darin's avatar
darin committed
48 49
}

mjs's avatar
mjs committed
50
void BrowserExtensionMac::createNewWindow(const ResourceRequest& request, 
mjs's avatar
mjs committed
51 52
                                          const WindowArgs& winArgs, 
                                          Frame*& part)
mjs's avatar
mjs committed
53
{
mjs's avatar
mjs committed
54
    createNewWindow(request, winArgs, &part);
mjs's avatar
mjs committed
55 56
}

mjs's avatar
mjs committed
57
void BrowserExtensionMac::createNewWindow(const ResourceRequest& request, 
mjs's avatar
mjs committed
58 59
                                          const WindowArgs& winArgs, 
                                          Frame** partResult)
mjs's avatar
mjs committed
60
{ 
darin's avatar
darin committed
61
    BEGIN_BLOCK_OBJC_EXCEPTIONS;
mjs's avatar
mjs committed
62

mjs's avatar
mjs committed
63
    ASSERT(!winArgs.dialog || request.frameName.isEmpty());
darin's avatar
darin committed
64 65

    if (partResult)
darin's avatar
darin committed
66
        *partResult = NULL;
mjs's avatar
mjs committed
67 68
    
    const KURL& url = request.url();
mjs's avatar
mjs committed
69

70
    NSString *frameName = request.frameName.isEmpty() ? nil : (NSString*)request.frameName;
ggaren's avatar
ggaren committed
71
    if (frameName) {
darin's avatar
darin committed
72
        // FIXME: Can't we just use m_frame->findFrame?
ggaren's avatar
ggaren committed
73
        if (WebCoreFrameBridge *frameBridge = [m_frame->bridge() findFrameNamed:frameName]) {
ggaren's avatar
ggaren committed
74
            if (!url.isEmpty()) {
darin's avatar
darin committed
75
                String argsReferrer = request.referrer();
ggaren's avatar
ggaren committed
76
                NSString *referrer;
darin's avatar
darin committed
77 78
                if (!argsReferrer.isEmpty())
                    referrer = argsReferrer;
ggaren's avatar
ggaren committed
79
                else
ggaren's avatar
ggaren committed
80
                    referrer = [frameBridge referrer];
ggaren's avatar
ggaren committed
81

ggaren's avatar
ggaren committed
82
                [frameBridge loadURL:url.getNSURL() 
ggaren's avatar
ggaren committed
83
                       referrer:referrer 
mjs's avatar
mjs committed
84
                         reload:request.reload 
ggaren's avatar
ggaren committed
85 86 87 88 89 90 91
                    userGesture:true 
                         target:nil 
                triggeringEvent:nil 
                           form:nil 
                     formValues:nil];
            }

ggaren's avatar
ggaren committed
92
            [frameBridge focusWindow];
ggaren's avatar
ggaren committed
93 94

            if (partResult)
ggaren's avatar
ggaren committed
95
                *partResult = [frameBridge impl];
ggaren's avatar
ggaren committed
96 97 98

            return;
        }
mjs's avatar
mjs committed
99
    }
mjs's avatar
mjs committed
100
    
ggaren's avatar
ggaren committed
101
    WebCorePageBridge *pageBridge;
darin's avatar
darin committed
102
    if (winArgs.dialog)
ggaren's avatar
ggaren committed
103
        pageBridge = [m_frame->bridge() createModalDialogWithURL:url.getNSURL()];
darin's avatar
darin committed
104
    else
ggaren's avatar
ggaren committed
105 106
        pageBridge = [m_frame->bridge() createWindowWithURL:url.getNSURL()];
    if (!pageBridge)
darin's avatar
darin committed
107
        return;
mjs's avatar
mjs committed
108
    
ggaren's avatar
ggaren committed
109 110 111
    WebCoreFrameBridge *frameBridge = [pageBridge mainFrame];
    if ([frameBridge impl])
        [frameBridge impl]->tree()->setName(AtomicString(request.frameName));
mjs's avatar
mjs committed
112
    
ggaren's avatar
ggaren committed
113
    if (partResult)
ggaren's avatar
ggaren committed
114
        *partResult = [frameBridge impl];
mjs's avatar
mjs committed
115
    
ggaren's avatar
ggaren committed
116 117 118 119
    [frameBridge setToolbarsVisible:winArgs.toolBarVisible || winArgs.locationBarVisible];
    [frameBridge setStatusbarVisible:winArgs.statusBarVisible];
    [frameBridge setScrollbarsVisible:winArgs.scrollBarsVisible];
    [frameBridge setWindowIsResizable:winArgs.resizable];
mjs's avatar
mjs committed
120
    
ggaren's avatar
ggaren committed
121
    NSRect windowRect = [pageBridge impl]->windowRect();
ggaren's avatar
ggaren committed
122
    if (winArgs.xSet)
ggaren's avatar
ggaren committed
123 124 125 126
      windowRect.origin.x = winArgs.x;
    if (winArgs.ySet)
      windowRect.origin.y = winArgs.y;
    
ggaren's avatar
ggaren committed
127
    // 'width' and 'height' specify the dimensions of the WebView, but we can only resize the window, 
ggaren's avatar
ggaren committed
128 129 130 131 132 133
    // so we compute a WebView delta and apply it to the window.
    NSRect webViewRect = [[pageBridge outerView] frame];
    if (winArgs.widthSet)
      windowRect.size.width += winArgs.width - webViewRect.size.width;
    if (winArgs.heightSet)
      windowRect.size.height += winArgs.height - webViewRect.size.height;
mjs's avatar
mjs committed
134
    
ggaren's avatar
ggaren committed
135
    [pageBridge impl]->setWindowRect(windowRect);
ggaren's avatar
ggaren committed
136
    
ggaren's avatar
ggaren committed
137
    [frameBridge showWindow];
darin's avatar
darin committed
138
    
darin's avatar
darin committed
139
    END_BLOCK_OBJC_EXCEPTIONS;
mjs's avatar
mjs committed
140
}
mjs's avatar
mjs committed
141

142
void BrowserExtensionMac::setIconURL(const KURL &url)
mjs's avatar
mjs committed
143
{
darin's avatar
darin committed
144
    BEGIN_BLOCK_OBJC_EXCEPTIONS;
mjs's avatar
mjs committed
145
    [m_frame->bridge() setIconURL:url.getNSURL()];
darin's avatar
darin committed
146
    END_BLOCK_OBJC_EXCEPTIONS;
mjs's avatar
mjs committed
147 148
}

149
void BrowserExtensionMac::setTypedIconURL(const KURL &url, const String &type)
mjs's avatar
mjs committed
150
{
darin's avatar
darin committed
151
    BEGIN_BLOCK_OBJC_EXCEPTIONS;
152
    [m_frame->bridge() setIconURL:url.getNSURL() withType:type];
darin's avatar
darin committed
153
    END_BLOCK_OBJC_EXCEPTIONS;
mjs's avatar
mjs committed
154
}
darin's avatar
darin committed
155

156
int BrowserExtensionMac::getHistoryLength()
157 158 159 160
{
    return [m_frame->bridge() historyLength];
}

161
void BrowserExtensionMac::goBackOrForward(int distance)
162
{
darin's avatar
darin committed
163
    BEGIN_BLOCK_OBJC_EXCEPTIONS;
164
    [m_frame->bridge() goBackOrForward:distance];
darin's avatar
darin committed
165
    END_BLOCK_OBJC_EXCEPTIONS;
166 167
}

168
bool BrowserExtensionMac::canRunModal()
darin's avatar
darin committed
169
{
darin's avatar
darin committed
170
    BEGIN_BLOCK_OBJC_EXCEPTIONS;
mjs's avatar
mjs committed
171
    return [m_frame->bridge() canRunModal];
darin's avatar
darin committed
172
    END_BLOCK_OBJC_EXCEPTIONS;
darin's avatar
darin committed
173 174 175
    return false;
}

176
bool BrowserExtensionMac::canRunModalNow()
darin's avatar
darin committed
177
{
darin's avatar
darin committed
178
    BEGIN_BLOCK_OBJC_EXCEPTIONS;
mjs's avatar
mjs committed
179
    return [m_frame->bridge() canRunModalNow];
darin's avatar
darin committed
180
    END_BLOCK_OBJC_EXCEPTIONS;
darin's avatar
darin committed
181 182 183
    return false;
}

184
void BrowserExtensionMac::runModal()
darin's avatar
darin committed
185
{
darin's avatar
darin committed
186
    BEGIN_BLOCK_OBJC_EXCEPTIONS;
mjs's avatar
mjs committed
187
    [m_frame->bridge() runModal];
darin's avatar
darin committed
188
    END_BLOCK_OBJC_EXCEPTIONS;
darin's avatar
darin committed
189
}
darin's avatar
darin committed
190 191

}