Commit 925d863b authored by Nate Chapin's avatar Nate Chapin Committed by Commit Bot

Add a new base class, NavigatorBase, for the shared logic between

Navigator and WorkerNavigator.

This allows a little bit of code-sharing. It also provides a
Supplementable interface for classes that want to Supplement
both Navigator and WorkerNavigator.

Bug: 1147612
Change-Id: I9d587a8184479fbb1854e262d8350f0300d2e80f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2535391Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Nate Chapin <japhet@chromium.org>
Cr-Commit-Position: refs/heads/master@{#827282}
parent 59a0e191
...@@ -13,6 +13,7 @@ blink_core_sources_execution_context = [ ...@@ -13,6 +13,7 @@ blink_core_sources_execution_context = [
"execution_context_lifecycle_observer.h", "execution_context_lifecycle_observer.h",
"execution_context_lifecycle_state_observer.cc", "execution_context_lifecycle_state_observer.cc",
"execution_context_lifecycle_state_observer.h", "execution_context_lifecycle_state_observer.h",
"navigator_base.h",
"remote_security_context.cc", "remote_security_context.cc",
"remote_security_context.h", "remote_security_context.h",
"security_context.cc", "security_context.cc",
......
/*
Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_EXECUTION_CONTEXT_NAVIGATOR_BASE_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_EXECUTION_CONTEXT_NAVIGATOR_BASE_H_
#include "third_party/blink/renderer/core/execution_context/execution_context_lifecycle_observer.h"
#include "third_party/blink/renderer/core/frame/navigator_concurrent_hardware.h"
#include "third_party/blink/renderer/core/frame/navigator_device_memory.h"
#include "third_party/blink/renderer/core/frame/navigator_id.h"
#include "third_party/blink/renderer/core/frame/navigator_language.h"
#include "third_party/blink/renderer/core/frame/navigator_on_line.h"
#include "third_party/blink/renderer/core/frame/navigator_ua.h"
#include "third_party/blink/renderer/platform/bindings/script_wrappable.h"
#include "third_party/blink/renderer/platform/heap/handle.h"
#include "third_party/blink/renderer/platform/supplementable.h"
namespace blink {
// NavigatorBase is a helper for shared logic between Navigator and
// WorkerNavigator. It is also a Supplementable, and can therefore be used for
// classes that need to Supplement both Navigator and WorkerNavigator.
class NavigatorBase : public ScriptWrappable,
public NavigatorConcurrentHardware,
public NavigatorDeviceMemory,
public NavigatorID,
public NavigatorLanguage,
public NavigatorOnLine,
public NavigatorUA,
public ExecutionContextClient,
public Supplementable<NavigatorBase> {
public:
explicit NavigatorBase(ExecutionContext* context)
: NavigatorLanguage(context), ExecutionContextClient(context) {}
void Trace(Visitor* visitor) const override {
ScriptWrappable::Trace(visitor);
NavigatorLanguage::Trace(visitor);
ExecutionContextClient::Trace(visitor);
Supplementable<NavigatorBase>::Trace(visitor);
}
protected:
ExecutionContext* GetUAExecutionContext() const override {
return GetExecutionContext();
}
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_EXECUTION_CONTEXT_NAVIGATOR_BASE_H_
...@@ -38,8 +38,7 @@ ...@@ -38,8 +38,7 @@
namespace blink { namespace blink {
Navigator::Navigator(ExecutionContext* context) Navigator::Navigator(ExecutionContext* context) : NavigatorBase(context) {}
: NavigatorLanguage(context), ExecutionContextClient(context) {}
String Navigator::productSub() const { String Navigator::productSub() const {
return "20030107"; return "20030107";
...@@ -114,14 +113,8 @@ String Navigator::GetAcceptLanguages() { ...@@ -114,14 +113,8 @@ String Navigator::GetAcceptLanguages() {
} }
void Navigator::Trace(Visitor* visitor) const { void Navigator::Trace(Visitor* visitor) const {
ScriptWrappable::Trace(visitor); NavigatorBase::Trace(visitor);
NavigatorLanguage::Trace(visitor);
ExecutionContextClient::Trace(visitor);
Supplementable<Navigator>::Trace(visitor); Supplementable<Navigator>::Trace(visitor);
} }
ExecutionContext* Navigator::GetUAExecutionContext() const {
return GetExecutionContext();
}
} // namespace blink } // namespace blink
...@@ -22,28 +22,14 @@ ...@@ -22,28 +22,14 @@
#include "third_party/blink/public/common/user_agent/user_agent_metadata.h" #include "third_party/blink/public/common/user_agent/user_agent_metadata.h"
#include "third_party/blink/renderer/core/core_export.h" #include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/execution_context/execution_context_lifecycle_observer.h" #include "third_party/blink/renderer/core/execution_context/navigator_base.h"
#include "third_party/blink/renderer/core/frame/navigator_concurrent_hardware.h"
#include "third_party/blink/renderer/core/frame/navigator_device_memory.h"
#include "third_party/blink/renderer/core/frame/navigator_id.h"
#include "third_party/blink/renderer/core/frame/navigator_language.h"
#include "third_party/blink/renderer/core/frame/navigator_on_line.h"
#include "third_party/blink/renderer/core/frame/navigator_ua.h"
#include "third_party/blink/renderer/platform/bindings/script_wrappable.h"
#include "third_party/blink/renderer/platform/heap/handle.h" #include "third_party/blink/renderer/platform/heap/handle.h"
#include "third_party/blink/renderer/platform/supplementable.h" #include "third_party/blink/renderer/platform/supplementable.h"
#include "third_party/blink/renderer/platform/wtf/forward.h" #include "third_party/blink/renderer/platform/wtf/forward.h"
namespace blink { namespace blink {
class CORE_EXPORT Navigator final : public ScriptWrappable, class CORE_EXPORT Navigator final : public NavigatorBase,
public NavigatorConcurrentHardware,
public NavigatorDeviceMemory,
public NavigatorID,
public NavigatorLanguage,
public NavigatorOnLine,
public NavigatorUA,
public ExecutionContextClient,
public Supplementable<Navigator> { public Supplementable<Navigator> {
DEFINE_WRAPPERTYPEINFO(); DEFINE_WRAPPERTYPEINFO();
...@@ -68,9 +54,6 @@ class CORE_EXPORT Navigator final : public ScriptWrappable, ...@@ -68,9 +54,6 @@ class CORE_EXPORT Navigator final : public ScriptWrappable,
void Trace(Visitor*) const override; void Trace(Visitor*) const override;
protected:
ExecutionContext* GetUAExecutionContext() const override;
private: private:
UserAgentMetadata metadata_; UserAgentMetadata metadata_;
}; };
......
...@@ -39,8 +39,7 @@ namespace blink { ...@@ -39,8 +39,7 @@ namespace blink {
WorkerNavigator::WorkerNavigator(const String& user_agent, WorkerNavigator::WorkerNavigator(const String& user_agent,
const UserAgentMetadata& ua_metadata, const UserAgentMetadata& ua_metadata,
ExecutionContext* execution_context) ExecutionContext* execution_context)
: ExecutionContextClient(execution_context), : NavigatorBase(execution_context),
NavigatorLanguage(execution_context),
user_agent_(user_agent), user_agent_(user_agent),
ua_metadata_(ua_metadata) {} ua_metadata_(ua_metadata) {}
...@@ -69,9 +68,7 @@ void WorkerNavigator::NotifyUpdate() { ...@@ -69,9 +68,7 @@ void WorkerNavigator::NotifyUpdate() {
} }
void WorkerNavigator::Trace(Visitor* visitor) const { void WorkerNavigator::Trace(Visitor* visitor) const {
ScriptWrappable::Trace(visitor); NavigatorBase::Trace(visitor);
ExecutionContextClient::Trace(visitor);
NavigatorLanguage::Trace(visitor);
Supplementable<WorkerNavigator>::Trace(visitor); Supplementable<WorkerNavigator>::Trace(visitor);
} }
......
...@@ -28,30 +28,18 @@ ...@@ -28,30 +28,18 @@
#include "third_party/blink/public/platform/web_worker_fetch_context.h" #include "third_party/blink/public/platform/web_worker_fetch_context.h"
#include "third_party/blink/renderer/core/core_export.h" #include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/execution_context/execution_context_lifecycle_observer.h" #include "third_party/blink/renderer/core/execution_context/navigator_base.h"
#include "third_party/blink/renderer/core/frame/navigator_concurrent_hardware.h"
#include "third_party/blink/renderer/core/frame/navigator_device_memory.h"
#include "third_party/blink/renderer/core/frame/navigator_id.h"
#include "third_party/blink/renderer/core/frame/navigator_language.h"
#include "third_party/blink/renderer/core/frame/navigator_on_line.h"
#include "third_party/blink/renderer/core/frame/navigator_ua.h"
#include "third_party/blink/renderer/platform/bindings/script_wrappable.h"
#include "third_party/blink/renderer/platform/heap/handle.h" #include "third_party/blink/renderer/platform/heap/handle.h"
#include "third_party/blink/renderer/platform/supplementable.h" #include "third_party/blink/renderer/platform/supplementable.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h" #include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
namespace blink { namespace blink {
// TODO(japhet): Move classes that Supplement WorkerNavigator to use
// NavigatorBase instead and remove Supplementable<WorkerNavigator> here.
class CORE_EXPORT WorkerNavigator final class CORE_EXPORT WorkerNavigator final
: public ScriptWrappable, : public NavigatorBase,
public AcceptLanguagesWatcher, public AcceptLanguagesWatcher,
public ExecutionContextClient,
public NavigatorConcurrentHardware,
public NavigatorDeviceMemory,
public NavigatorID,
public NavigatorLanguage,
public NavigatorOnLine,
public NavigatorUA,
public Supplementable<WorkerNavigator> { public Supplementable<WorkerNavigator> {
DEFINE_WRAPPERTYPEINFO(); DEFINE_WRAPPERTYPEINFO();
...@@ -76,9 +64,6 @@ class CORE_EXPORT WorkerNavigator final ...@@ -76,9 +64,6 @@ class CORE_EXPORT WorkerNavigator final
UserAgentMetadata GetUserAgentMetadata() const override { UserAgentMetadata GetUserAgentMetadata() const override {
return ua_metadata_; return ua_metadata_;
} }
ExecutionContext* GetUAExecutionContext() const override {
return GetExecutionContext();
}
private: private:
String user_agent_; String user_agent_;
......
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