Remove unused field from extension_sorting.cc
[chromium-blink-merge.git] / chrome / browser / extensions / suggest_permission_util.cc
blob6a61fa0d119f1cd0904c7d1a43bdccdffc4d53f2
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/extensions/extension_process_manager.h"
8 #include "chrome/browser/extensions/extension_system.h"
9 #include "chrome/common/extensions/extension.h"
10 #include "chrome/common/extensions/extension_messages.h"
11 #include "chrome/common/extensions/permissions/permissions_info.h"
12 #include "content/public/browser/render_view_host.h"
13 #include "content/public/common/console_message_level.h"
15 using content::CONSOLE_MESSAGE_LEVEL_WARNING;
16 using content::RenderViewHost;
18 const char kPermissionsHelpURLForExtensions[] =
19 "http://developer.chrome.com/extensions/manifest.html#permissions";
20 const char kPermissionsHelpURLForApps[] =
21 "http://developer.chrome.com/apps/declare_permissions.html";
23 namespace extensions {
25 void SuggestAPIPermissionInDevToolsConsole(APIPermission::ID permission,
26 const Extension* extension,
27 content::RenderViewHost* host) {
28 if (!extension || !host)
29 return;
31 const APIPermissionInfo* permission_info =
32 PermissionsInfo::GetInstance()->GetByID(permission);
33 CHECK(permission_info);
35 // Note, intentionally not internationalizing this string, as it is output
36 // as a log message to developers in the developer tools console.
37 std::string message = base::StringPrintf(
38 "Is the '%s' permission appropriate? See %s.",
39 permission_info->name(),
40 extension->is_platform_app() ?
41 kPermissionsHelpURLForApps : kPermissionsHelpURLForExtensions);
43 host->Send(new ExtensionMsg_AddMessageToConsole(
44 host->GetRoutingID(), CONSOLE_MESSAGE_LEVEL_WARNING, message));
47 void SuggestAPIPermissionInDevToolsConsole(APIPermission::ID permission,
48 const Extension* extension,
49 Profile* profile) {
50 ExtensionProcessManager* process_manager =
51 extensions::ExtensionSystem::Get(profile)->process_manager();
53 std::set<content::RenderViewHost*> views =
54 process_manager->GetRenderViewHostsForExtension(extension->id());
56 for (std::set<RenderViewHost*>::const_iterator iter = views.begin();
57 iter != views.end(); ++iter) {
58 RenderViewHost* host = *iter;
59 SuggestAPIPermissionInDevToolsConsole(permission, extension, host);
63 bool IsExtensionWithPermissionOrSuggestInConsole(
64 APIPermission::ID permission,
65 const Extension* extension,
66 content::RenderViewHost* host) {
67 if (extension && extension->HasAPIPermission(permission))
68 return true;
70 if (extension)
71 SuggestAPIPermissionInDevToolsConsole(permission, extension, host);
73 return false;
76 bool IsExtensionWithPermissionOrSuggestInConsole(
77 APIPermission::ID permission,
78 const Extension* extension,
79 Profile* profile) {
80 if (extension && extension->HasAPIPermission(permission))
81 return true;
83 if (extension)
84 SuggestAPIPermissionInDevToolsConsole(permission, extension, profile);
86 return false;
89 } // namespace extensions