Commit cf900630 authored by Aaron Bockover's avatar Aaron Bockover

Add Banshee.WebBrowser and Banshee.AmazonMp3.Store

This is a big commit that introduces two to-die-for features into
Banshee. First is a generic GTK WebKit-based embedded browser, called
OssiferWebView, which extends WebKitWebView. OssiferWebView is written
in C, because it makes fairly heavy use of WebKit and Soup APIs, for
which the C# bindings are rather lacking. A simple, easy-to-bind API is
exposed. In C#, Banshee.WebBrowser.OssiferWebView is available for
extensions to use for embedding a reliable web browser.

GTK WebKit 1.2.0+ is required. Fortunately, this is very easy to build
on openSUSE 11.2-era systems.

What is most important though, is the introduction of the
Banshee.AmazonMp3.Store extension, which leverages
Banshee.WebBrowser.OssiferWebView to provide an integrated and dedicated
Amazon MP3 store browser. Music can be browsed, searched, and purchased
in Banshee just as you would through Amazon MP3's web site in your
regular browser, however there are two (current) user experience
improvements:

  1. A cookie is always set by Banshee that tells the Amazon MP3 web
  site that a valid Amazon MP3 downloader is installed, thus avoiding
  nagging messages about downloading the installer (which notoriously
  does not work on Linux systems); and

  2. Mime-type hooks ensure that when audio/x-amzxml content is
  delivered by Amazon, that it is downloaded and immediately imported by
  the Banshee.AmazonMp3.AmazonMp3DownloaderService. The result being
  that as soon as a purchase is made, the purchase begins downloading
  and importing into your Banshee library automatically.

Further browser improvements and polish will be on the way:

  1. Basic back/forward navigation
  2. Searching from within the regular Banshee UI
  3. Ability to log out from within the regular Banshee UI
  4. Lots of other stuff I haven't thought of

I'm not as think as you drunk I am, Ossifer!
parent cac26f61
......@@ -40,6 +40,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Banshee.ThickClient", "src\
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Banshee.CollectionIndexer", "src\Core\Banshee.CollectionIndexer\Banshee.CollectionIndexer.csproj", "{CE2AB4B9-F618-4CCA-8805-E1603741147E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Banshee.WebBrowser", "src\Core\Banshee.WebBrowser\Banshee.WebBrowser.csproj", "{E7660EC3-6CBD-4809-93ED-B4B88E65D3D3}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Backends", "Backends", "{A03B194F-F644-4E95-A602-87200029240D}"
ProjectSection(SolutionItems) = postProject
EndProjectSection
......@@ -128,6 +130,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Banshee.LastfmStreaming", "
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Banshee.AmazonMp3", "src\Extensions\Banshee.AmazonMp3\Banshee.AmazonMp3.csproj", "{930ADBFD-07F1-4044-A1C5-8B28BD23DB5C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Banshee.AmazonMp3.Store", "src\Extensions\Banshee.AmazonMp3.Store\Banshee.AmazonMp3.Store.csproj", "{AF8A9C6D-2188-413D-8EB8-C5E242BD68AC}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Libraries", "Libraries", "{4F47D6F1-4047-4A89-AE85-3AE5EF9F2961}"
ProjectSection(SolutionItems) = postProject
EndProjectSection
......@@ -331,6 +335,12 @@ Global
{AC839523-7BDF-4AB6-8115-E17921B96EC6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AC839523-7BDF-4AB6-8115-E17921B96EC6}.Windows|Any CPU.ActiveCfg = Windows|Any CPU
{AC839523-7BDF-4AB6-8115-E17921B96EC6}.Windows|Any CPU.Build.0 = Windows|Any CPU
{AF8A9C6D-2188-413D-8EB8-C5E242BD68AC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AF8A9C6D-2188-413D-8EB8-C5E242BD68AC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AF8A9C6D-2188-413D-8EB8-C5E242BD68AC}.Release|Any CPU.ActiveCfg = Debug|Any CPU
{AF8A9C6D-2188-413D-8EB8-C5E242BD68AC}.Release|Any CPU.Build.0 = Debug|Any CPU
{AF8A9C6D-2188-413D-8EB8-C5E242BD68AC}.Windows|Any CPU.ActiveCfg = Windows|Any CPU
{AF8A9C6D-2188-413D-8EB8-C5E242BD68AC}.Windows|Any CPU.Build.0 = Windows|Any CPU
{B28354F0-BA87-44E8-989F-B864A3C7C09F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B28354F0-BA87-44E8-989F-B864A3C7C09F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B28354F0-BA87-44E8-989F-B864A3C7C09F}.Windows|Any CPU.ActiveCfg = Windows|Any CPU
......@@ -392,6 +402,12 @@ Global
{E0E10333-9B05-4463-8A15-6738C186BF87}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E0E10333-9B05-4463-8A15-6738C186BF87}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E0E10333-9B05-4463-8A15-6738C186BF87}.Windows|Any CPU.ActiveCfg = Windows|Any CPU
{E7660EC3-6CBD-4809-93ED-B4B88E65D3D3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E7660EC3-6CBD-4809-93ED-B4B88E65D3D3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E7660EC3-6CBD-4809-93ED-B4B88E65D3D3}.Release|Any CPU.ActiveCfg = Debug|Any CPU
{E7660EC3-6CBD-4809-93ED-B4B88E65D3D3}.Release|Any CPU.Build.0 = Debug|Any CPU
{E7660EC3-6CBD-4809-93ED-B4B88E65D3D3}.Windows|Any CPU.ActiveCfg = Windows|Any CPU
{E7660EC3-6CBD-4809-93ED-B4B88E65D3D3}.Windows|Any CPU.Build.0 = Windows|Any CPU
{EABA3019-7539-4430-9935-D36CEA96F250}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EABA3019-7539-4430-9935-D36CEA96F250}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EABA3019-7539-4430-9935-D36CEA96F250}.Windows|Any CPU.ActiveCfg = Windows|Any CPU
......@@ -428,6 +444,7 @@ Global
{2ADB831A-A050-47D0-B6B9-9C19D60233BB} = {48EA1A64-29EE-4555-9E79-49453EB51976}
{AC839523-7BDF-4AB6-8115-E17921B96EC6} = {48EA1A64-29EE-4555-9E79-49453EB51976}
{CE2AB4B9-F618-4CCA-8805-E1603741147E} = {48EA1A64-29EE-4555-9E79-49453EB51976}
{E7660EC3-6CBD-4809-93ED-B4B88E65D3D3} = {48EA1A64-29EE-4555-9E79-49453EB51976}
{6171E5DE-5B36-4AE4-8707-F6BEE0AD945B} = {A03B194F-F644-4E95-A602-87200029240D}
{5F696A8F-B216-4ECE-9E35-907DDFC760BD} = {A03B194F-F644-4E95-A602-87200029240D}
{CA8BAD3C-1545-4B04-AF6B-4105DFD3A9A1} = {A03B194F-F644-4E95-A602-87200029240D}
......@@ -466,6 +483,7 @@ Global
{387DC336-45F9-4263-9606-2881907D2105} = {4DD1DE63-F20B-4FC3-8FDA-F0BDF4183722}
{66617494-94CB-43E8-877C-A586F5A6F4EC} = {4DD1DE63-F20B-4FC3-8FDA-F0BDF4183722}
{930ADBFD-07F1-4044-A1C5-8B28BD23DB5C} = {4DD1DE63-F20B-4FC3-8FDA-F0BDF4183722}
{AF8A9C6D-2188-413D-8EB8-C5E242BD68AC} = {4DD1DE63-F20B-4FC3-8FDA-F0BDF4183722}
{95374549-9553-4C1E-9D89-667755F90E12} = {4F47D6F1-4047-4A89-AE85-3AE5EF9F2961}
{95374549-9553-4C1E-9D89-667755F90E13} = {4F47D6F1-4047-4A89-AE85-3AE5EF9F2961}
{C856EFD8-E812-4E61-8B76-E3583D94C233} = {4F47D6F1-4047-4A89-AE85-3AE5EF9F2961}
......
......@@ -99,6 +99,10 @@ LINK_BANSHEE_THICKCLIENT = -r:$(DIR_BIN)/Banshee.ThickClient.dll
LINK_BANSHEE_THICKCLIENT_DEPS = $(REF_BANSHEE_THICKCLIENT) \
$(LINK_BANSHEE_THICKCLIENT)
REF_BANSHEE_WEBBROWSER = $(LINK_BANSHEE_THICKCLIENT_DEPS)
LINK_BANSHEE_WEBBROWSER = -r:$(DIR_BIN)/Banshee.WebBrowser.dll
LINK_BANSHEE_WEBBROWSER_DEPS = $(REF_BANSHEE_WEBBROWSER) $(LINK_BANSHEE_WEBBROWSER)
REF_NEREID = $(LINK_BANSHEE_THICKCLIENT_DEPS)
LINK_NEREID = -r:$(DIR_BIN)/Nereid.exe $(REF_NEREID)
REF_MEEGO = $(LINK_NEREID) $(LINK_EXTENSION_MEEGO)
......@@ -117,7 +121,9 @@ REF_DAP_IPOD = $(LINK_DAP_DEPS) $(LINK_IPOD)
REF_DAP_KARMA = $(LINK_DAP_DEPS) $(LINK_KARMA_DEPS)
# Extensions
LINK_EXTENSION_AMAZONMP3 = -r:$(DIR_BIN)/Banshee.AmazonMp3.exe
REF_EXTENSION_AMAZONMP3 = $(LINK_BANSHEE_THICKCLIENT_DEPS)
REF_EXTENSION_AMAZONMP3_STORE = $(LINK_BANSHEE_WEBBROWSER_DEPS) $(LINK_EXTENSION_AMAZONMP3)
REF_EXTENSION_AUDIOCD = $(LINK_BANSHEE_THICKCLIENT_DEPS) $(LINK_MUSICBRAINZ_DEPS)
REF_EXTENSION_BOOSCRIPT = $(LINK_BANSHEE_THICKCLIENT_DEPS) $(LINK_BOO)
REF_EXTENSION_BPM = $(LINK_BANSHEE_THICKCLIENT_DEPS)
......
AC_DEFUN([BANSHEE_CHECK_LIBWEBKIT],
[
have_libwebkit=no
PKG_CHECK_MODULES(LIBWEBKIT, webkit-1.0 >= 1.2.0 libsoup-2.4 >= 2.26,
have_libwebkit=yes, have_libwebkit=no)
AC_SUBST(LIBWEBKIT_LIBS)
AC_SUBST(LIBWEBKIT_CFLAGS)
AM_CONDITIONAL(HAVE_LIBWEBKIT, [test x$have_libwebkit = xyes])
have_libsoup_gnome=no
PKG_CHECK_MODULES(LIBSOUP_GNOME, libsoup-gnome-2.4 >= 2.26,
have_libsoup_gnome=$have_libwebkit, have_libsoup_gnome=no)
AC_SUBST(LIBSOUP_GNOME_LIBS)
AC_SUBST(LIBSOUP_GNOME_CFLAGS)
AM_CONDITIONAL(HAVE_LIBSOUP_GNOME, [test x$have_libsoup_gnome = xyes])
if test x$have_libsoup_gnome = xyes; then
AC_DEFINE(HAVE_LIBSOUP_GNOME, 1, [libsoup-gnome-2.4 detected])
fi
])
......@@ -117,6 +117,7 @@ SHAMROCK_CHECK_MONODOC
dnl webkit (optional through --disable-webkit)
BANSHEE_CHECK_WEBKIT
BANSHEE_CHECK_LIBWEBKIT
dnl gdata (optional through --disable-youtube)
BANSHEE_CHECK_YOUTUBE
......@@ -295,6 +296,8 @@ src/Core/Banshee.Core/Makefile
src/Core/Banshee.Services/Makefile
src/Core/Banshee.ThickClient/Makefile
src/Core/Banshee.Widgets/Makefile
src/Core/Banshee.WebBrowser/Makefile
src/Core/Banshee.WebBrowser/libossifer/Makefile
src/Backends/Makefile
src/Backends/Banshee.Gio/Makefile
......@@ -325,6 +328,7 @@ src/Dap/Banshee.Dap.Karma/Makefile
src/Extensions/Makefile
src/Extensions/Banshee.AmazonMp3/Makefile
src/Extensions/Banshee.AmazonMp3.Store/Makefile
src/Extensions/Banshee.Audiobook/Makefile
src/Extensions/Banshee.AudioCd/Makefile
src/Extensions/Banshee.BooScript/Makefile
......@@ -386,15 +390,18 @@ ${PACKAGE}-${VERSION}
Karma: ${enable_karmasharp}
Extra Features:
Web Browser: ${have_libwebkit} (webkit-1.0 >= 1.2.0, libsoup-2.4 >= 2.26)
+ GNOME Proxy ${have_libsoup_gnome} (libsoup-gnome-2.4 >= 2.26)
+ Amazon MP3 ${have_libwebkit}
+ Wikipedia ${have_libwebkit}
Boo Scripting: ${enable_boo}
Builtin Equalizer: ${enable_builtin_equalizer}
DAAP: ${enable_daap}
GIO Backend: ${enable_gio} (requires glib >= 2.22, gtk-sharp-beans, and gio-sharp)
Library Watcher: ${HAVE_MONO_2_4_3} (requires Mono >= 2.4.3)
GIO Backend: ${enable_gio} (glib >= 2.22, gtk-sharp-beans, and gio-sharp)
Library Watcher: ${HAVE_MONO_2_4_3} (Mono >= 2.4.3)
Podcasts: ${enable_podcast}
Wikipedia: ${enable_webkit} (requires webkit-sharp)
Gapless playback: ${ENABLE_GAPLESS} (requires gstreamer-plugins-base > 0.10.25.2)
YouTube extension: ${enable_youtube} (requires gdata-sharp >= 1.4)
Gapless playback: ${ENABLE_GAPLESS} (gstreamer-plugins-base > 0.10.25.2)
YouTube extension: ${enable_youtube} (gdata-sharp >= 1.4)
Build/Development:
Unit Tests: ${do_tests} (requires nunit >= ${NUNIT_REQUIRED})
......
......@@ -61,6 +61,11 @@ internal static class AddinXmlStringCatalog
Catalog.GetString (@"Digital Media Player Support");
Catalog.GetString (@"Provides general support for many kinds of media player devices.");
// ../src/Extensions/Banshee.AmazonMp3.Store/Banshee.AmazonMp3.Store.addin.xml
Catalog.GetString (@"Amazon MP3 Store Source");
Catalog.GetString (@"Browse, search, and purchase music from the Amazon MP3 store");
Catalog.GetString (@"Online Sources");
// ../src/Extensions/Banshee.AmazonMp3/Banshee.AmazonMp3.addin.xml
Catalog.GetString (@"Amazon MP3 Import");
Catalog.GetString (@"Download and import music purchased from Amazon.com");
......
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.21022</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{E7660EC3-6CBD-4809-93ED-B4B88E65D3D3}</ProjectGuid>
<OutputType>Library</OutputType>
<AssemblyName>Banshee.WebBrowser</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<ReleaseVersion>1.3</ReleaseVersion>
<RootNamespace>Banshee.WebBrowser</RootNamespace>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<DefineConstants>DEBUG</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<OutputPath>..\..\..\bin</OutputPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Windows|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<WarningLevel>4</WarningLevel>
<Optimize>false</Optimize>
<OutputPath>..\..\..\bin</OutputPath>
</PropertyGroup>
<ItemGroup>
<Reference Include="gtk-sharp">
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="gdk-sharp">
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="System" />
<Reference Include="Mono.Posix">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..bin\Mono.Posix.dll</HintPath>
</Reference>
<Reference Include="glib-sharp">
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="atk-sharp">
<SpecificVersion>False</SpecificVersion>
</Reference>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
<ProjectReference Include="..\..\Libraries\Hyena.Gui\Hyena.Gui.csproj">
<Project>{C856EFD8-E812-4E61-8B76-E3583D94C233}</Project>
<Name>Hyena.Gui</Name>
</ProjectReference>
<ProjectReference Include="..\..\Libraries\Hyena\Hyena.csproj">
<Project>{95374549-9553-4C1E-9D89-667755F90E12}</Project>
<Name>Hyena</Name>
</ProjectReference>
<ProjectReference Include="..\Banshee.Core\Banshee.Core.csproj">
<Project>{2ADB831A-A050-47D0-B6B9-9C19D60233BB}</Project>
<Name>Banshee.Core</Name>
</ProjectReference>
<ProjectReference Include="..\Banshee.Services\Banshee.Services.csproj">
<Project>{B28354F0-BA87-44E8-989F-B864A3C7C09F}</Project>
<Name>Banshee.Services</Name>
</ProjectReference>
<ProjectReference Include="..\Banshee.ThickClient\Banshee.ThickClient.csproj">
<Project>{AC839523-7BDF-4AB6-8115-E17921B96EC6}</Project>
<Name>Banshee.ThickClient</Name>
</ProjectReference>
</ItemGroup>
<ProjectExtensions>
<MonoDevelop>
<Properties>
<MonoDevelop.Autotools.MakefileInfo IntegrationEnabled="true" RelativeMakefileName="Makefile.am">
<BuildFilesVar Sync="true" Name="SOURCES" />
<DeployFilesVar />
<ResourcesVar />
<OthersVar />
<GacRefVar />
<AsmRefVar />
<ProjectRefVar />
</MonoDevelop.Autotools.MakefileInfo>
</Properties>
</MonoDevelop>
</ProjectExtensions>
<ItemGroup>
<None Include="libossifer\ossifer-web-view.c" />
<None Include="libossifer\ossifer-web-view.h" />
</ItemGroup>
<ItemGroup>
<Folder Include="Banshee.WebBrowser\" />
</ItemGroup>
<ItemGroup>
<Compile Include="Banshee.WebBrowser\OssiferWebView.cs" />
<Compile Include="Banshee.WebBrowser\OssiferNavigationResponse.cs" />
<Compile Include="Banshee.WebBrowser\OssiferDownloadStatus.cs" />
</ItemGroup>
</Project>
//
// OssiferDownloadStatus.cs
//
// Author:
// Aaron Bockover <abockover@novell.com>
//
// Copyright 2010 Novell, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
namespace Banshee.WebBrowser
{
public enum OssiferDownloadStatus
{
Error = -1,
Created = 0,
Started,
Cancelled,
Finished
}
}
\ No newline at end of file
//
// OssiferNavigationResponse.cs
//
// Author:
// Aaron Bockover <abockover@novell.com>
//
// Copyright 2010 Novell, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
namespace Banshee.WebBrowser
{
public enum OssiferNavigationResponse
{
Accept,
Ignore,
Download,
// Ossifer specific (above mirrors WebKitNavigationResponse)
Unhandled = 1000
}
}
//
// OssiferWebView.cs
//
// Author:
// Aaron Bockover <abockover@novell.com>
//
// Copyright 2010 Novell, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System.Runtime.InteropServices;
namespace Banshee.WebBrowser
{
public class OssiferWebView : Gtk.Widget
{
private delegate OssiferNavigationResponse MimeTypePolicyDecisionRequestedCallback (IntPtr ossifer, IntPtr mimetype);
private delegate IntPtr DownloadRequestedCallback (IntPtr ossifer, IntPtr uri, IntPtr suggested_filename);
private delegate void DocumentLoadFinishedCallback (IntPtr ossifer, IntPtr uri);
private delegate void DownloadStatusChangedCallback (IntPtr ossifer, OssiferDownloadStatus status, IntPtr destnation_uri);
[StructLayout (LayoutKind.Sequential)]
private struct Callbacks
{
public MimeTypePolicyDecisionRequestedCallback MimeTypePolicyDecisionRequested;
public DownloadRequestedCallback DownloadRequested;
public DocumentLoadFinishedCallback DocumentLoadFinished;
public DownloadStatusChangedCallback DownloadStatusChanged;
}
private const string LIBOSSIFER = "ossifer";
private Callbacks callbacks;
[DllImport (LIBOSSIFER)]
private static extern IntPtr ossifer_web_view_get_type ();
public static new GLib.GType GType {
get { return new GLib.GType (ossifer_web_view_get_type ()); }
}
protected OssiferWebView (IntPtr raw) : base (raw)
{
}
[DllImport (LIBOSSIFER)]
private static extern void ossifer_web_view_set_callbacks (IntPtr ossifer, Callbacks callbacks);
public OssiferWebView ()
{
Initialize ();
CreateNativeObject (new string[0], new GLib.Value[0]);
ossifer_web_view_set_callbacks (Handle, callbacks = new Callbacks () {
MimeTypePolicyDecisionRequested =
new MimeTypePolicyDecisionRequestedCallback (HandleMimeTypePolicyDecisionRequested),
DownloadRequested = new DownloadRequestedCallback (HandleDownloadRequested),
DocumentLoadFinished = new DocumentLoadFinishedCallback (HandleDocumentLoadFinished),
DownloadStatusChanged = new DownloadStatusChangedCallback (HandleDownloadStatusChanged)
});
GC.KeepAlive (callbacks);
}
#region Callback Implementations
private OssiferNavigationResponse HandleMimeTypePolicyDecisionRequested (IntPtr ossifer, IntPtr mimetype)
{
return OnMimeTypePolicyDecisionRequested (GLib.Marshaller.Utf8PtrToString (mimetype));
}
protected virtual OssiferNavigationResponse OnMimeTypePolicyDecisionRequested (string mimetype)
{
return OssiferNavigationResponse.Unhandled;
}
private IntPtr HandleDownloadRequested (IntPtr ossifer, IntPtr uri, IntPtr suggested_filename)
{
var destination_uri = OnDownloadRequested (
GLib.Marshaller.Utf8PtrToString (uri),
GLib.Marshaller.Utf8PtrToString (suggested_filename));
return destination_uri == null
? IntPtr.Zero
: GLib.Marshaller.StringToPtrGStrdup (destination_uri);
}
protected virtual string OnDownloadRequested (string uri, string suggestedFilename)
{
return null;
}
private void HandleDocumentLoadFinished (IntPtr ossifer, IntPtr uri)
{
OnDocumentLoadFinished (GLib.Marshaller.Utf8PtrToString (uri));
}
protected virtual void OnDocumentLoadFinished (string uri)
{
}
private void HandleDownloadStatusChanged (IntPtr ossifer, OssiferDownloadStatus status, IntPtr destinationUri)
{
OnDownloadStatusChanged (status, GLib.Marshaller.Utf8PtrToString (destinationUri));
}
protected virtual void OnDownloadStatusChanged (OssiferDownloadStatus status, string destinationUri)
{
}
#endregion
#region Public Instance API
[DllImport (LIBOSSIFER)]
private static extern IntPtr ossifer_web_view_load_uri (IntPtr ossifer, IntPtr uri);
public void LoadUri (string uri)
{
var uri_raw = IntPtr.Zero;
try {
uri_raw = GLib.Marshaller.StringToPtrGStrdup (uri);
ossifer_web_view_load_uri (Handle, uri_raw);
} finally {
GLib.Marshaller.Free (uri_raw);
}
}
[DllImport (LIBOSSIFER)]
private static extern void ossifer_web_view_load_string (IntPtr ossifer,
IntPtr content, IntPtr mimetype, IntPtr encoding, IntPtr base_uri);
public void LoadString (string content, string mimetype, string encoding, string baseUri)
{
var content_raw = IntPtr.Zero;
var mimetype_raw = IntPtr.Zero;
var encoding_raw = IntPtr.Zero;
var base_uri_raw = IntPtr.Zero;
try {
ossifer_web_view_load_string (Handle,
content_raw = GLib.Marshaller.StringToPtrGStrdup (content),
mimetype_raw = GLib.Marshaller.StringToPtrGStrdup (mimetype),
encoding_raw = GLib.Marshaller.StringToPtrGStrdup (encoding),
base_uri_raw = GLib.Marshaller.StringToPtrGStrdup (baseUri));
} finally {
GLib.Marshaller.Free (content_raw);
GLib.Marshaller.Free (mimetype_raw);
GLib.Marshaller.Free (encoding_raw);
GLib.Marshaller.Free (base_uri_raw);
}
}
#endregion
#region Static API
[DllImport (LIBOSSIFER)]
private static extern void ossifer_web_view_global_initialize (IntPtr cookie_db_path);
public static void Initialize ()
{
var path = System.IO.Path.Combine (Hyena.Paths.ApplicationData, "ossifer-browser-cookies");
var path_raw = IntPtr.Zero;
try {
ossifer_web_view_global_initialize (path_raw = GLib.Marshaller.StringToPtrGStrdup (path));
} finally {
GLib.Marshaller.Free (path_raw);
}
}
[DllImport (LIBOSSIFER)]
private static extern void ossifer_web_view_global_set_cookie (IntPtr name, IntPtr value,
IntPtr domain, IntPtr path, int max_age);
public static void SetCookie (string name, string value, string domain, string path, TimeSpan maxAge)
{
var name_raw = IntPtr.Zero;
var value_raw = IntPtr.Zero;
var domain_raw = IntPtr.Zero;
var path_raw = IntPtr.Zero;
try {
ossifer_web_view_global_set_cookie (
name_raw = GLib.Marshaller.StringToPtrGStrdup (name),
value_raw = GLib.Marshaller.StringToPtrGStrdup (value),
domain_raw = GLib.Marshaller.StringToPtrGStrdup (domain),
path_raw = GLib.Marshaller.StringToPtrGStrdup (path),
(int)Math.Round (maxAge.TotalSeconds));
} finally {
GLib.Marshaller.Free (name_raw);
GLib.Marshaller.Free (value_raw);
GLib.Marshaller.Free (domain_raw);
GLib.Marshaller.Free (path_raw);
}
}
#endregion
}
}
\ No newline at end of file
SUBDIRS = libossifer
ASSEMBLY = Banshee.WebBrowser
TARGET = library
LINK = $(REF_BANSHEE_WEBBROWSER)
INSTALL_DIR = $(DEFAULT_INSTALL_DIR)
SOURCES = \
Banshee.WebBrowser/OssiferDownloadStatus.cs \
Banshee.WebBrowser/OssiferNavigationResponse.cs \
Banshee.WebBrowser/OssiferWebView.cs
if HAVE_LIBWEBKIT
include $(top_srcdir)/build/build.mk
else
EXTRA_DIST = $(SOURCES)
endif
SOURCES = ossifer-web-view.c
if HAVE_LIBWEBKIT
ossiferdir = $(pkglibdir)
ossifer_LTLIBRARIES = libossifer.la
libossifer_la_SOURCES = $(SOURCES)
libossifer_la_CFLAGS = $(LIBWEBKIT_CFLAGS) -D_FORTIFY_SOURCE=2 -ggdb3 -Wall
libossifer_la_LIBADD = $(LIBWEBKIT_LIBS)
libossifer_la_LDFLAGS = -avoid-version -module
if HAVE_LIBSOUP_GNOME
libossifer_la_CFLAGS += $(LIBSOUP_GNOME_CFLAGS)
libossifer_la_LIBADD += $(LIBSOUP_GNOME_LIBS)
endif
all: $(top_builddir)/bin/libossifer.so
$(top_builddir)/bin/libossifer.so: libossifer.la
mkdir -p $(top_builddir)/bin
cp -f .libs/$(notdir $@) $@
CLEANFILES = $(top_builddir)/bin/libossifer.so
else
EXTRA_DIST = $(SOURCES)
endif
MAINTAINERCLEANFILES = Makefile.in
//
// ossifer-web-view.c
//
// Author:
// Aaron Bockover <abockover@novell.com>
//
// Copyright 2010 Novell, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR