summaryrefslogtreecommitdiffstats
path: root/content/browser/geolocation/geolocation_dispatcher_host.h
blob: a73487f0b03844450de5ef73cb67dafa91f3d76a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_DISPATCHER_HOST_H_
#define CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_DISPATCHER_HOST_H_

#include "content/browser/geolocation/geolocation_provider_impl.h"
#include "content/public/browser/web_contents_observer.h"

class GURL;

namespace content {

class GeolocationPermissionContext;

// GeolocationDispatcherHost is an observer for Geolocation messages.
// It's the complement of GeolocationDispatcher (owned by RenderView).
class GeolocationDispatcherHost : public WebContentsObserver {
 public:
  explicit GeolocationDispatcherHost(WebContents* web_contents);
  virtual ~GeolocationDispatcherHost();

  // Pause or resumes geolocation. Resuming when nothing is paused is a no-op.
  // If the web contents is paused while not currently using geolocation but
  // then goes on to do so before being resumed, then it will not get
  // geolocation updates until it is resumed.
  void PauseOrResume(bool should_pause);

 private:
  // WebContentsObserver
  virtual void RenderViewHostChanged(RenderViewHost* old_host,
                                     RenderViewHost* new_host) OVERRIDE;
  virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;

  // Message handlers:
  void OnRequestPermission(int bridge_id,
                           const GURL& requesting_frame,
                           bool user_gesture);
  void OnCancelPermissionRequest(int bridge_id,
                                 const GURL& requesting_frame);
  void OnStartUpdating(const GURL& requesting_frame,
                       bool enable_high_accuracy);
  void OnStopUpdating();

  // Updates the geolocation provider with the currently required update
  // options.
  void RefreshGeolocationOptions();

  void OnLocationUpdate(const Geoposition& position);

  scoped_refptr<GeolocationPermissionContext> geolocation_permission_context_;

  bool watching_requested_;
  bool paused_;
  bool high_accuracy_;

  scoped_ptr<GeolocationProvider::Subscription> geolocation_subscription_;

  DISALLOW_COPY_AND_ASSIGN(GeolocationDispatcherHost);
};

}  // namespace content

#endif  // CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_DISPATCHER_HOST_H_