Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(513)

Side by Side Diff: extension/background.js

Issue 11092092: Support compiling templates in the browser. Base URL: git@github.com:dart-lang/dart-web-components.git@master
Patch Set: Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « extension/background.html ('k') | extension/build.sh » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Glue code that interacts with dwc_compiler.dart to proxy arbitrary content
6 // for urls.
7
8
9 var existingRuleIds = {};
10 var onParse = null;
11
12 // TODO(jacobr): set the onParse property directly from Dart.
13 function setOnParseCallback(cb) {
14 onParse = cb;
15 }
16
17 function proxyUrls(port, requests) {
18 // Unfortunately we have to create the data urls from the content script due
19 // to chrome security restrictions.
20 port.postMessage({type: 'CREATE_DATA_URLS', requests: requests});
21 }
22
23 function onProxyUrls(requests) {
24 var rulesToAdd = [];
25 var ruleIdsToRemove = [];
26 for (var i = 0; i < requests.length; i++) {
27 var request = requests[i];
28 var url = request.url;
29 var redirectUrl = request.redirectUrl;
30 var rule = {
31 conditions: [
32 new chrome.declarativeWebRequest.RequestMatcher(
33 {url: {urlEquals: url}})
34 ],
35 actions: [
36 new chrome.declarativeWebRequest.RedirectRequest(
37 {redirectUrl: redirectUrl})
38 ]};
39 if (existingRuleIds[url]) {
40 ruleIdsToRemove.push(existingRuleIds[url]);
41 }
42 rulesToAdd.push(rule);
43 }
44
45 if (ruleIdsToRemove.length > 0) {
46 chrome.declarativeWebRequest.onRequest.removeRules(ruleIdsToRemove);
47 }
48 chrome.declarativeWebRequest.onRequest.addRules(rulesToAdd, function(added) {
49 for(var i = 0; i < added.length; i++) {
50 var r = added[i];
51 existingRuleIds[r.conditions[0].url.urlEquals] = r.id;
52 }
53 // TODO(jacobr): notify caller that the proxy server is ready to use.
54 })
55 }
56 chrome.extension.onConnect.addListener(function(port) {
57 if (port.name == "parse") {
58 // Listen to requests from chrome tabs to parse templates.
59 port.onMessage.addListener(function(msg) {
60 onParse(port, msg.url);
61 });
62 } else if (port.name == "proxy") {
63 // Listen for requests to proxy urls.
64 port.onMessage.addListener(function(msg) {
65 onProxyUrls(msg.requests);
66 });
67 }
68 });
OLDNEW
« no previous file with comments | « extension/background.html ('k') | extension/build.sh » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698