Skip to content

Commit 0658b2d

Browse files
committed
Merge branch 'extension_chrome' into chrome-extension
2 parents 13cf9ab + 97ebd26 commit 0658b2d

File tree

3 files changed

+56
-13
lines changed

3 files changed

+56
-13
lines changed

Makefile

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ BUILD_TARGET := $(BUILD_DIR)/pdf.js
44
DEFAULT_BROWSERS := resources/browser_manifests/browser_manifest.json
55
DEFAULT_TESTS := test_manifest.json
66

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

1011
all: bundle
1112

@@ -125,7 +126,7 @@ browser-test:
125126
#
126127
# <http://code.google.com/closure/utilities/docs/linter_howto.html>
127128
SRC_DIRS := . src utils web test examples/helloworld extensions/firefox \
128-
extensions/firefox/components
129+
extensions/firefox/components extensions/chrome
129130
GJSLINT_FILES = $(foreach DIR,$(SRC_DIRS),$(wildcard $(DIR)/*.js))
130131
lint:
131132
gjslint --nojsdoc $(GJSLINT_FILES)
@@ -143,7 +144,7 @@ web: | production extension compiler pages-repo
143144
@cp $(BUILD_TARGET) $(GH_PAGES)/$(BUILD_TARGET)
144145
@cp -R web/* $(GH_PAGES)/web
145146
@cp web/images/* $(GH_PAGES)/web/images
146-
@cp $(EXTENSION_SRC)/*.xpi $(GH_PAGES)/$(EXTENSION_SRC)
147+
@cp $(EXTENSION_SRC)/firefox/*.xpi $(GH_PAGES)/$(EXTENSION_SRC)/firefox/
147148
@cp $(GH_PAGES)/web/index.html.template $(GH_PAGES)/index.html;
148149
@mv -f $(GH_PAGES)/web/viewer-production.html $(GH_PAGES)/web/viewer.html;
149150
@cd $(GH_PAGES); git add -A;
@@ -166,7 +167,7 @@ pages-repo: | $(BUILD_DIR)
166167
@mkdir -p $(GH_PAGES)/web;
167168
@mkdir -p $(GH_PAGES)/web/images;
168169
@mkdir -p $(GH_PAGES)/build;
169-
@mkdir -p $(GH_PAGES)/$(EXTENSION_SRC);
170+
@mkdir -p $(GH_PAGES)/$(EXTENSION_SRC)/firefox;
170171

171172
# # make compiler
172173
# #
@@ -186,6 +187,8 @@ pages-repo: | $(BUILD_DIR)
186187
# This target produce a restartless firefox extension containing a
187188
# copy of the pdf.js source.
188189
CONTENT_DIR := content
190+
FIREFOX_CONTENT_DIR := $(EXTENSION_SRC)/firefox/$(CONTENT_DIR)/
191+
CHROME_CONTENT_DIR := $(EXTENSION_SRC)/chrome/$(CONTENT_DIR)/
189192
PDF_WEB_FILES = \
190193
web/images \
191194
web/compatibility.js \
@@ -195,16 +198,28 @@ PDF_WEB_FILES = \
195198
$(NULL)
196199
extension: | production
197200
# Copy a standalone version of pdf.js inside the content directory
198-
@rm -Rf $(EXTENSION_SRC)/$(CONTENT_DIR)/
199-
@mkdir -p $(EXTENSION_SRC)/$(CONTENT_DIR)/$(BUILD_DIR)
200-
@mkdir -p $(EXTENSION_SRC)/$(CONTENT_DIR)/web
201-
@cp $(BUILD_TARGET) $(EXTENSION_SRC)/$(CONTENT_DIR)/$(BUILD_DIR)
202-
@cp -r $(PDF_WEB_FILES) $(EXTENSION_SRC)/$(CONTENT_DIR)/web/
203-
@mv -f $(EXTENSION_SRC)/$(CONTENT_DIR)/web/viewer-production.html $(EXTENSION_SRC)/$(CONTENT_DIR)/web/viewer.html
201+
@rm -Rf $(FIREFOX_CONTENT_DIR)
202+
@mkdir -p $(FIREFOX_CONTENT_DIR)/$(BUILD_DIR)
203+
@mkdir -p $(FIREFOX_CONTENT_DIR)/web
204+
@cp $(BUILD_TARGET) $(FIREFOX_CONTENT_DIR)/$(BUILD_DIR)
205+
@cp -r $(PDF_WEB_FILES) $(FIREFOX_CONTENT_DIR)/web/
206+
@mv -f $(FIREFOX_CONTENT_DIR)/web/viewer-production.html $(FIREFOX_CONTENT_DIR)/web/viewer.html
204207

205208
# Create the xpi
206-
@cd $(EXTENSION_SRC); zip -r $(EXTENSION_NAME) *
207-
@echo "extension created: " $(EXTENSION_NAME)
209+
@cd $(EXTENSION_SRC)/firefox; zip -r $(FIREFOX_EXTENSION_NAME) *
210+
@echo "extension created: " $(FIREFOX_EXTENSION_NAME)
211+
212+
# Copy a standalone version of pdf.js inside the extension directory
213+
@rm -Rf $(CHROME_CONTENT_DIR)
214+
@mkdir -p $(CHROME_CONTENT_DIR)/$(BUILD_DIR)
215+
@mkdir -p $(CHROME_CONTENT_DIR)/web
216+
@cp $(BUILD_TARGET) $(CHROME_CONTENT_DIR)/$(BUILD_DIR)
217+
@cp -r $(PDF_WEB_FILES) $(CHROME_CONTENT_DIR)/web/
218+
@mv -f $(CHROME_CONTENT_DIR)/web/viewer-production.html $(CHROME_CONTENT_DIR)/web/viewer.html
219+
220+
# Create the crx
221+
#TODO
222+
208223

209224

210225
# 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)