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

Side by Side Diff: Source/core/page/DOMWindow.cpp

Issue 19675008: Move btoa() / atob() implementation out of DOMWindow (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Take Kentaro's feedback into consideration Created 7 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/page/DOMWindow.h ('k') | Source/core/page/DOMWindowBase64.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2007, 2008, 2010 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 2008, 2010 Apple Inc. All rights reserved.
3 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) 3 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 11 matching lines...) Expand all
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */ 25 */
26 26
27 #include "config.h" 27 #include "config.h"
28 #include "core/page/DOMWindow.h" 28 #include "core/page/DOMWindow.h"
29 29
30 #include "wtf/MainThread.h" 30 #include "wtf/MainThread.h"
31 #include "wtf/MathExtras.h" 31 #include "wtf/MathExtras.h"
32 #include "wtf/text/Base64.h"
33 #include "wtf/text/WTFString.h" 32 #include "wtf/text/WTFString.h"
34 #include <algorithm> 33 #include <algorithm>
35 #include "RuntimeEnabledFeatures.h" 34 #include "RuntimeEnabledFeatures.h"
36 #include "bindings/v8/ScriptCallStackFactory.h" 35 #include "bindings/v8/ScriptCallStackFactory.h"
37 #include "bindings/v8/ScriptController.h" 36 #include "bindings/v8/ScriptController.h"
38 #include "bindings/v8/SerializedScriptValue.h" 37 #include "bindings/v8/SerializedScriptValue.h"
39 #include "core/css/CSSComputedStyleDeclaration.h" 38 #include "core/css/CSSComputedStyleDeclaration.h"
40 #include "core/css/CSSRuleList.h" 39 #include "core/css/CSSRuleList.h"
41 #include "core/css/DOMWindowCSS.h" 40 #include "core/css/DOMWindowCSS.h"
42 #include "core/css/MediaQueryList.h" 41 #include "core/css/MediaQueryList.h"
(...skipping 893 matching lines...) Expand 10 before | Expand all | Expand 10 after
936 if (!page) 935 if (!page)
937 return String(); 936 return String();
938 937
939 String returnValue; 938 String returnValue;
940 if (page->chrome().runJavaScriptPrompt(m_frame, message, defaultValue, retur nValue)) 939 if (page->chrome().runJavaScriptPrompt(m_frame, message, defaultValue, retur nValue))
941 return returnValue; 940 return returnValue;
942 941
943 return String(); 942 return String();
944 } 943 }
945 944
946 String DOMWindow::btoa(const String& stringToEncode, ExceptionCode& ec)
947 {
948 if (stringToEncode.isNull())
949 return String();
950
951 if (!stringToEncode.containsOnlyLatin1()) {
952 ec = InvalidCharacterError;
953 return String();
954 }
955
956 return base64Encode(stringToEncode.latin1());
957 }
958
959 String DOMWindow::atob(const String& encodedString, ExceptionCode& ec)
960 {
961 if (encodedString.isNull())
962 return String();
963
964 if (!encodedString.containsOnlyLatin1()) {
965 ec = InvalidCharacterError;
966 return String();
967 }
968
969 Vector<char> out;
970 if (!base64Decode(encodedString, out, Base64FailOnInvalidCharacter)) {
971 ec = InvalidCharacterError;
972 return String();
973 }
974
975 return String(out.data(), out.size());
976 }
977
978 bool DOMWindow::find(const String& string, bool caseSensitive, bool backwards, b ool wrap, bool /*wholeWord*/, bool /*searchInFrames*/, bool /*showDialog*/) cons t 945 bool DOMWindow::find(const String& string, bool caseSensitive, bool backwards, b ool wrap, bool /*wholeWord*/, bool /*searchInFrames*/, bool /*showDialog*/) cons t
979 { 946 {
980 if (!isCurrentlyDisplayedInFrame()) 947 if (!isCurrentlyDisplayedInFrame())
981 return false; 948 return false;
982 949
983 // FIXME (13016): Support wholeWord, searchInFrames and showDialog 950 // FIXME (13016): Support wholeWord, searchInFrames and showDialog
984 return m_frame->editor()->findString(string, !backwards, caseSensitive, wrap , false); 951 return m_frame->editor()->findString(string, !backwards, caseSensitive, wrap , false);
985 } 952 }
986 953
987 bool DOMWindow::offscreenBuffering() const 954 bool DOMWindow::offscreenBuffering() const
(...skipping 967 matching lines...) Expand 10 before | Expand all | Expand 10 after
1955 1922
1956 Frame* child = frame->tree()->scopedChild(index); 1923 Frame* child = frame->tree()->scopedChild(index);
1957 if (child) 1924 if (child)
1958 return child->domWindow(); 1925 return child->domWindow();
1959 1926
1960 return 0; 1927 return 0;
1961 } 1928 }
1962 1929
1963 1930
1964 } // namespace WebCore 1931 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/page/DOMWindow.h ('k') | Source/core/page/DOMWindowBase64.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698