Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / extensions / browser / suggest_permission_util.cc
blob85bf4fff86e1ec054d73816bda31f01593de2624
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 "extensions/browser/suggest_permission_util.h"
7 #include "content/public/browser/render_view_host.h"
8 #include "content/public/common/console_message_level.h"
9 #include "extensions/common/extension.h"
10 #include "extensions/common/extension_messages.h"
11 #include "extensions/common/permissions/permissions_data.h"
12 #include "extensions/common/permissions/permissions_info.h"
14 using content::CONSOLE_MESSAGE_LEVEL_WARNING;
15 using content::RenderViewHost;
17 namespace extensions {
19 namespace {
21 const char kPermissionsHelpURLForExtensions[] =
22 "http://developer.chrome.com/extensions/manifest.html#permissions";
23 const char kPermissionsHelpURLForApps[] =
24 "http://developer.chrome.com/apps/declare_permissions.html";
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 } // namespace
50 bool IsExtensionWithPermissionOrSuggestInConsole(
51 APIPermission::ID permission,
52 const Extension* extension,
53 content::RenderViewHost* host) {
54 if (extension && extension->permissions_data()->HasAPIPermission(permission))
55 return true;
57 if (extension)
58 SuggestAPIPermissionInDevToolsConsole(permission, extension, host);
60 return false;
63 } // namespace extensions