| OLD | NEW |
| 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 "apps/app_web_contents_helper.h" | 5 #include "extensions/browser/app_window/app_web_contents_helper.h" |
| 6 | 6 |
| 7 #include "apps/app_delegate.h" | |
| 8 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
| 9 #include "content/public/browser/native_web_keyboard_event.h" | 8 #include "content/public/browser/native_web_keyboard_event.h" |
| 10 #include "content/public/browser/page_navigator.h" | 9 #include "content/public/browser/page_navigator.h" |
| 11 #include "content/public/browser/render_view_host.h" | 10 #include "content/public/browser/render_view_host.h" |
| 12 #include "content/public/browser/web_contents.h" | 11 #include "content/public/browser/web_contents.h" |
| 12 #include "extensions/browser/app_window/app_delegate.h" |
| 13 #include "extensions/browser/extension_registry.h" | 13 #include "extensions/browser/extension_registry.h" |
| 14 #include "extensions/browser/suggest_permission_util.h" | 14 #include "extensions/browser/suggest_permission_util.h" |
| 15 #include "extensions/common/extension_messages.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 apps { | 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), |
| 26 extension_id_(extension_id), | 26 extension_id_(extension_id), |
| 27 web_contents_(web_contents), | 27 web_contents_(web_contents), |
| 28 app_delegate_(app_delegate) { | 28 app_delegate_(app_delegate) { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 extensions::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 extensions::APIPermission::kPointerLock, | 82 APIPermission::kPointerLock, |
| 83 extension, | 83 extension, |
| 84 web_contents_->GetRenderViewHost()); | 84 web_contents_->GetRenderViewHost()); |
| 85 | 85 |
| 86 web_contents_->GotResponseToLockMouseRequest(has_permission); | 86 web_contents_->GotResponseToLockMouseRequest(has_permission); |
| 87 } | 87 } |
| 88 | 88 |
| 89 void AppWebContentsHelper::RequestMediaAccessPermission( | 89 void AppWebContentsHelper::RequestMediaAccessPermission( |
| 90 const content::MediaStreamRequest& request, | 90 const content::MediaStreamRequest& request, |
| 91 const content::MediaResponseCallback& callback) const { | 91 const content::MediaResponseCallback& callback) const { |
| 92 const extensions::Extension* extension = GetExtension(); | 92 const Extension* extension = GetExtension(); |
| 93 if (!extension) | 93 if (!extension) |
| 94 return; | 94 return; |
| 95 | 95 |
| 96 app_delegate_->RequestMediaAccessPermission( | 96 app_delegate_->RequestMediaAccessPermission( |
| 97 web_contents_, request, callback, extension); | 97 web_contents_, request, callback, extension); |
| 98 } | 98 } |
| 99 | 99 |
| 100 const extensions::Extension* AppWebContentsHelper::GetExtension() const { | 100 const Extension* AppWebContentsHelper::GetExtension() const { |
| 101 return extensions::ExtensionRegistry::Get(browser_context_) | 101 return ExtensionRegistry::Get(browser_context_) |
| 102 ->enabled_extensions() | 102 ->enabled_extensions() |
| 103 .GetByID(extension_id_); | 103 .GetByID(extension_id_); |
| 104 } | 104 } |
| 105 | 105 |
| 106 void AppWebContentsHelper::AddMessageToDevToolsConsole( | 106 void AppWebContentsHelper::AddMessageToDevToolsConsole( |
| 107 content::ConsoleMessageLevel level, | 107 content::ConsoleMessageLevel level, |
| 108 const std::string& message) const { | 108 const std::string& message) const { |
| 109 content::RenderViewHost* rvh = web_contents_->GetRenderViewHost(); | 109 content::RenderViewHost* rvh = web_contents_->GetRenderViewHost(); |
| 110 rvh->Send(new ExtensionMsg_AddMessageToConsole( | 110 rvh->Send(new ExtensionMsg_AddMessageToConsole( |
| 111 rvh->GetRoutingID(), level, message)); | 111 rvh->GetRoutingID(), level, message)); |
| 112 } | 112 } |
| 113 | 113 |
| 114 } // namespace apps | 114 } // namespace extensions |
| OLD | NEW |