1/* 2 * Copyright (C) 2013 Apple Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 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. 12 * 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' 14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS 17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 23 * THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26#import "config.h" 27#import "WKWebProcessPlugInNodeHandleInternal.h" 28 29#import "WKWebProcessPlugInFrameInternal.h" 30#import <WebCore/IntRect.h> 31 32#if WK_API_ENABLED 33 34using namespace WebKit; 35 36@implementation WKWebProcessPlugInNodeHandle { 37 API::ObjectStorage<InjectedBundleNodeHandle> _nodeHandle; 38} 39 40- (void)dealloc 41{ 42 _nodeHandle->~InjectedBundleNodeHandle(); 43 [super dealloc]; 44} 45 46+ (WKWebProcessPlugInNodeHandle *)nodeHandleWithJSValue:(JSValue *)value inContext:(JSContext *)context 47{ 48 JSContextRef contextRef = [context JSGlobalContextRef]; 49 JSObjectRef objectRef = JSValueToObject(contextRef, [value JSValueRef], 0); 50 RefPtr<InjectedBundleNodeHandle> nodeHandle = InjectedBundleNodeHandle::getOrCreate(contextRef, objectRef); 51 if (!nodeHandle) 52 return nil; 53 54 return [wrapper(*nodeHandle.release().leakRef()) autorelease]; 55} 56 57- (WKWebProcessPlugInFrame *)htmlIFrameElementContentFrame 58{ 59 RefPtr<WebFrame> frame = _nodeHandle->htmlIFrameElementContentFrame(); 60 if (!frame) 61 return nil; 62 63 return [wrapper(*frame.release().leakRef()) autorelease]; 64} 65 66- (CGRect)elementBounds 67{ 68 return _nodeHandle->elementBounds(); 69} 70 71- (BOOL)HTMLInputElementIsAutoFilled 72{ 73 return _nodeHandle->isHTMLInputElementAutofilled(); 74} 75 76- (void)setHTMLInputElementIsAutoFilled:(BOOL)isAutoFilled 77{ 78 _nodeHandle->setHTMLInputElementAutofilled(isAutoFilled); 79} 80 81- (BOOL)HTMLInputElementIsUserEdited 82{ 83 return _nodeHandle->htmlInputElementLastChangeWasUserEdit(); 84} 85 86- (BOOL)HTMLTextAreaElementIsUserEdited 87{ 88 return _nodeHandle->htmlTextAreaElementLastChangeWasUserEdit(); 89} 90 91- (BOOL)isTextField 92{ 93 return _nodeHandle->isTextField(); 94} 95 96- (WKWebProcessPlugInNodeHandle *)HTMLTableCellElementCellAbove 97{ 98 auto nodeHandle = _nodeHandle->htmlTableCellElementCellAbove(); 99 if (!nodeHandle) 100 return nil; 101 102 return [wrapper(*nodeHandle.leakRef()) autorelease]; 103} 104 105- (InjectedBundleNodeHandle&)_nodeHandle 106{ 107 return *_nodeHandle; 108} 109 110#pragma mark WKObject protocol implementation 111 112- (API::Object&)_apiObject 113{ 114 return *_nodeHandle; 115} 116 117@end 118 119#endif // WK_API_ENABLED 120