UPDATE ...
를 작동하면 너무 나쁜 소리가 나지 않는다
http://code.google.com/chrome/extensions/storage.html
옛날 방식
내가하는 일은 내 저장소에서 로컬 저장소에서 필요한 설정을 가져온 스크립트가있는 페이지를 가리키는 iframe을 만든 다음 콘텐츠 스크립트가 가져 오는 메시지의 부모에게 보냅니다. 그게 쓰레기 설명 이었어. 코드가 더 잘한다.) .......
내용 스크립트
// create the iframe for our page that sends the settings
var el = document.createElement("iframe");
el.setAttribute('src', chrome.extension.getURL("gimmeSettings.html"));
el.style.visibility="hidden";
document.body.appendChild(el);
// create the listner that listens for a message from our page that sends the settings
window.addEventListener("message", receiveSettings, false);
// function that gets called when we recieve a message from the page that sends the settings
function receiveSettings(event) {
//check to make sure the message came from our page
if (event.origin !== "chrome-extension://"+chrome.i18n.getMessage("@@extension_id")) return;
//message came from our extension, do stuff with it
console.debug(event.data);
// clean up
window.removeEventListener("message", receiveSettings, false);
el.parentNode.removeChild(el);
}
gimmeSettings.html의 JS
// post the message with our settings
parent.postMessage(localStorage.getItem("testing"), "*");
Options.html의 JS
localStorage.setItem("testing","bleh");
매니페스트
{
"name": "Getting at an extensions local storage from a content script",
"description" : "Getting at an extensions local storage from a content script. Be aware that other pages/extensions can use this to get at your settings, but not change them...so dont include sensitvie data.",
"content_scripts": [
{
"matches": ["<all_urls>"],
"js" : ["myscript.js"],
"run_at":"document_idle"
}
],
"permissions": [
"tabs", "<all_urls>"
],
"manifest_version": 2,
"web_accessible_resources": [
"gimmeSettings.html"
],
"options_page": "options.html",
"version":"1.0"
}
몇 가지주의해야 할 ....
다른 페이지 및 확장이 용이하므로이 방법으로 민감한 데이터를 사용 해달라고, 또한 확장의 설정을 얻기 위해 이것을 사용할 수 있습니다.
내가 말할 수있는 최선의 방법은 그 사람들이 그 페이지를 통해 설정을 변경할 수있는 방법이 없다는 것입니다.
메니저 버전 2를 사용 중이며 페이지 gimmeSettings를 액세스 가능하도록 설정했습니다. 차이점을 알지 못하는 경우 버전 2를 추가하면 실제로 읽어야합니다. ... http://code.google.com/chrome/extensions/trunk/manifestVersion.html
그리고 작업 예제를 원할 경우 .....
http://forum.valorsolo.com/viewtopic.php?f=36&t=375
감사합니다. 좋은 소식입니다. 또한, 방금 라이브러리에 포장 될 수 있다고 생각했습니다 (이전에 Chrome 개발자가 더 예쁘게 API를 만들었다면 사용하게 될 것입니다). 사실이 대답은 나를 위해 옵션 페이지를 가진 확장을 만들고 싶습니다. :) 축하합니다. –
오, 나는 생각이났다 : 어쩌면 민감한 설정이 일부 [비대칭 encription] (http://www.hanewin.net/encrypt/) (링크가 해독을 구현하지 않지만 시작점 임)을 사용하여 전송 될 수 있습니다. 그러나 그것은 많은 해킹의 지옥처럼 보입니다. 그러나 재미있게 들린다! 이런 일을하는 데 하루 더 많은 시간을해야합니다. –