Update V8 to version 4.7.16.
[chromium-blink-merge.git] / extensions / browser / suggest_permission_util.cc
blobd0b018f7738d693d3d99a22c1e264a9908c02798
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 "base/strings/stringprintf.h"
8 #include "content/public/browser/render_frame_host.h"
9 #include "content/public/browser/web_contents.h"
10 #include "content/public/common/console_message_level.h"
11 #include "extensions/common/extension.h"
12 #include "extensions/common/permissions/permissions_data.h"
13 #include "extensions/common/permissions/permissions_info.h"
15 using content::CONSOLE_MESSAGE_LEVEL_WARNING;
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(
27 APIPermission::ID permission,
28 const Extension* extension,
29 content::RenderFrameHost* render_frame_host) {
30 const APIPermissionInfo* permission_info =
31 PermissionsInfo::GetInstance()->GetByID(permission);
32 CHECK(permission_info);
34 // Note, intentionally not internationalizing this string, as it is output
35 // as a log message to developers in the developer tools console.
36 std::string message = base::StringPrintf(
37 "Is the '%s' permission appropriate? See %s.",
38 permission_info->name(),
39 extension->is_platform_app() ?
40 kPermissionsHelpURLForApps : kPermissionsHelpURLForExtensions);
42 // Only the main frame handles dev tools messages.
43 content::WebContents::FromRenderFrameHost(render_frame_host)
44 ->GetMainFrame()
45 ->AddMessageToConsole(CONSOLE_MESSAGE_LEVEL_WARNING, message);
48 } // namespace
50 bool IsExtensionWithPermissionOrSuggestInConsole(
51 APIPermission::ID permission,
52 const Extension* extension,
53 content::RenderFrameHost* render_frame_host) {
54 if (extension && extension->permissions_data()->HasAPIPermission(permission))
55 return true;
57 if (extension && render_frame_host) {
58 SuggestAPIPermissionInDevToolsConsole(permission, extension,
59 render_frame_host);
62 return false;
65 } // namespace extensions