<commit_before>{
  namespace,
  locale,
  utils,
  jQuery: $
} = uploadcare

namespace 'uploadcare.widget.tabs', (ns) ->
  ns.RemoteTabFor = (service) ->
    class RemoteTab extends ns.BaseFileTab

      setContent: (@content) ->

        @dialog.progress (tab) =>
          if tab == service
            @createIframe()

        @dialog.fail =>
          @cleanup()


      createIframe: ->
        unless @iframe
          @windowId = utils.uuid()
          @createWatcher()

          src =
            "#{@settings.socialBase}/window/#{@windowId}/" +
            "#{service}?lang=#{locale.lang}&public_key=#{@settings.publicKey}" +
            "&widget_version=#{encodeURIComponent(uploadcare.version)}"
          @iframe = $('<iframe>')
            .attr('src', src)
            .css
              width: '100%'
              height: '100%'
              border: 0
              visibility: 'hidden'
            .appendTo(@content)
            .on 'load', -> $(this).css 'visibility', 'visible'


      createWatcher: ->
        unless @watcher
          @watcher = new utils.pubsub.PubSub @settings, 'window', @windowId
          $(@watcher).on('done', (e, state) =>
            @cleanup()
            @onSelected.fire 'url', state.url
          )
          @watcher.watch()

      cleanup: ->
        @watcher?.stop()
        @watcher = null
        @iframe?.remove()
        @iframe = null<commit_msg>Talk to social_source using postMessage<commit_after>{
  namespace,
  locale,
  utils,
  jQuery: $
} = uploadcare

namespace 'uploadcare.widget.tabs', (ns) ->
  ns.RemoteTabFor = (service) ->
    class RemoteTab extends ns.BaseFileTab

      setContent: (@content) ->

        @dialog.progress (tab) =>
          if tab == service
            @createIframe()

        $(window).on "message", ({originalEvent: e}) =>
          goodOrigin = e.origin is @settings.socialBase
          goodSource = e.source is @iframe?[0]?.contentWindow
          if goodOrigin and goodSource
            message = JSON.parse e.data
            if message.type is 'file-selected'
              @onSelected.fire 'url', message.url

      createIframe: ->
        unless @iframe
          src = "#{@settings.socialBase}/window/#{service}?" + $.param
            lang: @settings.locale
            public_key: @settings.publicKey
            widget_version: uploadcare.version
          @iframe = $('<iframe>')
            .attr('src', src)
            .css
              width: '100%'
              height: '100%'
              border: 0
              visibility: 'hidden'
            .appendTo(@content)
            .on 'load', -> $(this).css 'visibility', 'visible'
{'fraction_non_alphanumeric': 0.14054257724189903, 'fraction_numerical': 0.005651846269781462, 'mean_word_length': 1.7570093457943925, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5107331', 'n_tokens_mistral': 774, 'n_tokens_neox': 743, 'n_words': 161}