Skip to content

Commit 08af0c7

Browse files
committed
Initial Chrome extension import
1 parent b8a5b76 commit 08af0c7

File tree

3 files changed

+52
-9
lines changed

3 files changed

+52
-9
lines changed

Makefile

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ BUILD_DIR := build
33
DEFAULT_BROWSERS := resources/browser_manifests/browser_manifest.json
44
DEFAULT_TESTS := test_manifest.json
55

6-
EXTENSION_SRC := ./extensions/firefox
7-
EXTENSION_NAME := pdf.js.xpi
6+
EXTENSION_SRC := ./extensions/
7+
FIREFOX_EXTENSION_NAME := pdf.js.xpi
8+
CHROME_EXTENSION_NAME := pdf.js.crx
89

910
# Let folks define custom rules for their clones.
1011
-include local.mk
@@ -17,6 +18,7 @@ PDF_JS_FILES = \
1718
fonts.js \
1819
metrics.js \
1920
charsets.js \
21+
cidmaps.js \
2022
glyphlist.js \
2123
$(NULL)
2224

@@ -92,7 +94,7 @@ browser-test:
9294
#
9395
# <http://code.google.com/closure/utilities/docs/linter_howto.html>
9496
SRC_DIRS := . utils worker web test examples/helloworld extensions/firefox \
95-
extensions/firefox/components
97+
extensions/firefox/components extensions/chrome
9698
GJSLINT_FILES = $(foreach DIR,$(SRC_DIRS),$(wildcard $(DIR)/*.js))
9799
lint:
98100
gjslint $(GJSLINT_FILES)
@@ -110,7 +112,8 @@ web: | extension compiler pages-repo \
110112
$(addprefix $(GH_PAGES)/, $(PDF_JS_FILES)) \
111113
$(addprefix $(GH_PAGES)/, $(wildcard web/*.*)) \
112114
$(addprefix $(GH_PAGES)/, $(wildcard web/images/*.*)) \
113-
$(addprefix $(GH_PAGES)/, $(wildcard $(EXTENSION_SRC)/*.xpi))
115+
$(addprefix $(GH_PAGES)/, $(wildcard $(EXTENSION_SRC)/firefox/*.xpi)) \
116+
$(addprefix $(GH_PAGES)/, $(wildcard $(EXTENSION_SRC)/chrome/*.crx))
114117

115118
@cp $(GH_PAGES)/web/index.html.template $(GH_PAGES)/index.html;
116119
@cd $(GH_PAGES); git add -A;
@@ -132,7 +135,8 @@ pages-repo: | $(BUILD_DIR)
132135
fi;
133136
@mkdir -p $(GH_PAGES)/web;
134137
@mkdir -p $(GH_PAGES)/web/images;
135-
@mkdir -p $(GH_PAGES)/$(EXTENSION_SRC);
138+
@mkdir -p $(GH_PAGES)/$(EXTENSION_SRC)/firefox;
139+
@mkdir -p $(GH_PAGES)/$(EXTENSION_SRC)/chrome;
136140

137141
$(GH_PAGES)/%.js: %.js
138142
@cp $< $@
@@ -143,9 +147,11 @@ $(GH_PAGES)/web/%: web/%
143147
$(GH_PAGES)/web/images/%: web/images/%
144148
@cp $< $@
145149

146-
$(GH_PAGES)/$(EXTENSION_SRC)/%: $(EXTENSION_SRC)/%
150+
$(GH_PAGES)/$(EXTENSION_SRC)/firefox/%: $(EXTENSION_SRC)/firefox/%
147151
@cp -R $< $@
148152

153+
$(GH_PAGES)/$(EXTENSION_SRC)/chrome/%: $(EXTENSION_SRC)/chrome/%
154+
149155
# # make compiler
150156
# #
151157
# # This target downloads the Closure compiler, and places it in the
@@ -163,7 +169,7 @@ $(GH_PAGES)/$(EXTENSION_SRC)/%: $(EXTENSION_SRC)/%
163169
#
164170
# This target produce a restartless firefox extension containing a
165171
# copy of the pdf.js source.
166-
CONTENT_DIR := content
172+
CONTENT_DIR := firefox/content
167173
PDF_WEB_FILES = \
168174
web/images \
169175
web/compatibility.js \
@@ -179,8 +185,17 @@ extension:
179185
@cp -r $(PDF_WEB_FILES) $(EXTENSION_SRC)/$(CONTENT_DIR)/web/
180186

181187
# Create the xpi
182-
@cd $(EXTENSION_SRC); zip -r $(EXTENSION_NAME) *
183-
@echo "extension created: " $(EXTENSION_NAME)
188+
@cd $(EXTENSION_SRC)/firefox; zip -r $(FIREFOX_EXTENSION_NAME) *
189+
@echo "extension created: " $(FIREFOX_EXTENSION_NAME)
190+
191+
# Copy a standalone version of pdf.js inside the extension directory
192+
@cp $(PDF_JS_FILES) $(EXTENSION_SRC)/chrome/
193+
@mkdir -p $(EXTENSION_SRC)/chrome/web
194+
@cp -r $(PDF_WEB_FILES) $(EXTENSION_SRC)/chrome/web/
195+
196+
# Create the crx
197+
#TODO
198+
184199

185200

186201
# Make sure there's a build directory.

extensions/chrome/manifest.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "uriloader@pdf.js",
3+
"version": "0.1",
4+
"description": "Read PDF Document",
5+
"permissions": [
6+
"experimental",
7+
"http://*/*.pdf",
8+
"file:///*/*.pdf"
9+
],
10+
"background_page": "pdfHandler.html"
11+
}

extensions/chrome/pdfHandler.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!doctype html>
2+
<script>
3+
chrome.experimental.webRequest.onBeforeRequest.addListener(
4+
function(details) {
5+
var url = chrome.extension.getURL('') + 'web/viewer.html?file=' + details.url;
6+
return { redirectUrl: url };
7+
},
8+
{
9+
urls: [
10+
"http://*/*.pdf",
11+
"file://*/*.pdf",
12+
],
13+
types: [ "main_frame" ]
14+
},
15+
["blocking"]);
16+
</script>
17+

0 commit comments

Comments
 (0)