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

Side by Side Diff: Source/modules/geolocation/GeolocationController.cpp

Issue 27368003: Add page visibility observer for Geolocation (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix nit Created 7 years, 2 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/modules/geolocation/GeolocationController.h ('k') | no next file » | 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) 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2009 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 16 matching lines...) Expand all
27 #include "modules/geolocation/GeolocationController.h" 27 #include "modules/geolocation/GeolocationController.h"
28 28
29 #include "core/inspector/InspectorInstrumentation.h" 29 #include "core/inspector/InspectorInstrumentation.h"
30 #include "modules/geolocation/GeolocationClient.h" 30 #include "modules/geolocation/GeolocationClient.h"
31 #include "modules/geolocation/GeolocationError.h" 31 #include "modules/geolocation/GeolocationError.h"
32 #include "modules/geolocation/GeolocationPosition.h" 32 #include "modules/geolocation/GeolocationPosition.h"
33 33
34 namespace WebCore { 34 namespace WebCore {
35 35
36 GeolocationController::GeolocationController(Page* page, GeolocationClient* clie nt) 36 GeolocationController::GeolocationController(Page* page, GeolocationClient* clie nt)
37 : m_client(client) 37 : PageLifecycleObserver(page)
38 , m_page(page) 38 , m_client(client)
39 { 39 {
40 } 40 }
41 41
42 GeolocationController::~GeolocationController() 42 GeolocationController::~GeolocationController()
43 { 43 {
44 ASSERT(m_observers.isEmpty()); 44 ASSERT(m_observers.isEmpty());
45 45
46 if (m_client) 46 if (m_client)
47 m_client->geolocationDestroyed(); 47 m_client->geolocationDestroyed();
48 } 48 }
49 49
50 PassOwnPtr<GeolocationController> GeolocationController::create(Page* page, Geol ocationClient* client) 50 PassOwnPtr<GeolocationController> GeolocationController::create(Page* page, Geol ocationClient* client)
51 { 51 {
52 return adoptPtr(new GeolocationController(page, client)); 52 return adoptPtr(new GeolocationController(page, client));
53 } 53 }
54 54
55 void GeolocationController::addObserver(Geolocation* observer, bool enableHighAc curacy) 55 void GeolocationController::addObserver(Geolocation* observer, bool enableHighAc curacy)
56 { 56 {
57 // This may be called multiple times with the same observer, though removeOb server() 57 // This may be called multiple times with the same observer, though removeOb server()
58 // is called only once with each. 58 // is called only once with each.
59 bool wasEmpty = m_observers.isEmpty(); 59 bool wasEmpty = m_observers.isEmpty();
60 m_observers.add(observer); 60 m_observers.add(observer);
61 if (enableHighAccuracy) 61 if (enableHighAccuracy)
62 m_highAccuracyObservers.add(observer); 62 m_highAccuracyObservers.add(observer);
63 63
64 if (m_client) { 64 if (m_client) {
65 if (enableHighAccuracy) 65 if (enableHighAccuracy)
66 m_client->setEnableHighAccuracy(true); 66 m_client->setEnableHighAccuracy(true);
67 if (wasEmpty) 67 if (wasEmpty && page()->visibilityState() == PageVisibilityStateVisible)
68 m_client->startUpdating(); 68 m_client->startUpdating();
69 } 69 }
70 } 70 }
71 71
72 void GeolocationController::removeObserver(Geolocation* observer) 72 void GeolocationController::removeObserver(Geolocation* observer)
73 { 73 {
74 if (!m_observers.contains(observer)) 74 if (!m_observers.contains(observer))
75 return; 75 return;
76 76
77 m_observers.remove(observer); 77 m_observers.remove(observer);
(...skipping 14 matching lines...) Expand all
92 } 92 }
93 93
94 void GeolocationController::cancelPermissionRequest(Geolocation* geolocation) 94 void GeolocationController::cancelPermissionRequest(Geolocation* geolocation)
95 { 95 {
96 if (m_client) 96 if (m_client)
97 m_client->cancelPermissionRequest(geolocation); 97 m_client->cancelPermissionRequest(geolocation);
98 } 98 }
99 99
100 void GeolocationController::positionChanged(GeolocationPosition* position) 100 void GeolocationController::positionChanged(GeolocationPosition* position)
101 { 101 {
102 position = InspectorInstrumentation::overrideGeolocationPosition(m_page, pos ition); 102 position = InspectorInstrumentation::overrideGeolocationPosition(page(), pos ition);
103 if (!position) { 103 if (!position) {
104 errorOccurred(GeolocationError::create(GeolocationError::PositionUnavail able, "PositionUnavailable").get()); 104 errorOccurred(GeolocationError::create(GeolocationError::PositionUnavail able, "PositionUnavailable").get());
105 return; 105 return;
106 } 106 }
107 m_lastPosition = position; 107 m_lastPosition = position;
108 Vector<RefPtr<Geolocation> > observersVector; 108 Vector<RefPtr<Geolocation> > observersVector;
109 copyToVector(m_observers, observersVector); 109 copyToVector(m_observers, observersVector);
110 for (size_t i = 0; i < observersVector.size(); ++i) 110 for (size_t i = 0; i < observersVector.size(); ++i)
111 observersVector[i]->positionChanged(); 111 observersVector[i]->positionChanged();
112 } 112 }
(...skipping 10 matching lines...) Expand all
123 { 123 {
124 if (m_lastPosition.get()) 124 if (m_lastPosition.get())
125 return m_lastPosition.get(); 125 return m_lastPosition.get();
126 126
127 if (!m_client) 127 if (!m_client)
128 return 0; 128 return 0;
129 129
130 return m_client->lastPosition(); 130 return m_client->lastPosition();
131 } 131 }
132 132
133 void GeolocationController::pageVisibilityChanged()
134 {
135 if (m_observers.isEmpty() || !m_client)
136 return;
137
138 if (page()->visibilityState() == PageVisibilityStateVisible)
139 m_client->startUpdating();
140 else
141 m_client->stopUpdating();
142 }
143
133 const char* GeolocationController::supplementName() 144 const char* GeolocationController::supplementName()
134 { 145 {
135 return "GeolocationController"; 146 return "GeolocationController";
136 } 147 }
137 148
138 void provideGeolocationTo(Page* page, GeolocationClient* client) 149 void provideGeolocationTo(Page* page, GeolocationClient* client)
139 { 150 {
140 Supplement<Page>::provideTo(page, GeolocationController::supplementName(), G eolocationController::create(page, client)); 151 Supplement<Page>::provideTo(page, GeolocationController::supplementName(), G eolocationController::create(page, client));
141 } 152 }
142 153
143 } // namespace WebCore 154 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/modules/geolocation/GeolocationController.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698