~ubuntu-branches/ubuntu/karmic/gears/karmic

« back to all changes in this revision

Viewing changes to gears/base/android/webview_manager.h

  • Committer: Bazaar Package Importer
  • Author(s): Stefan Lesicnik
  • Date: 2009-04-30 19:15:25 UTC
  • Revision ID: james.westby@ubuntu.com-20090430191525-0790sb5wzg8ou0xb
Tags: upstream-0.5.21.0~svn3334+dfsg
ImportĀ upstreamĀ versionĀ 0.5.21.0~svn3334+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2008, Google Inc.
 
2
//
 
3
// Redistribution and use in source and binary forms, with or without
 
4
// modification, are permitted provided that the following conditions are met:
 
5
//
 
6
//  1. Redistributions of source code must retain the above copyright notice,
 
7
//     this list of conditions and the following disclaimer.
 
8
//  2. Redistributions in binary form must reproduce the above copyright notice,
 
9
//     this list of conditions and the following disclaimer in the documentation
 
10
//     and/or other materials provided with the distribution.
 
11
//  3. Neither the name of Google Inc. nor the names of its contributors may be
 
12
//     used to endorse or promote products derived from this software without
 
13
//     specific prior written permission.
 
14
//
 
15
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
 
16
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 
17
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
 
18
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 
19
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 
20
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 
21
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 
22
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 
23
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 
24
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
25
 
 
26
#ifndef GEARS_BASE_ANDROID_WEBVIEW_MANAGER_H__
 
27
#define GEARS_BASE_ANDROID_WEBVIEW_MANAGER_H__
 
28
 
 
29
#include <map>
 
30
 
 
31
#include "gears/base/android/java_global_ref.h"
 
32
#include "gears/base/common/mutex.h"
 
33
#include "gears/base/npapi/module.h"
 
34
 
 
35
 
 
36
// This class manages the association between an NPP instance
 
37
// and the webview corresponding to the page that created the Gears plugin.
 
38
// (See http://code.google.com/android/reference/android/webkit/WebView.html)
 
39
// Several Gears classes (e.g. Desktop, AndroidRadioDataProvider,
 
40
// AndroidGpsLocationProvider) need the webview object so that they
 
41
// can pass it to the Java side. The corresponding Java classes
 
42
// extract a Context object from the webview instance and use it
 
43
// to get access to various system services, such as the TelephonyManager
 
44
// or the LocationManager.
 
45
class WebViewManager {
 
46
 public:
 
47
  // Registers an NPP instance with a webview instance.
 
48
  static void RegisterWebView(NPP plugin_instance, jobject web_view);
 
49
  // Removes the association between an NPP instance and a webview instance.
 
50
  static void UnregisterWebView(NPP plugin_instance);
 
51
  // Retrieves the webview associated with the NPP instance that corresponds
 
52
  // to the current call context. Note that in order to succeeed, this method
 
53
  // must be called from sites that have a call context. This imposes an
 
54
  // important restriction: objects that need the webview must attempt to
 
55
  // acquire it only from the "main" javascript threads (either the thread
 
56
  // where the document JS runner is executed, or a worker thread) and only
 
57
  // from a script-invoked method call on a Gears object.
 
58
  // Attempting to acquire the webview from anywhere else is an error
 
59
  // and will trigger an assertion on debug builds.
 
60
  static bool GetWebView(jobject *web_view_out);
 
61
 
 
62
 private:
 
63
  typedef std::map<NPP, JavaGlobalRef<jobject> > WebViewMap;
 
64
  static WebViewMap map_;
 
65
  static Mutex map_mutex_;
 
66
 
 
67
  DISALLOW_EVIL_CONSTRUCTORS(WebViewManager);
 
68
};
 
69
 
 
70
#endif  // GEARS_BASE_ANDROID_WEBVIEW_MANAGER_H__