NaCl: Update revision in DEPS, r12770 -> r12773
[chromium-blink-merge.git] / chrome / browser / extensions / suggest_permission_util.cc
blob1c47450a88cd8b7a666654592aadbc296e6793a1
1 // Copyright (c) 2012 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.
5 #include "chrome/browser/extensions/suggest_permission_util.h"
7 #include "chrome/browser/profiles/profile.h"
8 #include "chrome/common/extensions/extension_messages.h"
9 #include "content/public/browser/render_view_host.h"
10 #include "content/public/common/console_message_level.h"
11 #include "extensions/browser/extension_system.h"
12 #include "extensions/browser/process_manager.h"
13 #include "extensions/common/extension.h"
14 #include "extensions/common/permissions/permissions_info.h"
16 using content::CONSOLE_MESSAGE_LEVEL_WARNING;
17 using content::RenderViewHost;
19 const char kPermissionsHelpURLForExtensions[] =
20 "http://developer.chrome.com/extensions/manifest.html#permissions";
21 const char kPermissionsHelpURLForApps[] =
22 "http://developer.chrome.com/apps/declare_permissions.html";
24 namespace extensions {
26 void SuggestAPIPermissionInDevToolsConsole(APIPermission::ID permission,
27 const Extension* extension,
28 content::RenderViewHost* host) {
29 if (!extension || !host)
30 return;
32 const APIPermissionInfo* permission_info =
33 PermissionsInfo::GetInstance()->GetByID(permission);
34 CHECK(permission_info);
36 // Note, intentionally not internationalizing this string, as it is output
37 // as a log message to developers in the developer tools console.
38 std::string message = base::StringPrintf(
39 "Is the '%s' permission appropriate? See %s.",
40 permission_info->name(),
41 extension->is_platform_app() ?
42 kPermissionsHelpURLForApps : kPermissionsHelpURLForExtensions);
44 host->Send(new ExtensionMsg_AddMessageToConsole(
45 host->GetRoutingID(), CONSOLE_MESSAGE_LEVEL_WARNING, message));
48 void SuggestAPIPermissionInDevToolsConsole(APIPermission::ID permission,
49 const Extension* extension,
50 Profile* profile) {
51 extensions::ProcessManager* process_manager =
52 extensions::ExtensionSystem::Get(profile)->process_manager();
54 std::set<content::RenderViewHost*> views =
55 process_manager->GetRenderViewHostsForExtension(extension->id());
57 for (std::set<RenderViewHost*>::const_iterator iter = views.begin();
58 iter != views.end(); ++iter) {
59 RenderViewHost* host = *iter;
60 SuggestAPIPermissionInDevToolsConsole(permission, extension, host);
64 bool IsExtensionWithPermissionOrSuggestInConsole(
65 APIPermission::ID permission,
66 const Extension* extension,
67 content::RenderViewHost* host) {
68 if (extension && extension->HasAPIPermission(permission))
69 return true;
71 if (extension)
72 SuggestAPIPermissionInDevToolsConsole(permission, extension, host);
74 return false;
77 bool IsExtensionWithPermissionOrSuggestInConsole(
78 APIPermission::ID permission,
79 const Extension* extension,
80 Profile* profile) {
81 if (extension && extension->HasAPIPermission(permission))
82 return true;
84 if (extension)
85 SuggestAPIPermissionInDevToolsConsole(permission, extension, profile);
87 return false;
90 } // namespace extensions