⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 webframeloaderclient.mm

📁 linux下开源浏览器WebKit的源码,市面上的很多商用浏览器都是移植自WebKit
💻 MM
📖 第 1 页 / 共 5 页
字号:
    WebBasePluginPackage *package = [getWebView(m_webFrame.get()) _pluginForMIMEType:type];    if (package) {#if ENABLE(NETSCAPE_PLUGIN_API)        if ([package isKindOfClass:[WebNetscapePluginPackage class]])            return ObjectContentNetscapePlugin;#endif        ASSERT([package isKindOfClass:[WebPluginPackage class]]);        return ObjectContentOtherPlugin;    }    if ([WebFrameView _viewClassForMIMEType:type])        return ObjectContentFrame;        return ObjectContentNone;    END_BLOCK_OBJC_EXCEPTIONS;    return ObjectContentNone;}static NSMutableArray* kit(const Vector<String>& vector){    unsigned len = vector.size();    NSMutableArray* array = [NSMutableArray arrayWithCapacity:len];    for (unsigned x = 0; x < len; x++)        [array addObject:vector[x]];    return array;}static String parameterValue(const Vector<String>& paramNames, const Vector<String>& paramValues, const String& name){    size_t size = paramNames.size();    ASSERT(size == paramValues.size());    for (size_t i = 0; i < size; ++i) {        if (equalIgnoringCase(paramNames[i], name))            return paramValues[i];    }    return String();}static NSView *pluginView(WebFrame *frame, WebPluginPackage *pluginPackage,    NSArray *attributeNames, NSArray *attributeValues, NSURL *baseURL,    DOMElement *element, BOOL loadManually){    WebHTMLView *docView = (WebHTMLView *)[[frame frameView] documentView];    ASSERT([docView isKindOfClass:[WebHTMLView class]]);            WebPluginController *pluginController = [docView _pluginController];        // Store attributes in a dictionary so they can be passed to WebPlugins.    NSMutableDictionary *attributes = [[NSMutableDictionary alloc] initWithObjects:attributeValues forKeys:attributeNames];        [pluginPackage load];    Class viewFactory = [pluginPackage viewFactory];        NSView *view = nil;    NSDictionary *arguments = nil;        if ([viewFactory respondsToSelector:@selector(plugInViewWithArguments:)]) {        arguments = [NSDictionary dictionaryWithObjectsAndKeys:            baseURL, WebPlugInBaseURLKey,            attributes, WebPlugInAttributesKey,            pluginController, WebPlugInContainerKey,            [NSNumber numberWithInt:loadManually ? WebPlugInModeFull : WebPlugInModeEmbed], WebPlugInModeKey,            [NSNumber numberWithBool:!loadManually], WebPlugInShouldLoadMainResourceKey,            element, WebPlugInContainingElementKey,            nil];        LOG(Plugins, "arguments:\n%@", arguments);    } else if ([viewFactory respondsToSelector:@selector(pluginViewWithArguments:)]) {        arguments = [NSDictionary dictionaryWithObjectsAndKeys:            baseURL, WebPluginBaseURLKey,            attributes, WebPluginAttributesKey,            pluginController, WebPluginContainerKey,            element, WebPlugInContainingElementKey,            nil];        LOG(Plugins, "arguments:\n%@", arguments);    }    view = [WebPluginController plugInViewWithArguments:arguments fromPluginPackage:pluginPackage];    [attributes release];    return view;}class PluginWidget : public Widget {public:    PluginWidget(NSView *view = 0)        : Widget(view)    {    }        virtual void invalidateRect(const IntRect& rect)    {        [platformWidget() setNeedsDisplayInRect:rect];    }};#if ENABLE(NETSCAPE_PLUGIN_API)class NetscapePluginWidget : public PluginWidget {public:    NetscapePluginWidget(WebBaseNetscapePluginView *view)        : PluginWidget(view)    {    }        virtual void handleEvent(Event*)    {        Frame* frame = Frame::frameForWidget(this);        if (!frame)            return;                NSEvent* event = frame->eventHandler()->currentNSEvent();        if ([event type] == NSMouseMoved)            [(WebBaseNetscapePluginView *)platformWidget() handleMouseMoved:event];    }    };#endif // ENABLE(NETSCAPE_PLUGIN_API)static Class netscapePluginViewClass(){#if USE(PLUGIN_HOST_PROCESS)    return [WebHostedNetscapePluginView class];#else    return [WebNetscapePluginView class];#endif}Widget* WebFrameLoaderClient::createPlugin(const IntSize& size, HTMLPlugInElement* element, const KURL& url,    const Vector<String>& paramNames, const Vector<String>& paramValues, const String& mimeType, bool loadManually){    BEGIN_BLOCK_OBJC_EXCEPTIONS;    ASSERT(paramNames.size() == paramValues.size());    int errorCode = 0;    WebView *webView = getWebView(m_webFrame.get());    SEL selector = @selector(webView:plugInViewWithArguments:);    NSURL *URL = url;    if ([[webView UIDelegate] respondsToSelector:selector]) {        NSMutableDictionary *attributes = [[NSMutableDictionary alloc] initWithObjects:kit(paramValues) forKeys:kit(paramNames)];        NSDictionary *arguments = [[NSDictionary alloc] initWithObjectsAndKeys:            attributes, WebPlugInAttributesKey,            [NSNumber numberWithInt:loadManually ? WebPlugInModeFull : WebPlugInModeEmbed], WebPlugInModeKey,            [NSNumber numberWithBool:!loadManually], WebPlugInShouldLoadMainResourceKey,            kit(element), WebPlugInContainingElementKey,            URL, WebPlugInBaseURLKey, // URL might be nil, so add it last            nil];        NSView *view = CallUIDelegate(webView, selector, arguments);        [attributes release];        [arguments release];        if (view)            return new PluginWidget(view);    }    NSString *MIMEType;    WebBasePluginPackage *pluginPackage;    if (mimeType.isEmpty()) {        MIMEType = nil;        pluginPackage = nil;    } else {        MIMEType = mimeType;        pluginPackage = [webView _pluginForMIMEType:mimeType];    }        NSString *extension = [[URL path] pathExtension];#if ENABLE(PLUGIN_PROXY_FOR_VIDEO)    // don't allow proxy plug-in selection by file extension    if (element->hasTagName(videoTag) || element->hasTagName(audioTag))        extension = @"";#endif    if (!pluginPackage && [extension length] != 0) {        pluginPackage = [webView _pluginForExtension:extension];        if (pluginPackage) {            NSString *newMIMEType = [pluginPackage MIMETypeForExtension:extension];            if ([newMIMEType length] != 0)                MIMEType = newMIMEType;        }    }    NSView *view = nil;    Document* document = core(m_webFrame.get())->document();    NSURL *baseURL = document->baseURL();    if (pluginPackage) {        if ([pluginPackage isKindOfClass:[WebPluginPackage class]])            view = pluginView(m_webFrame.get(), (WebPluginPackage *)pluginPackage, kit(paramNames), kit(paramValues), baseURL, kit(element), loadManually);            #if ENABLE(NETSCAPE_PLUGIN_API)        else if ([pluginPackage isKindOfClass:[WebNetscapePluginPackage class]]) {            WebBaseNetscapePluginView *pluginView = [[[netscapePluginViewClass() alloc]                initWithFrame:NSMakeRect(0, 0, size.width(), size.height())                pluginPackage:(WebNetscapePluginPackage *)pluginPackage                URL:URL                baseURL:baseURL                MIMEType:MIMEType                attributeKeys:kit(paramNames)                attributeValues:kit(paramValues)                loadManually:loadManually                element:element] autorelease];                        return new NetscapePluginWidget(pluginView);        } #endif    } else        errorCode = WebKitErrorCannotFindPlugIn;    if (!errorCode && !view)        errorCode = WebKitErrorCannotLoadPlugIn;    if (errorCode) {        NSError *error = [[NSError alloc] _initWithPluginErrorCode:errorCode            contentURL:URL            pluginPageURL:document->completeURL(parseURL(parameterValue(paramNames, paramValues, "pluginspage")))            pluginName:[pluginPackage name]            MIMEType:MIMEType];        WebNullPluginView *nullView = [[[WebNullPluginView alloc] initWithFrame:NSMakeRect(0, 0, size.width(), size.height())            error:error DOMElement:kit(element)] autorelease];        view = nullView;        [error release];    }        ASSERT(view);    return new PluginWidget(view);    END_BLOCK_OBJC_EXCEPTIONS;    return 0;}void WebFrameLoaderClient::redirectDataToPlugin(Widget* pluginWidget){    BEGIN_BLOCK_OBJC_EXCEPTIONS;    WebHTMLRepresentation *representation = (WebHTMLRepresentation *)[[m_webFrame.get() _dataSource] representation];    NSView *pluginView = pluginWidget->platformWidget();#if ENABLE(NETSCAPE_PLUGIN_API)    if ([pluginView isKindOfClass:[WebNetscapePluginView class]])        [representation _redirectDataToManualLoader:(WebNetscapePluginView *)pluginView forPluginView:pluginView];    else {#else    {#endif        WebHTMLView *documentView = (WebHTMLView *)[[m_webFrame.get() frameView] documentView];        ASSERT([documentView isKindOfClass:[WebHTMLView class]]);        [representation _redirectDataToManualLoader:[documentView _pluginController] forPluginView:pluginView];    }    END_BLOCK_OBJC_EXCEPTIONS;}    Widget* WebFrameLoaderClient::createJavaAppletWidget(const IntSize& size, HTMLAppletElement* element, const KURL& baseURL,     const Vector<String>& paramNames, const Vector<String>& paramValues){    BEGIN_BLOCK_OBJC_EXCEPTIONS;    NSView *view = nil;    NSString *MIMEType = @"application/x-java-applet";        WebView *webView = getWebView(m_webFrame.get());    WebBasePluginPackage *pluginPackage = [webView _pluginForMIMEType:MIMEType];    if (pluginPackage) {        if ([pluginPackage isKindOfClass:[WebPluginPackage class]]) {            // For some reason, the Java plug-in requires that we pass the dimension of the plug-in as attributes.            NSMutableArray *names = kit(paramNames);            NSMutableArray *values = kit(paramValues);            if (parameterValue(paramNames, paramValues, "width").isNull()) {                [names addObject:@"width"];                [values addObject:[NSString stringWithFormat:@"%d", size.width()]];            }            if (parameterValue(paramNames, paramValues, "height").isNull()) {                [names addObject:@"height"];                [values addObject:[NSString stringWithFormat:@"%d", size.height()]];            }            view = pluginView(m_webFrame.get(), (WebPluginPackage *)pluginPackage, names, values, baseURL, kit(element), NO);        } #if ENABLE(NETSCAPE_PLUGIN_API)        else if ([pluginPackage isKindOfClass:[WebNetscapePluginPackage class]]) {            view = [[[netscapePluginViewClass() alloc] initWithFrame:NSMakeRect(0, 0, size.width(), size.height())                pluginPackage:(WebNetscapePluginPackage *)pluginPackage                URL:nil                baseURL:baseURL                MIMEType:MIMEType                attributeKeys:kit(paramNames)                attributeValues:kit(paramValues)                loadManually:NO                element:element] autorelease];        } else {            ASSERT_NOT_REACHED();        }#endif    }    if (!view) {        NSError *error = [[NSError alloc] _initWithPluginErrorCode:WebKitErrorJavaUnavailable            contentURL:nil    

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -