Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 var chrome; | 5 var chrome; |
| 6 if (!chrome) | 6 if (!chrome) |
| 7 chrome = {}; | 7 chrome = {}; |
| 8 if (!chrome.searchBox) { | 8 if (!chrome.searchBox) { |
| 9 chrome.searchBox = new function() { | 9 chrome.searchBox = new function() { |
| 10 var safeObjects = {}; | 10 var safeObjects = {}; |
| 11 chrome.searchBoxOnWindowReady = function() { | 11 chrome.searchBoxOnWindowReady = function() { |
| 12 // |searchBoxOnWindowReady| is used for initializing window context and | 12 // |searchBoxOnWindowReady| is used for initializing window context and |
| 13 // should be called only once per context. | 13 // should be called only once per context. |
| 14 safeObjects.ShadowRoot = window.WebKitShadowRoot; | |
| 15 safeObjects.defineProperty = Object.defineProperty; | 14 safeObjects.defineProperty = Object.defineProperty; |
| 16 delete window.chrome.searchBoxOnWindowReady; | 15 delete window.chrome.searchBoxOnWindowReady; |
| 17 }; | 16 }; |
| 18 | 17 |
| 19 // ========================================================================= | 18 // ========================================================================= |
| 20 // Constants | 19 // Constants |
| 21 // ========================================================================= | 20 // ========================================================================= |
| 22 var MAX_CLIENT_SUGGESTIONS_TO_DEDUPE = 6; | 21 var MAX_CLIENT_SUGGESTIONS_TO_DEDUPE = 6; |
| 23 var MAX_ALLOWED_DEDUPE_ATTEMPTS = 5; | 22 var MAX_ALLOWED_DEDUPE_ATTEMPTS = 5; |
| 24 | 23 |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 51 native function SetQuerySuggestionFromAutocompleteResult(); | 50 native function SetQuerySuggestionFromAutocompleteResult(); |
| 52 native function SetQuery(); | 51 native function SetQuery(); |
| 53 native function SetQueryFromAutocompleteResult(); | 52 native function SetQueryFromAutocompleteResult(); |
| 54 native function Show(); | 53 native function Show(); |
| 55 native function StartCapturingKeyStrokes(); | 54 native function StartCapturingKeyStrokes(); |
| 56 native function StopCapturingKeyStrokes(); | 55 native function StopCapturingKeyStrokes(); |
| 57 | 56 |
| 58 // Returns the |restrictedText| wrapped in a ShadowDOM. | 57 // Returns the |restrictedText| wrapped in a ShadowDOM. |
| 59 function SafeWrap(restrictedText) { | 58 function SafeWrap(restrictedText) { |
| 60 var node = document.createElement('div'); | 59 var node = document.createElement('div'); |
| 61 var nodeShadow = new safeObjects.ShadowRoot(node); | 60 var nodeShadow = node.webkitCreateShadowRoot(); |
|
dglazkov
2012/12/12 15:22:14
This is no longer "safe" though. May need extra wo
hayato
2012/12/13 01:09:20
Yeah, I have no idea about the usage of *safe* obj
David Black
2012/12/13 04:31:08
Above in the searchBoxOnWindowReady function, stor
| |
| 62 nodeShadow.applyAuthorStyles = true; | 61 nodeShadow.applyAuthorStyles = true; |
| 63 nodeShadow.innerHTML = | 62 nodeShadow.innerHTML = |
| 64 '<div style="width:700px!important;' + | 63 '<div style="width:700px!important;' + |
| 65 ' height:22px!important;' + | 64 ' height:22px!important;' + |
| 66 ' font-family:\'' + GetFont() + '\',\'Arial\'!important;' + | 65 ' font-family:\'' + GetFont() + '\',\'Arial\'!important;' + |
| 67 ' overflow:hidden!important;' + | 66 ' overflow:hidden!important;' + |
| 68 ' text-overflow:ellipsis!important">' + | 67 ' text-overflow:ellipsis!important">' + |
| 69 ' <nobr>' + restrictedText + '</nobr>' + | 68 ' <nobr>' + restrictedText + '</nobr>' + |
| 70 '</div>'; | 69 '</div>'; |
| 71 safeObjects.defineProperty(node, 'webkitShadowRoot', { value: null }); | |
| 72 return node; | 70 return node; |
| 73 } | 71 } |
| 74 | 72 |
| 75 // Wraps the AutocompleteResult query and URL into ShadowDOM nodes so that | 73 // Wraps the AutocompleteResult query and URL into ShadowDOM nodes so that |
| 76 // the JS cannot access them and deletes the raw values. | 74 // the JS cannot access them and deletes the raw values. |
| 77 function GetAutocompleteResultsWrapper() { | 75 function GetAutocompleteResultsWrapper() { |
| 78 var autocompleteResults = DedupeAutocompleteResults( | 76 var autocompleteResults = DedupeAutocompleteResults( |
| 79 GetAutocompleteResults()); | 77 GetAutocompleteResults()); |
| 80 var userInput = GetQuery(); | 78 var userInput = GetQuery(); |
| 81 for (var i = 0, result; result = autocompleteResults[i]; ++i) { | 79 for (var i = 0, result; result = autocompleteResults[i]; ++i) { |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 232 this.onchange = null; | 230 this.onchange = null; |
| 233 this.onsubmit = null; | 231 this.onsubmit = null; |
| 234 this.oncancel = null; | 232 this.oncancel = null; |
| 235 this.onresize = null; | 233 this.onresize = null; |
| 236 this.onautocompleteresults = null; | 234 this.onautocompleteresults = null; |
| 237 this.onkeypress = null; | 235 this.onkeypress = null; |
| 238 this.onkeycapturechange = null; | 236 this.onkeycapturechange = null; |
| 239 this.oncontextchange = null; | 237 this.oncontextchange = null; |
| 240 }; | 238 }; |
| 241 } | 239 } |
| OLD | NEW |