Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(437)

Side by Side Diff: extensions/browser/app_window/app_web_contents_helper.cc

Issue 1200503002: [Extensions] Kill off ExtensionMsg_AddMessageToConsole (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/app_window/app_web_contents_helper.h" 5 #include "extensions/browser/app_window/app_web_contents_helper.h"
6 6
7 #include "base/strings/stringprintf.h" 7 #include "base/strings/stringprintf.h"
8 #include "content/public/browser/native_web_keyboard_event.h" 8 #include "content/public/browser/native_web_keyboard_event.h"
9 #include "content/public/browser/page_navigator.h" 9 #include "content/public/browser/page_navigator.h"
10 #include "content/public/browser/render_view_host.h" 10 #include "content/public/browser/render_frame_host.h"
11 #include "content/public/browser/web_contents.h" 11 #include "content/public/browser/web_contents.h"
12 #include "content/public/common/console_message_level.h"
12 #include "extensions/browser/app_window/app_delegate.h" 13 #include "extensions/browser/app_window/app_delegate.h"
13 #include "extensions/browser/extension_registry.h" 14 #include "extensions/browser/extension_registry.h"
14 #include "extensions/browser/suggest_permission_util.h" 15 #include "extensions/browser/suggest_permission_util.h"
15 #include "extensions/common/extension_messages.h"
16 #include "extensions/common/permissions/api_permission.h" 16 #include "extensions/common/permissions/api_permission.h"
17 17
18 namespace extensions { 18 namespace extensions {
19 19
20 AppWebContentsHelper::AppWebContentsHelper( 20 AppWebContentsHelper::AppWebContentsHelper(
21 content::BrowserContext* browser_context, 21 content::BrowserContext* browser_context,
22 const std::string& extension_id, 22 const std::string& extension_id,
23 content::WebContents* web_contents, 23 content::WebContents* web_contents,
24 AppDelegate* app_delegate) 24 AppDelegate* app_delegate)
25 : browser_context_(browser_context), 25 : browser_context_(browser_context),
(...skipping 13 matching lines...) Expand all
39 39
40 content::WebContents* AppWebContentsHelper::OpenURLFromTab( 40 content::WebContents* AppWebContentsHelper::OpenURLFromTab(
41 const content::OpenURLParams& params) const { 41 const content::OpenURLParams& params) const {
42 // Don't allow the current tab to be navigated. It would be nice to map all 42 // Don't allow the current tab to be navigated. It would be nice to map all
43 // anchor tags (even those without target="_blank") to new tabs, but right 43 // anchor tags (even those without target="_blank") to new tabs, but right
44 // now we can't distinguish between those and <meta> refreshes or window.href 44 // now we can't distinguish between those and <meta> refreshes or window.href
45 // navigations, which we don't want to allow. 45 // navigations, which we don't want to allow.
46 // TOOD(mihaip): Can we check for user gestures instead? 46 // TOOD(mihaip): Can we check for user gestures instead?
47 WindowOpenDisposition disposition = params.disposition; 47 WindowOpenDisposition disposition = params.disposition;
48 if (disposition == CURRENT_TAB) { 48 if (disposition == CURRENT_TAB) {
49 AddMessageToDevToolsConsole( 49 web_contents_->GetMainFrame()->AddMessageToConsole(
50 content::CONSOLE_MESSAGE_LEVEL_ERROR, 50 content::CONSOLE_MESSAGE_LEVEL_ERROR,
51 base::StringPrintf( 51 base::StringPrintf(
52 "Can't open same-window link to \"%s\"; try target=\"_blank\".", 52 "Can't open same-window link to \"%s\"; try target=\"_blank\".",
53 params.url.spec().c_str())); 53 params.url.spec().c_str()));
54 return NULL; 54 return NULL;
55 } 55 }
56 56
57 // These dispositions aren't really navigations. 57 // These dispositions aren't really navigations.
58 if (disposition == SUPPRESS_OPEN || disposition == SAVE_TO_DISK || 58 if (disposition == SUPPRESS_OPEN || disposition == SAVE_TO_DISK ||
59 disposition == IGNORE_ACTION) { 59 disposition == IGNORE_ACTION) {
60 return NULL; 60 return NULL;
61 } 61 }
62 62
63 content::WebContents* contents = 63 content::WebContents* contents =
64 app_delegate_->OpenURLFromTab(browser_context_, web_contents_, params); 64 app_delegate_->OpenURLFromTab(browser_context_, web_contents_, params);
65 if (!contents) { 65 if (!contents) {
66 AddMessageToDevToolsConsole( 66 web_contents_->GetMainFrame()->AddMessageToConsole(
67 content::CONSOLE_MESSAGE_LEVEL_ERROR, 67 content::CONSOLE_MESSAGE_LEVEL_ERROR,
68 base::StringPrintf( 68 base::StringPrintf(
69 "Can't navigate to \"%s\"; apps do not support navigation.", 69 "Can't navigate to \"%s\"; apps do not support navigation.",
70 params.url.spec().c_str())); 70 params.url.spec().c_str()));
71 } 71 }
72 72
73 return contents; 73 return contents;
74 } 74 }
75 75
76 void AppWebContentsHelper::RequestToLockMouse() const { 76 void AppWebContentsHelper::RequestToLockMouse() const {
77 const Extension* extension = GetExtension(); 77 const Extension* extension = GetExtension();
78 if (!extension) 78 if (!extension)
79 return; 79 return;
80 80
81 bool has_permission = IsExtensionWithPermissionOrSuggestInConsole( 81 bool has_permission = IsExtensionWithPermissionOrSuggestInConsole(
82 APIPermission::kPointerLock, 82 APIPermission::kPointerLock, extension, web_contents_);
83 extension,
84 web_contents_->GetRenderViewHost());
85 83
86 web_contents_->GotResponseToLockMouseRequest(has_permission); 84 web_contents_->GotResponseToLockMouseRequest(has_permission);
87 } 85 }
88 86
89 void AppWebContentsHelper::RequestMediaAccessPermission( 87 void AppWebContentsHelper::RequestMediaAccessPermission(
90 const content::MediaStreamRequest& request, 88 const content::MediaStreamRequest& request,
91 const content::MediaResponseCallback& callback) const { 89 const content::MediaResponseCallback& callback) const {
92 const Extension* extension = GetExtension(); 90 const Extension* extension = GetExtension();
93 if (!extension) 91 if (!extension)
94 return; 92 return;
(...skipping 12 matching lines...) Expand all
107 return app_delegate_->CheckMediaAccessPermission( 105 return app_delegate_->CheckMediaAccessPermission(
108 web_contents_, security_origin, type, extension); 106 web_contents_, security_origin, type, extension);
109 } 107 }
110 108
111 const Extension* AppWebContentsHelper::GetExtension() const { 109 const Extension* AppWebContentsHelper::GetExtension() const {
112 return ExtensionRegistry::Get(browser_context_) 110 return ExtensionRegistry::Get(browser_context_)
113 ->enabled_extensions() 111 ->enabled_extensions()
114 .GetByID(extension_id_); 112 .GetByID(extension_id_);
115 } 113 }
116 114
117 void AppWebContentsHelper::AddMessageToDevToolsConsole(
118 content::ConsoleMessageLevel level,
119 const std::string& message) const {
120 content::RenderViewHost* rvh = web_contents_->GetRenderViewHost();
121 rvh->Send(new ExtensionMsg_AddMessageToConsole(
122 rvh->GetRoutingID(), level, message));
123 }
124
125 } // namespace extensions 115 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698