OLD | NEW |
| (Empty) |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "webkit/tools/test_shell/test_geolocation_service.h" | |
6 | |
7 #include "third_party/WebKit/WebKit/chromium/public/WebGeolocationServiceBridge.
h" | |
8 | |
9 TestGeolocationService::TestGeolocationService() | |
10 : allowed_(false), | |
11 permission_set_(false) { | |
12 } | |
13 | |
14 TestGeolocationService::~TestGeolocationService() { | |
15 for (IDMap<WebKit::WebGeolocationServiceBridge>::iterator it(&bridges_map_); | |
16 !it.IsAtEnd(); it.Advance()) { | |
17 it.GetCurrentValue()->onWebGeolocationServiceDestroyed(); | |
18 } | |
19 } | |
20 | |
21 void TestGeolocationService::SetGeolocationPermission(bool allowed) { | |
22 allowed_ = allowed; | |
23 permission_set_ = true; | |
24 TryToSendPermissions(); | |
25 } | |
26 | |
27 void TestGeolocationService::requestPermissionForFrame( | |
28 int bridgeId, const WebKit::WebURL& url) { | |
29 DCHECK(bridges_map_.Lookup(bridgeId)) << "Unknown bridge " << bridgeId; | |
30 pending_permissions_.push_back(bridgeId); | |
31 TryToSendPermissions(); | |
32 } | |
33 | |
34 int TestGeolocationService::attachBridge( | |
35 WebKit::WebGeolocationServiceBridge* bridge) { | |
36 return bridges_map_.Add(bridge); | |
37 } | |
38 | |
39 void TestGeolocationService::detachBridge(int bridgeId) { | |
40 bridges_map_.Remove(bridgeId); | |
41 std::vector<int>::iterator i = pending_permissions_.begin(); | |
42 while (i != pending_permissions_.end()) { | |
43 if (*i == bridgeId) | |
44 pending_permissions_.erase(i); | |
45 else | |
46 ++i; | |
47 } | |
48 } | |
49 | |
50 void TestGeolocationService::TryToSendPermissions() { | |
51 if (permission_set_ && !permission_timer_.IsRunning()) | |
52 permission_timer_.Start(base::TimeDelta::FromMilliseconds(0), | |
53 this, &TestGeolocationService::SendPermission); | |
54 } | |
55 | |
56 void TestGeolocationService::SendPermission() { | |
57 DCHECK(permission_set_); | |
58 std::vector<int> pending_permissions; | |
59 pending_permissions.swap(pending_permissions_); | |
60 for (std::vector<int>::const_iterator i = pending_permissions.begin(); | |
61 i != pending_permissions.end(); ++i) { | |
62 WebKit::WebGeolocationServiceBridge* bridge = | |
63 bridges_map_.Lookup(*i); | |
64 DCHECK(bridge); | |
65 bridge->setIsAllowed(allowed_); | |
66 } | |
67 } | |
OLD | NEW |