Class: Google::Chrome::ExtensionPorts

Inherits:
Object
  • Object
show all
Defined in:
lib/google/chrome/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(client, id) ⇒ ExtensionPorts

Returns a new instance of ExtensionPorts.



152
153
154
155
# File 'lib/google/chrome/client.rb', line 152

def initialize(client, id)
  @client = client
  @id = id
end

Instance Method Details

#connectObject



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/google/chrome/client.rb', line 157

def connect
  h, r = @client.request({ 'Tool' => 'ExtensionPorts' },
                         { 'command' => 'connect',
                           'data' => { 'extensionId' => @id } })
  port = r['data']['portId'].to_i

  if block_given?
    begin
      yield(port)
    ensure
      disconnect(port)
    end
  else
    return port
  end
end

#disconnect(port) ⇒ Object



174
175
176
177
# File 'lib/google/chrome/client.rb', line 174

def disconnect(port)
  @client.request({ 'Tool' => 'ExtensionPorts', 'Destination' => port },
                  { 'command' => 'disconnect' })
end

#post(port, data) ⇒ Object



179
180
181
182
183
# File 'lib/google/chrome/client.rb', line 179

def post(port, data)
  @client.request({ 'Tool' => 'ExtensionPorts', 'Destination' => port },
                  { 'command' => 'postMessage',
                    'data' => data })
end