diff options
author | erikkay@chromium.org <erikkay@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-26 16:47:11 +0000 |
---|---|---|
committer | erikkay@chromium.org <erikkay@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-26 16:47:11 +0000 |
commit | 5ab79b06269c322e0446ebb8e9782e00ec1ccb96 (patch) | |
tree | 13f0dad86c052e0bdeed548ab69ad78dc837d676 /chrome | |
parent | 425f5ab811e965b212603d1500849072eb1f76f8 (diff) | |
download | chromium_src-5ab79b06269c322e0446ebb8e9782e00ec1ccb96.zip chromium_src-5ab79b06269c322e0446ebb8e9782e00ec1ccb96.tar.gz chromium_src-5ab79b06269c322e0446ebb8e9782e00ec1ccb96.tar.bz2 |
Add geolocation permission to extensions/apps.
BUG=41278
TEST=None
Review URL: http://codereview.chromium.org/1695013
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@45590 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
14 files changed, 99 insertions, 22 deletions
diff --git a/chrome/browser/extensions/extension_geolocation_apitest.cc b/chrome/browser/extensions/extension_geolocation_apitest.cc index 5baa272..940824a 100644 --- a/chrome/browser/extensions/extension_geolocation_apitest.cc +++ b/chrome/browser/extensions/extension_geolocation_apitest.cc @@ -18,6 +18,11 @@ public: }; IN_PROC_BROWSER_TEST_F(GeolocationApiTest, ExtensionGeolocationAccessFail) { - // Test that geolocation cannot be accessed from extension. - ASSERT_TRUE(RunExtensionTest("geolocation")) << message_; + // Test that geolocation cannot be accessed from extension without permission. + ASSERT_TRUE(RunExtensionTest("geolocation/no_permission")) << message_; +} + +IN_PROC_BROWSER_TEST_F(GeolocationApiTest, ExtensionGeolocationAccessPass) { + // Test that geolocation can be accessed from extension with permission. + ASSERT_TRUE(RunExtensionTest("geolocation/has_permission")) << message_; } diff --git a/chrome/browser/extensions/extension_process_manager.cc b/chrome/browser/extensions/extension_process_manager.cc index 2ef98d0..ffaaf75 100644 --- a/chrome/browser/extensions/extension_process_manager.cc +++ b/chrome/browser/extensions/extension_process_manager.cc @@ -208,6 +208,17 @@ void ExtensionProcessManager::UnregisterExtensionProcess(int process_id) { } RenderProcessHost* ExtensionProcessManager::GetExtensionProcess( + const GURL& url) { + if (!browsing_instance_->HasSiteInstance(url)) + return NULL; + scoped_refptr<SiteInstance> site = + browsing_instance_->GetSiteInstanceForURL(url); + if (site->HasProcess()) + return site->GetProcess(); + return NULL; +} + +RenderProcessHost* ExtensionProcessManager::GetExtensionProcess( const std::string& extension_id) { ProcessIDMap::const_iterator it = process_ids_.find(extension_id); if (it == process_ids_.end()) diff --git a/chrome/browser/extensions/extension_process_manager.h b/chrome/browser/extensions/extension_process_manager.h index 64061c0..843cc09 100644 --- a/chrome/browser/extensions/extension_process_manager.h +++ b/chrome/browser/extensions/extension_process_manager.h @@ -78,7 +78,12 @@ class ExtensionProcessManager : public NotificationObserver { // Unregisters an extension process with specified |process_id|. void UnregisterExtensionProcess(int process_id); + // Returns the extension process that |url| is associated with if it exists. + RenderProcessHost* GetExtensionProcess(const GURL& url); + // Returns the process that the extension with the given ID is running in. + // NOTE: This does not currently handle app processes with no + // ExtensionFunctionDispatcher objects. RenderProcessHost* GetExtensionProcess(const std::string& extension_id); // Returns true if |host| is managed by this process manager. diff --git a/chrome/browser/geolocation/geolocation_permission_context.cc b/chrome/browser/geolocation/geolocation_permission_context.cc index bf87271..5812c1a 100644 --- a/chrome/browser/geolocation/geolocation_permission_context.cc +++ b/chrome/browser/geolocation/geolocation_permission_context.cc @@ -8,15 +8,18 @@ #include "app/resource_bundle.h" #include "chrome/browser/browser.h" #include "chrome/browser/chrome_thread.h" +#include "chrome/browser/extensions/extensions_service.h" #include "chrome/browser/geolocation/geolocation_content_settings_map.h" #include "chrome/browser/geolocation/geolocation_dispatcher_host.h" #include "chrome/browser/pref_service.h" #include "chrome/browser/profile.h" +#include "chrome/browser/renderer_host/render_process_host.h" #include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/browser/renderer_host/render_view_host_notification_task.h" #include "chrome/browser/tab_contents/infobar_delegate.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/tab_contents/tab_util.h" +#include "chrome/common/extensions/extension.h" #include "chrome/common/pref_names.h" #include "chrome/common/render_messages.h" #include "grit/generated_resources.h" @@ -150,13 +153,29 @@ void GeolocationPermissionContext::RequestGeolocationPermission( } DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); + ExtensionsService* extensions = profile_->GetExtensionsService(); + if (extensions) { + Extension* ext = extensions->GetExtensionByURL(requesting_frame); + if (!ext) + ext = extensions->GetExtensionByWebExtent(requesting_frame); + if (ext && ext->HasApiPermission(Extension::kGeolocationPermission)) { + ExtensionProcessManager* epm = profile_->GetExtensionProcessManager(); + RenderProcessHost* process = epm->GetExtensionProcess(requesting_frame); + if (process && process->id() == render_process_id) { + NotifyPermissionSet(render_process_id, render_view_id, bridge_id, + requesting_frame, true); + return; + } + } + } + TabContents* tab_contents = tab_util::GetTabContentsByID(render_process_id, render_view_id); if (!tab_contents) { // The tab may have gone away, or the request may not be from a tab at all. LOG(WARNING) << "Attempt to use geolocation tabless renderer: " << render_process_id << "," << render_view_id << "," << bridge_id - << " (geolocation is not supported in extensions)"; + << " (can't prompt user without a visible tab)"; NotifyPermissionSet(render_process_id, render_view_id, bridge_id, requesting_frame, false); return; diff --git a/chrome/browser/renderer_host/site_instance.cc b/chrome/browser/renderer_host/site_instance.cc index 62c6bd7..cd409d9d 100644 --- a/chrome/browser/renderer_host/site_instance.cc +++ b/chrome/browser/renderer_host/site_instance.cc @@ -43,6 +43,10 @@ SiteInstance::~SiteInstance() { browsing_instance_->UnregisterSiteInstance(this); } +bool SiteInstance::HasProcess() const { + return (process_ != NULL); +} + RenderProcessHost* SiteInstance::GetProcess() { // Create a new process if ours went away or was reused. if (!process_) { diff --git a/chrome/browser/renderer_host/site_instance.h b/chrome/browser/renderer_host/site_instance.h index 4fbbdc8..98807d0 100644 --- a/chrome/browser/renderer_host/site_instance.h +++ b/chrome/browser/renderer_host/site_instance.h @@ -68,6 +68,9 @@ class SiteInstance : public base::RefCounted<SiteInstance>, } int32 max_page_id() const { return max_page_id_; } + // Whether this SiteInstance has a running process associated with it. + bool HasProcess() const; + // Returns the current process being used to render pages in this // SiteInstance. If the process has crashed or otherwise gone away, then // this method will create a new process and update our host ID accordingly. diff --git a/chrome/common/extensions/docs/static/manifest.html b/chrome/common/extensions/docs/static/manifest.html index 3250983..32b594c 100644 --- a/chrome/common/extensions/docs/static/manifest.html +++ b/chrome/common/extensions/docs/static/manifest.html @@ -209,6 +209,12 @@ The following table lists the permissions an extension can use. <a href="http://code.google.com/chrome/extensions/dev/experimental.html">chrome.experimental.* APIs</a>.</td> </tr> <tr> + <td> "geolocation" </td> + <td> Allows the extension to use the proposed HTML5 + <a href="http://dev.w3.org/geo/api/spec-source.html">geolocation API</a> + without prompting the user for permission. </td> +</tr> +<tr> <td> "notifications" </td> <td> Allows the extension to use the proposed HTML5 <a href="http://www.chromium.org/developers/design-documents/desktop-notifications/api-specification">notification API</a> diff --git a/chrome/common/extensions/extension.cc b/chrome/common/extensions/extension.cc index 213c7c7..8e9d711 100644 --- a/chrome/common/extensions/extension.cc +++ b/chrome/common/extensions/extension.cc @@ -120,20 +120,22 @@ const int Extension::kIconSizes[] = { const int Extension::kPageActionIconMaxSize = 19; const int Extension::kBrowserActionIconMaxSize = 19; -const char* Extension::kTabPermission = "tabs"; const char* Extension::kBookmarkPermission = "bookmarks"; -const char* Extension::kNotificationPermission = "notifications"; const char* Extension::kExperimentalPermission = "experimental"; -const char* Extension::kUnlimitedStoragePermission = "unlimited_storage"; +const char* Extension::kGeolocationPermission = "geolocation"; const char* Extension::kHistoryPermission = "history"; +const char* Extension::kNotificationPermission = "notifications"; +const char* Extension::kTabPermission = "tabs"; +const char* Extension::kUnlimitedStoragePermission = "unlimited_storage"; const char* Extension::kPermissionNames[] = { - Extension::kTabPermission, Extension::kBookmarkPermission, - Extension::kNotificationPermission, Extension::kExperimentalPermission, + Extension::kGeolocationPermission, + Extension::kHistoryPermission, + Extension::kNotificationPermission, + Extension::kTabPermission, Extension::kUnlimitedStoragePermission, - Extension::kHistoryPermission }; const size_t Extension::kNumPermissions = arraysize(Extension::kPermissionNames); diff --git a/chrome/common/extensions/extension.h b/chrome/common/extensions/extension.h index 6cc385c..f3b4ff3 100644 --- a/chrome/common/extensions/extension.h +++ b/chrome/common/extensions/extension.h @@ -87,12 +87,13 @@ class Extension { static const int kBrowserActionIconMaxSize; // Each permission is a module that the extension is permitted to use. - static const char* kTabPermission; static const char* kBookmarkPermission; - static const char* kNotificationPermission; static const char* kExperimentalPermission; - static const char* kUnlimitedStoragePermission; + static const char* kGeolocationPermission; static const char* kHistoryPermission; + static const char* kNotificationPermission; + static const char* kTabPermission; + static const char* kUnlimitedStoragePermission; static const char* kPermissionNames[]; static const size_t kNumPermissions; diff --git a/chrome/test/data/extensions/api_test/geolocation/has_permission/background.html b/chrome/test/data/extensions/api_test/geolocation/has_permission/background.html new file mode 100644 index 0000000..0ac1fb2 --- /dev/null +++ b/chrome/test/data/extensions/api_test/geolocation/has_permission/background.html @@ -0,0 +1,14 @@ +<script> +// These API calls should pass since geolocation is enabled for this +// extension. +chrome.test.runTests([ + function geolocation_getCurrentPosition() { + navigator.geolocation.getCurrentPosition(chrome.test.succeed, + chrome.test.fail); + }, + function geolocation_watchPosition() { + navigator.geolocation.watchPosition(chrome.test.succeed, + chrome.test.fail); + } +]); +</script>
\ No newline at end of file diff --git a/chrome/test/data/extensions/api_test/geolocation/has_permission/manifest.json b/chrome/test/data/extensions/api_test/geolocation/has_permission/manifest.json new file mode 100644 index 0000000..3a6c686 --- /dev/null +++ b/chrome/test/data/extensions/api_test/geolocation/has_permission/manifest.json @@ -0,0 +1,7 @@ +{ + "name": "geolocation access apitest pass", + "description": "tests that geolocation is accessible from this extension", + "version": "0.1", + "background_page": "background.html", + "permissions": [ "geolocation" ] +} diff --git a/chrome/test/data/extensions/api_test/geolocation/manifest.json b/chrome/test/data/extensions/api_test/geolocation/manifest.json deleted file mode 100644 index 3c7ff3f..0000000 --- a/chrome/test/data/extensions/api_test/geolocation/manifest.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "name": "geolocation access apitest", - "description": "tests geolocation is not accessible from extensions", - "version": "0.1", - "background_page": "background.html", - "permissions": [ ] -} diff --git a/chrome/test/data/extensions/api_test/geolocation/background.html b/chrome/test/data/extensions/api_test/geolocation/no_permission/background.html index 553fec5..30c499c 100644 --- a/chrome/test/data/extensions/api_test/geolocation/background.html +++ b/chrome/test/data/extensions/api_test/geolocation/no_permission/background.html @@ -1,7 +1,7 @@ <script> - // These API calls should fail since geolocation is not allowed from - // extensions. - chrome.test.runTests([ +// These API calls should fail since geolocation is not enabled for this +// extension. +chrome.test.runTests([ function geolocation_getCurrentPosition() { try { navigator.geolocation.getCurrentPosition(chrome.test.fail, diff --git a/chrome/test/data/extensions/api_test/geolocation/no_permission/manifest.json b/chrome/test/data/extensions/api_test/geolocation/no_permission/manifest.json new file mode 100644 index 0000000..2f87145 --- /dev/null +++ b/chrome/test/data/extensions/api_test/geolocation/no_permission/manifest.json @@ -0,0 +1,7 @@ +{ + "name": "geolocation access apitest fail", + "description": "tests geolocation is not accessible from this extensions", + "version": "0.1", + "background_page": "background.html", + "permissions": [ ] +} |