Commit 93b8d80e authored by Andrew Comminos's avatar Andrew Comminos Committed by Commit Bot

Unify WindowBase64 into WindowOrWorkerGlobalScope.

The HTML5 spec recently refactored WindowBase64 into
WindowOrWorkerGlobalScope, removing the need to reflect this in our IDL.
{btoa,atob} implementations have been merged into
window_or_worker_global_scope.{cc,h}.

This CL has no behavior changes.

Bug: 701498
Change-Id: Ib40b30e166ef3e4c0c92791f3ffecbb7bd1bed0b
Reviewed-on: https://chromium-review.googlesource.com/c/1351141Reviewed-by: default avatarKent Tamura <tkent@chromium.org>
Commit-Queue: Andrew Comminos <acomminos@fb.com>
Cr-Commit-Position: refs/heads/master@{#612020}
parent 1b39ce73
......@@ -540,7 +540,6 @@ core_dependency_idl_files =
"frame/navigator_language.idl",
"frame/navigator_on_line.idl",
"frame/navigator_user_activation.idl",
"frame/window_base64.idl",
"frame/window_event_handlers.idl",
"frame/window_or_worker_global_scope.idl",
"fullscreen/document_fullscreen.idl",
......
......@@ -42,8 +42,6 @@ blink_core_sources("frame") {
"dom_visual_viewport.h",
"dom_window.cc",
"dom_window.h",
"dom_window_base64.cc",
"dom_window_base64.h",
"embedded_content_view.h",
"event_handler_registry.cc",
"event_handler_registry.h",
......
......@@ -8,7 +8,6 @@
#include "third_party/blink/renderer/bindings/core/v8/serialization/transferables.h"
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/dom/events/event_target.h"
#include "third_party/blink/renderer/core/frame/dom_window_base64.h"
#include "third_party/blink/renderer/core/frame/frame.h"
#include "third_party/blink/renderer/platform/bindings/trace_wrapper_member.h"
#include "third_party/blink/renderer/platform/heap/handle.h"
......@@ -35,8 +34,7 @@ class WindowProxyManager;
// TODO(tkent): Rename DOMWindow to Window. The class was named as 'DOMWindow'
// because WebKit already had KJS::Window. We have no reasons to avoid
// blink::Window now.
class CORE_EXPORT DOMWindow : public EventTargetWithInlineData,
public DOMWindowBase64 {
class CORE_EXPORT DOMWindow : public EventTargetWithInlineData {
DEFINE_WRAPPERTYPEINFO();
public:
......
/*
* Copyright (C) 2006, 2007, 2008, 2010 Apple Inc. All rights reserved.
* Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
* Copyright (C) 2013 Samsung Electronics. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "third_party/blink/renderer/core/frame/dom_window_base64.h"
#include "third_party/blink/renderer/core/html/parser/html_parser_idioms.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/blink/renderer/platform/wtf/text/base64.h"
namespace blink {
String DOMWindowBase64::btoa(const String& string_to_encode,
ExceptionState& exception_state) {
if (string_to_encode.IsNull())
return String();
if (!string_to_encode.ContainsOnlyLatin1OrEmpty()) {
exception_state.ThrowDOMException(
DOMExceptionCode::kInvalidCharacterError,
"The string to be encoded contains "
"characters outside of the Latin1 range.");
return String();
}
return Base64Encode(string_to_encode.Latin1());
}
String DOMWindowBase64::atob(const String& encoded_string,
ExceptionState& exception_state) {
if (encoded_string.IsNull())
return String();
if (!encoded_string.ContainsOnlyLatin1OrEmpty()) {
exception_state.ThrowDOMException(
DOMExceptionCode::kInvalidCharacterError,
"The string to be decoded contains "
"characters outside of the Latin1 range.");
return String();
}
Vector<char> out;
if (!Base64Decode(encoded_string, out, IsHTMLSpace<UChar>,
kBase64ValidatePadding)) {
exception_state.ThrowDOMException(
DOMExceptionCode::kInvalidCharacterError,
"The string to be decoded is not correctly encoded.");
return String();
}
return String(out.data(), out.size());
}
} // namespace blink
/*
* Copyright (C) 2006, 2007, 2008, 2010 Apple Inc. All rights reserved.
* Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
* Copyright (C) 2013 Samsung Electronics. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_FRAME_DOM_WINDOW_BASE64_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_FRAME_DOM_WINDOW_BASE64_H_
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
namespace blink {
class ExceptionState;
class DOMWindowBase64 {
public:
String btoa(const String& string_to_encode, ExceptionState&);
String atob(const String& encoded_string, ExceptionState&);
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_FRAME_DOM_WINDOW_BASE64_H_
......@@ -232,6 +232,5 @@
};
Window implements GlobalEventHandlers;
Window implements WindowBase64;
Window implements WindowEventHandlers;
Window implements WindowOrWorkerGlobalScope;
/*
* Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
* Copyright (C) 2011 Google Inc. All rights reserved.
* Copyright (C) 2013 Samsung Electronics. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// https://html.spec.whatwg.org/#atob
[
NoInterfaceObject, // Always used on target of 'implements'
Exposed=(Window,Worker)
] interface WindowBase64 {
[RaisesException] DOMString btoa(DOMString btoa);
[RaisesException] DOMString atob(DOMString atob);
};
......@@ -39,10 +39,12 @@
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/core/frame/csp/content_security_policy.h"
#include "third_party/blink/renderer/core/frame/dom_timer.h"
#include "third_party/blink/renderer/core/html/parser/html_parser_idioms.h"
#include "third_party/blink/renderer/core/trustedtypes/trusted_types_util.h"
#include "third_party/blink/renderer/core/workers/worker_global_scope.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/blink/renderer/platform/weborigin/security_violation_reporting_policy.h"
#include "third_party/blink/renderer/platform/wtf/text/base64.h"
namespace blink {
......@@ -80,6 +82,48 @@ static bool IsAllowed(ScriptState* script_state,
return false;
}
String WindowOrWorkerGlobalScope::btoa(EventTarget&,
const String& string_to_encode,
ExceptionState& exception_state) {
if (string_to_encode.IsNull())
return String();
if (!string_to_encode.ContainsOnlyLatin1OrEmpty()) {
exception_state.ThrowDOMException(
DOMExceptionCode::kInvalidCharacterError,
"The string to be encoded contains "
"characters outside of the Latin1 range.");
return String();
}
return Base64Encode(string_to_encode.Latin1());
}
String WindowOrWorkerGlobalScope::atob(EventTarget&,
const String& encoded_string,
ExceptionState& exception_state) {
if (encoded_string.IsNull())
return String();
if (!encoded_string.ContainsOnlyLatin1OrEmpty()) {
exception_state.ThrowDOMException(
DOMExceptionCode::kInvalidCharacterError,
"The string to be decoded contains "
"characters outside of the Latin1 range.");
return String();
}
Vector<char> out;
if (!Base64Decode(encoded_string, out, IsHTMLSpace<UChar>,
kBase64ValidatePadding)) {
exception_state.ThrowDOMException(
DOMExceptionCode::kInvalidCharacterError,
"The string to be decoded is not correctly encoded.");
return String();
}
return String(out.data(), out.size());
}
int WindowOrWorkerGlobalScope::setTimeout(
ScriptState* script_state,
EventTarget& event_target,
......
......@@ -49,6 +49,13 @@ class WindowOrWorkerGlobalScope {
STATIC_ONLY(WindowOrWorkerGlobalScope);
public:
static String btoa(EventTarget&,
const String& string_to_encode,
ExceptionState&);
static String atob(EventTarget&,
const String& encoded_string,
ExceptionState&);
static int setTimeout(ScriptState*,
EventTarget&,
const ScriptValue& handler,
......
......@@ -33,6 +33,10 @@
NoInterfaceObject, // Always used on target of 'implements'
Exposed=(Window,Worker)
] interface WindowOrWorkerGlobalScope {
// base64 utility methods
[RaisesException] DOMString btoa(DOMString btoa);
[RaisesException] DOMString atob(DOMString atob);
// TODO(yukishiino): Use TimerHandler (or Function at least) to implement
// setTimeout and setInterval.
// https://html.spec.whatwg.org/C/webappapis.html#windoworworkerglobalscope-mixin
......
......@@ -39,7 +39,6 @@
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/core/frame/csp/content_security_policy.h"
#include "third_party/blink/renderer/core/frame/dom_timer_coordinator.h"
#include "third_party/blink/renderer/core/frame/dom_window_base64.h"
#include "third_party/blink/renderer/core/messaging/blink_transferable_message.h"
#include "third_party/blink/renderer/core/script/script.h"
#include "third_party/blink/renderer/core/workers/worker_animation_frame_provider.h"
......@@ -70,8 +69,7 @@ struct GlobalScopeCreationParams;
class CORE_EXPORT WorkerGlobalScope
: public WorkerOrWorkletGlobalScope,
public ActiveScriptWrappable<WorkerGlobalScope>,
public Supplementable<WorkerGlobalScope>,
public DOMWindowBase64 {
public Supplementable<WorkerGlobalScope> {
DEFINE_WRAPPERTYPEINFO();
USING_GARBAGE_COLLECTED_MIXIN(WorkerGlobalScope);
......
......@@ -79,7 +79,6 @@
[RuntimeEnabled=OffscreenCanvasText] readonly attribute FontFaceSet fonts;
};
WorkerGlobalScope implements WindowBase64;
WorkerGlobalScope implements WindowOrWorkerGlobalScope;
// TODO(fserb): this needs to be enabled once we get out of RuntimeEnabled.
//WorkerGlobalScope implements FontFaceSource;
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment