OSDN Git Service

firefox4 のcookie処理クラス
authoryukihane <yukihane.feather@gmail.com>
Sat, 17 Sep 2011 06:04:49 +0000 (15:04 +0900)
committeryukihane <yukihane.feather@gmail.com>
Sat, 17 Sep 2011 06:04:49 +0000 (15:04 +0900)
frontend/src/saccubus/net/BrowserInfo.java
frontend/src/saccubus/net/CookieWinFirefox4.java [new file with mode: 0644]

index 2e2d21d..d85a945 100644 (file)
@@ -135,36 +135,6 @@ public class BrowserInfo {
     }
 
     /// <summary>
-    /// Firefox4, 5 から user_session を取得。エラーが起こった場合、例外を投げずに空文字を返す
-    /// </summary>
-    /// <returns>user_session</returns>
-    private String GetUserSessionFromFilefox4() {
-        String user_session = "";
-        try {
-            String app_dir = System.getenv("APPDATA");
-            if (app_dir == null || app_dir.isEmpty()) {
-                return "";
-            }
-            String[] userLists = Path.GetFiles(app_dir + "\\Mozilla\\Firefox\\Profiles\\");
-            for (String user_dir : userLists) {
-                String sqlist_filename = user_dir + "\\cookies.sqlite";
-                if (Path.isFile(sqlist_filename)) {
-                    String dataStr = Path.ReadAllText(sqlist_filename, "US-ASCII");
-                    user_session = CutUserSession(dataStr, sqlist_filename);
-                    if (!user_session.isEmpty()) {
-                        return user_session;
-                    }
-                    // else continue
-                }
-            }
-            return ""; // not found
-        } catch (Exception e) {
-            e.printStackTrace();
-            return "";
-        }
-    }
-
-    /// <summary>
     /// IE6 から user_session を取得
     /// </summary>
     /// <param name="url">サイト(ニコニコ動画)のURL</param>
@@ -258,56 +228,6 @@ public class BrowserInfo {
     }
 
     /** <p>
-     *  Chrome から user_session を取得。エラーが起こった場合、例外を投げずに空文字を返す
-     *  </p>
-     *  @return user_session
-     */
-    private String GetUserSesionChrome() {
-        String user_session = "";
-        String cookie_file = "";
-        String googleChrome = "\\Google\\Chrome\\User Data\\Default\\Cookies";
-        try {
-            String local_Appdir = System.getenv("LOCALAPPDATA");
-            if (local_Appdir != null && !local_Appdir.isEmpty()) {
-                // Win7 32bit
-                cookie_file = local_Appdir + googleChrome;
-                if (Path.isFile(cookie_file)) {
-                    String dataStr = Path.ReadAllText(cookie_file, "UTF-8");
-                    user_session = CutUserSession(dataStr, cookie_file);
-                    if (!user_session.isEmpty()) {
-                        return user_session;
-                    }
-                }
-            }
-            String profile_dir = System.getenv("USERPROFILE");
-            if (profile_dir != null && !profile_dir.isEmpty()) {
-                // XP 32bit
-                cookie_file = profile_dir
-                        + "\\Local Settings\\Application Data" + googleChrome;
-                if (Path.isFile(cookie_file)) {
-                    String dataStr = Path.ReadAllText(cookie_file, "UTF-8");
-                    user_session = CutUserSession(dataStr, cookie_file);
-                    return user_session;
-                }
-            }
-            String app_dir = System.getenv("APPDATA");
-            if (app_dir != null && !app_dir.isEmpty()) {
-                // ??? just try
-                cookie_file = app_dir + googleChrome;
-                if (Path.isFile(cookie_file)) {
-                    String dataStr = Path.ReadAllText(cookie_file, "UTF-8");
-                    user_session = CutUserSession(dataStr, cookie_file);
-                    return user_session;
-                }
-            }
-            return user_session;
-        } catch (Exception e) {
-            e.printStackTrace();
-            return user_session;
-        }
-    }
-
-    /** <p>
      *  Chromium から user_session を取得。エラーが起こった場合、例外を投げずに空文字を返す
      *  </p>
      *  @return user_session
diff --git a/frontend/src/saccubus/net/CookieWinFirefox4.java b/frontend/src/saccubus/net/CookieWinFirefox4.java
new file mode 100644 (file)
index 0000000..ee55714
--- /dev/null
@@ -0,0 +1,42 @@
+package saccubus.net;
+
+import java.io.IOException;
+
+/**
+ *
+ * @author yuki
+ */
+public class CookieWinFirefox4 extends Cookie {
+
+    /// <summary>
+    /// Firefox4, 5 から user_session を取得。エラーが起こった場合、例外を投げずに空文字を返す
+    /// </summary>
+    /// <returns>user_session</returns>
+    @Override
+    public String getUserSessionString() throws IOException {
+        String user_session = "";
+        try {
+            String app_dir = System.getenv("APPDATA");
+            if (app_dir == null || app_dir.isEmpty()) {
+                return "";
+            }
+            String[] userLists = Path.GetFiles(app_dir + "\\Mozilla\\Firefox\\Profiles\\");
+            for (String user_dir : userLists) {
+                String sqlist_filename = user_dir + "\\cookies.sqlite";
+                if (Path.isFile(sqlist_filename)) {
+                    String dataStr = Path.ReadAllText(sqlist_filename, "US-ASCII");
+                    user_session = CutUserSession(dataStr, sqlist_filename);
+                    if (!user_session.isEmpty()) {
+                        return user_session;
+                    }
+                    // else continue
+                }
+            }
+            return ""; // not found
+        } catch (Exception e) {
+            e.printStackTrace();
+            return "";
+        }
+
+    }
+}