]> git.parisson.com Git - pdf.js.git/commitdiff
Initial Chrome extension import
authorVivien Nicolas <21@vingtetun.org>
Tue, 18 Oct 2011 17:43:43 +0000 (19:43 +0200)
committerVivien Nicolas <21@vingtetun.org>
Tue, 18 Oct 2011 17:43:43 +0000 (19:43 +0200)
Makefile
extensions/chrome/manifest.json [new file with mode: 0644]
extensions/chrome/pdfHandler.html [new file with mode: 0644]

index ebffb374c7d2a640357e646fefe6f885d94028ba..603b33b6ae4f2ad84899aa13666943db7f110442 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -3,8 +3,9 @@ BUILD_DIR := build
 DEFAULT_BROWSERS := resources/browser_manifests/browser_manifest.json
 DEFAULT_TESTS := test_manifest.json
 
-EXTENSION_SRC := ./extensions/firefox
-EXTENSION_NAME := pdf.js.xpi
+EXTENSION_SRC := ./extensions/
+FIREFOX_EXTENSION_NAME := pdf.js.xpi
+CHROME_EXTENSION_NAME := pdf.js.crx
 
 # Let folks define custom rules for their clones.
 -include local.mk
@@ -17,6 +18,7 @@ PDF_JS_FILES = \
        fonts.js \
        metrics.js \
        charsets.js \
+       cidmaps.js \
        glyphlist.js \
        $(NULL)
 
@@ -92,7 +94,7 @@ browser-test:
 #
 # <http://code.google.com/closure/utilities/docs/linter_howto.html>
 SRC_DIRS := . utils worker web test examples/helloworld extensions/firefox \
-            extensions/firefox/components
+            extensions/firefox/components extensions/chrome
 GJSLINT_FILES = $(foreach DIR,$(SRC_DIRS),$(wildcard $(DIR)/*.js))
 lint:
        gjslint $(GJSLINT_FILES)
@@ -110,7 +112,8 @@ web: | extension compiler pages-repo \
        $(addprefix $(GH_PAGES)/, $(PDF_JS_FILES)) \
        $(addprefix $(GH_PAGES)/, $(wildcard web/*.*)) \
        $(addprefix $(GH_PAGES)/, $(wildcard web/images/*.*)) \
-       $(addprefix $(GH_PAGES)/, $(wildcard $(EXTENSION_SRC)/*.xpi))
+       $(addprefix $(GH_PAGES)/, $(wildcard $(EXTENSION_SRC)/firefox/*.xpi)) \
+       $(addprefix $(GH_PAGES)/, $(wildcard $(EXTENSION_SRC)/chrome/*.crx))
 
        @cp $(GH_PAGES)/web/index.html.template $(GH_PAGES)/index.html;
        @cd $(GH_PAGES); git add -A;
@@ -132,7 +135,8 @@ pages-repo: | $(BUILD_DIR)
        fi;
        @mkdir -p $(GH_PAGES)/web;
        @mkdir -p $(GH_PAGES)/web/images;
-       @mkdir -p $(GH_PAGES)/$(EXTENSION_SRC);
+       @mkdir -p $(GH_PAGES)/$(EXTENSION_SRC)/firefox;
+       @mkdir -p $(GH_PAGES)/$(EXTENSION_SRC)/chrome;
 
 $(GH_PAGES)/%.js: %.js
        @cp $< $@
@@ -143,9 +147,11 @@ $(GH_PAGES)/web/%: web/%
 $(GH_PAGES)/web/images/%: web/images/%
        @cp $< $@
 
-$(GH_PAGES)/$(EXTENSION_SRC)/%: $(EXTENSION_SRC)/%
+$(GH_PAGES)/$(EXTENSION_SRC)/firefox/%: $(EXTENSION_SRC)/firefox/%
        @cp -R $< $@
 
+$(GH_PAGES)/$(EXTENSION_SRC)/chrome/%: $(EXTENSION_SRC)/chrome/%
+
 # # make compiler
 # #
 # # This target downloads the Closure compiler, and places it in the
@@ -163,7 +169,7 @@ $(GH_PAGES)/$(EXTENSION_SRC)/%: $(EXTENSION_SRC)/%
 #
 # This target produce a restartless firefox extension containing a
 # copy of the pdf.js source.
-CONTENT_DIR := content
+CONTENT_DIR := firefox/content
 PDF_WEB_FILES = \
        web/images \
        web/compatibility.js \
@@ -179,8 +185,17 @@ extension:
        @cp -r $(PDF_WEB_FILES) $(EXTENSION_SRC)/$(CONTENT_DIR)/web/
 
        # Create the xpi
-       @cd $(EXTENSION_SRC); zip -r $(EXTENSION_NAME) *
-       @echo "extension created: " $(EXTENSION_NAME)
+       @cd $(EXTENSION_SRC)/firefox; zip -r $(FIREFOX_EXTENSION_NAME) *
+       @echo "extension created: " $(FIREFOX_EXTENSION_NAME)
+
+  # Copy a standalone version of pdf.js inside the extension directory
+       @cp $(PDF_JS_FILES) $(EXTENSION_SRC)/chrome/ 
+       @mkdir -p $(EXTENSION_SRC)/chrome/web
+       @cp -r $(PDF_WEB_FILES) $(EXTENSION_SRC)/chrome/web/
+
+  # Create the crx
+  #TODO
+
 
 
 # Make sure there's a build directory.
diff --git a/extensions/chrome/manifest.json b/extensions/chrome/manifest.json
new file mode 100644 (file)
index 0000000..629e41b
--- /dev/null
@@ -0,0 +1,11 @@
+{
+  "name": "uriloader@pdf.js",
+  "version": "0.1",
+  "description": "Read PDF Document",
+  "permissions": [
+    "experimental",
+    "http://*/*.pdf",
+    "file:///*/*.pdf"
+  ],
+  "background_page": "pdfHandler.html"
+}
diff --git a/extensions/chrome/pdfHandler.html b/extensions/chrome/pdfHandler.html
new file mode 100644 (file)
index 0000000..dcce1a6
--- /dev/null
@@ -0,0 +1,17 @@
+<!doctype html>
+<script>
+chrome.experimental.webRequest.onBeforeRequest.addListener(
+  function(details) {
+    var url = chrome.extension.getURL('') + 'web/viewer.html?file=' + details.url;
+    return { redirectUrl: url };
+  },
+  {
+    urls: [
+      "http://*/*.pdf",
+      "file://*/*.pdf",
+    ],
+    types: [ "main_frame" ]
+  },
+  ["blocking"]);
+</script>
+