| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "extensions/browser/suggest_permission_util.h" | 5 #include "extensions/browser/suggest_permission_util.h" |
| 6 | 6 |
| 7 #include "content/public/browser/render_view_host.h" | 7 #include "base/strings/stringprintf.h" |
| 8 #include "content/public/browser/render_frame_host.h" |
| 9 #include "content/public/browser/web_contents.h" |
| 8 #include "content/public/common/console_message_level.h" | 10 #include "content/public/common/console_message_level.h" |
| 9 #include "extensions/common/extension.h" | 11 #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_data.h" |
| 12 #include "extensions/common/permissions/permissions_info.h" | 13 #include "extensions/common/permissions/permissions_info.h" |
| 13 | 14 |
| 14 using content::CONSOLE_MESSAGE_LEVEL_WARNING; | 15 using content::CONSOLE_MESSAGE_LEVEL_WARNING; |
| 15 using content::RenderViewHost; | |
| 16 | 16 |
| 17 namespace extensions { | 17 namespace extensions { |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 const char kPermissionsHelpURLForExtensions[] = | 21 const char kPermissionsHelpURLForExtensions[] = |
| 22 "http://developer.chrome.com/extensions/manifest.html#permissions"; | 22 "http://developer.chrome.com/extensions/manifest.html#permissions"; |
| 23 const char kPermissionsHelpURLForApps[] = | 23 const char kPermissionsHelpURLForApps[] = |
| 24 "http://developer.chrome.com/apps/declare_permissions.html"; | 24 "http://developer.chrome.com/apps/declare_permissions.html"; |
| 25 | 25 |
| 26 void SuggestAPIPermissionInDevToolsConsole(APIPermission::ID permission, | 26 void SuggestAPIPermissionInDevToolsConsole(APIPermission::ID permission, |
| 27 const Extension* extension, | 27 const Extension* extension, |
| 28 content::RenderViewHost* host) { | 28 content::WebContents* contents) { |
| 29 if (!extension || !host) | |
| 30 return; | |
| 31 | |
| 32 const APIPermissionInfo* permission_info = | 29 const APIPermissionInfo* permission_info = |
| 33 PermissionsInfo::GetInstance()->GetByID(permission); | 30 PermissionsInfo::GetInstance()->GetByID(permission); |
| 34 CHECK(permission_info); | 31 CHECK(permission_info); |
| 35 | 32 |
| 36 // Note, intentionally not internationalizing this string, as it is output | 33 // Note, intentionally not internationalizing this string, as it is output |
| 37 // as a log message to developers in the developer tools console. | 34 // as a log message to developers in the developer tools console. |
| 38 std::string message = base::StringPrintf( | 35 std::string message = base::StringPrintf( |
| 39 "Is the '%s' permission appropriate? See %s.", | 36 "Is the '%s' permission appropriate? See %s.", |
| 40 permission_info->name(), | 37 permission_info->name(), |
| 41 extension->is_platform_app() ? | 38 extension->is_platform_app() ? |
| 42 kPermissionsHelpURLForApps : kPermissionsHelpURLForExtensions); | 39 kPermissionsHelpURLForApps : kPermissionsHelpURLForExtensions); |
| 43 | 40 |
| 44 host->Send(new ExtensionMsg_AddMessageToConsole( | 41 contents->GetMainFrame()->AddMessageToConsole(CONSOLE_MESSAGE_LEVEL_WARNING, |
| 45 host->GetRoutingID(), CONSOLE_MESSAGE_LEVEL_WARNING, message)); | 42 message); |
| 46 } | 43 } |
| 47 | 44 |
| 48 } // namespace | 45 } // namespace |
| 49 | 46 |
| 50 bool IsExtensionWithPermissionOrSuggestInConsole( | 47 bool IsExtensionWithPermissionOrSuggestInConsole( |
| 51 APIPermission::ID permission, | 48 APIPermission::ID permission, |
| 52 const Extension* extension, | 49 const Extension* extension, |
| 53 content::RenderViewHost* host) { | 50 content::WebContents* web_contents) { |
| 54 if (extension && extension->permissions_data()->HasAPIPermission(permission)) | 51 if (extension && extension->permissions_data()->HasAPIPermission(permission)) |
| 55 return true; | 52 return true; |
| 56 | 53 |
| 57 if (extension) | 54 if (extension && web_contents) |
| 58 SuggestAPIPermissionInDevToolsConsole(permission, extension, host); | 55 SuggestAPIPermissionInDevToolsConsole(permission, extension, web_contents); |
| 59 | 56 |
| 60 return false; | 57 return false; |
| 61 } | 58 } |
| 62 | 59 |
| 63 } // namespace extensions | 60 } // namespace extensions |
| OLD | NEW |