Chromium Code Reviews

Side by Side Diff: third_party/WebKit/Source/modules/geolocation/Geolocation.cpp

Issue 1367853002: Move GeolocationDispatcher into blink. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2008, 2009, 2010, 2011 Apple Inc. All Rights Reserved. 2 * Copyright (C) 2008, 2009, 2010, 2011 Apple Inc. All Rights Reserved.
3 * Copyright (C) 2009 Torch Mobile, Inc. 3 * Copyright (C) 2009 Torch Mobile, Inc.
4 * Copyright 2010, The Android Open Source Project 4 * Copyright 2010, The Android Open Source Project
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 75 matching lines...)
86 Geolocation* Geolocation::create(ExecutionContext* context) 86 Geolocation* Geolocation::create(ExecutionContext* context)
87 { 87 {
88 Geolocation* geolocation = new Geolocation(context); 88 Geolocation* geolocation = new Geolocation(context);
89 geolocation->suspendIfNeeded(); 89 geolocation->suspendIfNeeded();
90 return geolocation; 90 return geolocation;
91 } 91 }
92 92
93 Geolocation::Geolocation(ExecutionContext* context) 93 Geolocation::Geolocation(ExecutionContext* context)
94 : ActiveDOMObject(context) 94 : ActiveDOMObject(context)
95 , m_geolocationPermission(PermissionUnknown) 95 , m_geolocationPermission(PermissionUnknown)
96 , m_controller(new GeolocationController(this))
Marijn Kruisselbrink 2015/09/30 19:56:55 Unless I'm missing something, the change to lifeti
Sam McNally 2015/10/01 01:54:50 For a real CL it's worth splitting this up, but I
Marijn Kruisselbrink 2015/10/01 03:36:09 But changing the ownership and lifetime management
Sam McNally 2015/10/02 05:12:37 Changing ownership of GeolocationController depend
96 { 97 {
97 } 98 }
98 99
99 Geolocation::~Geolocation() 100 Geolocation::~Geolocation()
100 { 101 {
101 ASSERT(m_geolocationPermission != PermissionRequested); 102 ASSERT(m_geolocationPermission != PermissionRequested);
102 } 103 }
103 104
104 DEFINE_TRACE(Geolocation) 105 DEFINE_TRACE(Geolocation)
105 { 106 {
106 visitor->trace(m_oneShots); 107 visitor->trace(m_oneShots);
107 visitor->trace(m_watchers); 108 visitor->trace(m_watchers);
108 visitor->trace(m_pendingForPermissionNotifiers); 109 visitor->trace(m_pendingForPermissionNotifiers);
109 visitor->trace(m_lastPosition); 110 visitor->trace(m_lastPosition);
110 visitor->trace(m_requestsAwaitingCachedPosition); 111 visitor->trace(m_requestsAwaitingCachedPosition);
112 visitor->trace(m_controller);
111 ActiveDOMObject::trace(visitor); 113 ActiveDOMObject::trace(visitor);
112 } 114 }
113 115
114 Document* Geolocation::document() const 116 Document* Geolocation::document() const
115 { 117 {
116 return toDocument(executionContext()); 118 return toDocument(executionContext());
117 } 119 }
118 120
119 LocalFrame* Geolocation::frame() const 121 LocalFrame* Geolocation::frame() const
120 { 122 {
121 return document() ? document()->frame() : 0; 123 return document() ? document()->frame() : 0;
122 } 124 }
123 125
124 void Geolocation::stop() 126 void Geolocation::stop()
125 { 127 {
126 LocalFrame* frame = this->frame(); 128 LocalFrame* frame = this->frame();
127 if (frame && m_geolocationPermission == PermissionRequested) 129 if (frame && m_geolocationPermission == PermissionRequested)
128 GeolocationController::from(frame)->cancelPermissionRequest(this); 130 m_controller->cancelPermissionRequest();
129 131
130 // The frame may be moving to a new page and we want to get the permissions from the new page's client. 132 // The frame may be moving to a new page and we want to get the permissions from the new page's client.
131 m_geolocationPermission = PermissionUnknown; 133 m_geolocationPermission = PermissionUnknown;
132 cancelAllRequests(); 134 cancelAllRequests();
133 stopUpdating(); 135 stopUpdating();
134 m_pendingForPermissionNotifiers.clear(); 136 m_pendingForPermissionNotifiers.clear();
135 } 137 }
136 138
137 Geoposition* Geolocation::lastPosition() 139 Geoposition* Geolocation::lastPosition()
138 { 140 {
139 LocalFrame* frame = this->frame(); 141 m_lastPosition = createGeoposition(m_controller->lastPosition());
140 if (!frame)
141 return 0;
142
143 m_lastPosition = createGeoposition(GeolocationController::from(frame)->lastP osition());
144 142
145 return m_lastPosition.get(); 143 return m_lastPosition.get();
146 } 144 }
147 145
148 void Geolocation::recordOriginTypeAccess() const 146 void Geolocation::recordOriginTypeAccess() const
149 { 147 {
150 ASSERT(frame()); 148 ASSERT(frame());
151 149
152 Document* document = this->document(); 150 Document* document = this->document();
153 ASSERT(document); 151 ASSERT(document);
(...skipping 306 matching lines...)
460 458
461 // Maintain a reference to the cached notifiers until their timer fires. 459 // Maintain a reference to the cached notifiers until their timer fires.
462 copyToSet(oneShotsWithCachedPosition, m_oneShots); 460 copyToSet(oneShotsWithCachedPosition, m_oneShots);
463 } 461 }
464 462
465 void Geolocation::requestPermission() 463 void Geolocation::requestPermission()
466 { 464 {
467 if (m_geolocationPermission != PermissionUnknown) 465 if (m_geolocationPermission != PermissionUnknown)
468 return; 466 return;
469 467
470 LocalFrame* frame = this->frame();
471 if (!frame)
472 return;
473
474 m_geolocationPermission = PermissionRequested; 468 m_geolocationPermission = PermissionRequested;
475 469
476 // Ask the embedder: it maintains the geolocation challenge policy itself. 470 // Ask the embedder: it maintains the geolocation challenge policy itself.
477 GeolocationController::from(frame)->requestPermission(this); 471 m_controller->requestPermission();
478 } 472 }
479 473
480 void Geolocation::makeSuccessCallbacks() 474 void Geolocation::makeSuccessCallbacks()
481 { 475 {
482 ASSERT(lastPosition()); 476 ASSERT(lastPosition());
483 ASSERT(isAllowed()); 477 ASSERT(isAllowed());
484 478
485 GeoNotifierVector oneShotsCopy; 479 GeoNotifierVector oneShotsCopy;
486 copyToVector(m_oneShots, oneShotsCopy); 480 copyToVector(m_oneShots, oneShotsCopy);
487 481
(...skipping 27 matching lines...)
515 makeSuccessCallbacks(); 509 makeSuccessCallbacks();
516 } 510 }
517 511
518 void Geolocation::setError(GeolocationError* error) 512 void Geolocation::setError(GeolocationError* error)
519 { 513 {
520 handleError(createPositionError(error)); 514 handleError(createPositionError(error));
521 } 515 }
522 516
523 bool Geolocation::startUpdating(GeoNotifier* notifier) 517 bool Geolocation::startUpdating(GeoNotifier* notifier)
524 { 518 {
525 LocalFrame* frame = this->frame(); 519 m_controller->startUpdating(notifier->options().enableHighAccuracy());
526 if (!frame)
527 return false;
528
529 GeolocationController::from(frame)->addObserver(this, notifier->options().en ableHighAccuracy());
530 return true; 520 return true;
531 } 521 }
532 522
533 void Geolocation::stopUpdating() 523 void Geolocation::stopUpdating()
534 { 524 {
535 LocalFrame* frame = this->frame(); 525 m_controller->stopUpdating();
536 if (!frame)
537 return;
538
539 GeolocationController::from(frame)->removeObserver(this);
540 } 526 }
541 527
542 void Geolocation::handlePendingPermissionNotifiers() 528 void Geolocation::handlePendingPermissionNotifiers()
543 { 529 {
544 // While we iterate through the list, we need not worry about list being mod ified as the permission 530 // While we iterate through the list, we need not worry about list being mod ified as the permission
545 // is already set to Yes/No and no new listeners will be added to the pendin g list. 531 // is already set to Yes/No and no new listeners will be added to the pendin g list.
546 for (GeoNotifier* notifier : m_pendingForPermissionNotifiers) { 532 for (GeoNotifier* notifier : m_pendingForPermissionNotifiers) {
547 if (isAllowed()) { 533 if (isAllowed()) {
548 // start all pending notification requests as permission granted. 534 // start all pending notification requests as permission granted.
549 // The notifier is always ref'ed by m_oneShots or m_watchers. 535 // The notifier is always ref'ed by m_oneShots or m_watchers.
550 if (startUpdating(notifier)) 536 if (startUpdating(notifier))
551 notifier->startTimer(); 537 notifier->startTimer();
552 else 538 else
553 notifier->setFatalError(PositionError::create(PositionError::POS ITION_UNAVAILABLE, failedToStartServiceErrorMessage)); 539 notifier->setFatalError(PositionError::create(PositionError::POS ITION_UNAVAILABLE, failedToStartServiceErrorMessage));
554 } else { 540 } else {
555 notifier->setFatalError(PositionError::create(PositionError::PERMISS ION_DENIED, permissionDeniedErrorMessage)); 541 notifier->setFatalError(PositionError::create(PositionError::PERMISS ION_DENIED, permissionDeniedErrorMessage));
556 } 542 }
557 } 543 }
558 } 544 }
559 545
560 } // namespace blink 546 } // namespace blink
OLDNEW

Powered by Google App Engine