adium 3350:2b9eb5aee00b: Pass a valid and custom baseURL to our ...

commits at adium.im commits at adium.im
Mon Oct 4 23:05:47 UTC 2010


details:	http://hg.adium.im/adium/rev/2b9eb5aee00b
revision:	3350:2b9eb5aee00b
author:		Thijs Alkemade <thijsalkemade at gmail.com>
date:		Tue Oct 05 01:02:56 2010 +0200

Pass a valid and custom baseURL to our WebView to fix permission errors when attempting to use HTML5 localStorage from a message style. Also set the localStorage path to inside the user directory.

diffs (150 lines):

diff -r 5878496f5b18 -r 2b9eb5aee00b Adium.xcodeproj/project.pbxproj
--- a/Adium.xcodeproj/project.pbxproj	Thu Sep 30 13:43:53 2010 +0200
+++ b/Adium.xcodeproj/project.pbxproj	Tue Oct 05 01:02:56 2010 +0200
@@ -1451,6 +1451,7 @@
 		6EC1684D06C170A000F9FAD3 /* DCInviteToChatPlugin.m in Sources */ = {isa = PBXBuildFile; fileRef = 6EC1684806C170A000F9FAD3 /* DCInviteToChatPlugin.m */; };
 		6EC1684F06C170A000F9FAD3 /* DCInviteToChatWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6EC1684A06C170A000F9FAD3 /* DCInviteToChatWindowController.m */; };
 		6EC1685006C170A000F9FAD3 /* InviteToChatWindow.nib in Resources */ = {isa = PBXBuildFile; fileRef = 6EC1684B06C170A000F9FAD3 /* InviteToChatWindow.nib */; };
+		76C1AF9C125A906A00D269A9 /* AIAdiumURLProtocol.m in Sources */ = {isa = PBXBuildFile; fileRef = 76C1AF9B125A906A00D269A9 /* AIAdiumURLProtocol.m */; };
 		7E6F8A94105611B700C6D80D /* libotr.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7E6F8A93105611B700C6D80D /* libotr.framework */; };
 		7E6F8ACD105613AD00C6D80D /* libotr.framework in Copy Frameworks */ = {isa = PBXBuildFile; fileRef = 7E6F8A93105611B700C6D80D /* libotr.framework */; };
 		7E7CF7F11124B982001CFC73 /* libgstsdp.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7E7CF7F01124B982001CFC73 /* libgstsdp.framework */; };
@@ -4759,6 +4760,8 @@
 		6FB330A20C7235BF00B001A8 /* EKEzvIncomingFileTransfer.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; name = EKEzvIncomingFileTransfer.m; path = Plugins/Bonjour/libezv/Classes/EKEzvIncomingFileTransfer.m; sourceTree = SOURCE_ROOT; };
 		6FB330A30C7235BF00B001A8 /* EKEzvOutgoingFileTransfer.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = EKEzvOutgoingFileTransfer.h; path = Plugins/Bonjour/libezv/Classes/EKEzvOutgoingFileTransfer.h; sourceTree = SOURCE_ROOT; };
 		6FB330A40C7235BF00B001A8 /* EKEzvOutgoingFileTransfer.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; name = EKEzvOutgoingFileTransfer.m; path = Plugins/Bonjour/libezv/Classes/EKEzvOutgoingFileTransfer.m; sourceTree = SOURCE_ROOT; };
+		76C1AF9A125A906A00D269A9 /* AIAdiumURLProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AIAdiumURLProtocol.h; path = "Plugins/WebKit Message View/AIAdiumURLProtocol.h"; sourceTree = "<group>"; };
+		76C1AF9B125A906A00D269A9 /* AIAdiumURLProtocol.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AIAdiumURLProtocol.m; path = "Plugins/WebKit Message View/AIAdiumURLProtocol.m"; sourceTree = "<group>"; };
 		77D903500B78CF1000B86C42 /* zhm */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.executable"; name = zhm; path = "Plugins/Purple Service/zhm"; sourceTree = "<group>"; };
 		7E1E8176063A3EEC00EB00F7 /* AIContextMenuTextView.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = AIContextMenuTextView.h; path = "Frameworks/Adium Framework/Source/AIContextMenuTextView.h"; sourceTree = "<group>"; };
 		7E1E8177063A3EEC00EB00F7 /* AIContextMenuTextView.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; name = AIContextMenuTextView.m; path = "Frameworks/Adium Framework/Source/AIContextMenuTextView.m"; sourceTree = "<group>"; };
@@ -5984,6 +5987,8 @@
 			children = (
 				346C9A2305FFE3DE000F5A8A /* ESWebView.h */,
 				346C9A2405FFE3DF000F5A8A /* ESWebView.m */,
+				76C1AF9A125A906A00D269A9 /* AIAdiumURLProtocol.h */,
+				76C1AF9B125A906A00D269A9 /* AIAdiumURLProtocol.m */,
 			);
 			name = "WebKit Additions";
 			sourceTree = "<group>";
@@ -10828,6 +10833,7 @@
 				11819A0410D0B8BE003E8ECA /* AIMediaController.m in Sources */,
 				1147FCC410D1CB4C004E9E8D /* AIMediaWindowController.m in Sources */,
 				5A9A9F8911F2951400328DF9 /* AIDoNothingContactAlertPlugin.m in Sources */,
+				76C1AF9C125A906A00D269A9 /* AIAdiumURLProtocol.m in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
diff -r 5878496f5b18 -r 2b9eb5aee00b Plugins/WebKit Message View/AIAdiumURLProtocol.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Plugins/WebKit Message View/AIAdiumURLProtocol.h	Tue Oct 05 01:02:56 2010 +0200
@@ -0,0 +1,24 @@
+/* 
+ * Adium is the legal property of its developers, whose names are listed in the copyright file included
+ * with this source distribution.
+ * 
+ * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
+ * General Public License as published by the Free Software Foundation; either version 2 of the License,
+ * or (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
+ * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
+ * Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License along with this program; if not,
+ * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+
+#import <Cocoa/Cocoa.h>
+#import <WebKit/WebKit.h>
+
+ at interface AIAdiumURLProtocol : NSURLProtocol {
+	
+}
+
+ at end
diff -r 5878496f5b18 -r 2b9eb5aee00b Plugins/WebKit Message View/AIAdiumURLProtocol.m
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Plugins/WebKit Message View/AIAdiumURLProtocol.m	Tue Oct 05 01:02:56 2010 +0200
@@ -0,0 +1,30 @@
+/* 
+ * Adium is the legal property of its developers, whose names are listed in the copyright file included
+ * with this source distribution.
+ * 
+ * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
+ * General Public License as published by the Free Software Foundation; either version 2 of the License,
+ * or (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
+ * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
+ * Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License along with this program; if not,
+ * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+
+#import "AIAdiumURLProtocol.h"
+
+/*!
+ * @class AIAdiumURLProtocol
+ * @brief Fake URL scheme for message views. Loads nothing and can not be opened on request.
+ */
+ at implementation AIAdiumURLProtocol
+
++ (BOOL)canInitWithRequest:(NSURLRequest *)request
+{
+    return [[[request URL] scheme] isEqualToString:@"adium"];
+}
+
+ at end
diff -r 5878496f5b18 -r 2b9eb5aee00b Plugins/WebKit Message View/AIWebKitMessageViewController.m
--- a/Plugins/WebKit Message View/AIWebKitMessageViewController.m	Thu Sep 30 13:43:53 2010 +0200
+++ b/Plugins/WebKit Message View/AIWebKitMessageViewController.m	Tue Oct 05 01:02:56 2010 +0200
@@ -502,7 +502,12 @@
 
 	//Hack: this will re-set us for all the delegates, but that shouldn't matter
 	[delegateProxy addDelegate:self forView:webView];
-	[[webView mainFrame] loadHTMLString:[messageStyle baseTemplateForChat:chat] baseURL:nil];
+	
+	// We need to pass a local URL to allow LocalStorage from the WebView.
+	// The hostname-part determines the namespace, which we seperate per style.
+	// The path-part may not end in a /, as directories don't get local permissions.
+	NSURL *baseURL = [NSURL URLWithString:[NSString stringWithFormat:@"adium://%@/adium", [messageStyle.bundle bundleIdentifier]]];
+	[[webView mainFrame] loadHTMLString:[messageStyle baseTemplateForChat:chat] baseURL:baseURL];
 
 	if(chat.isGroupChat && chat.supportsTopic) {
 		// Force a topic update, so we set our topic appropriately.
diff -r 5878496f5b18 -r 2b9eb5aee00b Plugins/WebKit Message View/ESWebView.m
--- a/Plugins/WebKit Message View/ESWebView.m	Thu Sep 30 13:43:53 2010 +0200
+++ b/Plugins/WebKit Message View/ESWebView.m	Tue Oct 05 01:02:56 2010 +0200
@@ -15,12 +15,18 @@
  */
 
 #import "ESWebView.h"
+#import "AIAdiumURLProtocol.h"
+#import <Adium/AILoginControllerProtocol.h>
 
 @interface WebView ()
 - (void)setDrawsBackground:(BOOL)flag;
 - (void)setBackgroundColor:(NSColor *)color;
 @end
 
+ at interface WebPreferences (WebPreferencesPrivate)
+- (void)_setLocalStorageDatabasePath:(NSString *)path;
+ at end
+
 @interface NSWindow ()
 - (void) _setContentHasShadow:(BOOL) shadow; 
 @end
@@ -38,6 +44,11 @@
 		allowsDragAndDrop = YES;
 		shouldForwardEvents = YES;
 		transparentBackground = NO;
+		
+		[NSURLProtocol registerClass:[AIAdiumURLProtocol class]];
+		[ESWebView registerURLSchemeAsLocal:@"adium"];
+		
+		[[self preferences] _setLocalStorageDatabasePath:[[adium.loginController userDirectory] stringByAppendingPathComponent:@"LocalStorage"]];
 	}
 	
 	return self;




More information about the commits mailing list