Commit 8a4645bf authored by Nate Chapin's avatar Nate Chapin Committed by Commit Bot

Merge NavigatorGeolocation and Geolocation

Bug: 1147612
Change-Id: I970c0dc32c56dd4b94273b5a29dd305925169a3b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2530737
Commit-Queue: Nate Chapin <japhet@chromium.org>
Auto-Submit: Nate Chapin <japhet@chromium.org>
Reviewed-by: default avatarMatt Reynolds <mattreynolds@chromium.org>
Cr-Commit-Position: refs/heads/master@{#826586}
parent dca4e656
......@@ -17,7 +17,5 @@ blink_modules_sources("geolocation") {
"geolocation_watchers.cc",
"geolocation_watchers.h",
"geoposition.h",
"navigator_geolocation.cc",
"navigator_geolocation.h",
]
}
......@@ -23,7 +23,7 @@ GeoNotifier::GeoNotifier(Geolocation* geolocation,
error_callback_(error_callback),
options_(options),
timer_(MakeGarbageCollected<Timer>(
geolocation->GetWindow()->GetTaskRunner(TaskType::kMiscPlatformAPI),
geolocation->DomWindow()->GetTaskRunner(TaskType::kMiscPlatformAPI),
this,
&GeoNotifier::TimerFired)),
use_cached_position_(false) {
......
......@@ -34,6 +34,7 @@
#include "third_party/blink/renderer/bindings/core/v8/source_location.h"
#include "third_party/blink/renderer/core/frame/deprecation.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/frame/navigator.h"
#include "third_party/blink/renderer/core/frame/performance_monitor.h"
#include "third_party/blink/renderer/core/frame/settings.h"
#include "third_party/blink/renderer/core/inspector/console_message.h"
......@@ -100,16 +101,29 @@ static void ReportGeolocationViolation(LocalDOMWindow* window) {
} // namespace
Geolocation* Geolocation::Create(ExecutionContext* context) {
return MakeGarbageCollected<Geolocation>(context);
// static
const char Geolocation::kSupplementName[] = "Geolocation";
// static
Geolocation* Geolocation::geolocation(Navigator& navigator) {
if (!navigator.DomWindow())
return nullptr;
Geolocation* supplement = Supplement<Navigator>::From<Geolocation>(navigator);
if (!supplement) {
supplement = MakeGarbageCollected<Geolocation>(navigator);
ProvideTo(navigator, supplement);
}
return supplement;
}
Geolocation::Geolocation(ExecutionContext* context)
: ExecutionContextLifecycleObserver(context),
PageVisibilityObserver(GetFrame()->GetPage()),
Geolocation::Geolocation(Navigator& navigator)
: Supplement<Navigator>(navigator),
ExecutionContextLifecycleObserver(navigator.DomWindow()),
PageVisibilityObserver(navigator.DomWindow()->GetFrame()->GetPage()),
watchers_(MakeGarbageCollected<GeolocationWatchers>()),
geolocation_(context),
geolocation_service_(context) {}
geolocation_(navigator.DomWindow()),
geolocation_service_(navigator.DomWindow()) {}
Geolocation::~Geolocation() = default;
......@@ -122,16 +136,13 @@ void Geolocation::Trace(Visitor* visitor) const {
visitor->Trace(geolocation_);
visitor->Trace(geolocation_service_);
ScriptWrappable::Trace(visitor);
Supplement<Navigator>::Trace(visitor);
ExecutionContextLifecycleObserver::Trace(visitor);
PageVisibilityObserver::Trace(visitor);
}
LocalDOMWindow* Geolocation::GetWindow() const {
return To<LocalDOMWindow>(GetExecutionContext());
}
LocalFrame* Geolocation::GetFrame() const {
return GetWindow() ? GetWindow()->GetFrame() : nullptr;
return DomWindow() ? DomWindow()->GetFrame() : nullptr;
}
void Geolocation::ContextDestroyed() {
......@@ -147,7 +158,7 @@ void Geolocation::ContextDestroyed() {
void Geolocation::RecordOriginTypeAccess() const {
DCHECK(GetFrame());
LocalDOMWindow* window = GetWindow();
LocalDOMWindow* window = DomWindow();
// It is required by isSecureContext() but isn't actually used. This could be
// used later if a warning is shown in the developer console.
......@@ -235,7 +246,7 @@ void Geolocation::StartRequest(GeoNotifier* notifier) {
return;
}
ReportGeolocationViolation(GetWindow());
ReportGeolocationViolation(DomWindow());
if (HaveSuitableCachedPosition(notifier->Options())) {
notifier->SetUseCachedPosition();
......
......@@ -43,6 +43,7 @@
#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/mojo/heap_mojo_remote.h"
#include "third_party/blink/renderer/platform/supplementable.h"
#include "third_party/blink/renderer/platform/timer.h"
namespace blink {
......@@ -51,21 +52,22 @@ namespace mojom {
enum class PermissionStatus;
} // namespace mojom
class LocalDOMWindow;
class LocalFrame;
class ExecutionContext;
class Navigator;
class MODULES_EXPORT Geolocation final
: public ScriptWrappable,
public ActiveScriptWrappable<Geolocation>,
public Supplement<Navigator>,
public ExecutionContextLifecycleObserver,
public PageVisibilityObserver {
DEFINE_WRAPPERTYPEINFO();
public:
static Geolocation* Create(ExecutionContext*);
static const char kSupplementName[];
static Geolocation* geolocation(Navigator&);
explicit Geolocation(ExecutionContext*);
explicit Geolocation(Navigator&);
~Geolocation() override;
void Trace(Visitor*) const override;
......@@ -73,7 +75,6 @@ class MODULES_EXPORT Geolocation final
// PageVisibilityObserver.
void ContextDestroyed() override;
LocalDOMWindow* GetWindow() const;
LocalFrame* GetFrame() const;
// Creates a oneshot and attempts to obtain a position that meets the
......
/*
* Copyright (C) 2000 Harri Porten (porten@kde.org)
* Copyright (c) 2000 Daniel Molkentin (molkentin@kde.org)
* Copyright (c) 2000 Stefan Schimanski (schimmi@kde.org)
* Copyright (C) 2003, 2004, 2005, 2006 Apple Computer, Inc.
* 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 Lesser 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
#include "third_party/blink/renderer/modules/geolocation/navigator_geolocation.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/frame/navigator.h"
#include "third_party/blink/renderer/modules/geolocation/geolocation.h"
namespace blink {
NavigatorGeolocation::NavigatorGeolocation(Navigator& navigator)
: Supplement<Navigator>(navigator) {}
// static
const char NavigatorGeolocation::kSupplementName[] = "NavigatorGeolocation";
NavigatorGeolocation& NavigatorGeolocation::From(Navigator& navigator) {
NavigatorGeolocation* supplement =
Supplement<Navigator>::From<NavigatorGeolocation>(navigator);
if (!supplement) {
supplement = MakeGarbageCollected<NavigatorGeolocation>(navigator);
ProvideTo(navigator, supplement);
}
return *supplement;
}
Geolocation* NavigatorGeolocation::geolocation(Navigator& navigator) {
return NavigatorGeolocation::From(navigator).geolocation();
}
Geolocation* NavigatorGeolocation::geolocation() {
if (!geolocation_ && GetSupplementable()->DomWindow())
geolocation_ = Geolocation::Create(GetSupplementable()->DomWindow());
return geolocation_;
}
void NavigatorGeolocation::Trace(Visitor* visitor) const {
visitor->Trace(geolocation_);
Supplement<Navigator>::Trace(visitor);
}
} // namespace blink
/*
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_MODULES_GEOLOCATION_NAVIGATOR_GEOLOCATION_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_GEOLOCATION_NAVIGATOR_GEOLOCATION_H_
#include "third_party/blink/renderer/core/frame/navigator.h"
#include "third_party/blink/renderer/platform/bindings/name_client.h"
#include "third_party/blink/renderer/platform/heap/handle.h"
#include "third_party/blink/renderer/platform/supplementable.h"
namespace blink {
class Geolocation;
class Navigator;
class NavigatorGeolocation final
: public GarbageCollected<NavigatorGeolocation>,
public Supplement<Navigator>,
public NameClient {
public:
static const char kSupplementName[];
static NavigatorGeolocation& From(Navigator&);
static Geolocation* geolocation(Navigator&);
Geolocation* geolocation();
explicit NavigatorGeolocation(Navigator&);
void Trace(Visitor*) const override;
const char* NameInHeapSnapshot() const override {
return "NavigatorGeolocation";
}
private:
Member<Geolocation> geolocation_;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_GEOLOCATION_NAVIGATOR_GEOLOCATION_H_
......@@ -18,7 +18,7 @@
*/
[
ImplementedAs=NavigatorGeolocation
ImplementedAs=Geolocation
] partial interface Navigator {
readonly attribute Geolocation geolocation;
};
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