Skip to content

Commit

Permalink
added Weinre remote debugger support
Browse files Browse the repository at this point in the history
  • Loading branch information
sgrebnov committed Aug 7, 2012
1 parent 59402b9 commit d7d330b
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Libraries/Cordova/framework/CordovaView.xaml.cs
Expand Up @@ -327,7 +327,7 @@ void GapBrowser_LoadCompleted(object sender, System.Windows.Navigation.Navigatio

void GapBrowser_Navigating(object sender, NavigatingEventArgs e)
{
DebugConsole.WriteLine("GapBrowser_Navigating to :: " + e.Uri.ToString());
//DebugConsole.WriteLine("GapBrowser_Navigating to :: " + e.Uri.ToString());
// TODO: tell any running plugins to stop doing what they are doing.
// TODO: check whitelist / blacklist
// NOTE: Navigation can be cancelled by setting : e.Cancel = true;
Expand Down
9 changes: 0 additions & 9 deletions Libraries/IE.Debug.Core/DebugTraceListener.cs
@@ -1,13 +1,4 @@
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace IE.Debug.Core
{
Expand Down
4 changes: 4 additions & 0 deletions Libraries/IE.Debug.Core/IE.Debug.Core.csproj
Expand Up @@ -60,6 +60,10 @@
<Project>{FC6A1A70-892D-46AD-9E4A-9793F72AF780}</Project>
<Name>WP7CordovaClassLib</Name>
</ProjectReference>
<ProjectReference Include="..\Support\Support.csproj">
<Project>{5F99E641-C43E-49A2-A771-06FC091BE010}</Project>
<Name>Support</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Microsoft\Silverlight for Phone\$(TargetFrameworkVersion)\Microsoft.Silverlight.$(TargetFrameworkProfile).Overrides.targets" />
<Import Project="$(MSBuildExtensionsPath)\Microsoft\Silverlight for Phone\$(TargetFrameworkVersion)\Microsoft.Silverlight.CSharp.targets" />
Expand Down
7 changes: 7 additions & 0 deletions Libraries/IE.Debug.Core/Scripting.cs
Expand Up @@ -24,6 +24,13 @@ public static string BuilInjectScript(string link)
link);
}

public static string BuilInjectInlineScript(string text)
{
return String.Format(
@"var head = document.getElementsByTagName('head')[0]; var sc1 = document.createElement('script');sc1.innerHTML = '{0}';sc1.type = 'text/javascript'; (head || document.body).appendChild(sc1);",
text);
}

public static string PhoneGapInjectScript
{
get {return BuilInjectScript(PhoneGapLink); }
Expand Down
25 changes: 25 additions & 0 deletions Libraries/IE.Debug.Core/WebPageDebugger.cs
Expand Up @@ -9,6 +9,9 @@
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.IO.IsolatedStorage;
using System.IO;
using Support;

namespace IE.Debug.Core
{
Expand Down Expand Up @@ -36,12 +39,34 @@ public static void InstallDebugConsole()
browser.InvokeScript("eval", new string[] { Scripting.PhoneGapInjectScript });
browser.InvokeScript("eval", new string[] { Scripting.BuilInjectScript(@"http://mshare.akvelon.net:8184/cordova-init.js")});
}

public static void ConnectWeinerDebugger()
{
ConnectWeiner();
}

public static void InstallFirebug()
{
browser.InvokeScript("eval", new string[] { Scripting.FirebugInjectScript });
//(@"function(F,i,r,e,b,u,g,L,I,T,E){if(F.getElementById(b))return;E=F[i+'NS']&&F.documentElement.namespaceURI;E=E?F[i+'NS'](E,'script'):F[i]('script');E[r]('id',b);E[r]('src',I+g+T);E[r](b,u);(F[e]('head')[0]||F[e]('body')[0]).appendChild(E);E=new%20Image;E[r]('src',I+L);})(document,'createElement','setAttribute','getElementsByTagName','FirebugLite','4','firebug-lite.js','releases/lite/latest/skin/xp/sprite.png','https://getfirebug.com/','#startOpened')();");
}

public static void ExecuteCustomScript(string script)
{
browser.InvokeScript("eval", new string[] { script});
}

public static void ConnectWeiner()
{

browser.InvokeScript("eval", new string[] { @"window.WeinreServerId='wp7'" });
browser.InvokeScript("eval", new string[] { @"window.WeinreServerURL='http://debug.shadow.adobe.com:8080'" });

browser.InvokeScript("eval", new string[] { FileUtils.ReadFileContent("app/www/wp-hacks.js") });
browser.InvokeScript("eval", new string[] { FileUtils.ReadFileContent(@"app/www/target-script-min.js") });

}

public static void InjectTestScript()
{
browser.InvokeScript("eval", new string[] { Scripting.BuilInjectScript(Scripting.TestLink) });
Expand Down
1 change: 1 addition & 0 deletions Libraries/Support/Support.csproj
Expand Up @@ -50,6 +50,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="ExceptionHandler.cs" />
<Compile Include="FileUtils.cs" />
<Compile Include="Messages.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions WindowsPhone/Controls/PageHostControl.xaml
Expand Up @@ -15,8 +15,8 @@
<my:CordovaView HorizontalAlignment="Stretch"
Margin="0,64,0,0"
Name="PGView"
VerticalAlignment="Stretch" StartPageUri="http://google.com" />
<TextBox Height="72" HorizontalAlignment="Left" Name="txtUrl" Text="http://google.com" VerticalAlignment="Top" Width="414" Margin="-10,-3,0,0" />
VerticalAlignment="Stretch" StartPageUri="http://microsoft.com" />
<TextBox Height="72" HorizontalAlignment="Left" Name="txtUrl" Text="http://microsoft.com" VerticalAlignment="Top" Width="414" Margin="-10,-3,0,0" />
<Button Content="go" Height="72" HorizontalAlignment="Left" Margin="384,-1,0,0" Name="btnNavigate" VerticalAlignment="Top" Width="82" Click="btnNavigate_Click" />
</Grid>

Expand Down
2 changes: 2 additions & 0 deletions WindowsPhone/CordovaSourceDictionary.xml
Expand Up @@ -4,5 +4,7 @@
<FilePath Value="www\cordova-1.5.0.js"/>
<FilePath Value="www\index.html"/>
<FilePath Value="www\master.css"/>
<FilePath Value="www\target-script-min.js"/>
<FilePath Value="www\test.js"/>
<FilePath Value="www\wp-hacks.js"/>
</CordovaSourceDictionary>
2 changes: 2 additions & 0 deletions WindowsPhone/IE.Debug.WindowsPhone.csproj
Expand Up @@ -93,6 +93,7 @@
<Content Include="www\cordova-1.5.0.js" />
<Content Include="www\index.html" />
<Content Include="www\master.css" />
<Content Include="www\target-script-min.js" />
<Content Include="www\test.js" />
<Content Include="Images\appbar.debug.rest.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
Expand All @@ -106,6 +107,7 @@
<Content Include="Images\appbar.plus.rest.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="www\wp-hacks.js" />
<None Include="BuildManifestProcessor.js" />
<None Include="Properties\AppManifest.xml">
<SubType>Designer</SubType>
Expand Down
17 changes: 12 additions & 5 deletions WindowsPhone/Views/MainPage.xaml
Expand Up @@ -15,12 +15,16 @@
shell:SystemTray.IsVisible="True"
xmlns:local="clr-namespace:IE.Debug.WindowsPhone.Controls">

<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid x:Name="LayoutRoot" Margin="0,0,0,0" Height="Auto" Background="Transparent" VerticalAlignment="Top">
<!--Pivot Control-->
<controls:Pivot Title="Windows Phone IE debugger" Name="pivotControl" SelectionChanged="Pivot_SelectionChanged">

<controls:PivotItem Header="main" Tag="pvtMain">
<local:PageHostControl x:Name="pvtMain"></local:PageHostControl>
<!--<controls:Pivot.HeaderTemplate>
<DataTemplate>
<TextBlock Text="{Binding Title}"/>
</DataTemplate>
</controls:Pivot.HeaderTemplate>-->
<controls:PivotItem Header="main" Height="800" Margin="0,-124,0,0" Tag="pvtMain">
<local:PageHostControl x:Name="pvtMain" Width="Auto"></local:PageHostControl>
</controls:PivotItem>

<controls:PivotItem Header="console" Tag="pvtConsole">
Expand All @@ -38,7 +42,10 @@
<shell:ApplicationBar x:Key="pvtMainApplicationBar" IsMenuEnabled="True" Opacity="0.5" IsVisible="True">
<shell:ApplicationBarIconButton Click="ActionInstallDebugConsole" IconUri="/Images/appbar.debug.rest.png" Text="Debug"/>
<shell:ApplicationBar.MenuItems>
<shell:ApplicationBarMenuItem Click="ActionRunFirebug" Text="Run firebug"/>
<shell:ApplicationBarMenuItem Click="ActionConnectWeinreDebugger" Text="Weinre debugger"/>
<shell:ApplicationBarMenuItem Click="ActionRunFirebug" Text="Run firebug"/>
<shell:ApplicationBarMenuItem Click="ActionClearPerfLog" Text="Clear Perf Log"/>
<shell:ApplicationBarMenuItem Click="ActionGetPerfLog" Text="Get Perf Log"/>
<!--<shell:ApplicationBarMenuItem Click="ActionRunTestScript" Text="Run test script"/>-->
</shell:ApplicationBar.MenuItems>
</shell:ApplicationBar>
Expand Down
17 changes: 17 additions & 0 deletions WindowsPhone/Views/MainPage.xaml.cs
Expand Up @@ -17,6 +17,7 @@
using IE.Debug.Core;
using IE.Debug.WindowsPhone.Controls;
using Microsoft.Phone.Shell;
using Microsoft.Phone.Info;

namespace IE.Debug.WindowsPhone.Views
{
Expand All @@ -38,6 +39,22 @@ private void ActionRunFirebug(object sender, EventArgs e)
{
WebPageDebugger.InstallFirebug();
}

private void ActionConnectWeinreDebugger(object sender, EventArgs e)
{
WebPageDebugger.ConnectWeinerDebugger();
}

private void ActionClearPerfLog(object sender, EventArgs e)
{
WebPageDebugger.ExecuteCustomScript("window.profiler.reset();");
}

private void ActionGetPerfLog(object sender, EventArgs e)
{
WebPageDebugger.ExecuteCustomScript("console.log($dumpProfileJSON (window.profiler));");
}

private void ActionInstallDebugConsole(object sender, EventArgs e)
{
WebPageDebugger.InstallDebugConsole();
Expand Down

0 comments on commit d7d330b

Please sign in to comment.