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( |
27 const Extension* extension, | 27 APIPermission::ID permission, |
28 content::RenderViewHost* host) { | 28 const Extension* extension, |
29 if (!extension || !host) | 29 content::RenderFrameHost* render_frame_host) { |
30 return; | |
31 | |
32 const APIPermissionInfo* permission_info = | 30 const APIPermissionInfo* permission_info = |
33 PermissionsInfo::GetInstance()->GetByID(permission); | 31 PermissionsInfo::GetInstance()->GetByID(permission); |
34 CHECK(permission_info); | 32 CHECK(permission_info); |
35 | 33 |
36 // Note, intentionally not internationalizing this string, as it is output | 34 // Note, intentionally not internationalizing this string, as it is output |
37 // as a log message to developers in the developer tools console. | 35 // as a log message to developers in the developer tools console. |
38 std::string message = base::StringPrintf( | 36 std::string message = base::StringPrintf( |
39 "Is the '%s' permission appropriate? See %s.", | 37 "Is the '%s' permission appropriate? See %s.", |
40 permission_info->name(), | 38 permission_info->name(), |
41 extension->is_platform_app() ? | 39 extension->is_platform_app() ? |
42 kPermissionsHelpURLForApps : kPermissionsHelpURLForExtensions); | 40 kPermissionsHelpURLForApps : kPermissionsHelpURLForExtensions); |
43 | 41 |
44 host->Send(new ExtensionMsg_AddMessageToConsole( | 42 // Only the main frame handles dev tools messages. |
45 host->GetRoutingID(), CONSOLE_MESSAGE_LEVEL_WARNING, message)); | 43 content::WebContents::FromRenderFrameHost(render_frame_host) |
| 44 ->GetMainFrame() |
| 45 ->AddMessageToConsole(CONSOLE_MESSAGE_LEVEL_WARNING, message); |
46 } | 46 } |
47 | 47 |
48 } // namespace | 48 } // namespace |
49 | 49 |
50 bool IsExtensionWithPermissionOrSuggestInConsole( | 50 bool IsExtensionWithPermissionOrSuggestInConsole( |
51 APIPermission::ID permission, | 51 APIPermission::ID permission, |
52 const Extension* extension, | 52 const Extension* extension, |
53 content::RenderViewHost* host) { | 53 content::RenderFrameHost* render_frame_host) { |
54 if (extension && extension->permissions_data()->HasAPIPermission(permission)) | 54 if (extension && extension->permissions_data()->HasAPIPermission(permission)) |
55 return true; | 55 return true; |
56 | 56 |
57 if (extension) | 57 if (extension && render_frame_host) { |
58 SuggestAPIPermissionInDevToolsConsole(permission, extension, host); | 58 SuggestAPIPermissionInDevToolsConsole(permission, extension, |
| 59 render_frame_host); |
| 60 } |
59 | 61 |
60 return false; | 62 return false; |
61 } | 63 } |
62 | 64 |
63 } // namespace extensions | 65 } // namespace extensions |
OLD | NEW |