define(["Ti/_/declare","Ti/_/UI/Widget","Ti/_/dom","Ti/_/event","Ti/_/lang","Ti/_/text!Ti/_/UI/WebViewBridge.js","Ti/App","Ti/API","Ti/UI","Ti/_/style"],function(t,i,e,r,o,n,s,a,h,l){var d=require.on;return t("Ti.UI.WebView",i,{constructor:function(){s.addEventListener(this.widgetId+":unload",o.hitch(this,function(){this._loading(1)})),this.backgroundColor="#fff",l.set(this.domNode,{overflow:"auto",overflowScrolling:"touch"})},destroy:function(){s.removeEventListener(this.widgetId+":unload"),this._destroy(),i.prototype.destroy.apply(this,arguments)},_destroy:function(){this._iframe&&(r.off(this._iframeHandles),e.destroy(this._iframe))},_createIFrame:function(){if(this._parent){this._destroy(),this._loading(1);var t=this.url||"",i=t.match(/(https?)\:\/\/([^\:\/]*)(:?\d*)(.*)/),r=window.location,o=!i||i[0]+":"===r.protocol&&i[1]+i[2]===window.location.host,s=this._iframe=e.create("iframe",{frameborder:0,marginwidth:0,marginheight:0,hspace:0,vspace:0,scrolling:this.showScrollbars?"auto":"no",src:t||require.toUrl("Ti/_/UI/blank.html"),style:{width:"100%",height:"100%",position:"absolute"}},this.domNode);return this._iframeHandles=[d(s,"load",this,function(){var t,i,e,r=Math.max(0|o,0),h=s.contentWindow;if(-1!==r)o=-1;else for(t in h){r++;break}r>0?(i=h.location.href,this.evalJS(n.replace("WEBVIEW_ID",this.widgetId+":unload")),(e=this.__values__.properties.html)&&this._setContent(e)):a.warn("Unable to inject WebView bridge into cross-domain URL, ignore browser security message"),this._loading(),this.fireEvent("load",{url:i?this.__values__.properties.url=i:this.url})}),d(s,"error",this,function(){this._loading(),this.fireEvent("error",{message:"Page failed to load",url:this.url})})],1}},_setParent:function(){i.prototype._setParent.apply(this,arguments),(this.url||this.html)&&this._createIFrame()},_getWindow:function(){return this._iframe.contentWindow},_getDoc:function(){return this._getWindow().document},_getHistory:function(){return this._getWindow().history},_loading:function(t){this.loading||t&&this.fireEvent("beforeload",{url:this.url}),this.__values__.constants.loading=!!t},canGoBack:function(){return this.url&&!!this._getHistory().length},canGoForward:function(){return this.url&&!!this._getHistory().length},evalJS:function(t){var i=this._getWindow(),e=null;try{e=t&&i&&i.eval&&i.eval(t)}catch(r){}return e},goBack:function(){if(this.canGoBack()){var t=this._getHistory();t&&(this._loading(1),t.go(-1))}},goForward:function(){if(this.canGoForward()){var t=this._getHistory();t&&(this._loading(1),t.go(1))}},reload:function(){var t=this._getWindow();this.url&&t?t.location.href=this.url:this._createIFrame()},stopLoading:function(t){try{this.loading&&t?this._destroy():this._getWindow().stop()}catch(i){}this._loading()},_defaultWidth:h.FILL,_defaultHeight:h.FILL,_getContentSize:function(){return{width:this._iframe?this._iframe.clientWidth:0,height:this._iframe?this._iframe.clientHeight:0}},_setContent:function(t){try{var i=this._getDoc();i.open(),i.write(t),i.close()}catch(e){}return t},properties:{data:{set:function(t){var i=t;switch(i&&i.declaredClass){case"Ti.Filesystem.File":i=i.read();case"Ti.Blob":i=i.toString();default:this.html=i}return t}},html:{get:function(t){var i=this._iframe&&this._getDoc();return void 0===t&&i?i.documentElement.innerHTML:t},post:function(t){var i=this.__values__.properties;i.data=void 0,i.url=void 0,this._createIFrame()&&this._setContent(t)}},showScrollbars:{set:function(t){return this._iframe&&e.attr.set(this._iframe,"scrolling",t?"auto":"no"),t},value:!0},url:{post:function(){var t=this.__values__.properties;t.data=void 0,t.html=void 0,this._createIFrame()}}},constants:{loading:!1}})});