Class: Selenium::WebDriver::Firefox::Extension Private
Do not use. This class is for internal use only.
Relationships & Source Files | |
Inherits: | Object |
Defined in: | rb/lib/selenium/webdriver/firefox/extension.rb |
Constant Summary
-
NAMESPACE =
# File 'rb/lib/selenium/webdriver/firefox/extension.rb', line 28'http://www.mozilla.org/2004/em-rdf#'
Class Method Summary
- .new(path) ⇒ Extension constructor Internal use only
Instance Method Summary
- #write_to(extensions_dir) Internal use only
- #applications_gecko_id(manifest) private Internal use only
- #create_root private Internal use only
- #name_and_version(manifest) private Internal use only
- #read_id(directory) private Internal use only
- #read_id_from_install_rdf(directory) private Internal use only
- #read_id_from_manifest_json(directory) private Internal use only
Constructor Details
.new(path) ⇒ Extension
Instance Method Details
#applications_gecko_id(manifest) (private)
[ GitHub ]# File 'rb/lib/selenium/webdriver/firefox/extension.rb', line 93
def applications_gecko_id(manifest) manifest.dig('applications', 'gecko', 'id')&.strip end
#create_root (private)
[ GitHub ]# File 'rb/lib/selenium/webdriver/firefox/extension.rb', line 50
def create_root if File.directory? @path @path else unless Zipper::EXTENSIONS.include? File.extname(@path) raise Error::WebDriverError, "expected #{Zipper::EXTENSIONS.join(' or ')}, got #{@path.inspect}" end @should_reap_root = true Zipper.unzip(@path) end end
#name_and_version(manifest) (private)
[ GitHub ]# File 'rb/lib/selenium/webdriver/firefox/extension.rb', line 97
def name_and_version(manifest) [manifest['name'].delete(' '), manifest['version']].join('@') end
#read_id(directory) (private)
[ GitHub ]# File 'rb/lib/selenium/webdriver/firefox/extension.rb', line 63
def read_id(directory) read_id_from_install_rdf(directory) || read_id_from_manifest_json(directory) end
#read_id_from_install_rdf(directory) (private)
# File 'rb/lib/selenium/webdriver/firefox/extension.rb', line 67
def read_id_from_install_rdf(directory) rdf_path = File.join(directory, 'install.rdf') return unless File.exist?(rdf_path) doc = REXML::Document.new(File.read(rdf_path)) namespace = doc.root.namespaces.key(NAMESPACE) if namespace id_node = REXML::XPath.first(doc, "//#{namespace}:id") return id_node.text if id_node attr_node = REXML::XPath.first(doc, "//@#{namespace}:id") return attr_node.value if attr_node end raise Error::WebDriverError, "cannot locate extension id in #{rdf_path}" end
#read_id_from_manifest_json(directory) (private)
[ GitHub ]# File 'rb/lib/selenium/webdriver/firefox/extension.rb', line 85
def read_id_from_manifest_json(directory) manifest_path = File.join(directory, 'manifest.json') return unless File.exist?(manifest_path) manifest = JSON.parse(File.read(manifest_path)) applications_gecko_id(manifest) || name_and_version(manifest) end
#write_to(extensions_dir)
[ GitHub ]# File 'rb/lib/selenium/webdriver/firefox/extension.rb', line 37
def write_to(extensions_dir) root_dir = create_root ext_path = File.join extensions_dir, read_id(root_dir) FileUtils.rm_rf ext_path FileUtils.mkdir_p File.dirname(ext_path), mode: 0o700 FileUtils.cp_r root_dir, ext_path FileReaper.reap(root_dir) if @should_reap_root end