Skip to content

Commit

Permalink
Working on Google Chrome extension
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeche committed Feb 9, 2011
1 parent 7f50f62 commit e317aa1
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .externalToolBuilders/XML View builder.launch
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.ant.AntBuilderLaunchConfigurationType">
<stringAttribute key="org.eclipse.ant.ui.ATTR_ANT_AUTO_TARGETS" value="chrome.extension,"/>
<booleanAttribute key="org.eclipse.ant.ui.ATTR_TARGETS_UPDATED" value="true"/>
<booleanAttribute key="org.eclipse.ant.ui.DEFAULT_VM_INSTALL" value="false"/>
<stringAttribute key="org.eclipse.debug.core.ATTR_REFRESH_SCOPE" value="${project}"/>
Expand All @@ -8,6 +9,6 @@
<booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="true"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="xmlview"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${workspace_loc:/xmlview/build/build.xml}"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS" value=""/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS" value="full,incremental,auto,"/>
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED" value="true"/>
</launchConfiguration>
2 changes: 1 addition & 1 deletion .project
Expand Up @@ -12,7 +12,7 @@
</buildCommand>
<buildCommand>
<name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
<triggers>full,incremental,</triggers>
<triggers>auto,full,incremental,</triggers>
<arguments>
<dictionary>
<key>LaunchConfigHandle</key>
Expand Down
4 changes: 4 additions & 0 deletions build/build.properties
Expand Up @@ -3,9 +3,13 @@ dist.css.dir=${dist.dir}/css
dist.css-full.dir=${dist.dir}/css-full
dist.js.dir=${dist.dir}/js

dist.chrome.dir=${dist.dir}/chrome

js-src.dir=${basedir}/src
css-src.dir=${basedir}/css

chrome-src.dir=${basedir}/extensions/chrome

webtasks.dir=${basedir}/ant-tools
webtasks.use-cc=false
force-rebuild=no
25 changes: 23 additions & 2 deletions build/build.xml
Expand Up @@ -19,8 +19,9 @@
<file name="settings.js"/>
<file name="renderer.js"/>
<file name="search.js"/>
<file name="search_ui.js"/>
<file name="controller.js"/>
<!-- <file name="dnd.js"/> -->
<file name="dnd.js"/>
</filelist>

<target name="compile.js" depends="init">
Expand All @@ -38,7 +39,27 @@
<compress-css dir="${css-src.dir}" todir="${dist.css.dir}" force="${force-rebuild}"/>
</target>

<target name="compile" depends="compile.css, compile.js">
<target name="chrome.extension" depends="init" description="Build Google Chrome extension">
<mkdir dir="${dist.chrome.dir}"/>
<copy todir="${dist.chrome.dir}">
<fileset dir="${chrome-src.dir}"/>
</copy>
<concat destfile="${dist.chrome.dir}/xv.js">
<filelist dir="${js-src.dir}">
<file name="lib/underscore.js"/>
<file name="lib/js-signals.js"/>
<file name="signals.js"/>
<file name="utils.js"/>
<file name="dom.js"/>
<file name="settings.js"/>
<file name="renderer.js"/>
<file name="search.js"/>
<file name="controller.js"/>
</filelist>
</concat>
</target>

<target name="compile" depends="compile.css, compile.js, chrome.extension">
<copy file="${basedir}/xml-pretty-print.xslt" tofile="${dist.dir}/xmlview.xsl"/>
<echo>Build done</echo>
</target>
Expand Down
3 changes: 3 additions & 0 deletions extensions/chrome/background.html
@@ -0,0 +1,3 @@
<html>

</html>
26 changes: 26 additions & 0 deletions extensions/chrome/controller.js
@@ -0,0 +1,26 @@
function isXML(doc) {
return !(doc instanceof HTMLDocument || doc instanceof SVGDocument);
}

function canTransform() {
return document && isXML(document) && document.documentElement;
}

xv_dom.getByClass = function(class_name, context) {
return _.filter((context || document).getElementsByTagName('*'), function(n) {
return xv_dom.hasClass(n, class_name);
});
};

if (canTransform()) {
var html = xv_dom.fromHTML('<html><body>' +
'<div class="xv-source-pane"><div class="xv-source-pane-inner"></div></div>' +
'</body></html>');

var source_doc = document.documentElement;

var pi = document.createProcessingInstruction('xml-stylesheet', 'type="text/css" href="' + chrome.extension.getURL('xv.css') + '"');
document.insertBefore(pi, document.firstChild);

document.replaceChild(html, document.documentElement);
}
16 changes: 16 additions & 0 deletions extensions/chrome/manifest.json
@@ -0,0 +1,16 @@
{
"name" : "XV",
"version" : "1.0",
"description" : "View XML files in Google Chrome",
"background_page": "background.html",
"permissions" : [
"tabs",
"http://*/*",
"https://*/*"
],
"content_scripts": [{
"js": ["xv.js", "controller.js"],
"matches": ["http://*/*", "https://*/*", "file://*/*"],
"run_at": "document_end"
}]
}
15 changes: 15 additions & 0 deletions extensions/chrome/xv.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e317aa1

Please sign in to comment.