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 "content/public/browser/render_view_host.h"
9 #include "content/public/common/console_message_level.h"
10 #include "extensions/browser/extension_system.h"
11 #include "extensions/browser/process_manager.h"
12 #include "extensions/common/extension.h"
13 #include "extensions/common/extension_messages.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
)
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 bool IsExtensionWithPermissionOrSuggestInConsole(
49 APIPermission::ID permission
,
50 const Extension
* extension
,
51 content::RenderViewHost
* host
) {
52 if (extension
&& extension
->HasAPIPermission(permission
))
56 SuggestAPIPermissionInDevToolsConsole(permission
, extension
, host
);
61 } // namespace extensions