Path: blob/trunk/rb/lib/selenium/webdriver/firefox/profiles_ini.rb
1865 views
# frozen_string_literal: true12# Licensed to the Software Freedom Conservancy (SFC) under one3# or more contributor license agreements. See the NOTICE file4# distributed with this work for additional information5# regarding copyright ownership. The SFC licenses this file6# to you under the Apache License, Version 2.0 (the7# "License"); you may not use this file except in compliance8# with the License. You may obtain a copy of the License at9#10# http://www.apache.org/licenses/LICENSE-2.011#12# Unless required by applicable law or agreed to in writing,13# software distributed under the License is distributed on an14# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY15# KIND, either express or implied. See the License for the16# specific language governing permissions and limitations17# under the License.1819module Selenium20module WebDriver21module Firefox22# @api private23class ProfilesIni24def initialize25@ini_path = File.join(Util.app_data_path, 'profiles.ini')26@profile_paths = {}2728parse if File.exist?(@ini_path)29end3031def [](name)32path = @profile_paths[name]33path && Profile.new(path)34end3536def refresh37@profile_paths.clear38parse39end4041private4243def parse44string = File.read @ini_path45name = nil46is_relative = nil47path = nil4849string.split("\n").each do |line|50case line51when /^\[Profile/52name, path = nil if path_for(name, is_relative, path)53when /^Name=(.+)$/54name = Regexp.last_match(1)&.strip55when /^IsRelative=(.+)$/56is_relative = Regexp.last_match(1).strip == '1'57when /^Path=(.+)$/58path = Regexp.last_match(1).strip59p = path_for(name, is_relative, path)60@profile_paths[name] = p if p61end62end63end6465def path_for(name, is_relative, path)66return unless [name, path].any?6768is_relative ? File.join(Util.app_data_path, path) : path69end70end # ProfilesIni71end # Firefox72end # WebDriver73end # Selenium747576