Class: Selenium::WebDriver::Safari::Extensions Private

Inherits:
Object
  • Object
show all
Defined in:
rb/lib/selenium/webdriver/safari/extensions.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Defined Under Namespace

Classes: Backup

Constant Summary

PLIST =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

<<-XML
  <?xml version="1.0" encoding="UTF-8"?>
  <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
  <plist version="1.0">
  <dict>
    <key>Available Updates</key>
    <dict>
      <key>Last Update Check Time</key>
      <real>370125644.75941497</real>
      <key>Updates List</key>
      <array/>
    </dict>
    <key>Installed Extensions</key>
    <array>
      %s
    </array>
    <key>Version</key>
    <integer>1</integer>
  </dict>
  </plist>
XML
PLIST_EXTENSION_LINE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

<<-XML
  <dict>
    <key>Added Non-Default Toolbar Items</key>
    <array/>
    <key>Archive File Name</key>
    <string>%s.safariextz</string>
    <key>Bundle Directory Name</key>
    <string>%s.safariextension</string>
    <key>Enabled</key>
    <true/>
    <key>Hidden Bars</key>
    <array/>
    <key>Removed Default Toolbar Items</key>
    <array/>
  </dict>
XML

Instance Method Summary (collapse)

Constructor Details

- (Extensions) initialize(opts = {})

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Extensions



49
50
51
52
53
54
55
# File 'rb/lib/selenium/webdriver/safari/extensions.rb', line 49

def initialize(opts = {})
  @data_dir   = opts.data_dir || safari_data_dir
  @skip       = opts.skip_extension_installation?
  @extensions = opts.extensions
  @backup     = Backup.new
  @installed  = false
end

Instance Method Details

- (Object) extension_destination

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



111
112
113
# File 'rb/lib/selenium/webdriver/safari/extensions.rb', line 111

def extension_destination
  install_directory.join('WebDriver.safariextz')
end

- (Object) extension_source

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



107
108
109
# File 'rb/lib/selenium/webdriver/safari/extensions.rb', line 107

def extension_source
  Safari.resource_path.join('SafariDriver.safariextz')
end

- (Object) install

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'rb/lib/selenium/webdriver/safari/extensions.rb', line 57

def install
  return if @installed
  installed_extensions = []

  if install_directory.exist?
    @backup.backup install_directory
  end

  install_directory.mkpath

  unless @skip
    extension_destination.rmtree if extension_destination.exist?
    FileUtils.cp extension_source.to_s, extension_destination.to_s

    installed_extensions << extension_destination
  end

  @extensions.each do |extension|
    target = install_directory.join(extension.basename)

    if extension.expand_path == target.expand_path
      @backup.backup(target)
    else
      FileUtils.cp extension, target
    end

    installed_extensions << target
  end

  plist_destination.open('w') do |io|
    extension_lines = installed_extensions.map do |ext|
      name = ext.basename('.safariextz').to_s
      PLIST_EXTENSION_LINE % [name, name]
    end
    io << PLIST % extension_lines.join("\n")
  end

  Platform.exit_hook { uninstall }
  @installed = true
end

- (Object) install_directory

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



119
120
121
122
123
124
125
126
127
128
129
# File 'rb/lib/selenium/webdriver/safari/extensions.rb', line 119

def install_directory
  @install_directory ||= (
    data_dir = Pathname.new(@data_dir || safari_data_dir)

    unless data_dir.exist? && data_dir.directory?
      raise Errno::ENOENT, "Safari data directory not found at #{data_dir.to_s}"
    end

    data_dir.join('Extensions')
  )
end

- (Object) plist_destination

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



115
116
117
# File 'rb/lib/selenium/webdriver/safari/extensions.rb', line 115

def plist_destination
  install_directory.join('Extensions.plist')
end

- (Object) safari_data_dir

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



131
132
133
134
135
136
137
138
139
140
141
142
# File 'rb/lib/selenium/webdriver/safari/extensions.rb', line 131

def safari_data_dir
  current = Platform.os

  case current
  when :macosx
    Pathname.new(Platform.home).join('Library/Safari')
  when :windows
    Pathname.new(ENV['APPDATA']).join('Apple Computer/Safari')
  else
    raise Error::WebDriverError, "unsupported platform: #{current}"
  end
end

- (Object) uninstall

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



98
99
100
101
102
103
104
105
# File 'rb/lib/selenium/webdriver/safari/extensions.rb', line 98

def uninstall
  return unless @installed

  install_directory.rmtree if install_directory.exist?
  @backup.restore_all
ensure
  @installed = false
end