blob: d0b018f7738d693d3d99a22c1e264a9908c02798 [file] [log] [blame]
[email protected]eb4832a2012-12-08 01:57:521// 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.
4
[email protected]84aa73c2014-08-19 07:12:195#include "extensions/browser/suggest_permission_util.h"
[email protected]eb4832a2012-12-08 01:57:526
rdevlin.croninb2cec912015-06-24 20:36:017#include "base/strings/stringprintf.h"
8#include "content/public/browser/render_frame_host.h"
9#include "content/public/browser/web_contents.h"
[email protected]eb4832a2012-12-08 01:57:5210#include "content/public/common/console_message_level.h"
[email protected]e4452d32013-11-15 23:07:4111#include "extensions/common/extension.h"
[email protected]076ebeda2014-06-06 21:47:2612#include "extensions/common/permissions/permissions_data.h"
[email protected]793964a2013-10-08 00:47:1913#include "extensions/common/permissions/permissions_info.h"
[email protected]eb4832a2012-12-08 01:57:5214
15using content::CONSOLE_MESSAGE_LEVEL_WARNING;
[email protected]eb4832a2012-12-08 01:57:5216
[email protected]84aa73c2014-08-19 07:12:1917namespace extensions {
18
19namespace {
20
[email protected]eb4832a2012-12-08 01:57:5221const char kPermissionsHelpURLForExtensions[] =
22 "http://developer.chrome.com/extensions/manifest.html#permissions";
23const char kPermissionsHelpURLForApps[] =
24 "http://developer.chrome.com/apps/declare_permissions.html";
25
rdevlin.croninb2cec912015-06-24 20:36:0126void SuggestAPIPermissionInDevToolsConsole(
27 APIPermission::ID permission,
28 const Extension* extension,
29 content::RenderFrameHost* render_frame_host) {
[email protected]eb4832a2012-12-08 01:57:5230 const APIPermissionInfo* permission_info =
31 PermissionsInfo::GetInstance()->GetByID(permission);
[email protected]e44fd8f2013-02-05 21:55:2032 CHECK(permission_info);
[email protected]eb4832a2012-12-08 01:57:5233
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);
41
rdevlin.croninb2cec912015-06-24 20:36:0142 // Only the main frame handles dev tools messages.
43 content::WebContents::FromRenderFrameHost(render_frame_host)
44 ->GetMainFrame()
45 ->AddMessageToConsole(CONSOLE_MESSAGE_LEVEL_WARNING, message);
[email protected]eb4832a2012-12-08 01:57:5246}
47
[email protected]84aa73c2014-08-19 07:12:1948} // namespace
49
[email protected]eb4832a2012-12-08 01:57:5250bool IsExtensionWithPermissionOrSuggestInConsole(
51 APIPermission::ID permission,
52 const Extension* extension,
rdevlin.croninb2cec912015-06-24 20:36:0153 content::RenderFrameHost* render_frame_host) {
[email protected]076ebeda2014-06-06 21:47:2654 if (extension && extension->permissions_data()->HasAPIPermission(permission))
[email protected]eb4832a2012-12-08 01:57:5255 return true;
56
rdevlin.croninb2cec912015-06-24 20:36:0157 if (extension && render_frame_host) {
58 SuggestAPIPermissionInDevToolsConsole(permission, extension,
59 render_frame_host);
60 }
[email protected]eb4832a2012-12-08 01:57:5261
62 return false;
63}
64
[email protected]84aa73c2014-08-19 07:12:1965} // namespace extensions