| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 function customMailtoUrl() { | 5 function customMailtoUrl() { |
| 6 if (window.localStorage == null) | 6 if (window.localStorage == null) |
| 7 return ""; | 7 return ""; |
| 8 if (window.localStorage.customMailtoUrl == null) | 8 if (window.localStorage.customMailtoUrl == null) |
| 9 return ""; | 9 return ""; |
| 10 return window.localStorage.customMailtoUrl; | 10 return window.localStorage.customMailtoUrl; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 console.log('Custom url: ' + action_url); | 35 console.log('Custom url: ' + action_url); |
| 36 chrome.tabs.create({ url: action_url }); | 36 chrome.tabs.create({ url: action_url }); |
| 37 } else { | 37 } else { |
| 38 // Plain vanilla mailto links open up in the same tab to prevent | 38 // Plain vanilla mailto links open up in the same tab to prevent |
| 39 // blank tabs being left behind. | 39 // blank tabs being left behind. |
| 40 console.log('Action url: ' + action_url); | 40 console.log('Action url: ' + action_url); |
| 41 chrome.tabs.update(tab_id, { url: action_url }); | 41 chrome.tabs.update(tab_id, { url: action_url }); |
| 42 } | 42 } |
| 43 } | 43 } |
| 44 | 44 |
| 45 chrome.extension.onConnect.addListener(function(port) { | 45 chrome.runtime.onConnect.addListener(function(port) { |
| 46 var tab = port.sender.tab; | 46 var tab = port.sender.tab; |
| 47 | 47 |
| 48 // This will get called by the content script we execute in | 48 // This will get called by the content script we execute in |
| 49 // the tab as a result of the user pressing the browser action. | 49 // the tab as a result of the user pressing the browser action. |
| 50 port.onMessage.addListener(function(info) { | 50 port.onMessage.addListener(function(info) { |
| 51 var max_length = 1024; | 51 var max_length = 1024; |
| 52 if (info.selection.length > max_length) | 52 if (info.selection.length > max_length) |
| 53 info.selection = info.selection.substring(0, max_length); | 53 info.selection = info.selection.substring(0, max_length); |
| 54 executeMailto(tab.id, info.title, tab.url, info.selection); | 54 executeMailto(tab.id, info.title, tab.url, info.selection); |
| 55 }); | 55 }); |
| 56 }); | 56 }); |
| 57 | 57 |
| 58 // Called when the user clicks on the browser action icon. | 58 // Called when the user clicks on the browser action icon. |
| 59 chrome.browserAction.onClicked.addListener(function(tab) { | 59 chrome.browserAction.onClicked.addListener(function(tab) { |
| 60 // We can only inject scripts to find the title on pages loaded with http | 60 // We can only inject scripts to find the title on pages loaded with http |
| 61 // and https so for all other pages, we don't ask for the title. | 61 // and https so for all other pages, we don't ask for the title. |
| 62 if (tab.url.indexOf("http:") != 0 && | 62 if (tab.url.indexOf("http:") != 0 && |
| 63 tab.url.indexOf("https:") != 0) { | 63 tab.url.indexOf("https:") != 0) { |
| 64 executeMailto(tab.id, "", tab.url, ""); | 64 executeMailto(tab.id, "", tab.url, ""); |
| 65 } else { | 65 } else { |
| 66 chrome.tabs.executeScript(null, {file: "content_script.js"}); | 66 chrome.tabs.executeScript(null, {file: "content_script.js"}); |
| 67 } | 67 } |
| 68 }); | 68 }); |
| OLD | NEW |